1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-13 23:46:42 +00:00
TegraExplorer/source/script/standardLibrary.c

638 lines
16 KiB
C
Raw Normal View History

2021-07-09 21:56:13 +01:00
#include "model.h"
#include "compat.h"
#include "genericClass.h"
#include "eval.h"
#include "garbageCollector.h"
#include "intClass.h"
#include "standardLibrary.h"
2021-07-10 13:45:09 +01:00
#include "scriptError.h"
2021-07-09 21:56:13 +01:00
#include <string.h>
2021-07-23 00:10:03 +01:00
#include "dictionaryClass.h"
2021-07-27 19:36:30 +01:00
#include "StringClass.h"
2021-07-09 21:56:13 +01:00
#ifndef WIN32
#include "../storage/mountmanager.h"
#include "../keys/keys.h"
2021-07-21 14:19:27 +01:00
#include "../fs/readers/folderReader.h"
#include "../fs/fscopy.h"
#include <mem/heap.h>
#include "../keys/nca.h"
2021-07-23 00:10:03 +01:00
#include "../hid/hid.h"
2021-07-23 13:03:49 +01:00
#include "../gfx/menu.h"
#include "../gfx/gfxutils.h"
#include "../tegraexplorer/tconf.h"
#include "../storage/emummc.h"
#include <utils/util.h>
#include "../fs/fsutils.h"
#include <storage/nx_sd.h>
2021-07-27 16:42:34 +01:00
#include "../storage/emmcfile.h"
2021-08-01 18:29:04 +01:00
#include <soc/fuse.h>
2021-07-09 21:56:13 +01:00
#endif
2021-07-23 13:03:49 +01:00
// Takes [int, function]. Returns elseable.
2021-07-09 21:56:13 +01:00
ClassFunction(stdIf) {
s64 value = getIntValue(args[0]);
if (value) {
Variable_t* res = genericCallDirect(args[1], NULL, 0);
if (res == NULL)
return NULL;
removePendingReference(res);
}
2021-07-09 22:46:21 +01:00
Variable_t* ret = newIntVariablePtr(value);
ret->variableType = ElseClass;
2021-07-09 21:56:13 +01:00
2021-07-09 22:46:21 +01:00
return ret;
}
2021-07-09 21:56:13 +01:00
2024-05-23 19:46:59 +01:00
// Takes [int]. Returns empty.
ClassFunction(stdSleep)
{
s64 value = getIntValue(args[0]);
if (value)
{
msleep(value);
}
return &emptyClass;
}
2021-07-23 13:03:49 +01:00
// Takes [function, function]. Returns empty. Works by evaling the first function and running the 2nd if true.
2021-07-09 21:56:13 +01:00
ClassFunction(stdWhile) {
Variable_t* result = eval(args[0]->function.function.operations.data, args[0]->function.function.operations.count, 1);
if (result == NULL || result->variableType != IntClass)
return NULL;
while (result->integer.value) {
removePendingReference(result);
Variable_t* res = genericCallDirect(args[1], NULL, 0);
2021-07-10 13:45:09 +01:00
if (res == NULL) {
if (scriptLastError == SCRIPT_BREAK) {
break;
}
else {
return NULL;
}
}
2021-07-09 21:56:13 +01:00
removePendingReference(res);
result = eval(args[0]->function.function.operations.data, args[0]->function.function.operations.count, 1);
if (result == NULL || result->variableType != IntClass)
return NULL;
}
removePendingReference(result);
return &emptyClass;
}
2021-07-23 13:03:49 +01:00
// Takes [???]. Returns empty. Works by calling .print on every argument
2021-07-09 21:56:13 +01:00
ClassFunction(stdPrint) {
for (int i = 0; i < argsLen; i++) {
Variable_t* res = callMemberFunctionDirect(args[i], "print", NULL, 0);
if (res == NULL)
return NULL;
2021-07-24 22:00:05 +01:00
if (i + 1 != argsLen)
gfx_putc(' ');
2021-07-09 21:56:13 +01:00
}
return &emptyClass;
}
2021-07-23 13:03:49 +01:00
// Takes [???]. Returns empty. Calls stdPrint
ClassFunction(stdPrintLn) {
stdPrint(caller, args, argsLen);
gfx_printf("\n");
return &emptyClass;
}
2021-07-23 13:03:49 +01:00
// Takes none. Returns none. Returning NULL will cause a cascade of errors and will exit runtime
2021-07-09 21:56:13 +01:00
ClassFunction(stdExit) {
return NULL;
}
2021-07-23 13:03:49 +01:00
// Takes none. Returns none. See stdExit. stdWhile and array.foreach look for SCRIPT_BREAK and break when seen.
2021-07-10 13:45:09 +01:00
ClassFunction(stdBreak) {
scriptLastError = SCRIPT_BREAK;
return NULL;
}
2021-07-23 13:03:49 +01:00
// Takes none. Returns empty dictionary.
2021-07-12 17:04:52 +01:00
ClassFunction(stdDict) {
Variable_t a = { 0 };
a.variableType = DictionaryClass;
a.dictionary.vector = newVec(sizeof(Dict_t), 0);
return copyVariableToPtr(a);
}
2021-07-09 21:56:13 +01:00
#ifndef WIN32
int mountMmc(u8 mmc, char *part){
if (connectMMC(mmc))
return 1;
if (mountMMCPart(part).err)
return 1;
return 0;
}
2021-07-23 13:03:49 +01:00
// Takes [str]. Returns int (0=success). str=partition to mount
2021-07-09 21:56:13 +01:00
ClassFunction(stdMountSysmmc){
return newIntVariablePtr(mountMmc(MMC_CONN_EMMC, args[0]->string.value));
}
2021-07-09 21:56:13 +01:00
ClassFunction(stdMountEmummc){
if (!emu_cfg.enabled){
SCRIPT_FATAL_ERR("emummc is not enabled");
}
2021-07-09 21:56:13 +01:00
return newIntVariablePtr(mountMmc(MMC_CONN_EMUMMC, args[0]->string.value));
2021-07-09 21:56:13 +01:00
}
2021-07-23 13:03:49 +01:00
// Takes [str]. Returns int (0=success) str=path to save
2021-07-09 21:56:13 +01:00
ClassFunction(stdMountSave){
2021-07-23 00:10:03 +01:00
2021-07-09 21:56:13 +01:00
Variable_t *arg = (*args);
Variable_t var = {.variableType = SaveClass};
SaveClass_t* save = calloc(1, sizeof(SaveClass_t));
2021-07-26 00:45:35 +01:00
if (f_open(&save->saveFile, arg->string.value, FA_READ | FA_WRITE))
2021-07-09 21:56:13 +01:00
return NULL;
save_init(&save->saveCtx, &save->saveFile, dumpedKeys.save_mac_key, 0);
if (!save_process(&save->saveCtx))
return NULL;
var.save = save;
return copyVariableToPtr(var);
}
2021-07-23 13:03:49 +01:00
// Takes [int, int, int]. Returns empty. 0: posX, 1: posY, 2: hexColor
2021-07-13 15:30:34 +01:00
ClassFunction(stdSetPixel) {
u32 color = getIntValue(args[2]);
gfx_set_pixel_horz(args[0]->integer.value, args[1]->integer.value, color);
return &emptyClass;
}
2021-07-21 14:19:27 +01:00
2021-07-27 13:16:01 +01:00
ClassFunction(stdSetPixels){
gfx_box(getIntValue(args[0]), getIntValue(args[1]), getIntValue(args[2]), getIntValue(args[3]), (u32)getIntValue(args[4]));
return &emptyClass;
}
ClassFunction(stdSetPrintPos){
if (getIntValue(args[0]) > 0 && getIntValue(args[1]) > 0){
gfx_con_setpos((getIntValue(args[0]) % 78) * 16, (getIntValue(args[1]) % 42) * 16);
}
return &emptyClass;
}
2021-07-23 13:03:49 +01:00
// Takes [str]. Returns empty. str: path to dir
2021-07-21 14:19:27 +01:00
ClassFunction(stdReadDir){
Variable_t* resPtr = newIntVariablePtr(0);
2021-07-23 00:10:03 +01:00
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 4)};
addVariableToDict(&ret, "result", resPtr);
2021-07-21 14:19:27 +01:00
Variable_t fileNamesArray = {.variableType = StringArrayClass, .solvedArray.vector = newVec(sizeof(char*), 0)};
Variable_t dirNamesArray = {.variableType = StringArrayClass, .solvedArray.vector = newVec(sizeof(char*), 0)};
Variable_t fileSizeArray = {.variableType = IntArrayClass, .solvedArray.vector = newVec(sizeof(s64), 0)};
DIR dir;
if ((resPtr->integer.value = f_opendir(&dir, args[0]->string.value))){
return copyVariableToPtr(ret);
}
FILINFO fno;
while (!(resPtr->integer.value = f_readdir(&dir, &fno)) && fno.fname[0]){
char *name = CpyStr(fno.fname);
if (fno.fattrib & AM_DIR){
vecAdd(&dirNamesArray.solvedArray.vector, name);
}
else {
vecAdd(&fileNamesArray.solvedArray.vector, name);
s64 size = fno.fsize;
vecAdd(&fileSizeArray.solvedArray.vector, size);
}
}
f_closedir(&dir);
2021-07-23 00:10:03 +01:00
addVariableToDict(&ret, "files", copyVariableToPtr(fileNamesArray));
addVariableToDict(&ret, "folders", copyVariableToPtr(dirNamesArray));
addVariableToDict(&ret, "fileSizes", copyVariableToPtr(fileSizeArray));
return copyVariableToPtr(ret);
}
char *abxyNames[] = {
"y",
"x",
"b",
"a"
};
char *ulrdNames[] = {
"down",
"up",
"right",
"left",
};
char *powNames[] = {
"power",
"volplus",
"volminus",
};
2021-07-21 14:19:27 +01:00
2021-09-16 22:44:20 +01:00
Variable_t *hidToVar(u32 raw){
2021-07-23 00:10:03 +01:00
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 9)};
addIntToDict(&ret, "raw", raw);
for (int i = 0; i < ARRAY_SIZE(abxyNames); i++){
addIntToDict(&ret, abxyNames[i], raw & 0x1);
raw >>= 1;
}
raw >>= 12;
for (int i = 0; i < ARRAY_SIZE(ulrdNames); i++){
addIntToDict(&ret, ulrdNames[i], raw & 0x1);
raw >>= 1;
}
raw >>= 4;
for (int i = 0; i < ARRAY_SIZE(powNames); i++){
addIntToDict(&ret, powNames[i], raw & 0x1);
raw >>= 1;
}
2021-07-21 14:19:27 +01:00
return copyVariableToPtr(ret);
}
2021-09-16 22:44:20 +01:00
ClassFunction(stdRead){
Input_t *i = hidRead();
u32 raw = i->buttons;
return hidToVar(raw);
}
// Takes [int]. Returns dict[a,b,x,y,down,up,right,left,power,volplus,volminus,raw]. int: mask for hidWaitMask
ClassFunction(stdPauseMask){
Input_t *i = hidWaitMask((u32)getIntValue(*args));
u32 raw = i->buttons;
return hidToVar(raw);
}
2021-07-23 13:03:49 +01:00
// Takes none. Returns dict (same as stdPauseMask).
2021-07-23 00:10:03 +01:00
ClassFunction(stdPause){
Variable_t a = {.integer.value = 0xFFFFFFFF};
Variable_t *b = &a;
return stdPauseMask(caller, &b, 1);
}
2021-07-23 13:03:49 +01:00
// Takes [str, str]. Returns int (0=success). 0: src path, 1: dst path
2021-07-21 14:19:27 +01:00
ClassFunction(stdFileCopy){
2021-08-01 23:14:43 +01:00
ErrCode_t e = FileCopy(args[0]->string.value, args[1]->string.value, COPY_MODE_PRINT);
2021-07-21 14:19:27 +01:00
return newIntVariablePtr(e.err);
}
ClassFunction(stdMkdir){
return newIntVariablePtr(f_mkdir(args[0]->string.value));
}
// Broken????
ClassFunction(stdGetMemUsage){
heap_monitor_t mon;
heap_monitor(&mon, false);
Dict_t a = {.name = CpyStr("used"), .var = newIntVariablePtr((s64)mon.used)};
Dict_t b = {.name = CpyStr("total"), .var = newIntVariablePtr((s64)mon.total)};
Variable_t ret = {.variableType = DictionaryClass, .dictionary.vector = newVec(sizeof(Dict_t), 2)};
2021-07-23 00:10:03 +01:00
vecAdd(&ret.dictionary.vector, a);
vecAdd(&ret.dictionary.vector, b);
2021-07-21 14:19:27 +01:00
return copyVariableToPtr(ret);
}
2021-07-23 13:03:49 +01:00
// Takes [int]. Returns empty. int: hex color
2021-07-23 00:10:03 +01:00
ClassFunction(stdColor){
gfx_con_setcol((u32)getIntValue(*args) | 0xFF000000, gfx_con.fillbg, gfx_con.bgcol);
return &emptyClass;
}
2021-07-23 13:03:49 +01:00
// Takes [str]. Returns int. str: path to nca
2021-07-21 14:19:27 +01:00
ClassFunction(stdGetNcaType){
int type = GetNcaType(args[0]->string.value);
return newIntVariablePtr(type);
}
2021-07-23 13:03:49 +01:00
// 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);
2021-07-27 20:43:11 +01:00
int res = newMenu(&v, getIntValue(args[1]), ScreenDefaultLenX - ((x + 1) / 16), 40 - ((y + 1) / 16) - 1, ENABLEB | ALWAYSREDRAW, 0);
2021-07-23 13:03:49 +01:00
vecFree(v);
return newIntVariablePtr(res);
}
ClassFunction(stdHasEmu){
return newIntVariablePtr(emu_cfg.enabled);
}
ClassFunction(stdClear){
gfx_clearscreen();
return &emptyClass;
}
ClassFunction(stdRmDir){
return newIntVariablePtr(FolderDelete(args[0]->string.value).err);
}
ClassFunction(stdGetMs){
return newIntVariablePtr(get_tmr_ms());
}
ClassFunction(stdFileExists){
return newIntVariablePtr(FileExists(args[0]->string.value));
}
2021-07-24 22:00:05 +01:00
ClassFunction(stdFileDel){
return newIntVariablePtr(f_unlink(args[0]->string.value));
}
ClassFunction(stdCopyDir){
return newIntVariablePtr(FolderCopy(args[0]->string.value, args[1]->string.value).err);
}
ClassFunction(stdFileMove){
return newIntVariablePtr(f_rename(args[0]->string.value, args[1]->string.value));
}
ClassFunction(stdFileRead){
u32 fSize = 0;
u8 *buff = sd_file_read(args[0]->string.value, &fSize);
if (buff == NULL){
SCRIPT_FATAL_ERR("Failed to read file");
}
Vector_t vec = vecFromArray(buff, fSize, sizeof(u8));
Variable_t v = {.variableType = ByteArrayClass, .solvedArray.vector = vec};
return copyVariableToPtr(v);
}
ClassFunction(stdFileReadSize) {
u32 fSize = 0;
u8* buff = sd_file_read(args[0]->string.value, &fSize);
if (buff == NULL) {
SCRIPT_FATAL_ERR("Failed to read file");
}
return newIntVariablePtr(fSize);
}
ClassFunction(stdFileWrite){
return newIntVariablePtr(sd_save_to_file(args[1]->solvedArray.vector.data, args[1]->solvedArray.vector.count, args[0]->string.value));
}
extern int launch_payload(char *path);
ClassFunction(stdLaunchPayload){
return newIntVariablePtr(launch_payload(args[0]->string.value));
}
2021-07-27 16:42:34 +01:00
int emmcFile(char *sdFile, char *sysPart, u8 mmc, u8 write){
if (!emu_cfg.enabled && mmc == MMC_CONN_EMUMMC){
return 1;
}
if (connectMMC(mmc))
return 1;
return DumpOrWriteEmmcPart(sdFile, sysPart, write, 1).err;
}
ClassFunction(stdEmmcFileRead){
return newIntVariablePtr(emmcFile(args[0]->string.value, args[1]->string.value, MMC_CONN_EMMC, 0));
}
ClassFunction(stdEmmcFileWrite){
return newIntVariablePtr(emmcFile(args[0]->string.value, args[1]->string.value, MMC_CONN_EMMC, 1));
}
ClassFunction(stdEmummcFileRead){
return newIntVariablePtr(emmcFile(args[0]->string.value, args[1]->string.value, MMC_CONN_EMUMMC, 0));
}
ClassFunction(stdEmummcFileWrite){
return newIntVariablePtr(emmcFile(args[0]->string.value, args[1]->string.value, MMC_CONN_EMUMMC, 1));
}
2021-07-27 19:36:30 +01:00
ClassFunction(stdCombinePaths){
if (argsLen < 2 || args[0]->variableType != StringClass){
SCRIPT_FATAL_ERR("stdCombinePaths needs 2+ args");
}
char *res = CpyStr(args[0]->string.value);
for (int i = 1; i < argsLen; i++){
if (args[i]->variableType != StringClass){
SCRIPT_FATAL_ERR("stdCombinePaths needs 2+ args");
}
char *temp = CombinePaths(res, args[i]->string.value);
free(res);
res = temp;
}
return newStringVariablePtr(res, 0, 1);
}
ClassFunction(stdEscPaths){
return newStringVariablePtr(EscapeFolder(args[0]->string.value), 0, 1);
}
ClassFunction(stdGetCwd){
return newStringVariablePtr(CpyStr(TConf.scriptCWD), 0, 1);
}
2021-07-27 23:31:36 +01:00
ClassFunction(stdPower){
2021-07-28 10:30:14 +01:00
power_set_state(MAX(0, (getIntValue(args[0]) % POWER_OFF_REBOOT)));
2021-07-27 23:31:36 +01:00
return &emptyClass;
}
2021-08-01 18:29:04 +01:00
ClassFunction(stdIsPatched){
return newIntVariablePtr(fuse_check_patched_rcm());
}
ClassFunction(stdHwType){
return newIntVariablePtr(fuse_read_hw_type());
}
2021-07-09 21:56:13 +01:00
#else
2021-07-23 13:03:49 +01:00
#define STUBBED(name) ClassFunction(name) { return newIntVariablePtr(0); }
2021-07-27 23:46:39 +01:00
STUBBED(stdMountSysmmc)
STUBBED(stdMountSave)
STUBBED(stdSetPixel)
STUBBED(stdReadDir)
STUBBED(stdFileCopy)
STUBBED(stdMkdir)
STUBBED(stdGetMemUsage)
STUBBED(stdGetNcaType)
2021-07-23 13:03:49 +01:00
STUBBED(stdPause)
2021-09-25 14:27:47 +01:00
STUBBED(stdRead)
2021-07-23 13:03:49 +01:00
STUBBED(stdPauseMask)
STUBBED(stdColor)
STUBBED(stdMenuFull)
2021-07-24 22:00:05 +01:00
STUBBED(stdMountEmummc)
STUBBED(stdHasEmu)
STUBBED(stdGetMs)
STUBBED(stdClear)
STUBBED(stdRmDir)
STUBBED(stdFileExists)
2021-07-24 23:54:21 +01:00
STUBBED(stdFileDel)
STUBBED(stdCopyDir)
STUBBED(stdFileMove)
STUBBED(stdLaunchPayload)
STUBBED(stdFileWrite)
STUBBED(stdFileRead)
STUBBED(stdFileReadSize)
2021-07-27 23:46:39 +01:00
STUBBED(stdCombinePaths)
STUBBED(stdEmmcFileWrite)
STUBBED(stdEmmcFileRead)
STUBBED(stdEmummcFileRead)
STUBBED(stdEmummcFileWrite)
STUBBED(stdEscPaths)
STUBBED(stdGetCwd)
STUBBED(stdPower)
STUBBED(stdSetPrintPos)
STUBBED(stdSetPixels)
2021-08-01 23:14:43 +01:00
STUBBED(stdIsPatched)
STUBBED(stdHwType)
2021-07-09 21:56:13 +01:00
#endif
u8 oneIntoneFunction[] = { IntClass, FunctionClass };
u8 doubleFunctionClass[] = { FunctionClass, FunctionClass };
2021-07-27 13:16:01 +01:00
u8 threeIntsStd[] = { IntClass, IntClass, IntClass, IntClass, IntClass };
2021-07-21 14:19:27 +01:00
u8 twoStringArgStd[] = {StringClass, StringClass};
2021-07-23 13:03:49 +01:00
u8 menuArgsStd[] = {StringArrayClass, IntClass, IntArrayClass};
u8 oneStringOneByteArrayStd[] = {StringClass, ByteArrayClass};
2021-07-09 21:56:13 +01:00
ClassFunctionTableEntry_t standardFunctionDefenitions[] = {
// Flow control
{"if", stdIf, 2, oneIntoneFunction},
{"while", stdWhile, 2, doubleFunctionClass},
{"exit", stdExit, 0, 0},
{"break", stdBreak, 0, 0},
// Class creation
2021-07-27 16:42:34 +01:00
{"readsave", stdMountSave, 1, twoStringArgStd},
{"dict", stdDict, 0, 0},
// Utils
{"print", stdPrint, VARARGCOUNT, 0},
{"println", stdPrintLn, VARARGCOUNT, 0},
2021-07-27 13:16:01 +01:00
{"printpos", stdSetPrintPos, 2, threeIntsStd},
{"setpixel", stdSetPixel, 3, threeIntsStd},
{"setpixels", stdSetPixels, 5, threeIntsStd},
{"emu", stdHasEmu, 0, 0},
{"cwd", stdGetCwd, 0, 0},
{"clear", stdClear, 0, 0},
{"timer", stdGetMs, 0, 0},
2021-07-27 16:42:34 +01:00
{"pause", stdPauseMask, 1, threeIntsStd},
2021-07-23 00:10:03 +01:00
{"pause", stdPause, 0, 0},
2021-09-16 22:44:20 +01:00
{"hidread", stdRead, 0, 0},
2021-07-27 16:42:34 +01:00
{"color", stdColor, 1, threeIntsStd},
2021-07-23 13:03:49 +01:00
{"menu", stdMenuFull, 3, menuArgsStd},
{"menu", stdMenuFull, 2, menuArgsStd},
2021-07-27 23:31:36 +01:00
{"power", stdPower, 1, threeIntsStd},
2024-05-23 19:46:59 +01:00
{"sleep", stdSleep, 1, threeIntsStd},
// System
2021-07-27 16:42:34 +01:00
{"mountsys", stdMountSysmmc, 1, twoStringArgStd},
{"mountemu", stdMountEmummc, 1, twoStringArgStd},
{"ncatype", stdGetNcaType, 1, twoStringArgStd},
{"emmcread", stdEmmcFileRead, 2, twoStringArgStd},
{"emmcwrite", stdEmmcFileWrite, 2, twoStringArgStd},
{"emummcread", stdEmummcFileRead, 2, twoStringArgStd},
{"emummcwrite", stdEmummcFileWrite, 2, twoStringArgStd},
2021-08-01 18:29:04 +01:00
{"fuse_patched", stdIsPatched, 0, 0},
{"fuse_hwtype", stdHwType, 0, 0},
// FileSystem
// Dir
2021-07-27 16:42:34 +01:00
{"readdir", stdReadDir, 1, twoStringArgStd},
{"deldir", stdRmDir, 1, twoStringArgStd},
{"mkdir", stdMkdir, 1, twoStringArgStd},
{"copydir", stdCopyDir, 2, twoStringArgStd},
// File
{"copyfile", stdFileCopy, 2, twoStringArgStd},
{"movefile", stdFileMove, 2, twoStringArgStd},
2021-07-27 16:42:34 +01:00
{"delfile", stdFileDel, 1, twoStringArgStd},
{"readfile", stdFileRead, 1, twoStringArgStd},
{"getfilesize", stdFileReadSize, 1, twoStringArgStd},
{"writefile", stdFileWrite, 2, oneStringOneByteArrayStd},
// Utils
2021-07-27 16:42:34 +01:00
{"fsexists", stdFileExists, 1, twoStringArgStd},
{"payload", stdLaunchPayload, 1, twoStringArgStd},
2021-07-27 19:36:30 +01:00
{"combinepath", stdCombinePaths, VARARGCOUNT, 0},
{"escapepath", stdEscPaths, 1, twoStringArgStd},
2021-07-09 21:56:13 +01:00
};
2021-07-23 13:03:49 +01:00
ClassFunctionTableEntry_t* searchStdLib(char* funcName, u8 *len) {
u8 lenInternal = 0;
*len = 0;
ClassFunctionTableEntry_t *ret = NULL;
2021-07-09 21:56:13 +01:00
for (int i = 0; i < ARRAY_SIZE(standardFunctionDefenitions); i++) {
2021-07-23 13:03:49 +01:00
if (!strcmp(funcName, standardFunctionDefenitions[i].name)) {
lenInternal++;
if (ret == NULL){
ret = &standardFunctionDefenitions[i];
}
}
else if (lenInternal != 0){
*len = lenInternal;
return ret;
}
2021-07-09 21:56:13 +01:00
}
2021-07-23 13:03:49 +01:00
*len = lenInternal;
return ret;
2021-07-28 10:30:14 +01:00
}