Page 1 of 1

Javaesque library

Posted: Mon Feb 01, 2021 6:23 am
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.

Re: Javaesque library

Posted: Mon Feb 01, 2021 7:43 am
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!

Re: Javaesque library

Posted: Wed Feb 03, 2021 5:05 pm
by 4vZEROv
Interesting way to use lua syntax sugar

Re: Javaesque library

Posted: Sat Mar 27, 2021 1:17 am
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.