Make eval command go thru tic_script_config.
This commit is contained in:
		@@ -25,7 +25,6 @@
 | 
				
			|||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
#include "ext/gif.h"
 | 
					#include "ext/gif.h"
 | 
				
			||||||
#include "ext/file_dialog.h"
 | 
					#include "ext/file_dialog.h"
 | 
				
			||||||
#include "machine.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <zlib.h>
 | 
					#include <zlib.h>
 | 
				
			||||||
#include <ctype.h>
 | 
					#include <ctype.h>
 | 
				
			||||||
@@ -2221,20 +2220,8 @@ static void onConsoleEvalCommand(Console* console, const char* param)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	printLine(console);
 | 
						printLine(console);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tic_machine* machine = (tic_machine*)console->tic;
 | 
						const tic_script_config* script_config = console->tic->api.get_script_config(console->tic);
 | 
				
			||||||
	lua_State* lua = machine->lua;
 | 
						script_config->eval(console->tic, param);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// TODO: check for other languages/runtimes?
 | 
					 | 
				
			||||||
	if(lua)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		if(luaL_dostring(lua, param) != LUA_OK)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
			printError(console, lua_tostring(lua, -1));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		lua_settop(lua, 0);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
		printError(console, "Lua state uninitialized.\n");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commandDone(console);
 | 
						commandDone(console);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1001,6 +1001,10 @@ static const tic_outline_item* getJsOutline(const char* code, s32* size)
 | 
				
			|||||||
	return items;
 | 
						return items;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void evalJs(tic_mem* tic, const char* code) {
 | 
				
			||||||
 | 
						printf("TODO: JS eval not yet implemented\n.");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const tic_script_config JsSyntaxConfig = 
 | 
					static const tic_script_config JsSyntaxConfig = 
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	.init 				= initJavascript,
 | 
						.init 				= initJavascript,
 | 
				
			||||||
@@ -1011,6 +1015,7 @@ static const tic_script_config JsSyntaxConfig =
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	.getOutline			= getJsOutline,
 | 
						.getOutline			= getJsOutline,
 | 
				
			||||||
	.parse 				= parseCode,
 | 
						.parse 				= parseCode,
 | 
				
			||||||
 | 
						.eval				= evalJs,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.blockCommentStart 	= "/*",
 | 
						.blockCommentStart 	= "/*",
 | 
				
			||||||
	.blockCommentEnd 	= "*/",
 | 
						.blockCommentEnd 	= "*/",
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										41
									
								
								src/luaapi.c
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								src/luaapi.c
									
									
									
									
									
								
							@@ -1402,6 +1402,22 @@ static const tic_outline_item* getLuaOutline(const char* code, s32* size)
 | 
				
			|||||||
	return items;
 | 
						return items;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void evalLua(tic_mem* tic, const char* code) {
 | 
				
			||||||
 | 
						tic_machine* machine = (tic_machine*)tic;
 | 
				
			||||||
 | 
						lua_State* lua = machine->lua;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						lua_settop(lua, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(luaL_loadstring(lua, code) != LUA_OK || lua_pcall(lua, 0, LUA_MULTRET, 0) != LUA_OK)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							machine->data->error(machine->data->data, lua_tostring(lua, -1));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void evalPlaceholder(tic_mem* tic, const char* code) {
 | 
				
			||||||
 | 
						printf("TODO: not yet implemented\n.");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const tic_script_config LuaSyntaxConfig = 
 | 
					static const tic_script_config LuaSyntaxConfig = 
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	.init 				= initLua,
 | 
						.init 				= initLua,
 | 
				
			||||||
@@ -1412,6 +1428,7 @@ static const tic_script_config LuaSyntaxConfig =
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	.getOutline			= getLuaOutline,
 | 
						.getOutline			= getLuaOutline,
 | 
				
			||||||
	.parse 				= parseCode,
 | 
						.parse 				= parseCode,
 | 
				
			||||||
 | 
						.eval				= evalLua,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.blockCommentStart 	= "--[[",
 | 
						.blockCommentStart 	= "--[[",
 | 
				
			||||||
	.blockCommentEnd 	= "]]",
 | 
						.blockCommentEnd 	= "]]",
 | 
				
			||||||
@@ -1580,6 +1597,7 @@ static const tic_script_config MoonSyntaxConfig =
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	.getOutline			= getMoonOutline,
 | 
						.getOutline			= getMoonOutline,
 | 
				
			||||||
	.parse 				= parseCode,
 | 
						.parse 				= parseCode,
 | 
				
			||||||
 | 
						.eval				= evalPlaceholder,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.blockCommentStart 	= NULL,
 | 
						.blockCommentStart 	= NULL,
 | 
				
			||||||
	.blockCommentEnd 	= NULL,
 | 
						.blockCommentEnd 	= NULL,
 | 
				
			||||||
@@ -1712,6 +1730,28 @@ static const tic_outline_item* getFennelOutline(const char* code, s32* size)
 | 
				
			|||||||
	return items;
 | 
						return items;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void evalFennel(tic_mem* tic, const char* code) {
 | 
				
			||||||
 | 
						tic_machine* machine = (tic_machine*)tic;
 | 
				
			||||||
 | 
						lua_State* fennel = machine->lua;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						lua_settop(fennel, 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");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						lua_pushstring(fennel, code);
 | 
				
			||||||
 | 
						lua_call(fennel, 1, 1);
 | 
				
			||||||
 | 
						const char* err = lua_tostring(fennel, -1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (err)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							machine->data->error(machine->data->data, err);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const tic_script_config FennelSyntaxConfig =
 | 
					static const tic_script_config FennelSyntaxConfig =
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	.init 				= initFennel,
 | 
						.init 				= initFennel,
 | 
				
			||||||
@@ -1722,6 +1762,7 @@ static const tic_script_config FennelSyntaxConfig =
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	.getOutline			= getFennelOutline,
 | 
						.getOutline			= getFennelOutline,
 | 
				
			||||||
	.parse 				= parseCode,
 | 
						.parse 				= parseCode,
 | 
				
			||||||
 | 
						.eval				= evalFennel,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.blockCommentStart 	= NULL,
 | 
						.blockCommentStart 	= NULL,
 | 
				
			||||||
	.blockCommentEnd 	= NULL,
 | 
						.blockCommentEnd 	= NULL,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -106,6 +106,7 @@ struct tic_script_config
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	const tic_outline_item* (*getOutline)(const char* code, s32* size);
 | 
						const tic_outline_item* (*getOutline)(const char* code, s32* size);
 | 
				
			||||||
	void (*parse)(const tic_script_config* config, const char* start, u8* color, const tic_code_theme* theme);
 | 
						void (*parse)(const tic_script_config* config, const char* start, u8* color, const tic_code_theme* theme);
 | 
				
			||||||
 | 
						void (*eval)(tic_mem* tic, const char* code);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const char* blockCommentStart;
 | 
						const char* blockCommentStart;
 | 
				
			||||||
	const char* blockCommentEnd;
 | 
						const char* blockCommentEnd;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1344,6 +1344,10 @@ static const tic_outline_item* getWrenOutline(const char* code, s32* size)
 | 
				
			|||||||
	return items;
 | 
						return items;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void evalWren(tic_mem* tic, const char* code) {
 | 
				
			||||||
 | 
						printf("TODO: Wren eval not yet implemented\n.");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const tic_script_config WrenSyntaxConfig = 
 | 
					static const tic_script_config WrenSyntaxConfig = 
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	.init 				= initWren,
 | 
						.init 				= initWren,
 | 
				
			||||||
@@ -1354,6 +1358,7 @@ static const tic_script_config WrenSyntaxConfig =
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	.getOutline			= getWrenOutline,
 | 
						.getOutline			= getWrenOutline,
 | 
				
			||||||
	.parse 				= parseCode,
 | 
						.parse 				= parseCode,
 | 
				
			||||||
 | 
						.eval				= evalWren,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.blockCommentStart 	= "/*",
 | 
						.blockCommentStart 	= "/*",
 | 
				
			||||||
	.blockCommentEnd 	= "*/",
 | 
						.blockCommentEnd 	= "*/",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user