diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/rclauncher.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/bin/rclauncher.c b/src/bin/rclauncher.c index 4ff23e4a..4a99c491 100644 --- a/src/bin/rclauncher.c +++ b/src/bin/rclauncher.c | |||
| @@ -42,8 +42,17 @@ static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) | |||
| 42 | err_func = lua_gettop (L); | 42 | err_func = lua_gettop (L); |
| 43 | err = luaL_loadstring (L, lua_string); | 43 | err = luaL_loadstring (L, lua_string); |
| 44 | if(!err) { | 44 | if(!err) { |
| 45 | // fill global arg table | ||
| 46 | lua_getglobal(L, "arg"); | ||
| 45 | int i; | 47 | int i; |
| 46 | for(i = 1; i < argc; i++) | 48 | for(i = 1; i < argc; i++) |
| 49 | { | ||
| 50 | lua_pushstring(L, argv[i]); | ||
| 51 | lua_rawseti(L, -2, i); | ||
| 52 | } | ||
| 53 | lua_pop(L, 1); | ||
| 54 | // fill parameters (in vararg '...') | ||
| 55 | for(i = 1; i < argc; i++) | ||
| 47 | lua_pushstring(L, argv[i]); | 56 | lua_pushstring(L, argv[i]); |
| 48 | return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); | 57 | return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); |
| 49 | } else return err; | 58 | } else return err; |
| @@ -84,9 +93,15 @@ int main (int argc, char *argv[]) { | |||
| 84 | lua_State *L = lua_open(); | 93 | lua_State *L = lua_open(); |
| 85 | (void)argc; /* avoid "unused parameter" warning */ | 94 | (void)argc; /* avoid "unused parameter" warning */ |
| 86 | luaL_openlibs(L); | 95 | luaL_openlibs(L); |
| 96 | lua_newtable(L); // create arg table | ||
| 97 | lua_pushstring(L, argv[0]); // add interpreter to arg table | ||
| 98 | lua_rawseti(L, -2, -1); | ||
| 87 | dwLength = GetModulePath( NULL, name, MAX_PATH ); | 99 | dwLength = GetModulePath( NULL, name, MAX_PATH ); |
| 88 | if(dwLength) { /* Optional bootstrap */ | 100 | if(dwLength) { /* Optional bootstrap */ |
| 89 | strcat(name, ".lua"); | 101 | strcat(name, ".lua"); |
| 102 | lua_pushstring(L, name); // add lua script to arg table | ||
| 103 | lua_rawseti(L, -2, 0); | ||
| 104 | lua_setglobal(L,"arg"); // set global arg table | ||
| 90 | if(!luaL_loadfile (L, name)) { | 105 | if(!luaL_loadfile (L, name)) { |
| 91 | if(lua_pcall (L, 0, LUA_MULTRET, 0)) { | 106 | if(lua_pcall (L, 0, LUA_MULTRET, 0)) { |
| 92 | report (L); | 107 | report (L); |
| @@ -95,6 +110,13 @@ int main (int argc, char *argv[]) { | |||
| 95 | } | 110 | } |
| 96 | } | 111 | } |
| 97 | } | 112 | } |
| 113 | else | ||
| 114 | { | ||
| 115 | lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script | ||
| 116 | lua_rawseti(L, -2, 0); | ||
| 117 | lua_setglobal(L,"arg"); // set global arg table | ||
| 118 | } | ||
| 119 | |||
| 98 | luaL_buffinit(L, &b); | 120 | luaL_buffinit(L, &b); |
| 99 | for(i = 1; ; i++) { | 121 | for(i = 1; ; i++) { |
| 100 | #ifdef UNICODE | 122 | #ifdef UNICODE |
