Merge pull request #597 from technomancy/fennel
Add Fennel as an option for creating games.
This commit is contained in:
		 Submodule 3rd-party updated: d0688b04c6...1829881440
									
								
							
							
								
								
									
										5
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Makefile
									
									
									
									
									
								
							@@ -20,6 +20,7 @@ INCLUDES= \
 | 
				
			|||||||
	-I$(3RD_PARTY)/sdl-gpu/include \
 | 
						-I$(3RD_PARTY)/sdl-gpu/include \
 | 
				
			||||||
	-I$(3RD_PARTY)/wren-0.1.0/src/include \
 | 
						-I$(3RD_PARTY)/wren-0.1.0/src/include \
 | 
				
			||||||
	-I$(3RD_PARTY)/moonscript \
 | 
						-I$(3RD_PARTY)/moonscript \
 | 
				
			||||||
 | 
						-I$(3RD_PARTY)/fennel \
 | 
				
			||||||
	-I$(BLIPBUF_LIB) \
 | 
						-I$(BLIPBUF_LIB) \
 | 
				
			||||||
	-I$(DUKTAPE_LIB) \
 | 
						-I$(DUKTAPE_LIB) \
 | 
				
			||||||
	-I$(SDL_NET_LIB) \
 | 
						-I$(SDL_NET_LIB) \
 | 
				
			||||||
@@ -173,6 +174,7 @@ DEMO_ASSETS= \
 | 
				
			|||||||
	bin/assets/jsdemo.tic.dat \
 | 
						bin/assets/jsdemo.tic.dat \
 | 
				
			||||||
	bin/assets/luademo.tic.dat \
 | 
						bin/assets/luademo.tic.dat \
 | 
				
			||||||
	bin/assets/moondemo.tic.dat \
 | 
						bin/assets/moondemo.tic.dat \
 | 
				
			||||||
 | 
						bin/assets/fenneldemo.tic.dat \
 | 
				
			||||||
	bin/assets/wrendemo.tic.dat \
 | 
						bin/assets/wrendemo.tic.dat \
 | 
				
			||||||
	bin/assets/benchmark.tic.dat \
 | 
						bin/assets/benchmark.tic.dat \
 | 
				
			||||||
	bin/assets/config.tic.dat
 | 
						bin/assets/config.tic.dat
 | 
				
			||||||
@@ -444,6 +446,9 @@ bin/assets/wrendemo.tic.dat: demos/wrendemo.tic
 | 
				
			|||||||
bin/assets/moondemo.tic.dat: demos/moondemo.tic
 | 
					bin/assets/moondemo.tic.dat: demos/moondemo.tic
 | 
				
			||||||
	$(BIN2TXT) $< $@ -z
 | 
						$(BIN2TXT) $< $@ -z
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bin/assets/fenneldemo.tic.dat: demos/fenneldemo.tic
 | 
				
			||||||
 | 
						$(BIN2TXT) $< $@ -z
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bin/assets/benchmark.tic.dat: demos/benchmark.tic
 | 
					bin/assets/benchmark.tic.dat: demos/benchmark.tic
 | 
				
			||||||
	$(BIN2TXT) $< $@ -z
 | 
						$(BIN2TXT) $< $@ -z
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								bin/assets/fenneldemo.tic.dat
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								bin/assets/fenneldemo.tic.dat
									
									
									
									
									
										Normal file
									
								
							@@ -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, 0xbb, 0x8e, 0x8e, 0x0f, 0xef, 0x94, 0x9a, 0x3e, 0xbc, 0xfb, 0xdf, 0xff, 0xe1, 0xff, 0x87, 0xfe, 0x0f, 0x1f, 0x60, 0x18, 0xbb, 0xfe, 0xff, 0x78, 0xf5, 0xff, 0x47, 0xd2, 0xcf, 0x30, 0x0a, 0x06, 0x14, 0x80, 0xe3, 0x0a, 0x14, 0x77, 0x60, 0xf8, 0x03, 0xcc, 0xd6, 0x07, 0xc6, 0xe3, 0x7f, 0x86, 0x0f, 0xff, 0x81, 0x71, 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89, 0xbb, 0xf7, 0xee, 0x1a, 0x17, 0x00, 0x6e, 0x06, 0x4f, 0xb2, 
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								demos/fenneldemo.tic
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								demos/fenneldemo.tic
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -24,6 +24,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#define TIC_BUILD_WITH_LUA 		1
 | 
					#define TIC_BUILD_WITH_LUA 		1
 | 
				
			||||||
