- require() implementat
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
other = require("other")
|
||||
|
||||
x=0
|
||||
|
||||
function _init()
|
||||
text="HOLA MINI"
|
||||
text=other.peiv()
|
||||
keyRight = tonumber(getconf("keyright")) or KEY_RIGHT
|
||||
keyLeft = tonumber(getconf("keyleft")) or KEY_LEFT
|
||||
_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");
|
||||
}
|
||||
|
||||
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) {
|
||||
L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
push_lua_funcs();
|
||||
lua_register(L, "mini_loader", MiniLoader);
|
||||
luaL_dostring(L, "table.insert(package.searchers,2,mini_loader)\n");
|
||||
|
||||
char *pointer = filenames;
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user