1
0

Implement FILES ARRAY$[]

This commit is contained in:
otya128
2016-12-24 19:07:53 +09:00
parent be2127ea89
commit 7f6b159deb

View File

@@ -2297,20 +2297,22 @@ class BuiltinFunction
} }
//FILES TYPE$ //FILES TYPE$
//((TXT|DAT):)?\w+/? //((TXT|DAT):)?\w+/?
static void FILES(PetitComputer p, DefaultValue!(wstring, false) name) static void FILES(PetitComputer p)
{
FILES(p, Value(cast(wchar[])p.currentProject));
}
static void FILES(PetitComputer p, Value nameOrArray)
{ {
import otya.smilebasic.project; import otya.smilebasic.project;
if(name.isDefault) if(nameOrArray.isString)
{ {
name.setDefaultValue(p.currentProject); auto t = Projects.splitResourceName(nameOrArray.castDString);
}
auto t = Projects.splitResourceName(name.value);
auto res = t[0]; auto res = t[0];
if(t[1].length && t[2].length) if(t[1].length && t[2].length)
{ {
throw new IllegalFunctionCall("FILES"); throw new IllegalFunctionCall("FILES");
} }
if(t[2].length && name.value.indexOf("/") != -1) if(t[2].length && nameOrArray.castDString.indexOf("/") != -1)
{ {
//"TXT:A":OK //"TXT:A":OK
//"TXT:A/":OK //"TXT:A/":OK
@@ -2328,9 +2330,42 @@ class BuiltinFunction
p.console.print(i, "\n"); p.console.print(i, "\n");
} }
} }
static void FILES(PetitComputer p, wstring name, Value[] array) else if (nameOrArray.type == ValueType.StringArray)
{ {
writeln("NOTIMPL"); FILES(p, p.currentProject, nameOrArray);
}
else
{
throw new TypeMismatch("FILES"/*, 1*/);
}
}
static void FILES(PetitComputer p, wstring name, Value array)
{
import otya.smilebasic.project;
if (array.type != ValueType.StringArray)
{
throw new TypeMismatch("FILES"/*, 1*/);
}
auto t = Projects.splitResourceName(name);
auto res = t[0];
if(t[1].length && t[2].length)
{
throw new IllegalFunctionCall("FILES");
}
if(t[2].length && name.indexOf("/") != -1)
{
throw new IllegalFunctionCall("FILES");
}
auto project = t[1].length ? t[1] : t[2];
auto l = p.project.getFileList(project, res);
if (l.length > array.length)
{
array.length = l.length;
}
foreach (i, j; l)
{
array[i] = Value(j);
}
} }
static void ACLS(PetitComputer p) static void ACLS(PetitComputer p)
{ {