Skip to content

Lua Properties Design #27

Open
Open
@perbone

Description

@perbone

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.

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:properties {
  { name = 'width', type = Types.number, default = 10 },
  { name = 'height', type = Types.number },
  { name = 'title', type = Types.string, get = 'get_title', set = 'set_title' },
  { name = 'description' }
}

function Main:ready()
  self.height = 5
end

function Main:process(delta)
  print(self.width * self.height) -- Should print 50
end

function Main:get_title()
  return 'The title is ' .. (self.title and self.title or 'undefined')
end

function Main:set_title(title)
  self.title = title
end

return Main

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions