Merge branch 'add-squirrel' of https://github.com/GrahamClemo/TIC-80 into add-squirrel
This commit is contained in:
commit
b4222fdb2a
22
Makefile
22
Makefile
|
@ -21,6 +21,7 @@ INCLUDES= \
|
|||
-I$(3RD_PARTY)/wren-0.1.0/src/include \
|
||||
-I$(3RD_PARTY)/moonscript \
|
||||
-I$(3RD_PARTY)/fennel \
|
||||
-I$(3RD_PARTY)/squirrel3.1/include \
|
||||
-I$(BLIPBUF_LIB) \
|
||||
-I$(DUKTAPE_LIB) \
|
||||
-I$(SDL_NET_LIB) \
|
||||
|
@ -48,6 +49,7 @@ LINUX_LIBS= \
|
|||
-L$(3RD_PARTY)/wren-0.1.0/lib \
|
||||
-L$(3RD_PARTY)/sdl-gpu/build/linux \
|
||||
-L$(3RD_PARTY)/lua-5.3.1/src \
|
||||
-L$(3RD_PARTY)/squirrel3.1/lib \
|
||||
-L$(3RD_PARTY)/SDL2-2.0.7/build/.libs
|
||||
|
||||
LINUX64_LIBS= \
|
||||
|
@ -66,6 +68,7 @@ LINUX_LINKER_LTO_FLAGS= \
|
|||
-lsdlgpu \
|
||||
-llua \
|
||||
-lwren \
|
||||
-lsquirrel -lsqstdlib -lstdc++ \
|
||||
-lgif \
|
||||
-ldl \
|
||||
-lm \
|
||||
|
@ -77,6 +80,7 @@ LINUX_LINKER_LTO_FLAGS= \
|
|||
LINUX_LINKER_FLAGS= \
|
||||
-llua \
|
||||
-lwren \
|
||||
-lsquirrel -lsqstdlib -lstdc++ \
|
||||
-ldl \
|
||||
-lm \
|
||||
-lpthread \
|
||||
|
@ -103,6 +107,7 @@ EMS_LINKER_FLAGS= \
|
|||
-L$(PRE_BUILT)/emscripten \
|
||||
-llua \
|
||||
-lwren \
|
||||
-lsquirrel \
|
||||
-lgif \
|
||||
-lz \
|
||||
-lsdlgpu
|
||||
|
@ -176,6 +181,7 @@ DEMO_ASSETS= \
|
|||
bin/assets/moondemo.tic.dat \
|
||||
bin/assets/fenneldemo.tic.dat \
|
||||
bin/assets/wrendemo.tic.dat \
|
||||
bin/assets/squirreldemo.tic.dat \
|
||||
bin/assets/benchmark.tic.dat \
|
||||
bin/assets/config.tic.dat
|
||||
|
||||
|
@ -309,14 +315,17 @@ bin/jsapi.o: src/jsapi.c $(TIC80_H)
|
|||
bin/luaapi.o: src/luaapi.c $(TIC80_H)
|
||||
$(CC) $< $(OPT) $(INCLUDES) -c -o $@
|
||||
|
||||
bin/squirrelapi.o: src/squirrelapi.c $(TIC80_H)
|
||||
$(CC) $< $(OPT) $(INCLUDES) -c -o $@
|
||||
|
||||
bin/wrenapi.o: src/wrenapi.c $(TIC80_H)
|
||||
$(CC) $< $(OPT) $(INCLUDES) -c -o $@
|
||||
|
||||
bin/duktape.o: $(DUKTAPE_LIB)/duktape.c $(TIC80_H)
|
||||
$(CC) $< $(OPT) $(INCLUDES) -c -o $@
|
||||
|
||||
TIC80_SRC = src/tic80.c src/tic.c $(BLIP_SRC) src/jsapi.c src/luaapi.c src/wrenapi.c $(DUKTAPE_LIB)/duktape.c
|
||||
TIC80_O = bin/tic80.o bin/tic.o bin/tools.o bin/blip_buf.o bin/jsapi.o bin/luaapi.o bin/wrenapi.o bin/duktape.o bin/gif.o
|
||||
TIC80_SRC = src/tic80.c src/tic.c $(BLIP_SRC) src/jsapi.c src/luaapi.c src/wrenapi.c src/squirrelapi.c $(DUKTAPE_LIB)/duktape.c
|
||||
TIC80_O = bin/squirrelapi.o bin/tic80.o bin/tic.o bin/tools.o bin/blip_buf.o bin/jsapi.o bin/luaapi.o bin/wrenapi.o bin/duktape.o bin/gif.o
|
||||
TIC80_A = bin/libtic80.a
|
||||
TIC80_DLL = bin/tic80.dll
|
||||
|
||||
|
@ -370,6 +379,7 @@ WREN_A=$(3RD_PARTY)/wren-0.1.0/lib/libwren.a
|
|||
SDLGPU_A=$(3RD_PARTY)/sdl-gpu/build/linux/libsdlgpu.a
|
||||
LUA_A=$(3RD_PARTY)/lua-5.3.1/src/liblua.a
|
||||
SDL2_A=$(3RD_PARTY)/SDL2-2.0.7/build/.libs/libSDL2.a
|
||||
SQUIRREL_A=$(3RD_PARTY)/squirrel3.1/lib/libsquirrel.a
|
||||
|
||||
$(WREN_A):
|
||||
make static -C $(3RD_PARTY)/wren-0.1.0/
|
||||
|
@ -383,7 +393,10 @@ $(LUA_A):
|
|||
$(SDL2_A):
|
||||
cd $(3RD_PARTY)/SDL2-2.0.7/ && ./configure --enable-sndio=no && make && cd ../..
|
||||
|
||||
linux: $(WREN_A) $(SDLGPU_A) $(LUA_A) $(SDL2_A)
|
||||
$(SQUIRREL_A):
|
||||
cd $(3RD_PARTY)/squirrel3.1/ && make && cd ../..
|
||||
|
||||
linux: $(WREN_A) $(SDLGPU_A) $(LUA_A) $(SDL2_A) $(SQUIRREL_A)
|
||||
$(CC) $(LINUX_INCLUDES) $(SOURCES) $(SYSTEM) $(LPEG_SRC) $(GIF_SRC) $(SOURCES_EXT) $(TIC80_SRC) $(OPT) $(INCLUDES) $(LINUX_LIBS) $(LINUX_LINKER_FLAGS) -o $(BIN_NAME)
|
||||
|
||||
linux-pro:
|
||||
|
@ -449,6 +462,9 @@ bin/assets/moondemo.tic.dat: demos/moondemo.tic
|
|||
bin/assets/fenneldemo.tic.dat: demos/fenneldemo.tic
|
||||
$(BIN2TXT) $< $@ -z
|
||||
|
||||
bin/assets/squirreldemo.tic.dat: demos/squirreldemo.tic
|
||||
$(BIN2TXT) $< $@ -z
|
||||
|
||||
bin/assets/benchmark.tic.dat: demos/benchmark.tic
|
||||
$(BIN2TXT) $< $@ -z
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
0x78, 0xda, 0x63, 0x5c, 0xc0, 0xc4, 0x40, 0x08, 0xfc, 0xfb, 0x0f, 0x04, 0x4a, 0x4a, 0x4a, 0xfd, 0x1d, 0x1d, 0x1d, 0xfd, 0x20, 0x1a, 0xc8, 0xed, 0xff, 0xff, 0x01, 0x8e, 0xff, 0xff, 0x7f, 0xff, 0x4e, 0x49, 0xe9, 0xff, 0xb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, 0x1e, 0xa5, 0x85, 0x89, 0x91, 0xb5, 0xe7, 0x2e, 0xd5, 0xea, 0xb4, 0x4e, 0x5d, 0x98, 0xbb, 0x4a, 0xe7, 0xd2, 0xaa, 0x99, 0xb9, 0x87, 0x4e, 0xdd, 0xba, 0x12, 0x77, 0xef, 0xdd, 0x35, 0x00, 0x34, 0x53, 0x38, 0x01,
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -70,6 +70,10 @@ typedef enum
|
|||
WrenScript,
|
||||
#endif
|
||||
|
||||
#if defined(TIC_BUILD_WITH_SQUIRREL)
|
||||
Squirrel,
|
||||
#endif
|
||||
|
||||
} ScriptLang;
|
||||
|
||||
#if defined(__TIC_WINDOWS__) || defined(__TIC_LINUX__) || defined(__TIC_MACOSX__)
|
||||
|
@ -115,6 +119,10 @@ static const char DefaultJSTicPath[] = TIC_LOCAL "default_js.tic";
|
|||
static const char DefaultWrenTicPath[] = TIC_LOCAL "default_wren.tic";
|
||||
#endif
|
||||
|
||||
#if defined(TIC_BUILD_WITH_SQUIRREL)
|
||||
static const char DefaultSquirrelTicPath[] = TIC_LOCAL "default_squirrel.tic";
|
||||
#endif
|
||||
|
||||
static inline s32 BufferSize(const tic_mem* tic)
|
||||
{
|
||||
return BufferWidth(tic) * BufferHeight(tic) * CONSOLE_BUFFER_SCREENS;
|
||||
|
@ -490,6 +498,9 @@ static void* getDemoCart(Console* console, ScriptLang script, s32* size)
|
|||
|
||||
#if defined(TIC_BUILD_WITH_WREN)
|
||||
case WrenScript: strcpy(path, DefaultWrenTicPath); break;
|
||||
#endif
|
||||
#if defined(TIC_BUILD_WITH_SQUIRREL)
|
||||
case Squirrel: strcpy(path, DefaultSquirrelTicPath); break;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -545,8 +556,22 @@ static void* getDemoCart(Console* console, ScriptLang script, s32* size)
|
|||
break;
|
||||
# endif
|
||||
|
||||
|
||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
|
||||
|
||||
#if defined(TIC_BUILD_WITH_SQUIRREL)
|
||||
case Squirrel:
|
||||
{
|
||||
static const u8 SquirrelDemoRom[] =
|
||||
{
|
||||
#include "../bin/assets/squirreldemo.tic.dat"
|
||||
};
|
||||
|
||||
demo = SquirrelDemoRom;
|
||||
romSize = sizeof SquirrelDemoRom;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(TIC_BUILD_WITH_JS)
|
||||
case JavaScript:
|
||||
|
@ -627,6 +652,10 @@ static void onConsoleLoadDemoCommandConfirmed(Console* console, const char* para
|
|||
data = getDemoCart(console, WrenScript, &size);
|
||||
#endif
|
||||
|
||||
#if defined(TIC_BUILD_WITH_SQUIRREL)
|
||||
if(strcmp(param, DefaultSquirrelTicPath) == 0)
|
||||
data = getDemoCart(console, Squirrel, &size);
|
||||
#endif
|
||||
const char* name = getCartName(param);
|
||||
|
||||
setCartName(console, name);
|
||||
|
@ -665,12 +694,12 @@ static bool hasExt(const char* name, const char* ext)
|
|||
|
||||
static bool hasProjectExt(const char* name)
|
||||
{
|
||||
return hasExt(name, PROJECT_LUA_EXT) || hasExt(name, PROJECT_MOON_EXT) || hasExt(name, PROJECT_JS_EXT) || hasExt(name, PROJECT_WREN_EXT);
|
||||
return hasExt(name, PROJECT_LUA_EXT) || hasExt(name, PROJECT_MOON_EXT) || hasExt(name, PROJECT_JS_EXT) || hasExt(name, PROJECT_WREN_EXT) || hasExt(name, PROJECT_SQUIRREL_EXT);
|
||||
}
|
||||
|
||||
static const char* projectComment(const char* name)
|
||||
{
|
||||
return hasExt(name, PROJECT_JS_EXT) || hasExt(name, PROJECT_WREN_EXT) ? "//" : "--";
|
||||
return (hasExt(name, PROJECT_SQUIRREL_EXT) || hasExt(name, PROJECT_JS_EXT) || hasExt(name, PROJECT_WREN_EXT)) ? "//" : "--";
|
||||
}
|
||||
|
||||
static void buf2str(const void* data, s32 size, char* ptr, bool flip)
|
||||
|
@ -1058,6 +1087,9 @@ static void onConsoleLoadCommandConfirmed(Console* console, const char* param)
|
|||
if(!fsExistsFile(console->fs, name))
|
||||
name = getName(param, PROJECT_WREN_EXT);
|
||||
|
||||
if(!fsExistsFile(console->fs, name))
|
||||
name = getName(param, PROJECT_SQUIRREL_EXT);
|
||||
|
||||
void* data = fsLoadFile(console->fs, name, &size);
|
||||
|
||||
if(data)
|
||||
|
@ -1223,6 +1255,14 @@ static void onConsoleNewCommandConfirmed(Console* console, const char* param)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(TIC_BUILD_WITH_SQUIRREL)
|
||||
if(strcmp(param, "squirrel") == 0)
|
||||
{
|
||||
loadDemo(console, Squirrel);
|
||||
done = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!done)
|
||||
{
|
||||
printError(console, "\nunknown parameter: ");
|
||||
|
@ -1506,6 +1546,7 @@ static void onConsoleConfigCommand(Console* console, const char* param)
|
|||
}
|
||||
# endif
|
||||
|
||||
|
||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
|
||||
|
||||
#if defined(TIC_BUILD_WITH_JS)
|
||||
|
@ -1522,6 +1563,13 @@ static void onConsoleConfigCommand(Console* console, const char* param)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(TIC_BUILD_WITH_SQUIRREL)
|
||||
else if(strcmp(param, "default squirrel") == 0)
|
||||
{
|
||||
onConsoleLoadDemoCommand(console, DefaultSquirrelTicPath);
|
||||
}
|
||||
#endif
|
||||
|
||||
else
|
||||
{
|
||||
printError(console, "\nunknown parameter: ");
|
||||
|
@ -2851,6 +2899,8 @@ static void tick(Console* console)
|
|||
loadDemo(console, JavaScript);
|
||||
#elif defined(TIC_BUILD_WITH_WREN)
|
||||
loadDemo(console, WrenScript);
|
||||
#elif defined(TIC_BUILD_WITH_SQUIRREL)
|
||||
loadDemo(console, Squirrel);
|
||||
#endif
|
||||
|
||||
printBack(console, "\n hello! type ");
|
||||
|
|
|
@ -86,6 +86,16 @@ static tic_machine* getSquirrelMachine(HSQUIRRELVM vm)
|
|||
#endif
|
||||
}
|
||||
|
||||
void squirrel_compilerError(HSQUIRRELVM vm, const SQChar* desc, const SQChar* source,
|
||||
SQInteger line, SQInteger column)
|
||||
{
|
||||
tic_machine* machine = getSquirrelMachine(vm);
|
||||
char buffer[1024];
|
||||
snprintf(buffer, 1023, "%.40s line %.6d column %.6d: %s\n", source, (int)line, (int)column, desc);
|
||||
|
||||
machine->data->error(machine->data->data, buffer);
|
||||
}
|
||||
|
||||
static SQInteger squirrel_errorHandler(HSQUIRRELVM vm)
|
||||
{
|
||||
tic_machine* machine = getSquirrelMachine(vm);
|
||||
|
@ -1257,6 +1267,8 @@ static void initAPI(tic_machine* machine)
|
|||
//lua_setglobal(machine->lua, TicMachine);
|
||||
HSQUIRRELVM vm = machine->squirrel;
|
||||
|
||||
sq_setcompilererrorhandler(vm, squirrel_compilerError);
|
||||
|
||||
sq_pushregistrytable(vm);
|
||||
sq_pushstring(vm, TicMachine, -1);
|
||||
sq_pushuserpointer(machine->squirrel, machine);
|
||||
|
@ -1311,7 +1323,7 @@ static bool initSquirrel(tic_mem* tic, const char* code)
|
|||
|
||||
sq_settop(vm, 0);
|
||||
|
||||
if((SQ_FAILED(sq_compilebuffer(vm, code, strlen(code), "squirrel", SQFalse))) ||
|
||||
if((SQ_FAILED(sq_compilebuffer(vm, code, strlen(code), "squirrel", SQTrue))) ||
|
||||
(sq_pushroottable(vm), false) ||
|
||||
(SQ_FAILED(sq_call(vm, 1, SQFalse, SQTrue))))
|
||||
{
|
||||
|
@ -1512,7 +1524,7 @@ void evalSquirrel(tic_mem* tic, const char* code) {
|
|||
|
||||
sq_settop(vm, 0);
|
||||
|
||||
if((SQ_FAILED(sq_compilebuffer(vm, code, strlen(code), "squirrel", SQFalse))) ||
|
||||
if((SQ_FAILED(sq_compilebuffer(vm, code, strlen(code), "squirrel", SQTrue))) ||
|
||||
(sq_pushroottable(vm), false) ||
|
||||
(SQ_FAILED(sq_call(vm, 1, SQFalse, SQTrue))))
|
||||
{
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#define PROJECT_MOON_EXT ".moon"
|
||||
#define PROJECT_JS_EXT ".js"
|
||||
#define PROJECT_WREN_EXT ".wren"
|
||||
#define PROJECT_SQUIRREL_EXT ".nut"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue