-
-
Notifications
You must be signed in to change notification settings - Fork 46
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 Properties Design #27
Comments
How about design like this 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(Sprite)
function Main:ctor(...)
self:super("ctor", ...)
self:signal("sum_calculated", { "sum"}, {"num1", "number"}, {"num2", "number"}}})
self:signal("completed")
self:signal("new_title", {"title"})
end
function Main:_ready()
self.height = 5
end
function Main:_process(delta)
print(self.width * self.height) -- Should print 50
local num1 = math.random(100)
local num2 = math.random(100)
local sum = num1 + num2
emit_signal( 'sum_calculated', sum, num1, num2 )
end
function Main:get_title()
return 'The title is ' .. (self.title and self.title or 'undefined')
end
function Main:set_title(title)
self:super("set_title", title)
self.title = title
end
|
That is interesting... I think it's possible to support both models with the same underlying API. I'll think about it. P.S. For future comments please try to stay in the issue topic, this one is about properties, not signals. And I know they are related! Thanks! |
After thinking a little bit more about this, I realise it would not work that well with the statics analysis where the parser identifies properties and signals to be use in the editor. It would be too fragile to deduct this kind of information based on code to be executed on runtime only. In my initial design this information is captured on object creation, a most stable place to do statics analysis. |
Main:property {
'width', 'number',
set = function() end,
get = function() end
}
Main:property { 'height', 'number' }
Main:property { 'description' } The first and second item of the array side are respectively the property name and type. Default value may be the third? Or can be included in the hash side like set/get. |
The idea is to design how properties will work in Lua and Godot. A property will be a variable in the class object and will follow the definitions from the initial call for the implicit available properties method.
Following below is an excerpt for some of the the designs I have so far.
The description property in the code above has the default data type of string.
Please share your thoughts on this idea or show us a new idea that you come up about this topic.
-- Perbone
The text was updated successfully, but these errors were encountered: