[syslinux:master] lua: make the file operations methods
syslinux-bot for Ferenc Wágner
wferi at niif.hu
Sat Feb 14 11:09:22 PST 2015
Commit-ID: be151c64e724d8a8d250b9a2dd9426a584ed76bc
Gitweb: http://www.syslinux.org/commit/be151c64e724d8a8d250b9a2dd9426a584ed76bc
Author: Ferenc Wágner <wferi at niif.hu>
AuthorDate: Fri, 10 Oct 2014 11:29:12 +0200
Committer: Ferenc Wágner <wferi at niif.hu>
CommitDate: Sun, 12 Oct 2014 10:13:14 +0200
lua: make the file operations methods
This also enables manual unloading of files by callig f:__gc().
Signed-off-by: Ferenc Wágner <wferi at niif.hu>
---
com32/lua/src/syslinux.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c
index 22fd0df..6b57144 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);
More information about the Syslinux-commits
mailing list