- require() implementat
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
|
other = require("other")
|
||||||
|
|
||||||
x=0
|
x=0
|
||||||
|
|
||||||
function _init()
|
function _init()
|
||||||
text="HOLA MINI"
|
text=other.peiv()
|
||||||
keyRight = tonumber(getconf("keyright")) or KEY_RIGHT
|
keyRight = tonumber(getconf("keyright")) or KEY_RIGHT
|
||||||
keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT
|
keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT
|
||||||
_update=normal_update
|
_update=normal_update
|
||||||
|
|||||||
5
data/other.lua
Normal file
5
data/other.lua
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
return {
|
||||||
|
peiv = function()
|
||||||
|
return "HOLA OTHER UNIT"
|
||||||
|
end
|
||||||
|
}
|
||||||
19
lua.cpp
19
lua.cpp
@@ -1079,10 +1079,29 @@ void push_lua_funcs() {
|
|||||||
lua_pushinteger(L, 1); lua_setglobal(L, "FILE_WRITE");
|
lua_pushinteger(L, 1); lua_setglobal(L, "FILE_WRITE");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MiniLoader(lua_State *L) {
|
||||||
|
const char *name = luaL_checkstring(L, 1);
|
||||||
|
char filename[strlen(name)+5];
|
||||||
|
strcpy(filename, name);
|
||||||
|
strcat(filename, ".lua");
|
||||||
|
int size;
|
||||||
|
char* buffer = file_getfilebuffer(filename, size);
|
||||||
|
if (luaL_loadbuffer(L, buffer, size, filename)) {
|
||||||
|
debug("REQUIRE LOADING ERROR: ");
|
||||||
|
debug("%s\n",lua_tostring(L, -1));
|
||||||
|
lua_pop(L,1);
|
||||||
|
//return ;
|
||||||
|
}
|
||||||
|
free(buffer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void lua_init(char* filenames) {
|
void lua_init(char* filenames) {
|
||||||
L = luaL_newstate();
|
L = luaL_newstate();
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
push_lua_funcs();
|
push_lua_funcs();
|
||||||
|
lua_register(L, "mini_loader", MiniLoader);
|
||||||
|
luaL_dostring(L, "table.insert(package.searchers,2,mini_loader)\n");
|
||||||
|
|
||||||
char *pointer = filenames;
|
char *pointer = filenames;
|
||||||
do {
|
do {
|
||||||
|
|||||||
Reference in New Issue
Block a user