Wren Support #392

This commit is contained in:
BADIM-PC\Vadim
2018-02-05 16:52:55 +03:00
parent 4a60393a1c
commit 4ff6f926f0
30 changed files with 2120 additions and 43 deletions

View File

@@ -46,6 +46,7 @@ typedef enum
LuaScript,
MoonScript,
JavaScript,
WrenScript,
} ScriptLang;
#if defined(__WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__)
@@ -73,6 +74,7 @@ static const char* ExeExt = ".exe";
static const char DefaultLuaTicPath[] = TIC_LOCAL "default.tic";
static const char DefaultMoonTicPath[] = TIC_LOCAL "default_moon.tic";
static const char DefaultJSTicPath[] = TIC_LOCAL "default_js.tic";
static const char DefaultWrenTicPath[] = TIC_LOCAL "default_wren.tic";
static const char* getName(const char* name, const char* ext)
{
@@ -417,7 +419,10 @@ static void* getDemoCart(Console* console, ScriptLang script, s32* size)
strcpy(path, DefaultMoonTicPath);
break;
case JavaScript:
strcpy(path, DefaultJSTicPath);
strcpy(path, DefaultJSTicPath);
break;
case WrenScript:
strcpy(path, DefaultWrenTicPath);
break;
}
@@ -442,6 +447,11 @@ static void* getDemoCart(Console* console, ScriptLang script, s32* size)
#include "../bin/assets/moondemo.tic.dat"
};
static const u8 WrenDemoRom[] =
{
#include "../bin/assets/wrendemo.tic.dat"
};
const u8* demo = NULL;
s32 romSize = 0;
@@ -459,6 +469,10 @@ static void* getDemoCart(Console* console, ScriptLang script, s32* size)
demo = JsDemoRom;
romSize = sizeof JsDemoRom;
break;
case WrenScript:
demo = WrenDemoRom;
romSize = sizeof WrenDemoRom;
break;
}
u8* data = NULL;
@@ -491,6 +505,8 @@ static void onConsoleLoadDemoCommandConfirmed(Console* console, const char* para
data = getDemoCart(console, MoonScript, &size);
else if(strcmp(param, DefaultJSTicPath) == 0)
data = getDemoCart(console, JavaScript, &size);
else if(strcmp(param, DefaultWrenTicPath) == 0)
data = getDemoCart(console, WrenScript, &size);
const char* name = getCartName(param);
@@ -530,12 +546,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);
return hasExt(name, PROJECT_LUA_EXT) || hasExt(name, PROJECT_MOON_EXT) || hasExt(name, PROJECT_JS_EXT) || hasExt(name, PROJECT_WREN_EXT);
}
static const char* projectComment(const char* name)
{
return hasExt(name, PROJECT_JS_EXT) ? "//" : "--";
return hasExt(name, PROJECT_JS_EXT) || hasExt(name, PROJECT_WREN_EXT) ? "//" : "--";
}
static void buf2str(const void* data, s32 size, char* ptr, bool flip)
@@ -925,6 +941,9 @@ static void onConsoleLoadCommandConfirmed(Console* console, const char* param)
if(!fsExistsFile(console->fs, name))
name = getName(param, PROJECT_JS_EXT);
if(!fsExistsFile(console->fs, name))
name = getName(param, PROJECT_WREN_EXT);
void* data = fsLoadFile(console->fs, name, &size);
if(data)
@@ -1053,6 +1072,8 @@ static void onConsoleNewCommandConfirmed(Console* console, const char* param)
loadDemo(console, MoonScript);
else if(strcmp(param, "js") == 0 || strcmp(param, "javascript") == 0)
loadDemo(console, JavaScript);
else if(strcmp(param, "wren") == 0)
loadDemo(console, WrenScript);
else
{
printError(console, "\nunknown parameter: ");
@@ -1317,6 +1338,10 @@ static void onConsoleConfigCommand(Console* console, const char* param)
{
onConsoleLoadDemoCommand(console, DefaultJSTicPath);
}
else if(strcmp(param, "default wren") == 0)
{
onConsoleLoadDemoCommand(console, DefaultWrenTicPath);
}
else
{
printError(console, "\nunknown parameter: ");

View File

@@ -121,6 +121,7 @@ typedef struct
{
struct duk_hthread* js;
struct lua_State* lua;
struct WrenVM* wren;
};
blip_buffer_t* blip;
@@ -159,3 +160,4 @@ void parseCode(const tic_script_config* config, const char* start, u8* color, co
const tic_script_config* getLuaScriptConfig();
const tic_script_config* getMoonScriptConfig();
const tic_script_config* getJsScriptConfig();
const tic_script_config* getWrenScriptConfig();

View File

@@ -64,6 +64,7 @@
#define PROJECT_LUA_EXT ".lua"
#define PROJECT_MOON_EXT ".moon"
#define PROJECT_JS_EXT ".js"
#define PROJECT_WREN_EXT ".wren"
typedef struct
{

View File

@@ -395,6 +395,7 @@ static bool addMenuItem(const char* name, const char* info, s32 id, void* ptr, b
|| hasExt(name, PROJECT_LUA_EXT)
|| hasExt(name, PROJECT_MOON_EXT)
|| hasExt(name, PROJECT_JS_EXT)
|| hasExt(name, PROJECT_WREN_EXT)
#endif
)
{

View File

@@ -561,6 +561,7 @@ void tic_close(tic_mem* memory)
getLuaScriptConfig()->close(memory);
getMoonScriptConfig()->close(memory);
getJsScriptConfig()->close(memory);
getWrenScriptConfig()->close(memory);
blip_delete(machine->blip);
@@ -1528,10 +1529,16 @@ static bool isJavascript(const char* code)
|| compareMetatag(code, "script", "javascript", getJsScriptConfig()->singleComment);
}
static bool isWren(const char* code)
{
return compareMetatag(code, "script", "wren", getWrenScriptConfig()->singleComment);
}
static const tic_script_config* getScriptConfig(const char* code)
{
if(isMoonscript(code)) return getMoonScriptConfig();
if(isJavascript(code)) return getJsScriptConfig();
if(isWren(code)) return getWrenScriptConfig();
return getLuaScriptConfig();
}

1423
src/wrenapi.c Normal file

File diff suppressed because it is too large Load Diff