Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua OOP Design #26

Open
perbone opened this issue Sep 16, 2020 · 2 comments
Open

Lua OOP Design #26

perbone opened this issue Sep 16, 2020 · 2 comments

Comments

@perbone
Copy link
Owner

perbone commented Sep 16, 2020

The idea is to design how OOP will work in Lua and Godot. Classes will be implemented with tables and should be as close as possible to the Godot API used by other languages.

Following below is an excerpt for some of the the designs I have so far.

1. Explicitly imports the class Lua module and the node class to be extended and defines new classes through the class's 'extends' method

Although more verbose it gives a classic oop look and feel

local class = require 'lua.class' -- Import the system class library
local Sprite = require 'godot.Sprite' -- Make sure to import the base class

local Main = class.extends(Sprite) -- Creates the user subclass

function Main:ready()
end

function Main:process(delta)
end

return Main

2. Explicitly imports only the node class to be extended and defines new classes through the implicity available 'extends' method

This is more streamlined and concise and gives a mixed oop look and feel

local Sprite = require 'godot.Sprite' -- Make sure to import the base class

local Main = extends(Sprite) -- Creates the user subclass

function Main:ready()
end

function Main:process(delta)
end

return Main

Please share your thoughts on this two ideas or show us a new idea that you come up about this topic.

-- Perbone

@carabalonepaulo
Copy link

local Sprite = require 'godot.sprite'
local Main = Sprite:extend()

function Main:ready()
end

function Main:process()
end

return Main

I think it gets cleaner and more pleasurable.
_ before de method name is a gdscript thing, don't need to bring it to lua.

rxi/classic for reference

@perbone perbone pinned this issue May 1, 2022
@Hedwig7s
Copy link

Hedwig7s commented Dec 4, 2023

If anything it should be done similar to the Roblox OOP style

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants