lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Apr 6, 2014 at 3:37 AM, Benoit Germain <bnt.germain@gmail.com> wrote:



2014-04-05 18:57 GMT+02:00 Rena <hyperhacker@gmail.com>:

I've actually implemented some functions that can copy nearly any value between Lua states: http://pastie.org/8996668




Hi,

When you copy Lua functions, you should also take care of their upvalues else they won't work as expected (if at all) in the destination state.

You may want to have a look at lanes, which supports inter-state data copying.

--
Benoit.

If anyone's using this code, here's a bug fix you'll want to apply:

    if(luaL_getmetafield(from, pos, "__xcopy")) { //-1: func
lua_pushvalue(from, pos); //-1: obj, -2: func
lua_pushlightuserdata(from, to); //-1: to, -2: obj, -3: func
- lua_call(from, 2, 0); //-1: result
+ lua_call(from, 2, 1); //-1: result
int res = lua_toboolean(from, -1);
lua_pop(from, 1); //remove result
return res;

--
Sent from my Game Boy.