Skip to content

Lua Signals Design #28

Open
Open
@perbone

Description

@perbone

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions