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 Coroutines once stated:
> On Sat, Apr 19, 2014 at 1:49 PM, Sean Conner <sean@conman.org> wrote:
> 
> >   You could always code it up and hope it gets adopted.
> 
> I haven't tested but I think it would look like this?
> 
> int debug_userdump(lua_State *L)
> {
>     luaL_Buffer b;
>     char * ud;
>     size_t ud_size;
> 
>     luaL_argcheck(L, t == LUA_TUSERDATA || t == LUA_TLIGHTUSERDATA, 1,
> "userdata expected");
> 
>     lua_settop(L, 1); /* string.dump() does this */
> 
>     ud = lua_touserdata(L, 1);
>     ud_size = lua_rawlen(L, 1);
> 
>     /* we copy the "reference" itself if lightuserdata */
>     if (lua_islightuserdata(L, 1))
>         ud = (char *) &ud;
> 
>     /* allocate for the whole userdata in 1 go */
>     luaL_prepbuffsize(b, ud_size);
> 
>     luaL_addlstring(b, ud, ud_size);
>     luaL_pushresult(b);
> 
>     return 1;
> }

  What about metatables?

> 
> >   -spc (So how do you transfer a string.dump()ed function from x86 to ARM?)
> 
> There would definitely be limitations -- I imagined this for
> transferring data between lua states on the same platform, though.

  I hope you mean "same process" otherwise, you'll have problems with
pointers in the userdata.

> +1 for ASCII85! :D

  -spc