Javaesque library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
jotapapel
Prole
Posts: 4
Joined: Tue Aug 18, 2020 4:17 am

Javaesque library

Post by jotapapel »

HI!

I've been working in an oop library for Löve2D for a few months. I am very pleased at the result so I'm sharing it with you guys.

https://github.com/jotapapel/javaesque-lua

It's very simple but functional.

Code: Select all

require 'javaesque'

enum 'Colors' {
	'RED', 'GREEN', 'BLUE'
}

interface 'Coloreable' {
	color = Colors.RED,
	set_color = function(self, color)
		self.color = color
	end
}

interface 'Drawable' : extends 'Coloreable' {
	draw = function(self)
		print(self.width, self.height, self.color)
	end
}

class 'Shape' : implements 'Drawable' {
	constructor = function(self, width, height)
		self.width, self.height = width or self.width, height or self.height
	end;
	width = 10, height = 10
}

local shape1 = Shape(30, 30)
shape1:draw() -- 30	30	RED
shape1:set_color(Colors.BLUE)
shape1:draw() -- 30 30. BLUE
I would really appreciate it if you could test it. So far I've had no issues with it, and I'm using it in my main game engine.

Thanks in advance.
User avatar
Tabaqui
Prole
Posts: 34
Joined: Tue Mar 24, 2020 2:47 pm
Location: Italy

Re: Javaesque library

Post by Tabaqui »

Wow! I've developed my own OOP library with property support in lua and i was planning to release it today, but now looking at yours i feel ashamed :brows:

I didn't even think it was possible to simulate keywords like you did!

Very good job by the way. I'll stick to mine at the moment because i need properties to speed up the development of my project, but i'll give it a try for sure!
User avatar
4vZEROv
Party member
Posts: 126
Joined: Wed Jan 02, 2019 8:44 pm

Re: Javaesque library

Post by 4vZEROv »

Interesting way to use lua syntax sugar
jotapapel
Prole
Posts: 4
Joined: Tue Aug 18, 2020 4:17 am

Re: Javaesque library

Post by jotapapel »

Quarantine has me working a lot on this.

The library is now called LuaScript and comes with a preprocessor for luascript files (.lss) that transforms this

Code: Select all

import engine.schema

local fieldController
local class Love2d: Callbacks {
	let fieldController = FieldController()
	let mainWindow = Canvas(320, 200, &000)

	func load() {
		fieldController = self.fieldController
		fieldController:goTo(Field, "TestField", 640, 640)
	}
	
	func update(dt: number) {
		fieldController:getCurrent():update(dt)
	}

	func draw() {
		local w, h, _ = love.window.getMode()
		local x, y = (w - (dimens.screen.width * dimens.scale)) / 2, (h - (dimens.screen.height * dimens.scale)) / 2
		
		love.graphics.clear()
		fieldController:getCurrent():draw()
	}

	func keypressed(key: string, scancode: string, isrepeat: boolean) {
		fieldController:getCurrent():keypressed(key, scancode, isrepeat)
		if (key == "return") then fieldController:goTo(Field, "AnotherField", 320, 200) end
	}
}

return Love2d
Into this:

Code: Select all

process("engine/schema.lss")
local fieldController
local Love2d = (class(false, "Callbacks"))({
   ["prototype.constant.fieldController"] = FieldController(),
   ["prototype.constant.mainWindow"] = Canvas(320, 200, torgb("000")),
   ["prototype.function.load"] = function(self)
      fieldController = self.fieldController
      fieldController:goTo(Field, "TestField", 640, 640)
   end,
   ["prototype.function.update"] = function(self, dt)
      local dt = args({dt}, {"number"})
      fieldController:getCurrent():update(dt)
   end,
   ["prototype.function.draw"] = function(self)
      local w, h, _ = love.window.getMode()
      local x, y = (w - (dimens.screen.width * dimens.scale)) / 2, (h - (dimens.screen.height * dimens.scale)) / 2
      love.graphics.clear()
      fieldController:getCurrent():draw()
   end,
   ["prototype.function.keypressed"] = function(self, key, scancode, isrepeat)
      local key, scancode, isrepeat = args({key, scancode, isrepeat}, {"string", "string", "boolean"})
      fieldController:getCurrent():keypressed(key, scancode, isrepeat)
      if (key == "return") then fieldController:goTo(Field, "return", 320, 200) end
   end
})
return Love2d
I also added a tmLanguage syntax highlight file for .lss files.

It's currently in beta and I'm testing it everyday.

Here's the GitHub link https://github.com/jotapapel/luascript

For anyone interested.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 13 guests