More lua stuff, yay.
Some checks failed
Build Dusk / run-tests (push) Failing after 1m18s
Build Dusk / build-linux (push) Failing after 1m43s
Build Dusk / build-psp (push) Failing after 1m46s

This commit is contained in:
2026-02-01 21:54:33 -06:00
parent 053778a502
commit c6f4518684
14 changed files with 131 additions and 202 deletions

View File

@@ -6,6 +6,8 @@
#include "scene.h"
#include "assert/assert.h"
#include "util/memory.h"
#include "debug/debug.h"
#include "time/time.h"
#include "display/camera/camera.h"
#include "display/screen.h"
@@ -19,31 +21,49 @@ errorret_t sceneInit(void) {
errorOk();
}
void sceneUpdate(void) {
if(!scriptContextHasFunc(&SCENE.scriptContext, "sceneUpdate")) return;
errorret_t sceneUpdate(void) {
lua_getglobal(SCENE.scriptContext.luaState, "sceneUpdate");
if(!lua_isfunction(SCENE.scriptContext.luaState, -1)) {
lua_pop(SCENE.scriptContext.luaState, 1);
errorOk();
}
errorret_t err = scriptContextCallFunc(
&SCENE.scriptContext, "sceneUpdate", NULL, 0, NULL
);
errorCatch(errorPrint(err));
if(lua_pcall(SCENE.scriptContext.luaState, 0, 0, 0) != LUA_OK) {
const char_t *strErr = lua_tostring(SCENE.scriptContext.luaState, -1);
lua_pop(SCENE.scriptContext.luaState, 1);
errorThrow("Failed to call function '%s': %s", "sceneUpdate", strErr);
}
errorOk();
}
void sceneRender(void) {
if(!scriptContextHasFunc(&SCENE.scriptContext, "sceneRender")) return;
errorret_t sceneRender(void) {
lua_getglobal(SCENE.scriptContext.luaState, "sceneRender");
if(!lua_isfunction(SCENE.scriptContext.luaState, -1)) {
lua_pop(SCENE.scriptContext.luaState, 1);
errorOk();
}
errorret_t err = scriptContextCallFunc(
&SCENE.scriptContext, "sceneRender", NULL, 0, NULL
);
errorCatch(errorPrint(err));
if(lua_pcall(SCENE.scriptContext.luaState, 0, 0, 0) != LUA_OK) {
const char_t *strErr = lua_tostring(SCENE.scriptContext.luaState, -1);
lua_pop(SCENE.scriptContext.luaState, 1);
errorThrow("Failed to call function '%s': %s", "sceneRender", strErr);
}
errorOk();
}
errorret_t sceneSet(const char_t *script) {
// Cleanup old script context.
if(scriptContextHasFunc(&SCENE.scriptContext, "sceneDispose")) {
errorret_t err = scriptContextCallFunc(
&SCENE.scriptContext, "sceneDispose", NULL, 0, NULL
);
errorCatch(errorPrint(err));
lua_getglobal(SCENE.scriptContext.luaState, "sceneDispose");
if(lua_isfunction(SCENE.scriptContext.luaState, -1)) {
if(lua_pcall(SCENE.scriptContext.luaState, 0, 0, 0) != LUA_OK) {
const char_t *strErr = lua_tostring(SCENE.scriptContext.luaState, -1);
lua_pop(SCENE.scriptContext.luaState, 1);
errorThrow("Failed to call function '%s': %s", "sceneDispose", strErr);
}
} else {
lua_pop(SCENE.scriptContext.luaState, 1);
}
scriptContextDispose(&SCENE.scriptContext);
@@ -55,11 +75,15 @@ errorret_t sceneSet(const char_t *script) {
}
void sceneDispose(void) {
if(scriptContextHasFunc(&SCENE.scriptContext, "sceneDispose")) {
errorret_t err = scriptContextCallFunc(
&SCENE.scriptContext, "sceneDispose", NULL, 0, NULL
);
errorCatch(errorPrint(err));
lua_getglobal(SCENE.scriptContext.luaState, "sceneDispose");
if(lua_isfunction(SCENE.scriptContext.luaState, -1)) {
if(lua_pcall(SCENE.scriptContext.luaState, 0, 0, 0) != LUA_OK) {
const char_t *strErr = lua_tostring(SCENE.scriptContext.luaState, -1);
lua_pop(SCENE.scriptContext.luaState, 1);
debugPrint("Failed to call function '%s': %s\n", "sceneDispose", strErr);
}
} else {
lua_pop(SCENE.scriptContext.luaState, 1);
}
scriptContextDispose(&SCENE.scriptContext);

View File

@@ -16,18 +16,24 @@ extern scene_t SCENE;
/**
* Initialize the scene subsystem.
*
* @return The error return value.
*/
errorret_t sceneInit(void);
/**
* Update the current scene.
*
* @return The error return value.
*/
void sceneUpdate(void);
errorret_t sceneUpdate(void);
/**
* Render the current scene.
*
* @return The error return value.
*/
void sceneRender(void);
errorret_t sceneRender(void);
/**
* Set the current scene by script name.