- require() implementat

This commit is contained in:
2023-08-04 13:52:11 +02:00
parent 88237804f7
commit 4fd9a443f2
4 changed files with 28 additions and 2 deletions

View File

@@ -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
View File

@@ -0,0 +1,5 @@
return {
peiv = function()
return "HOLA OTHER UNIT"
end
}

19
lua.cpp
View File

@@ -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 {

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define MINI_VERSION "0.9.64d" #define MINI_VERSION "0.9.72d"