#define TIC_BUILD_WITH_MOON 	1
 | 
					#define TIC_BUILD_WITH_MOON 	1
 | 
				
			||||||
 | 
					#define TIC_BUILD_WITH_FENNEL 	1
 | 
				
			||||||
#define TIC_BUILD_WITH_JS 		1
 | 
					#define TIC_BUILD_WITH_JS 		1
 | 
				
			||||||
#define TIC_BUILD_WITH_WREN 	1
 | 
					#define TIC_BUILD_WITH_WREN 	1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,6 +56,10 @@ typedef enum
 | 
				
			|||||||
	MoonScript,	
 | 
						MoonScript,	
 | 
				
			||||||
#	endif
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
						Fennel,
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TIC_BUILD_WITH_JS)
 | 
					#if defined(TIC_BUILD_WITH_JS)
 | 
				
			||||||
@@ -97,6 +101,10 @@ static const char DefaultLuaTicPath[] = TIC_LOCAL "default.tic";
 | 
				
			|||||||
static const char DefaultMoonTicPath[] = TIC_LOCAL "default_moon.tic";
 | 
					static const char DefaultMoonTicPath[] = TIC_LOCAL "default_moon.tic";
 | 
				
			||||||
#	endif
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
					static const char DefaultFennelTicPath[] = TIC_LOCAL "default_fennel.tic";
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TIC_BUILD_WITH_JS)
 | 
					#if defined(TIC_BUILD_WITH_JS)
 | 
				
			||||||
@@ -470,6 +478,10 @@ static void* getDemoCart(Console* console, ScriptLang script, s32* size)
 | 
				
			|||||||
		case MoonScript: strcpy(path, DefaultMoonTicPath); break;
 | 
							case MoonScript: strcpy(path, DefaultMoonTicPath); break;
 | 
				
			||||||
#	endif
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	if defined(TIC_BUILD_WITH_MOON)
 | 
				
			||||||
 | 
							case Fennel: strcpy(path, DefaultFennelTicPath); break;
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TIC_BUILD_WITH_JS)
 | 
					#if defined(TIC_BUILD_WITH_JS)
 | 
				
			||||||
@@ -519,6 +531,20 @@ static void* getDemoCart(Console* console, ScriptLang script, s32* size)
 | 
				
			|||||||
		break;
 | 
							break;
 | 
				
			||||||
#	endif
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
						case Fennel:
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								static const u8 FennelDemoRom[] =
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									#include "../bin/assets/fenneldemo.tic.dat"
 | 
				
			||||||
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								demo = FennelDemoRom;
 | 
				
			||||||
 | 
								romSize = sizeof FennelDemoRom;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -584,6 +610,11 @@ static void onConsoleLoadDemoCommandConfirmed(Console* console, const char* para
 | 
				
			|||||||
		data = getDemoCart(console, MoonScript, &size);
 | 
							data = getDemoCart(console, MoonScript, &size);
 | 
				
			||||||
#	endif
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
						if(strcmp(param, DefaultFennelTicPath) == 0)
 | 
				
			||||||
 | 
							data = getDemoCart(console, Fennel, &size);
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TIC_BUILD_WITH_JS)
 | 
					#if defined(TIC_BUILD_WITH_JS)
 | 
				
			||||||
@@ -1166,6 +1197,14 @@ static void onConsoleNewCommandConfirmed(Console* console, const char* param)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
#	endif
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
							if(strcmp(param, "fennel") == 0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								loadDemo(console, Fennel);
 | 
				
			||||||
 | 
								done = true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TIC_BUILD_WITH_JS)
 | 
					#if defined(TIC_BUILD_WITH_JS)
 | 
				
			||||||
