Component.lua 611 B

12345678910111213141516171819
  1. local ffi = require("ffi")
  2. local class, object = require("class"), require("class.object")
  3. require("ecs")
  4. local Component = class(object)
  5. local function make_component(name, struct)
  6. if type(struct) == "string" then
  7. -- Assuming FFI cdef
  8. -- TODO : find a way to merge class and userdata
  9. local ct = ffi.cdef("typdef struct {"..struct.."} "..name..";")
  10. return ffi.metatype(ct, class(Component))
  11. elseif struct.instanceof and struct:instanceof(Component) then
  12. -- Assuming parent class
  13. return class(struct)
  14. else
  15. return class(Component)
  16. end
  17. end