1
0
forked from redo/BlockLua
Files
BlockLua/src/util/libts-ts.cs

75 lines
2.3 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 "";
}
// Public Lua library for TS
function luacall(%func, %a,%b,%c,%d,%e,%f,%g,%h,%i,%j,%k,%l,%m,%n,%o,%p) {
if($_bllua_active)
return _bllua_luacall("_bllua_call", %func, %a,%b,%c,%d,%e,%f,%g,%h,%i,%j,%k,%l,%m,%n,%o,%p);
}
function luaexec(%fn) {
if($_bllua_active)
return _bllua_luacall("_bllua_exec", %fn);
}
function luaeval(%code) {
if($_bllua_active)
return _bllua_luacall("_bllua_eval", %code);
}
function luaget(%name) {
if($_bllua_active)
return _bllua_luacall("_bllua_getvar", %name);
}
function luaset(%name, %val) {
if($_bllua_active)
_bllua_luacall("_bllua_setvar", %name, %val);
}
echo(" Executed libts-ts.cs");