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