lua-users home
lua-l archive

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




Thanks!
 
On Thu, Apr 8, 2010 at 3:47 PM, Patrick Donnelly <batrick@batbytes.com> wrote:
Look at how liolib.c (in Lua source) handles passing file pointers to
and from Lua. You will see that Lua uses a full userdata to hold these
pointers. Assuming the io library is included in your application, you
can add a new file from C using something like:

#include "lualib.h"

...

*(lua_newuserdata(L, sizeof(FILE *))) = fp;
luaL_getmetatable(L, LUA_FILEHANDLE);
lua_setmetable(L, -2);
/* you now have a Lua FILE object on the stack */

--
- Patrick Donnelly