Fix dolphin
This commit is contained in:
@@ -39,7 +39,7 @@ set(LUA_C_FILES
|
||||
list(TRANSFORM LUA_C_FILES PREPEND "${LUA_SRC_DIR}/")
|
||||
add_library(liblua STATIC ${LUA_C_FILES})
|
||||
target_include_directories(liblua PUBLIC "${LUA_SRC_DIR}")
|
||||
target_compile_definitions(liblua PRIVATE LUA_USE_C89)
|
||||
target_compile_definitions(liblua PUBLIC LUA_USE_C89)
|
||||
add_library(lua::lua ALIAS liblua)
|
||||
set(Lua_FOUND TRUE CACHE BOOL "Lua found" FORCE)
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ errorret_t assetScriptLoader(assetfile_t *file) {
|
||||
errorChain(assetFileOpen(file));
|
||||
|
||||
// Request loading
|
||||
if(!lua_load(
|
||||
if(lua_load(
|
||||
script->ctx->luaState,
|
||||
assetScriptReader,
|
||||
file,
|
||||
file->filename,
|
||||
NULL
|
||||
) == LUA_OK) {
|
||||
) != LUA_OK) {
|
||||
const char_t *strErr = lua_tostring(script->ctx->luaState, -1);
|
||||
lua_pop(script->ctx->luaState, 1);
|
||||
errorThrow("Failed to load Lua script: %s", strErr);
|
||||
|
||||
+20
-20
@@ -95,27 +95,27 @@ void inputUpdate(void) {
|
||||
if(TIME.dynamicUpdate) return;
|
||||
#endif
|
||||
|
||||
if(INPUT.eventPressed.listenerCount > 0) {
|
||||
action = &INPUT.actions[0];
|
||||
do {
|
||||
if(inputPressed(action->action)) {
|
||||
inputevent_t inputEvent = { .action = action->action };
|
||||
eventInvoke(&INPUT.eventPressed, &inputEvent, "input_mt");
|
||||
}
|
||||
action++;
|
||||
} while(action < &INPUT.actions[INPUT_ACTION_COUNT]);
|
||||
}
|
||||
// if(INPUT.eventPressed.listenerCount > 0) {
|
||||
// action = &INPUT.actions[0];
|
||||
// do {
|
||||
// if(inputPressed(action->action)) {
|
||||
// inputevent_t inputEvent = { .action = action->action };
|
||||
// eventInvoke(&INPUT.eventPressed, &inputEvent, "input_mt");
|
||||
// }
|
||||
// action++;
|
||||
// } while(action < &INPUT.actions[INPUT_ACTION_COUNT]);
|
||||
// }
|
||||
|
||||
if(INPUT.eventReleased.listenerCount > 0) {
|
||||
action = &INPUT.actions[0];
|
||||
do {
|
||||
if(inputReleased(action->action)) {
|
||||
inputevent_t inputEvent = { .action = action->action };
|
||||
eventInvoke(&INPUT.eventReleased, &inputEvent, "input_mt");
|
||||
}
|
||||
action++;
|
||||
} while(action < &INPUT.actions[INPUT_ACTION_COUNT]);
|
||||
}
|
||||
// if(INPUT.eventReleased.listenerCount > 0) {
|
||||
// action = &INPUT.actions[0];
|
||||
// do {
|
||||
// if(inputReleased(action->action)) {
|
||||
// inputevent_t inputEvent = { .action = action->action };
|
||||
// eventInvoke(&INPUT.eventReleased, &inputEvent, "input_mt");
|
||||
// }
|
||||
// action++;
|
||||
// } while(action < &INPUT.actions[INPUT_ACTION_COUNT]);
|
||||
// }
|
||||
}
|
||||
|
||||
float_t inputGetCurrentValue(const inputaction_t action) {
|
||||
|
||||
+19
-2
@@ -37,19 +37,34 @@ static void sceneReset(void) {
|
||||
// Calls sceneClass:method() if it exists. Returns an error if the call fails.
|
||||
static errorret_t sceneCall(const char_t *method) {
|
||||
lua_State *L = SCRIPT_MANAGER.mainContext.luaState;
|
||||
|
||||
if(SCENE.scriptRef == LUA_NOREF || SCENE.scriptRef == LUA_REFNIL) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, SCENE.scriptRef);
|
||||
|
||||
if(!lua_istable(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
errorThrow("Scene script ref %d is not a table", SCENE.scriptRef);
|
||||
}
|
||||
|
||||
lua_getfield(L, -1, method);
|
||||
|
||||
if(!lua_isfunction(L, -1)) {
|
||||
lua_pop(L, 2);
|
||||
errorOk();
|
||||
}
|
||||
|
||||
lua_pushvalue(L, -2); // self
|
||||
|
||||
if(lua_pcall(L, 1, 0, 0) != LUA_OK) {
|
||||
const char_t *err = lua_tostring(L, -1);
|
||||
lua_pop(L, 2);
|
||||
lua_pop(L, 2); // error + scene table
|
||||
errorThrow("Scene:%s failed: %s", method, err);
|
||||
}
|
||||
lua_pop(L, 1); // pop scene class
|
||||
|
||||
lua_pop(L, 1); // scene table
|
||||
errorOk();
|
||||
}
|
||||
|
||||
@@ -211,6 +226,7 @@ errorret_t sceneSetImmediate(const char_t *scene) {
|
||||
|
||||
if(scene != NULL) {
|
||||
lua_State *L = SCRIPT_MANAGER.mainContext.luaState;
|
||||
|
||||
int32_t stackBase = lua_gettop(L);
|
||||
|
||||
errorChain(scriptContextExecFile(&SCRIPT_MANAGER.mainContext, scene));
|
||||
@@ -221,6 +237,7 @@ errorret_t sceneSetImmediate(const char_t *scene) {
|
||||
errorThrow("Scene '%s' must return a table", scene);
|
||||
}
|
||||
lua_settop(L, stackBase + 1);
|
||||
|
||||
SCENE.scriptRef = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
|
||||
errorChain(sceneCall("init"));
|
||||
|
||||
@@ -81,7 +81,7 @@ static int moduleTextureLoad(lua_State *l) {
|
||||
static void moduleTexture(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be null");
|
||||
|
||||
if(luaL_newmetatable(L, "texture_mt") == 1) {
|
||||
if(luaL_newmetatable(L, "texture_mt")) {
|
||||
lua_pushcfunction(L, moduleTextureIndex);
|
||||
lua_setfield(L, -2, "__index");
|
||||
lua_pushcfunction(L, moduleTextureToString);
|
||||
@@ -89,6 +89,7 @@ static void moduleTexture(lua_State *L) {
|
||||
lua_pushcfunction(L, moduleTextureGC);
|
||||
lua_setfield(L, -2, "__gc");
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_pushnumber(L, TEXTURE_FORMAT_RGBA);
|
||||
lua_setglobal(L, "TEXTURE_FORMAT_RGBA");
|
||||
|
||||
@@ -30,7 +30,7 @@ static int moduleLocaleGetText(lua_State *L) {
|
||||
luaL_error(L, "Expected plural as second argument");
|
||||
return 0;
|
||||
}
|
||||
plural = (int32_t)lua_tointeger(L, 2);
|
||||
plural = (int32_t)lua_tonumber(L, 2);
|
||||
if(plural < 0) {
|
||||
luaL_error(L, "Plural cannot be negative");
|
||||
return 0;
|
||||
|
||||
@@ -42,5 +42,4 @@ void moduleRegister(lua_State *L) {
|
||||
moduleScreen(L);
|
||||
moduleTexture(L);
|
||||
moduleTileset(L);
|
||||
moduleScript(L);
|
||||
}
|
||||
Reference in New Issue
Block a user