@@ -1460,6 +1499,13 @@ static void onConsoleConfigCommand(Console* console, const char* param)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
#	endif
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
						else if(strcmp(param, "default fennel") == 0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							onConsoleLoadDemoCommand(console, DefaultFennelTicPath);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TIC_BUILD_WITH_JS)
 | 
					#if defined(TIC_BUILD_WITH_JS)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										163
									
								
								src/luaapi.c
									
									
									
									
									
								
							
							
						
						
									
										163
									
								
								src/luaapi.c
									
									
									
									
									
								
							@@ -1613,4 +1613,167 @@ const tic_script_config* getMoonScriptConfig()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_MOON) */
 | 
					#endif /* defined(TIC_BUILD_WITH_MOON) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "fennel.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define FENNEL_CODE(...) #__VA_ARGS__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char* execute_fennel_src = FENNEL_CODE(
 | 
				
			||||||
 | 
						local ok, val = pcall(require('fennel').eval, ...)
 | 
				
			||||||
 | 
					    -- allow you to return a function instead of setting TIC global
 | 
				
			||||||
 | 
					    if(not TIC and type(val) == "function") then TIC = val end
 | 
				
			||||||
 | 
						return val
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool initFennel(tic_mem* tic, const char* code)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						tic_machine* machine = (tic_machine*)tic;
 | 
				
			||||||
 | 
						closeLua(tic);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						lua_State* lua = machine->lua = luaL_newstate();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static const luaL_Reg loadedlibs[] =
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							{ "_G", luaopen_base },
 | 
				
			||||||
 | 
							{ LUA_LOADLIBNAME, luaopen_package },
 | 
				
			||||||
 | 
							{ LUA_COLIBNAME, luaopen_coroutine },
 | 
				
			||||||
 | 
							{ LUA_TABLIBNAME, luaopen_table },
 | 
				
			||||||
 | 
							{ LUA_STRLIBNAME, luaopen_string },
 | 
				
			||||||
 | 
							{ LUA_MATHLIBNAME, luaopen_math },
 | 
				
			||||||
 | 
							{ LUA_DBLIBNAME, luaopen_debug },
 | 
				
			||||||
 | 
							{ NULL, NULL }
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (const luaL_Reg *lib = loadedlibs; lib->func; lib++)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							luaL_requiref(lua, lib->name, lib->func, 1);
 | 
				
			||||||
 | 
							lua_pop(lua, 1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						initAPI(machine);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							lua_State* fennel = machine->lua;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							lua_settop(fennel, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (luaL_loadbuffer(fennel, (const char *)fennel_lua, fennel_lua_len, "fennel.lua") != LUA_OK)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								machine->data->error(machine->data->data, "failed to load fennel.lua");
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							lua_call(fennel, 0, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (luaL_loadbuffer(fennel, execute_fennel_src, strlen(execute_fennel_src), "execute_fennel") != LUA_OK)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								machine->data->error(machine->data->data, "failed to load fennel compiler");
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							lua_pushstring(fennel, code);
 | 
				
			||||||
 | 
							if (lua_pcall(fennel, 1, 1, 0) != LUA_OK)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								const char* msg = lua_tostring(fennel, -1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (msg)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									machine->data->error(machine->data->data, msg);
 | 
				
			||||||
 | 
									return false;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char* const FennelKeywords [] =
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"do", "values", "if", "when", "each", "for", "fn", "lambda", "partial",
 | 
				
			||||||
 | 
						"while", "set", "global", "var", "local", "let", "tset",
 | 
				
			||||||
 | 
						"or", "and", "true", "false", "nil", "#", ":", "->", "->>"
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const tic_outline_item* getFennelOutline(const char* code, s32* size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						enum{Size = sizeof(tic_outline_item)};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*size = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static tic_outline_item* items = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(items)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							free(items);
 | 
				
			||||||
 | 
							items = NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const char* ptr = code;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while(true)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							static const char FuncString[] = "fn"; /* this probably doesn't work */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ptr = strstr(ptr, FuncString);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(ptr)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								const char* end = ptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								ptr += sizeof FuncString - 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								while(end >= code && !isalnum_(*end))  end--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								const char* start = end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								for (const char* val = start-1; val >= code && (isalnum_(*val)); val--, start--);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if(end > start)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									items = items ? realloc(items, (*size + 1) * Size) : malloc(Size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									items[*size].pos = start - code;
 | 
				
			||||||
 | 
									items[*size].size = end - start + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									(*size)++;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return items;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const tic_script_config FennelSyntaxConfig =
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						.init 				= initFennel,
 | 
				
			||||||
 | 
						.close 				= closeLua,
 | 
				
			||||||
 | 
						.tick 				= callLuaTick,
 | 
				
			||||||
 | 
						.scanline 			= callLuaScanline,
 | 
				
			||||||
 | 
						.overline 			= callLuaOverline,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						.getOutline			= getFennelOutline,
 | 
				
			||||||
 | 
						.parse 				= parseCode,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						.blockCommentStart 	= NULL,
 | 
				
			||||||
 | 
						.blockCommentEnd 	= NULL,
 | 
				
			||||||
 | 
						.blockStringStart	= NULL,
 | 
				
			||||||
 | 
						.blockStringEnd		= NULL,
 | 
				
			||||||
 | 
						.singleComment 		= ";",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						.keywords 			= FennelKeywords,
 | 
				
			||||||
 | 
						.keywordsCount 		= COUNT_OF(FennelKeywords),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						.api 				= ApiKeywords,
 | 
				
			||||||
 | 
						.apiCount 			= COUNT_OF(ApiKeywords),
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const tic_script_config* getFennelConfig()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return &FennelSyntaxConfig;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* defined(TIC_BUILD_WITH_FENNEL) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -123,7 +123,7 @@ typedef struct
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	struct
 | 
						struct
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
#if defined(TIC_BUILD_WITH_LUA) || defined(TIC_BUILD_WITH_MOON)
 | 
					#if defined(TIC_BUILD_WITH_LUA) || defined(TIC_BUILD_WITH_MOON) || defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
		struct lua_State* lua;
 | 
							struct lua_State* lua;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -176,6 +176,10 @@ const tic_script_config* getLuaScriptConfig();
 | 
				
			|||||||
const tic_script_config* getMoonScriptConfig();
 | 
					const tic_script_config* getMoonScriptConfig();
 | 
				
			||||||
#	endif
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
					const tic_script_config* getFennelConfig();
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -566,6 +566,10 @@ void tic_close(tic_mem* tic)
 | 
				
			|||||||
	getMoonScriptConfig()->close(tic);
 | 
						getMoonScriptConfig()->close(tic);
 | 
				
			||||||
#	endif
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#	if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
						getFennelConfig()->close(tic);
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
					#endif /* defined(TIC_BUILD_WITH_LUA) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1566,6 +1570,11 @@ static const tic_script_config* getScriptConfig(const char* code)
 | 
				
			|||||||
		return getMoonScriptConfig();
 | 
							return getMoonScriptConfig();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(TIC_BUILD_WITH_FENNEL)
 | 
				
			||||||
 | 
						if(compareMetatag(code, "script", "fennel", getFennelConfig()->singleComment))
 | 
				
			||||||
 | 
							return getFennelConfig();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TIC_BUILD_WITH_JS)
 | 
					#if defined(TIC_BUILD_WITH_JS)
 | 
				
			||||||
	if(compareMetatag(code, "script", "js", getJsScriptConfig()->singleComment) ||
 | 
						if(compareMetatag(code, "script", "js", getJsScriptConfig()->singleComment) ||
 | 
				
			||||||
		compareMetatag(code, "script", "javascript", getJsScriptConfig()->singleComment)) 
 | 
							compareMetatag(code, "script", "javascript", getJsScriptConfig()->singleComment)) 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user