summaryrefslogtreecommitdiff
path: root/src/wrapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wrapper.c')
-rw-r--r--src/wrapper.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/wrapper.c b/src/wrapper.c
index 3d11e01..b27651c 100644
--- a/src/wrapper.c
+++ b/src/wrapper.c
@@ -28,7 +28,16 @@ protected_main(lua_State *L)
prot_args *parg = (prot_args *)lua_touserdata(L, 1);
luaL_openlibs(L);
-
+
+#ifdef TESTING_SUPPLE
+ if (getenv("LUA_INIT") != NULL) {
+ if (luaL_dostring(L, getenv("LUA_INIT")) != 0) {
+ parg->retcode = 1;
+ return 0;
+ }
+ }
+#endif
+
lua_getglobal(L, "require");
lua_pushstring(L, "supple");
lua_call(L, 1, 1);
@@ -57,8 +66,8 @@ main(int argc, char **argv)
unsetenv("LUA_PATH");
unsetenv("LUA_CPATH");
unsetenv("SUPPLE_MKDTEMP");
-#endif
unsetenv("LUA_INIT");
+#endif
L = luaL_newstate();
if (L == NULL) {
@@ -70,11 +79,11 @@ main(int argc, char **argv)
lua_pushcclosure(L, &protected_main, 0);
lua_pushlightuserdata(L, &parg);
- success = lua_pcall(L, -1, 0, 0);
+ success = lua_pcall(L, 1, 0, 0);
if (success != 0) {
size_t l;
- const char *s = lua_tolstring(L, 1, &l);
+ const char *s = lua_tolstring(L, -1, &l);
write(2, s, l);
}