mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-22 11:56:42 +00:00
add comments, fix std bugs, add menu
This commit is contained in:
parent
6543a245c4
commit
5bd4dd3a48
10 changed files with 111 additions and 19 deletions
|
@ -2,10 +2,16 @@ println("Testing pause")
|
||||||
x = pause()
|
x = pause()
|
||||||
println(x.raw, " ", x.a, "", x.power)
|
println(x.raw, " ", x.a, "", x.power)
|
||||||
println("Testing masked pause")
|
println("Testing masked pause")
|
||||||
x = pausemask(1 << 3)
|
x = pause(1 << 3)
|
||||||
println(x.raw, " ", x.a)
|
println(x.raw, " ", x.a)
|
||||||
color(0xFF0000)
|
color(0xFF0000)
|
||||||
println("This text should be red!")
|
println("This text should be red!")
|
||||||
color(0x00FF00)
|
color(0x00FF00)
|
||||||
println("and this green!")
|
println("and this green!")
|
||||||
|
|
||||||
|
COLOR_RED = 0xFF0000
|
||||||
|
COLOR_BLUE = 0x0000FF
|
||||||
|
|
||||||
|
menu(["a", "b", "c"], 1, [COLOR_BLUE, COLOR_RED | 0x1000000, COLOR_BLUE]).print()
|
||||||
|
|
||||||
exit()
|
exit()
|
|
@ -19,4 +19,4 @@ println(a.fileSizes.len())
|
||||||
|
|
||||||
a.files.foreach("b") {
|
a.files.foreach("b") {
|
||||||
println(b)
|
println(b)
|
||||||
}
|
}
|
|
@ -68,7 +68,7 @@ int main()
|
||||||
|
|
||||||
//parseScript("#REQUIRE VER 3.0.5\nmain = { two = 1 + 1 }");
|
//parseScript("#REQUIRE VER 3.0.5\nmain = { two = 1 + 1 }");
|
||||||
//ParserRet_t ret = parseScript("a.b.c(1){ a.b.c() }");
|
//ParserRet_t ret = parseScript("a.b.c(1){ a.b.c() }");
|
||||||
while (1) {
|
//while (1) {
|
||||||
ParserRet_t ret = parseScript(script, strlen(script));
|
ParserRet_t ret = parseScript(script, strlen(script));
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ int main()
|
||||||
exitFunction(ret.main.operations.data, ret.main.operations.count);
|
exitFunction(ret.main.operations.data, ret.main.operations.count);
|
||||||
vecFree(ret.staticVarHolder);
|
vecFree(ret.staticVarHolder);
|
||||||
vecFree(ret.main.operations);
|
vecFree(ret.main.operations);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
free(script);
|
free(script);
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#define LP_VER_BF 5
|
#define LP_VER_BF 5
|
||||||
#define LP_VER "3.0.5"
|
#define LP_VER "3.0.5"
|
||||||
#define FREE(x) if (x) free(x)
|
#define FREE(x) if (x) free(x)
|
||||||
#define CpyStr(x) _strdup(x);
|
#define CpyStr(x) _strdup(x)
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#pragma _CRT_SECURE_NO_WARNINGS
|
#pragma _CRT_SECURE_NO_WARNINGS
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -69,7 +69,9 @@ Variable_t* opToVar(Operator_t* op, Callback_SetVar_t *setCallback, u8 possibleC
|
||||||
}
|
}
|
||||||
else if (op->variable.staticVariableType == 3) {
|
else if (op->variable.staticVariableType == 3) {
|
||||||
var = copyVariableToPtr(newFunctionVariable(createFunctionClass((Function_t) { 0 }, op->variable.staticFunction)));
|
var = copyVariableToPtr(newFunctionVariable(createFunctionClass((Function_t) { 0 }, op->variable.staticFunction)));
|
||||||
|
var->function.len = op->variable.staticFunctionLen;
|
||||||
var->reference = 1;
|
var->reference = 1;
|
||||||
|
|
||||||
|
|
||||||
if (!strcmp(var->function.builtInPtr->name,"while")) {
|
if (!strcmp(var->function.builtInPtr->name,"while")) {
|
||||||
var->function.firstArgAsFunction = 1;
|
var->function.firstArgAsFunction = 1;
|
||||||
|
|
|
@ -229,7 +229,10 @@ typedef struct _VariableReference_t {
|
||||||
Array_t betweenBrackets;
|
Array_t betweenBrackets;
|
||||||
s64 integerType;
|
s64 integerType;
|
||||||
char* stringType;
|
char* stringType;
|
||||||
ClassFunctionTableEntry_t* staticFunction;
|
struct {
|
||||||
|
ClassFunctionTableEntry_t* staticFunction;
|
||||||
|
u8 staticFunctionLen;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
} VariableReference_t;
|
} VariableReference_t;
|
||||||
|
|
||||||
|
|
|
@ -320,15 +320,15 @@ ParserRet_t parseScript(char* in, u32 len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenType == Token_Variable) {
|
if (tokenType == Token_Variable) {
|
||||||
|
u8 stdLen = 0;
|
||||||
ClassFunctionTableEntry_t* cfte = searchStdLib(var);
|
ClassFunctionTableEntry_t* cfte = searchStdLib(var, &stdLen);
|
||||||
|
|
||||||
if (cfte == NULL) {
|
if (cfte == NULL) {
|
||||||
CreateVariableReferenceStr(var);
|
CreateVariableReferenceStr(var);
|
||||||
op.variable = reference;
|
op.variable = reference;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VariableReference_t reference = { .staticVariableType = 3, .staticFunction = cfte };
|
VariableReference_t reference = { .staticVariableType = 3, .staticFunction = cfte, .staticFunctionLen = stdLen };
|
||||||
op.variable = reference;
|
op.variable = reference;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
#include <mem/heap.h>
|
#include <mem/heap.h>
|
||||||
#include "../keys/nca.h"
|
#include "../keys/nca.h"
|
||||||
#include "../hid/hid.h"
|
#include "../hid/hid.h"
|
||||||
|
#include "../gfx/menu.h"
|
||||||
|
#include "../gfx/gfxutils.h"
|
||||||
#endif
|
#endif
|
||||||
|
// Takes [int, function]. Returns elseable.
|
||||||
ClassFunction(stdIf) {
|
ClassFunction(stdIf) {
|
||||||
s64 value = getIntValue(args[0]);
|
s64 value = getIntValue(args[0]);
|
||||||
|
|
||||||
|
@ -36,6 +38,7 @@ ClassFunction(stdIf) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [function, function]. Returns empty. Works by evaling the first function and running the 2nd if true.
|
||||||
ClassFunction(stdWhile) {
|
ClassFunction(stdWhile) {
|
||||||
Variable_t* result = eval(args[0]->function.function.operations.data, args[0]->function.function.operations.count, 1);
|
Variable_t* result = eval(args[0]->function.function.operations.data, args[0]->function.function.operations.count, 1);
|
||||||
if (result == NULL || result->variableType != IntClass)
|
if (result == NULL || result->variableType != IntClass)
|
||||||
|
@ -65,6 +68,7 @@ ClassFunction(stdWhile) {
|
||||||
return &emptyClass;
|
return &emptyClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [???]. Returns empty. Works by calling .print on every argument
|
||||||
ClassFunction(stdPrint) {
|
ClassFunction(stdPrint) {
|
||||||
for (int i = 0; i < argsLen; i++) {
|
for (int i = 0; i < argsLen; i++) {
|
||||||
Variable_t* res = callMemberFunctionDirect(args[i], "print", NULL, 0);
|
Variable_t* res = callMemberFunctionDirect(args[i], "print", NULL, 0);
|
||||||
|
@ -76,21 +80,25 @@ ClassFunction(stdPrint) {
|
||||||
return &emptyClass;
|
return &emptyClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [???]. Returns empty. Calls stdPrint
|
||||||
ClassFunction(stdPrintLn) {
|
ClassFunction(stdPrintLn) {
|
||||||
stdPrint(caller, args, argsLen);
|
stdPrint(caller, args, argsLen);
|
||||||
gfx_printf("\n");
|
gfx_printf("\n");
|
||||||
return &emptyClass;
|
return &emptyClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes none. Returns none. Returning NULL will cause a cascade of errors and will exit runtime
|
||||||
ClassFunction(stdExit) {
|
ClassFunction(stdExit) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes none. Returns none. See stdExit. stdWhile and array.foreach look for SCRIPT_BREAK and break when seen.
|
||||||
ClassFunction(stdBreak) {
|
ClassFunction(stdBreak) {
|
||||||
scriptLastError = SCRIPT_BREAK;
|
scriptLastError = SCRIPT_BREAK;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes none. Returns empty dictionary.
|
||||||
ClassFunction(stdDict) {
|
ClassFunction(stdDict) {
|
||||||
Variable_t a = { 0 };
|
Variable_t a = { 0 };
|
||||||
a.variableType = DictionaryClass;
|
a.variableType = DictionaryClass;
|
||||||
|
@ -99,6 +107,7 @@ ClassFunction(stdDict) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
// Takes [str]. Returns int (0=success). str=partition to mount
|
||||||
ClassFunction(stdMountSysmmc){
|
ClassFunction(stdMountSysmmc){
|
||||||
if (connectMMC(MMC_CONN_EMMC))
|
if (connectMMC(MMC_CONN_EMMC))
|
||||||
return newIntVariablePtr(1);
|
return newIntVariablePtr(1);
|
||||||
|
@ -110,6 +119,7 @@ ClassFunction(stdMountSysmmc){
|
||||||
return newIntVariablePtr(0);
|
return newIntVariablePtr(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [str]. Returns int (0=success) str=path to save
|
||||||
ClassFunction(stdMountSave){
|
ClassFunction(stdMountSave){
|
||||||
|
|
||||||
Variable_t *arg = (*args);
|
Variable_t *arg = (*args);
|
||||||
|
@ -123,15 +133,16 @@ ClassFunction(stdMountSave){
|
||||||
|
|
||||||
var.save = save;
|
var.save = save;
|
||||||
return copyVariableToPtr(var);
|
return copyVariableToPtr(var);
|
||||||
|
|
||||||
return newIntVariablePtr(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [int, int, int]. Returns empty. 0: posX, 1: posY, 2: hexColor
|
||||||
ClassFunction(stdSetPixel) {
|
ClassFunction(stdSetPixel) {
|
||||||
u32 color = getIntValue(args[2]);
|
u32 color = getIntValue(args[2]);
|
||||||
gfx_set_pixel_horz(args[0]->integer.value, args[1]->integer.value, color);
|
gfx_set_pixel_horz(args[0]->integer.value, args[1]->integer.value, color);
|
||||||
return &emptyClass;
|
return &emptyClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [str]. Returns empty. str: path to dir
|
||||||
ClassFunction(stdReadDir){
|
ClassFunction(stdReadDir){
|
||||||
Variable_t* resPtr = newIntVariablePtr(0);
|
Variable_t* resPtr = newIntVariablePtr(0);
|
||||||
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 4)};
|
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 4)};
|
||||||
|
@ -188,6 +199,7 @@ char *powNames[] = {
|
||||||
"volminus",
|
"volminus",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Takes [int]. Returns dict[a,b,x,y,down,up,right,left,power,volplus,volminus,raw]. int: mask for hidWaitMask
|
||||||
ClassFunction(stdPauseMask){
|
ClassFunction(stdPauseMask){
|
||||||
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 9)};
|
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 9)};
|
||||||
Input_t *i = hidWaitMask((u32)getIntValue(*args));
|
Input_t *i = hidWaitMask((u32)getIntValue(*args));
|
||||||
|
@ -218,12 +230,14 @@ ClassFunction(stdPauseMask){
|
||||||
return copyVariableToPtr(ret);
|
return copyVariableToPtr(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes none. Returns dict (same as stdPauseMask).
|
||||||
ClassFunction(stdPause){
|
ClassFunction(stdPause){
|
||||||
Variable_t a = {.integer.value = 0xFFFFFFFF};
|
Variable_t a = {.integer.value = 0xFFFFFFFF};
|
||||||
Variable_t *b = &a;
|
Variable_t *b = &a;
|
||||||
return stdPauseMask(caller, &b, 1);
|
return stdPauseMask(caller, &b, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [str, str]. Returns int (0=success). 0: src path, 1: dst path
|
||||||
ClassFunction(stdFileCopy){
|
ClassFunction(stdFileCopy){
|
||||||
ErrCode_t e = FileCopy(args[0]->string.value, args[1]->string.value, 0);
|
ErrCode_t e = FileCopy(args[0]->string.value, args[1]->string.value, 0);
|
||||||
return newIntVariablePtr(e.err);
|
return newIntVariablePtr(e.err);
|
||||||
|
@ -245,16 +259,62 @@ ClassFunction(stdGetMemUsage){
|
||||||
return copyVariableToPtr(ret);
|
return copyVariableToPtr(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [int]. Returns empty. int: hex color
|
||||||
ClassFunction(stdColor){
|
ClassFunction(stdColor){
|
||||||
gfx_con_setcol((u32)getIntValue(*args) | 0xFF000000, gfx_con.fillbg, gfx_con.bgcol);
|
gfx_con_setcol((u32)getIntValue(*args) | 0xFF000000, gfx_con.fillbg, gfx_con.bgcol);
|
||||||
return &emptyClass;
|
return &emptyClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [str]. Returns int. str: path to nca
|
||||||
ClassFunction(stdGetNcaType){
|
ClassFunction(stdGetNcaType){
|
||||||
int type = GetNcaType(args[0]->string.value);
|
int type = GetNcaType(args[0]->string.value);
|
||||||
return newIntVariablePtr(type);
|
return newIntVariablePtr(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Takes [str[], int, int[]]. Returns int (index). str[]: names of entries, int: starting index, int[]: colors & options. The 3rd argument is optional
|
||||||
|
ClassFunction(stdMenuFull){
|
||||||
|
if (argsLen > 2){
|
||||||
|
if (args[2]->solvedArray.vector.count < args[0]->solvedArray.vector.count){
|
||||||
|
SCRIPT_FATAL_ERR("invalid menu args");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector_t v = newVec(sizeof(MenuEntry_t), args[0]->solvedArray.vector.count);
|
||||||
|
|
||||||
|
vecDefArray(char**, menuEntryNames, args[0]->solvedArray.vector);
|
||||||
|
vecDefArray(s64*, menuEntryOptions, args[2]->solvedArray.vector);
|
||||||
|
|
||||||
|
for (int i = 0; i < args[0]->solvedArray.vector.count; i++){
|
||||||
|
MenuEntry_t a = {.name = menuEntryNames[i]};
|
||||||
|
if (argsLen > 2){
|
||||||
|
u32 options = (u32)menuEntryOptions[i];
|
||||||
|
if (options & BIT(26)){
|
||||||
|
a.icon = 128;
|
||||||
|
}
|
||||||
|
else if (options & BIT(27)){
|
||||||
|
a.icon = 127;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.optionUnion = options;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a.optionUnion = COLORTORGB(COLOR_WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
vecAdd(&v, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 x=0,y=0;
|
||||||
|
gfx_con_getpos(&x,&y);
|
||||||
|
|
||||||
|
int res = newMenu(&v, getIntValue(args[1]), ScreenDefaultLenX - ((x + 1) / 16), ScreenDefaultLenY - ((y + 1) / 16) - 1, ENABLEB | ALWAYSREDRAW, 0);
|
||||||
|
vecFree(v);
|
||||||
|
return newIntVariablePtr(res);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
#define STUBBED(name) ClassFunction(name) { return newIntVariablePtr(0); }
|
||||||
|
|
||||||
ClassFunction(stdMountSysmmc){
|
ClassFunction(stdMountSysmmc){
|
||||||
return newIntVariablePtr(0);
|
return newIntVariablePtr(0);
|
||||||
}
|
}
|
||||||
|
@ -284,6 +344,11 @@ ClassFunction(stdGetMemUsage) {
|
||||||
ClassFunction(stdGetNcaType) {
|
ClassFunction(stdGetNcaType) {
|
||||||
return newIntVariablePtr(0);
|
return newIntVariablePtr(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STUBBED(stdPause)
|
||||||
|
STUBBED(stdPauseMask)
|
||||||
|
STUBBED(stdColor)
|
||||||
|
STUBBED(stdMenuFull)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
u8 oneIntoneFunction[] = { IntClass, FunctionClass };
|
u8 oneIntoneFunction[] = { IntClass, FunctionClass };
|
||||||
|
@ -292,6 +357,7 @@ u8 oneStringArgStd[] = {StringClass};
|
||||||
u8 threeIntsStd[] = { IntClass, IntClass, IntClass };
|
u8 threeIntsStd[] = { IntClass, IntClass, IntClass };
|
||||||
u8 twoStringArgStd[] = {StringClass, StringClass};
|
u8 twoStringArgStd[] = {StringClass, StringClass};
|
||||||
u8 oneIntStd[] = {IntClass};
|
u8 oneIntStd[] = {IntClass};
|
||||||
|
u8 menuArgsStd[] = {StringArrayClass, IntClass, IntArrayClass};
|
||||||
|
|
||||||
ClassFunctionTableEntry_t standardFunctionDefenitions[] = {
|
ClassFunctionTableEntry_t standardFunctionDefenitions[] = {
|
||||||
{"if", stdIf, 2, oneIntoneFunction},
|
{"if", stdIf, 2, oneIntoneFunction},
|
||||||
|
@ -309,16 +375,31 @@ ClassFunctionTableEntry_t standardFunctionDefenitions[] = {
|
||||||
{"mkdir", stdMkdir, 1, oneStringArgStd},
|
{"mkdir", stdMkdir, 1, oneStringArgStd},
|
||||||
{"memory", stdGetMemUsage, 0, 0},
|
{"memory", stdGetMemUsage, 0, 0},
|
||||||
{"ncatype", stdGetNcaType, 1, oneStringArgStd},
|
{"ncatype", stdGetNcaType, 1, oneStringArgStd},
|
||||||
|
{"pause", stdPauseMask, 1, oneIntStd},
|
||||||
{"pause", stdPause, 0, 0},
|
{"pause", stdPause, 0, 0},
|
||||||
{"pausemask", stdPauseMask, 1, oneIntStd},
|
|
||||||
{"color", stdColor, 1, oneIntStd},
|
{"color", stdColor, 1, oneIntStd},
|
||||||
|
{"menu", stdMenuFull, 3, menuArgsStd},
|
||||||
|
{"menu", stdMenuFull, 2, menuArgsStd},
|
||||||
};
|
};
|
||||||
|
|
||||||
ClassFunctionTableEntry_t* searchStdLib(char* funcName) {
|
ClassFunctionTableEntry_t* searchStdLib(char* funcName, u8 *len) {
|
||||||
|
u8 lenInternal = 0;
|
||||||
|
*len = 0;
|
||||||
|
ClassFunctionTableEntry_t *ret = NULL;
|
||||||
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(standardFunctionDefenitions); i++) {
|
for (int i = 0; i < ARRAY_SIZE(standardFunctionDefenitions); i++) {
|
||||||
if (!strcmp(funcName, standardFunctionDefenitions[i].name))
|
if (!strcmp(funcName, standardFunctionDefenitions[i].name)) {
|
||||||
return &standardFunctionDefenitions[i];
|
lenInternal++;
|
||||||
|
if (ret == NULL){
|
||||||
|
ret = &standardFunctionDefenitions[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (lenInternal != 0){
|
||||||
|
*len = lenInternal;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
*len = lenInternal;
|
||||||
|
return ret;
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|
||||||
ClassFunctionTableEntry_t* searchStdLib(char* funcName);
|
ClassFunctionTableEntry_t* searchStdLib(char* funcName, u8 *len);
|
|
@ -25,7 +25,7 @@
|
||||||
#define INCLUDE_BUILTIN_SCRIPTS 1
|
#define INCLUDE_BUILTIN_SCRIPTS 1
|
||||||
|
|
||||||
#ifdef INCLUDE_BUILTIN_SCRIPTS
|
#ifdef INCLUDE_BUILTIN_SCRIPTS
|
||||||
#include "../script/builtin.h"
|
#include "../../build/TegraExplorer/script/builtin.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern hekate_config h_cfg;
|
extern hekate_config h_cfg;
|
||||||
|
|
Loading…
Reference in a new issue