More lua stuff, yay.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user