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