Re: is it possible to obtain the lua state during a call from lua to c++ function via luabind?
Nigel Atkinson <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <1269400775.1449.11.camel@vimes> |
Thanks to the magic of luabind, it's actually quite simple...
luabind::object cppfunction( lua_State* l )
{
//i need a lua state here which invoking thisfunction.
luabind::object table = luabind::newtable(l);
table[1]="asdfjkl;";
return table;
}
bind it as before.
module(l)
[
def( "cppfunction", &cppfunction )
];
you still call the function from Lua like:
mytable = cppfunction()
luabind recognizes "lua_State*" and removes it from the parameter list
for when calling from Lua. It then gets supplied by luabind when you
actually call the function from Lua. At least that's how I think it
works from my quick look at the code... ;-)
This and automatic down-casting, are my picks for the "Totally awesome
new feature" award. :-D
Nigel
On Wed, 2010-03-24 at 10:17 +0800, [email protected] wrote:
> consider i have such a function in c++:
> luabind::object cppfunction()
> {
> lua_State* l; //i need a lua state here which invoking this
> function.
>
>
> luabind::object table = luabind::newtable(l);
> table[1]="asdfjkl;";
> return table;
> }
>
>
> and it was registered to lua:
> module(l)
> [
> def("cppfunction",&cppfunction)
> ];
>
>
> now how do i obtain the state in my cpp function?is it possible?
> i can not use a singleton luastate,because i need more than one states
> running parallel.
>
>
>
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________ luabind-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/luabind-user
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev