Re: Best Practice Scoping Different Scripts+Expose Object/ luabind:resume with optional return value

Harakiri <[email protected]> Wed, 13 Jun 2012 13:38:06 -0700 (PDT)
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Hello,

thanks for your samples - however i was able to work it out without requiring to using local .. definitions in the lua files and prepending namespace.XX before every function.

basically i was able to put the script data into a table of its own

luaL_loadfile(L, fileID);
lua_newtable(L);	

..

lua_pushvalue(L, -1);
lua_setfield(L, LUA_REGISTRYINDEX, fileID);
lua_setupvalue(L, -2, 1);
lua_call(L, 0, 0);

....

to exec a specific function i just retrieve the table first (filename) and then the function, then a lua_call

I was even able to put my object into a scope - albit with a stupid workaround - maybe somebody can help me out here - after

lua_newtable(L);	
..
i do

luabind::globals(L)["actor"] = actor1Obj; 
lua_getglobal(L, "actor");
lua_setfield(L, -2, "actor");	 

so the actor obj is now within the table of the file only (also in the global but it can be overwritten there and doesnt bother the specific fileID table).

Is there a better way to do the above without first putting the actor in global - then copying to my table ? 

Also a more general question - when objects are exposed to lua - they seem to be references (not copies) - because when i change an attribute in my actor object - and without re exposing it to the fileID specific table - i see the changes with printing my objects attribute from lua - this is as i imagined it - but are there any pitfalls here ? do i have to "update" or put the object into the table under specific circumstances?

Thanks

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/