Compare commits
2 Commits
88237804f7
...
040697fcbd
| Author | SHA1 | Date | |
|---|---|---|---|
| 040697fcbd | |||
| 4fd9a443f2 |
@@ -3,4 +3,3 @@ config=minitest
|
|||||||
width=160
|
width=160
|
||||||
height=120
|
height=120
|
||||||
zoom=3
|
zoom=3
|
||||||
files=game.lua
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
62
lua.cpp
62
lua.cpp
@@ -1079,37 +1079,45 @@ void push_lua_funcs() {
|
|||||||
lua_pushinteger(L, 1); lua_setglobal(L, "FILE_WRITE");
|
lua_pushinteger(L, 1); lua_setglobal(L, "FILE_WRITE");
|
||||||
}
|
}
|
||||||
|
|
||||||
void lua_init(char* filenames) {
|
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() {
|
||||||
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;
|
int size;
|
||||||
do {
|
char* buffer = file_getfilebuffer("main.lua", size);
|
||||||
// Get next filename...
|
if (luaL_loadbuffer(L, buffer, size, "main")) {
|
||||||
char *file_start=pointer;
|
debug("LOADING ERROR: ");
|
||||||
while (*pointer!=',' && *pointer!=0) pointer++;
|
debug("%s\n",lua_tostring(L, -1));
|
||||||
if (*pointer!=0) *(pointer++)=0;
|
lua_pop(L,1);
|
||||||
|
return;
|
||||||
// Load and execute file
|
}
|
||||||
//if (luaL_loadfile(L, file_start)) { // "game.lua"
|
free(buffer);
|
||||||
int size;
|
if (lua_pcall(L,0, LUA_MULTRET, 0)) {
|
||||||
char* buffer = file_getfilebuffer(file_start, size);
|
debug("RUNTIME ERROR: ");
|
||||||
if (luaL_loadbuffer(L, buffer, size, file_start)) {
|
debug("%s\n",lua_tostring(L, -1));
|
||||||
debug("LOADING ERROR: ");
|
lua_pop(L,1);
|
||||||
debug("%s\n",lua_tostring(L, -1));
|
return;
|
||||||
lua_pop(L,1);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
free(buffer);
|
|
||||||
if (lua_pcall(L,0, LUA_MULTRET, 0)) {
|
|
||||||
debug("RUNTIME ERROR: ");
|
|
||||||
debug("%s\n",lua_tostring(L, -1));
|
|
||||||
lua_pop(L,1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (*pointer!=0) *(pointer-1)=',';
|
|
||||||
} while (*pointer!=0);
|
|
||||||
|
|
||||||
// Check if _init and _update exist
|
// Check if _init and _update exist
|
||||||
lua_getglobal(L, "_init");
|
lua_getglobal(L, "_init");
|
||||||
|
|||||||
2
lua.h
2
lua.h
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
bool lua_is_playing();
|
bool lua_is_playing();
|
||||||
void lua_init(char* filenames);
|
void lua_init();
|
||||||
void lua_call_init();
|
void lua_call_init();
|
||||||
void lua_call_update();
|
void lua_call_update();
|
||||||
void lua_quit();
|
void lua_quit();
|
||||||
|
|||||||
10
mini.cpp
10
mini.cpp
@@ -41,7 +41,7 @@ FILE *file = NULL;
|
|||||||
//uint8_t file_mode = 0;
|
//uint8_t file_mode = 0;
|
||||||
bool file_ignore_comma=true;
|
bool file_ignore_comma=true;
|
||||||
|
|
||||||
char lua_files[1024];
|
//char lua_files[1024];
|
||||||
|
|
||||||
#define DEST(x, y) dest_surface->p[x+y*dest_surface->w]
|
#define DEST(x, y) dest_surface->p[x+y*dest_surface->w]
|
||||||
#define SOURCE(x, y) source_surface->p[x+y*source_surface->w]
|
#define SOURCE(x, y) source_surface->p[x+y*source_surface->w]
|
||||||
@@ -119,10 +119,10 @@ void read_ini() {
|
|||||||
else if (strcmp(line, "height") == 0) screen_height = atoi(value);
|
else if (strcmp(line, "height") == 0) screen_height = atoi(value);
|
||||||
else if (strcmp(line, "zoom") == 0) screen_zoom = atoi(value);
|
else if (strcmp(line, "zoom") == 0) screen_zoom = atoi(value);
|
||||||
else if (strcmp(line, "fullscreen") == 0) screen_fullscreen = atoi(value);
|
else if (strcmp(line, "fullscreen") == 0) screen_fullscreen = atoi(value);
|
||||||
else if (strcmp(line, "files") == 0) {
|
//else if (strcmp(line, "files") == 0) {
|
||||||
//lua_files = (char*)malloc(strlen(value));
|
//lua_files = (char*)malloc(strlen(value));
|
||||||
strcpy(lua_files, value);
|
// strcpy(lua_files, value);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
@@ -280,7 +280,7 @@ int main(int argc,char*argv[]){
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug("MINI v%s\n",MINI_VERSION);
|
debug("MINI v%s\n",MINI_VERSION);
|
||||||
#endif
|
#endif
|
||||||
lua_init(lua_files);
|
lua_init();
|
||||||
lua_call_init();
|
lua_call_init();
|
||||||
|
|
||||||
Uint32 dt=SDL_GetTicks();
|
Uint32 dt=SDL_GetTicks();
|
||||||
|
|||||||
Reference in New Issue
Block a user