initial
This commit is contained in:
44
src/util/libbl-support.cs
Normal file
44
src/util/libbl-support.cs
Normal 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");
|
||||
Reference in New Issue
Block a user