diff options
author | Ferenc Wágner <wferi@niif.hu> | 2014-10-10 11:29:12 +0200 |
---|---|---|
committer | Ferenc Wágner <wferi@niif.hu> | 2014-10-12 10:13:14 +0200 |
commit | be151c64e724d8a8d250b9a2dd9426a584ed76bc (patch) | |
tree | 3e6340d6d8eb06838920d61de9d01f6cab1ebe74 | |
parent | 32fb30f8bcd6f44f4301108de707a3daa32d1fca (diff) | |
download | syslinux-be151c64e724d8a8d250b9a2dd9426a584ed76bc.tar.gz syslinux-be151c64e724d8a8d250b9a2dd9426a584ed76bc.tar.xz syslinux-be151c64e724d8a8d250b9a2dd9426a584ed76bc.zip |
lua: make the file operations methods
This also enables manual unloading of files by callig f:__gc().
Signed-off-by: Ferenc Wágner <wferi@niif.hu>
-rw-r--r-- | com32/lua/src/syslinux.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c index 22fd0dff..6b57144d 100644 --- a/com32/lua/src/syslinux.c +++ b/com32/lua/src/syslinux.c @@ -262,6 +262,8 @@ static int sl_unloadfile (lua_State *L) free (file->name); free (file->data); + /* the __gc method may also be (repeatedly) called before garbage collection, so: */ + file->name = file->data = NULL; return 0; } @@ -423,8 +425,6 @@ static const luaL_Reg syslinuxlib[] = { {"sleep", sl_sleep}, {"msleep", sl_msleep}, {"loadfile", sl_loadfile}, - {"filesize", sl_filesize}, - {"filename", sl_filename}, {"initramfs_init", sl_initramfs_init}, {"initramfs_load_archive", sl_initramfs_load_archive}, {"initramfs_add_file", sl_initramfs_add_file}, @@ -441,6 +441,8 @@ static const luaL_Reg syslinuxlib[] = { static const luaL_Reg file_methods[] = { {"__gc", sl_unloadfile}, + {"name", sl_filename}, + {"size", sl_filesize}, {NULL, NULL} }; @@ -450,6 +452,9 @@ LUALIB_API int luaopen_syslinux(lua_State * L) { luaL_newmetatable(L, SYSLINUX_FILE); + lua_pushstring (L, "__index"); + lua_pushvalue (L, -2); + lua_settable (L, -3); luaL_setfuncs (L, file_methods, 0); luaL_newlib(L, syslinuxlib); |