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 Signals Design #28

Open
perbone opened this issue Sep 16, 2020 · 1 comment
Open

Lua Signals Design #28

perbone opened this issue Sep 16, 2020 · 1 comment

Comments

@perbone
Copy link
Owner

perbone commented Sep 16, 2020

The idea is to design how signals will work in Lua and Godot. A signal will be an element in a table in the class object and will follow the definitions from the initial call for the implicit available signals method.

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

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)      -- Create the user subclass

Main:signals {
    { name = 'sum_calculated', parameters = { name = 'sum', type = 'number' } },
    { name = 'completed' } },
    { name = 'new_title', parameters = { name = 'title' } },
}

function Main:ready()
    math.randomseed(os.time())          -- Randomize from whatever the time is
end

function Main:process(delta)
    local sum = math.random(100)
    emit_signal( 'sum_calculated', sum )
end

return Main

The signals in the code above have the following characteristics:

  • sum_calculated has one parameter called sum with the data type defined as string
  • completed signal has no parameters
  • new_title has one parameter called title with the default data type string

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

-- Perbone

@carabalonepaulo
Copy link

A less verbose approach:

Main:signals {
    { 'sum_calculated',  { 'sum', 'number' } },
    'completed',
    { 'new_title', 'title' },
}

sum_calculated has one parameter defined as number
completed has no parameters
new_title has one parameter with no explicit type.

@perbone perbone unpinned this issue May 1, 2022
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

2 participants