-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathmoonscript.c
More file actions
39 lines (29 loc) · 768 Bytes
/
moonscript.c
File metadata and controls
39 lines (29 loc) · 768 Bytes
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
38
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "moonscript.h"
#include <stdio.h>
// put whatever is on top of stack into package.loaded under name something is
// already there
void setloaded(lua_State* l, char* name) {
int top = lua_gettop(l);
lua_getglobal(l, "package");
lua_getfield(l, -1, "loaded");
lua_getfield(l, -1, name);
if (lua_isnil(l, -1)) {
lua_pop(l, 1);
lua_pushvalue(l, top);
lua_setfield(l, -2, name);
}
lua_settop(l, top);
}
extern int luaopen_lpeg(lua_State *l);
LUALIB_API int luaopen_moonscript(lua_State *l) {
luaopen_lpeg(l);
setloaded(l, "lpeg");
if (luaL_loadbuffer(l, (const char *)moonscript_lua, moonscript_lua_len, "moonscript.lua") == 0) {
lua_call(l, 0, 1);
return 1;
}
return 0;
};