1pass.c
changeset 7 682d7ea1e7f3
parent 4 bf5593e5ddbb
child 11 b52e0f1798b8
--- a/1pass.c	Wed Dec 18 00:24:01 2013 -0500
+++ b/1pass.c	Thu Dec 19 09:27:25 2013 -0500
@@ -168,6 +168,7 @@
 } // decryptBase64UsingKey
 
 
+
 static void *luaAlloc(void *ud, void *ptr, size_t osize, size_t nsize)
 {
     if (nsize == 0)
@@ -195,7 +196,7 @@
 } // luaFatal
 
 
-static int initLua(void)
+static int initLua(const int argc, char **argv)
 {
     assert(luaState == NULL);
     luaState = lua_newstate(luaAlloc, NULL);
@@ -208,6 +209,17 @@
     luaSetCFunc(luaState, decryptUsingPBKDF2, "decryptUsingPBKDF2");
     luaSetCFunc(luaState, decryptBase64UsingKey, "decryptBase64UsingKey");
 
+    // Set up argv table...
+    lua_newtable(luaState);
+    int i;
+    for (i = 0; i < argc; i++)
+    {
+        lua_pushinteger(luaState, i+1);
+        lua_pushstring(luaState, argv[i]);
+        lua_settable(luaState, -3);
+    } // for
+    lua_setglobal(luaState, "argv");
+
     // Transfer control to Lua...
     if (luaL_dofile(luaState, "1pass.lua") != 0)
     {
@@ -235,7 +247,7 @@
 {
     atexit(deinitLua);
 
-    if (!initLua())  // this will move control to 1pass.lua
+    if (!initLua(argc, argv))  // this will move control to 1pass.lua
         return 1;
 
     return 0;