From e0cc606d2c43663cc0cf843e4e31b8d0644198cb Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Mon, 22 Jan 2018 14:28:14 +0300 Subject: [PATCH] Special functions should have common formatting #503 --- src/jsapi.c | 14 ++++++++++---- src/luaapi.c | 16 +++++++++++----- src/machine.h | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/jsapi.c b/src/jsapi.c index 020bd6a..694bcc4 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -899,14 +899,12 @@ static void callJavascriptTick(tic_mem* tic) } } -static void callJavascriptScanline(tic_mem* memory, s32 row, void* data) +static void callJavascriptScanlineName(tic_mem* memory, s32 row, void* data, const char* name) { tic_machine* machine = (tic_machine*)memory; duk_context* duk = machine->js; - const char* ScanlineFunc = ApiKeywords[1]; - - if(duk_get_global_string(duk, ScanlineFunc)) + if(duk_get_global_string(duk, name)) { duk_push_int(duk, row); @@ -917,6 +915,14 @@ static void callJavascriptScanline(tic_mem* memory, s32 row, void* data) duk_pop(duk); } +static void callJavascriptScanline(tic_mem* memory, s32 row, void* data) +{ + callJavascriptScanlineName(memory, row, data, ApiKeywords[1]); + + // try to call old scanline + callJavascriptScanlineName(memory, row, data, "scanline"); +} + static void callJavascriptOverlap(tic_mem* memory, void* data) { tic_machine* machine = (tic_machine*)memory; diff --git a/src/luaapi.c b/src/luaapi.c index 89611b1..f1a7984 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -1335,17 +1335,15 @@ static void callLuaTick(tic_mem* tic) } } -static void callLuaScanline(tic_mem* memory, s32 row, void* data) +static void callLuaScanlineName(tic_mem* memory, s32 row, void* data, const char* name) { tic_machine* machine = (tic_machine*)memory; lua_State* lua = machine->lua; if (lua) { - const char* ScanlineFunc = ApiKeywords[1]; - - lua_getglobal(lua, ScanlineFunc); - if(lua_isfunction(lua, -1)) + lua_getglobal(lua, name); + if(lua_isfunction(lua, -1)) { lua_pushinteger(lua, row); if(lua_pcall(lua, 1, 0, 0) != LUA_OK) @@ -1355,6 +1353,14 @@ static void callLuaScanline(tic_mem* memory, s32 row, void* data) } } +static void callLuaScanline(tic_mem* memory, s32 row, void* data) +{ + callLuaScanlineName(memory, row, data, ApiKeywords[1]); + + // try to call old scanline + callLuaScanlineName(memory, row, data, "scanline"); +} + static void callLuaOverlap(tic_mem* memory, void* data) { tic_machine* machine = (tic_machine*)memory; diff --git a/src/machine.h b/src/machine.h index a18a3b8..b2c073b 100644 --- a/src/machine.h +++ b/src/machine.h @@ -28,7 +28,7 @@ #define SFX_DEF_SPEED (1 << SFX_SPEED_BITS) -#define API_KEYWORDS {"TIC", "scanline", "OVR", "print", "cls", "pix", "line", "rect", "rectb", \ +#define API_KEYWORDS {"TIC", "SCN", "OVR", "print", "cls", "pix", "line", "rect", "rectb", \ "spr", "btn", "btnp", "sfx", "map", "mget", "mset", "peek", "poke", "peek4", "poke4", \ "memcpy", "memset", "trace", "pmem", "time", "exit", "font", "mouse", "circ", "circb", "tri", "textri", \ "clip", "music", "sync", "reset", "key", "keyp"}