🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How do you create a new Lua function...

Started by
1 comment, last by hmon007 20 years, 3 months ago
from within another Lua function? To illustrate what I mean: function func1() hostFunction() -- This host C function wants to create a -- new Lua function end Is it possible to create a new Lua function from here without doing something like: lua_dostring( L, "function newFunc() end" ); btw, the reason I want to create new functions from within other functions is so that I can dynamically create object interfaces in Lua. For instance, I would call a registered host function like createObject() and createObject() would define all the Lua functions needed for the interface to that object. Thanks in advance!
Advertisement
You can use luabind
or toLua or some other wrapper that can help you with this.

From within a Lua script it''s straight forward to create
new functions:

function returnObject()   object = {}   object.execute = function (self, x, y)      -- do something   end   -- add other functions or variables   return objectend-- examplenewObj = returnObject()newObj.execute(newObj, 12, 20) 


If you want to register a new C or C++ interface you will have to
use Lua''s stack mechanisms to register the function name within
the Lua state (see Lua docs for that).


Hey thanks darookie!

My program does what I need now!



cheers!

This topic is closed to new replies.

Advertisement