aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lua
diff options
context:
space:
mode:
authorFerenc Wágner <wferi@niif.hu>2014-10-10 11:29:12 +0200
committerFerenc Wágner <wferi@niif.hu>2014-10-12 10:13:14 +0200
commitbe151c64e724d8a8d250b9a2dd9426a584ed76bc (patch)
tree3e6340d6d8eb06838920d61de9d01f6cab1ebe74 /com32/lua
parent32fb30f8bcd6f44f4301108de707a3daa32d1fca (diff)
downloadsyslinux-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>
Diffstat (limited to 'com32/lua')
-rw-r--r--com32/lua/src/syslinux.c9
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);