This commit is contained in:
Redo
2025-10-01 16:26:18 -07:00
commit 36ba54b248
43 changed files with 9810 additions and 0 deletions

44
src/util/libbl-support.cs Normal file
View File

@@ -0,0 +1,44 @@
// 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);
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);
if($_bllua_active) luacall("_bllua_objectDeleted", %obj);
}
};
activatePackage(_bllua_objectDeletionHook);
echo(" Executed libbl-support.cs");