Add RESULT system variable
This commit is contained in:
@@ -1457,7 +1457,11 @@ class BuiltinFunction
|
||||
wstring resname = type[0];
|
||||
wstring projectname = type[1];
|
||||
wstring filename = type[2];
|
||||
if(projectname != "" && projectname != "SYS")
|
||||
if (!Projects.isValidFileName(filename))
|
||||
{
|
||||
throw new IllegalFunctionCall("LOAD");
|
||||
}
|
||||
if(projectname != "" && projectname.toUpper != "SYS")
|
||||
{
|
||||
throw new IllegalFunctionCall("LOAD");
|
||||
}
|
||||
@@ -1471,7 +1475,8 @@ class BuiltinFunction
|
||||
{
|
||||
return Value(txt);
|
||||
}
|
||||
throw new IllegalFunctionCall("LOAD");
|
||||
//not exist
|
||||
return Value("");
|
||||
}
|
||||
throw new IllegalFunctionCall("LOAD");
|
||||
}
|
||||
@@ -1482,10 +1487,14 @@ class BuiltinFunction
|
||||
flag.setDefaultValue(0);
|
||||
auto type = Projects.splitResourceName(name);
|
||||
wstring txt;
|
||||
wstring resname = type[0];
|
||||
wstring resname = type[0].toUpper;
|
||||
wstring projectname = type[1];
|
||||
wstring filename = type[2];
|
||||
if(projectname != "" && projectname != "SYS")
|
||||
if (!Projects.isValidFileName(filename))
|
||||
{
|
||||
throw new IllegalFunctionCall("LOAD");
|
||||
}
|
||||
if(projectname != "" && projectname.toUpper != "SYS")
|
||||
{
|
||||
throw new IllegalFunctionCall("LOAD");
|
||||
}
|
||||
@@ -1503,7 +1512,8 @@ class BuiltinFunction
|
||||
}
|
||||
if(!p.project.loadFile(projectname, "TXT", filename, txt))
|
||||
{
|
||||
throw new IllegalFunctionCall("LOAD");
|
||||
//not exist
|
||||
return;
|
||||
}
|
||||
p.slot[lot].load(txt);
|
||||
return;
|
||||
|
||||
@@ -226,6 +226,7 @@ class Compiler
|
||||
addSystemVariable("VERSION", new Version());
|
||||
addSystemVariable("FREEMEM", new FreeMem());
|
||||
addSystemVariable("TABSTEP", new TabStep());
|
||||
addSystemVariable("RESULT", new Result());
|
||||
}
|
||||
void addSystemVariable(wstring name, SystemVariable var)
|
||||
{
|
||||
|
||||
@@ -8,11 +8,19 @@ import std.conv;
|
||||
import std.uni;
|
||||
import std.typecons;
|
||||
import std.range;
|
||||
enum DialogResult
|
||||
{
|
||||
FAILURE = 0,
|
||||
SUCCESS = 1,
|
||||
CANCEL = -1,
|
||||
}
|
||||
|
||||
class Projects
|
||||
{
|
||||
wstring rootPath;
|
||||
wstring projectPath;
|
||||
string projectPathU8;
|
||||
DialogResult result = DialogResult.FAILURE;//Default value
|
||||
this(wstring root)
|
||||
{
|
||||
rootPath = root;
|
||||
@@ -130,10 +138,14 @@ class Projects
|
||||
bool loadFile(wstring project, wstring type, wstring name, out wstring contents)
|
||||
{
|
||||
contents = "";
|
||||
result = DialogResult.FAILURE;
|
||||
if(!isValidProjectName(project))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
type = type.toUpper;
|
||||
//TODO:case-sensitive filesystem...
|
||||
name = name.toUpper;
|
||||
if(project == "") project = "[DEFAULT]";
|
||||
if(type != "TXT" && type != "DAT")
|
||||
{
|
||||
@@ -144,6 +156,14 @@ class Projects
|
||||
return false;
|
||||
}
|
||||
auto path = buildPath(projectPath, project, type, name).to!string;
|
||||
if (!path.exists)
|
||||
{
|
||||
//show dialog
|
||||
return false;
|
||||
}
|
||||
|
||||
//show dialog
|
||||
result = DialogResult.SUCCESS;
|
||||
contents = readText(path).to!wstring;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -108,3 +108,11 @@ class FreeMem : SystemVariable
|
||||
return Value(8327164);
|
||||
}
|
||||
}
|
||||
class Result : SystemVariable
|
||||
{
|
||||
@property
|
||||
override Value value()
|
||||
{
|
||||
return Value(vm.petitcomputer.project.result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user