46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
|
|
// Private - Utilities used by libbl from the Lua side
|
|
|
|
package _bllua_smartEval {
|
|
// Allow prepending ' to console commands to eval in lua instead of TS
|
|
// Also wraps TS lines with echo(...); if they don't end in ; or }
|
|
function ConsoleEntry::eval() {
|
|
%text = ConsoleEntry.getValue();
|
|
if(getSubStr(%text, 0, 1)$="\'") { // lua eval
|
|
if($_bllua_active) {
|
|
%text = getSubStr(%text, 1, strLen(%text));
|
|
echo("Lua ==> " @ %text);
|
|
_bllua_luacall("_bllua_smarteval", %text);
|
|
} else {
|
|
echo("Lua: not loaded");
|
|
}
|
|
ConsoleEntry.setValue("");
|
|
} else {
|
|
%textT = trim(%text);
|
|
if(strLen(%textT)>0) {
|
|
%lastChar = getSubStr(%textT, strLen(%textT)-1, 1);
|
|
if(%lastChar!$=";" && %lastChar!$="}") {
|
|
%text = "echo(" @ %text @ ");";
|
|
ConsoleEntry.setValue(%text);
|
|
}
|
|
}
|
|
parent::eval();
|
|
}
|
|
}
|
|
};
|
|
activatePackage(_bllua_smartEval);
|
|
|
|
package _bllua_objectDeletionHook {
|
|
// Hook object deletion to clean up its lua data
|
|
function SimObject::onRemove(%obj) {
|
|
// note: no parent function exists by default,
|
|
// and this is loaded before any addons
|
|
//parent::onRemove(%obj);
|
|
// assuming obj is an ID and never a name
|
|
if($_bllua_active) _bllua_luacall("_bllua_objectDeleted", %obj);
|
|
}
|
|
};
|
|
activatePackage(_bllua_objectDeletionHook);
|
|
|
|
echo(" Executed libbl-support.cs");
|