Special functions should have common formatting #503

This commit is contained in:
BADIM-PC\Vadim 2018-01-22 14:28:14 +03:00
parent 607515947c
commit e0cc606d2c
3 changed files with 22 additions and 10 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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"}