Files
BlockLua/src/util/libts-ts.cs

53 lines
1.7 KiB
C#

// Read an entire file as text and return its contents as a string
// Used for reading files from zips
function _bllua_ReadEntireFile(%fn) {
%text = "";
%file = new FileObject();
%file.openForRead(%fn);
while (!%file.isEOF()) { %text = %text @ %file.readLine() @ "\r\n"; }
%file.close();
%file.delete();
return %text;
}
// Hack to create/set global variables
// since there's no easy way to do this from the DLL directly
function _bllua_set_var(%name, %val) {
%first = strLwr(getSubStr(%name, 0, 1));
%rest = getSubStr(%name, 1, strLen(%name));
switch$(%first) {
case "a": $a[%rest] = %val; return;
case "b": $b[%rest] = %val; return;
case "c": $c[%rest] = %val; return;
case "d": $d[%rest] = %val; return;
case "e": $e[%rest] = %val; return;
case "f": $f[%rest] = %val; return;
case "g": $g[%rest] = %val; return;
case "h": $h[%rest] = %val; return;
case "i": $i[%rest] = %val; return;
case "j": $j[%rest] = %val; return;
case "k": $k[%rest] = %val; return;
case "l": $l[%rest] = %val; return;
case "m": $m[%rest] = %val; return;
case "n": $n[%rest] = %val; return;
case "o": $o[%rest] = %val; return;
case "p": $p[%rest] = %val; return;
case "q": $q[%rest] = %val; return;
case "r": $r[%rest] = %val; return;
case "s": $s[%rest] = %val; return;
case "t": $t[%rest] = %val; return;
case "u": $u[%rest] = %val; return;
case "v": $v[%rest] = %val; return;
case "w": $w[%rest] = %val; return;
case "x": $x[%rest] = %val; return;
case "y": $y[%rest] = %val; return;
case "z": $z[%rest] = %val; return;
case "_": $_[%rest] = %val; return;
}
error("_bllua_set_var: invalid variable name " @ %name);
return "";
}
echo(" Executed libts-ts.cs");