- [NEW] configuration file working.

- [NEW] zoom(), fullscreen(), cursor(), getconf(), setconf().
- [CHG] now zoom and fullscreen are controlled by the game, not by mini.
- [FIX] quit() now actually quits.
- [NEW] btnp() without parameters returns key pressed.
- [NEW] zoom, fullscreen and cursor are saved to config automatically.
This commit is contained in:
2023-01-18 17:41:57 +01:00
parent 4c0cf979d3
commit e53befb700
8 changed files with 207 additions and 18 deletions

64
lua.cpp
View File

@@ -445,8 +445,12 @@ extern "C" {
}
static int cpp_btnp(lua_State *L) {
uint8_t i = luaL_checkinteger(L, 1);
lua_pushboolean(L, btnp(i));
if (lua_gettop(L) >=1 ) {
uint8_t i = luaL_checkinteger(L, 1);
lua_pushboolean(L, btnp(i));
} else {
lua_pushinteger(L, wbtnp());
}
return 1;
}
@@ -696,6 +700,55 @@ extern "C" {
return 0;
}
static int cpp_zoom(lua_State *L) {
const int value = luaL_optinteger(L, 1, 0);
if (value==0) {
lua_pushinteger(L, getzoom());
return 1;
} else {
setzoom(value);
return 0;
}
}
static int cpp_fullscreen(lua_State *L) {
if (lua_gettop(L) >= 1) {
setfullscreen(lua_toboolean(L, 1));
return 0;
} else {
lua_pushboolean(L, getfullscreen());
return 1;
}
}
static int cpp_cursor(lua_State *L) {
if (lua_gettop(L) >= 1) {
setcursor(lua_toboolean(L, 1));
return 0;
} else {
lua_pushboolean(L, getcursor());
return 1;
}
}
static int cpp_getconf(lua_State *L) {
const char* key = luaL_checkstring(L, 1);
const char* value = getconfig(key);
if (value==NULL) {
lua_pushnil(L);
} else {
lua_pushstring(L, value);
}
return 1;
}
static int cpp_setconf(lua_State *L) {
const char* key = luaL_checkstring(L, 1);
const char* value = luaL_checkstring(L, 2);
setconfig(key, value);
return 0;
}
static int cpp_exit(lua_State *L) {
exit();
return 0;
@@ -806,6 +859,13 @@ void push_lua_funcs() {
lua_pushcfunction(L,cpp_playsound); lua_setglobal(L, "playsound");
lua_pushcfunction(L,cpp_stopsound); lua_setglobal(L, "stopsound");
lua_pushcfunction(L,cpp_zoom); lua_setglobal(L, "zoom");
lua_pushcfunction(L,cpp_fullscreen); lua_setglobal(L, "fullscreen");
lua_pushcfunction(L,cpp_cursor); lua_setglobal(L, "cursor");
lua_pushcfunction(L,cpp_getconf); lua_setglobal(L, "getconf");
lua_pushcfunction(L,cpp_setconf); lua_setglobal(L, "setconf");
lua_pushcfunction(L,cpp_exit); lua_setglobal(L, "quit");
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");