Code Editor WIP

This commit is contained in:
2021-12-14 20:09:23 +01:00
parent be083a23e2
commit acfaf873ce
4 changed files with 318 additions and 80 deletions

43
lua.cpp
View File

@@ -350,7 +350,7 @@ extern "C" {
static int cpp_setmode(lua_State *L) {
int val = luaL_checkinteger(L, 1);
setmode(val);
setmode(mid(0,val,3));
return 0;
}
@@ -400,8 +400,8 @@ extern "C" {
lua_State *L;
uint8_t lua_state = STATE_STOPPED;
bool init_exists = false;
bool update_exists = false;
//bool init_exists = false;
//bool update_exists = false;
bool lua_is_playing() {
return lua_state == STATE_PLAYING;
@@ -412,7 +412,7 @@ const char boot[] = "function init()setmode(1)cls()play('o5l0v5cegv4cegv3cegv2ce
void lua_init(const char* filename, const bool start_playing) {
if (lua_state != STATE_STOPPED) lua_quit();
L = luaL_newstate();
init_exists = update_exists = false;
//init_exists = update_exists = false;
bool file_loaded = true;
if (filename == NULL) {
@@ -622,6 +622,7 @@ void lua_init(const char* filename, const bool start_playing) {
return;
}
/*
lua_getglobal(L, "init");
if (lua_isfunction(L,-1)) init_exists = true;
lua_pop(L,1);
@@ -629,7 +630,7 @@ void lua_init(const char* filename, const bool start_playing) {
lua_getglobal(L, "update");
if (lua_isfunction(L,-1)) update_exists = true;
lua_pop(L,1);
*/
lua_state = start_playing ? STATE_PLAYING : STATE_PAUSED;
}
@@ -656,26 +657,30 @@ void lua_call_cmd(const char* str) {
}
void lua_call_init() {
if (!init_exists) return;
lua_getglobal(L, "init");
if (lua_pcall(L, 0, 0, 0)) {
debug("RUNTIME ERROR:",false);
debug(lua_tostring(L, -1));
lua_pop(L,1);
setmode(0);
lua_state = STATE_STOPPED;
if (lua_isfunction(L,-1)) {
if (lua_pcall(L, 0, 0, 0)) {
debug("RUNTIME ERROR:",false);
debug(lua_tostring(L, -1));
lua_pop(L,1);
setmode(0);
lua_state = STATE_STOPPED;
}
}
}
void lua_call_update() {
if (!update_exists) { lua_state = STATE_PAUSED; return; }
lua_getglobal(L, "update");
if (lua_pcall(L, 0, 0, 0)) {
debug("RUNTIME ERROR:",false);
debug(lua_tostring(L, -1));
lua_pop(L,1);
setmode(0);
lua_state = STATE_STOPPED;
if (lua_isfunction(L,-1)) {
if (lua_pcall(L, 0, 0, 0)) {
debug("RUNTIME ERROR:",false);
debug(lua_tostring(L, -1));
lua_pop(L,1);
setmode(0);
lua_state = STATE_STOPPED;
}
} else {
lua_state = STATE_PAUSED;
}
}