lua-users home
lua-l archive

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


It was thus said that the Great Philipp Kraus once stated:
> 
> Am 07.10.2014 um 20:10 schrieb Sean Conner <sean@conman.org>:
> 
> > It was thus said that the Great Philipp Kraus once stated:
> >> Hello,
> >> 
> >> thanks for this code excerpt. 
> >> 
> >> 
> >> Am 07.10.2014 um 13:05 schrieb Udo Schroeter <udo.schroeter@gmail.com>:
> >> 
> >>>    luaL_checktype(L, 1, LUA_TFUNCTION);
> >>>          lua_settop(L, 1);
> >> 
> >> I would like to dump all script functions. Can I iterate over all script function and
> >> push the functions on the stack top and run after this the dump?
> > 
> >  You can compile Lua scripts using "luac".  The output will be Lua
> > bytecode, which can then be loaded using the same functions that you use to
> > load regular Lua scripts.
> 
> Sorry for my bad description, my Lua script ist added by the user, so I have got a script
> with a lot of global functions, so on the dump process, I need to get all non-default functions.
> I must do something like:
> 
> std::vector< std::string > function = lua_getglobalfunction();
> for(std::size_t i=0; i < function.size(); ++i
> {
>      lua_getglobal( L, function[i].c_str() );
>      lua_dump
> }

  Okay, *a* way to get a deep copy is to assign your own memory allocator
when you create the Lua state (lua_newstate() instead of luaL_newstate())
that can duplicate itself (but beware any pointers).  Or perhaps use two
separate Lua states in parallel (do A in Lua state 1, then do A in Lua state
2, etc).  

  I think the better question is:  what problem are you trying to solve by
deep copying a Lua state?

  -spc