r448 - trunk

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Jan 20 08:30:43 EST 2008


Author: icculus
Date: 2008-01-20 08:30:43 -0500 (Sun, 20 Jan 2008)
New Revision: 448

Modified:
   trunk/lua_glue.c
Log:
Added Lua hooks for checksumming a MojoInput and running scripts in other
 directories.


Modified: trunk/lua_glue.c
===================================================================
--- trunk/lua_glue.c	2008-01-20 12:12:30 UTC (rev 447)
+++ trunk/lua_glue.c	2008-01-20 13:30:43 UTC (rev 448)
@@ -566,6 +566,16 @@
 } // luahook_runfile
 
 
+// Lua interface to MojoLua_runFileFromDir(). This is needed instead of Lua's
+//  require(), since it can access scripts inside an archive.
+static int luahook_runfilefromdir(lua_State *L)
+{
+    const char *dir = luaL_checkstring(L, 1);
+    const char *fname = luaL_checkstring(L, 2);
+    return retvalBoolean(L, MojoLua_runFileFromDir(dir, fname));
+} // luahook_runfile
+
+
 // Lua interface to translate().
 static int luahook_translate(lua_State *L)
 {
@@ -839,6 +849,38 @@
 } // luahook_isvalidperms
 
 
+static int do_checksum(lua_State *L, MojoInput *in)
+{
+    MojoChecksumContext ctx;
+    MojoChecksums sums;
+    int64 br = 0;
+
+    MojoChecksum_init(&ctx);
+
+    while (1)
+    {
+        br = in->read(in, scratchbuf_128k, sizeof (scratchbuf_128k));
+        if (br <= 0)
+            break;
+        MojoChecksum_append(&ctx, scratchbuf_128k, (uint32) br);
+    } // while
+
+    MojoChecksum_finish(&ctx, &sums);
+
+    in->close(in);
+
+    return (br < 0) ? 0 : retvalChecksums(L, &sums);
+} // do_checksum
+
+
+static int luahook_checksum(lua_State *L)
+{
+    const char *fname = luaL_checkstring(L, 1);
+    MojoInput *in = MojoInput_newFromFile(fname);
+    return do_checksum(L, in);
+} // luahook_checksum
+
+
 static int luahook_archive_fromdir(lua_State *L)
 {
     const char *path = luaL_checkstring(L, 1);
@@ -1517,6 +1559,7 @@
     lua_newtable(luaState);
         // Set up initial C functions, etc we want to expose to Lua code...
         set_cfunc(luaState, luahook_runfile, "runfile");
+        set_cfunc(luaState, luahook_runfilefromdir, "runfilefromdir");
         set_cfunc(luaState, luahook_translate, "translate");
         set_cfunc(luaState, luahook_ticks, "ticks");
         set_cfunc(luaState, luahook_format, "format");
@@ -1543,6 +1586,7 @@
         set_cfunc(luaState, luahook_truncatenum, "truncatenum");
         set_cfunc(luaState, luahook_date, "date");
         set_cfunc(luaState, luahook_isvalidperms, "isvalidperms");
+        set_cfunc(luaState, luahook_checksum, "checksum");
 
         // Set some information strings...
         lua_newtable(luaState);




More information about the mojosetup-commits mailing list