I'm trying to give a scripting ability to my component system. Of couse each component has a field "parent" which holds access to the parent Actor. I can write the code so I can access my C++ methods from Lua, but I got stuck when I want to return custom userdata, like actor. I have a method getParent(), and I want to return the Actor userdata, so I can write Lua code like this:
parent = getParent()
parent.<some method>
How can I achieve this? With lightuserdata? Or when getParent get called, create a new userdata, and point that pointer to the original one?
getParent()
in your example a global function?? – W.B.player = Actor.new() player:addComponent(ImageComponent.new(player)) imgc = player:getComponent("ImageComponent") imgc.setImagePath("testimg.png") function player:tick() player.setPosition(0,0) end
(it could be invalid code, but nevermind now) and then in my c++ class, i would retrieve the tick method of the player object or table or what should i call, and calls it every time the engine calls tick() – RobeeZ