-
Notifications
You must be signed in to change notification settings - Fork 0
/
spook.c
37 lines (29 loc) · 660 Bytes
/
spook.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
int main(int argc, char **argv)
{
int status, i;
lua_State *L = luaL_newstate();
luaL_openlibs(L);
lua_newtable(L);
for(i = 0; i < argc; i++)
{
lua_pushinteger(L, i);
lua_pushstring(L, argv[i]);
lua_settable(L, -3);
}
lua_setglobal(L, "arg");
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
lua_remove(L, -2); // Remove package
lua_getglobal(L, "require");
lua_pushliteral(L, "init");
status = lua_pcall(L, 1, 0, 0);
if (status) {
fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
return 1;
}
return 0;
}