[mojosetup] [9/13] Make the {open, read, close}dir() functions available to the Lua code.

Francois Gouget fgouget at codeweavers.com
Mon May 21 14:08:17 EDT 2012


---

They will be needed for the next patch. I'm submitting this patch 
separately because they could also be useful in their own right for the 
application Lua scripts.

 lua_glue.c |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/lua_glue.c b/lua_glue.c
index 833257a..d5c6cde 100644
--- a/lua_glue.c
+++ b/lua_glue.c
@@ -1019,6 +1019,31 @@ static int luahook_archive_offsetofstart(lua_State *L)
 } // luahook_archive_offsetofstart
 
 
+static int luahook_platform_opendir(lua_State *L)
+{
+    const char *path = luaL_checkstring(L, 1);
+    return retvalLightUserData(L, MojoPlatform_opendir(path));
+} // luahook_platform_opendir
+
+
+static int luahook_platform_readdir(lua_State *L)
+{
+    void *dir = lua_touserdata(L, 1);
+    char *dent = MojoPlatform_readdir(dir);
+    int retval = retvalString(L, dent);
+    free(dent);
+    return retval;
+} // luahook_platform_readdir
+
+
+static int luahook_platform_closedir(lua_State *L)
+{
+    void *dir = lua_touserdata(L, 1);
+    MojoPlatform_closedir(dir);
+    return retvalBoolean(L, 0);
+} // luahook_platform_closedir
+
+
 static int luahook_platform_unlink(lua_State *L)
 {
     const char *path = luaL_checkstring(L, 1);
@@ -1850,6 +1875,9 @@ boolean MojoLua_initLua(void)
 
         // Set the platform functions...
         lua_newtable(luaState);
+            set_cfunc(luaState, luahook_platform_opendir, "opendir");
+            set_cfunc(luaState, luahook_platform_readdir, "readdir");
+            set_cfunc(luaState, luahook_platform_closedir, "closedir");
             set_cfunc(luaState, luahook_platform_unlink, "unlink");
             set_cfunc(luaState, luahook_platform_exists, "exists");
             set_cfunc(luaState, luahook_platform_writable, "writable");
-- 
1.7.10


More information about the mojosetup mailing list