summaryrefslogtreecommitdiff
path: root/luaxpedite.c
blob: e0abe8a5b4cc9a70e27907143b34a8b72948cce1 (plain)
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
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

int main(int argc, char **argv) {
    lua_State *L;
    int i;
    L = luaL_newstate();

#define LUAOPEN(name) \
    lua_pushcfunction(L, luaopen_##name); \
    lua_pushstring(L, #name); \
    lua_call(L, 1, 0);

    LUAOPEN(base)
    LUAOPEN(string)
    LUAOPEN(bit)
    LUAOPEN(jit)

    lua_pushcfunction(L, luaopen_ffi);
    lua_pushstring(L, "ffi");
    lua_call(L, 1, 1);
    lua_setglobal(L, "ffi");

    lua_createtable(L, argc, 0);
    for (i = 0; i < argc; ++i) {
        lua_pushstring(L, argv[i]);
        lua_rawseti(L, -2, i);
    }
    lua_setglobal(L, "arg");
    if (!luaL_loadfile(L, "main.lua")) lua_call(L, 0, 0);
    else lua_pop(L, argc);
    lua_close(L);
    return 0;
}