added escape sequences to arbitrary strings; reworked callback system
This commit is contained in:
parent
d47e6a50dc
commit
518deaca68
@ -7,5 +7,5 @@ return function(gate, argv)
|
||||
gate.ports[1]:setstate(not gate.ports[1].state)
|
||||
gate.ports[2]:setstate(not gate.ports[2].state)
|
||||
end
|
||||
gate:cb("1\t" .. bool_to_int[gate.ports[1].state])
|
||||
gate:cb(bool_to_int[gate.ports[1].state])
|
||||
end
|
||||
|
@ -121,7 +121,7 @@ function llr(){
|
||||
deleteVariables("$LuaLogic*");
|
||||
$LuaLogic::Path = %path;
|
||||
|
||||
resetAllOpCallFunc();
|
||||
//resetAllOpCallFunc();
|
||||
exec("./lualogic.cs");
|
||||
schedule(3000, 0, lualogic_connect, 25000);
|
||||
}
|
||||
|
@ -89,21 +89,18 @@ function LuaLogicTCP::onLine(%this, %line)
|
||||
case "CB":
|
||||
%data = getFields(%line, 1, getFieldCount(%line));
|
||||
%data = nextToken(%data, brick, "\t");
|
||||
while(%brick !$= "")
|
||||
{
|
||||
while(%brick !$= ""){
|
||||
%data = nextToken(%data, argc, "\t");
|
||||
if(%argc > 0)
|
||||
{
|
||||
%data = nextToken(%data, args, "\t");
|
||||
for(%i = 1; %i < %argc; %i++)
|
||||
{
|
||||
%data = nextToken(%data, arg, "\t");
|
||||
%args = %args TAB %arg;
|
||||
}
|
||||
|
||||
for(%i=0; %i<%argc; %i++){
|
||||
%data = nextToken(%data, av, "\t");
|
||||
%argv[%i] = lualogic_collapseescape(%av);
|
||||
//talk("argv[" @ %i @ "] = " @ %argv[%i]);
|
||||
}
|
||||
|
||||
if(isObject(%brick))
|
||||
%brick.getDatablock().LuaLogic_Callback(%brick, %args);
|
||||
if(isObject(%brick)){
|
||||
%brick.getDatablock().LuaLogic_Callback(%brick, %argv0, %argv1, %argv2, %argv3, %argv4, %argv5, %argv6, %argv7, %argv8, %argv9);
|
||||
}
|
||||
|
||||
%data = nextToken(%data, brick, "\t");
|
||||
}
|
||||
|
@ -1,15 +1,4 @@
|
||||
|
||||
function lualogic_escapelogicfunction(%text){
|
||||
%text = strReplace(%text, "\\", "\\/");
|
||||
|
||||
%text = strReplace(%text, "\r", "\\r");
|
||||
%text = strReplace(%text, "\n", "\\n");
|
||||
%text = strReplace(%text, "\t", "\\t");
|
||||
%text = strReplace(%text, ";" , "\\:");
|
||||
|
||||
return %text;
|
||||
}
|
||||
|
||||
function lualogic_registergatedefinition(%data){
|
||||
//lualogic_registergatedefinition_auto(%data);
|
||||
|
||||
@ -36,9 +25,9 @@ function lualogic_registergatedefinition_auto(%data)
|
||||
%def = %id @ ";" @
|
||||
%data.logicUIName @ ";" @
|
||||
%data.logicUIDesc @ ";" @
|
||||
lualogic_escapelogicfunction(%data.logicInit) @ ";" @
|
||||
lualogic_escapelogicfunction(%data.logicUpdate) @ ";" @
|
||||
lualogic_escapelogicfunction(%data.logicInput) @ ";" @
|
||||
lualogic_expandescape(%data.logicInit) @ ";" @
|
||||
lualogic_expandescape(%data.logicUpdate) @ ";" @
|
||||
lualogic_expandescape(%data.logicInput) @ ";" @
|
||||
(%ports = %data.numLogicPorts)
|
||||
;
|
||||
|
||||
@ -141,7 +130,7 @@ function lualogic_sendinput(%gate, %argc, %arg0, %arg1, %arg2, %arg3, %arg4, %ar
|
||||
{
|
||||
%args = %arg0;
|
||||
for(%i = 1; %i < %argc; %i++)
|
||||
%args = %args @ ";" @ %arg[%i];
|
||||
%args = %args @ ";" @ lualogic_expandescape(%arg[%i]);
|
||||
|
||||
if(%argc > 0)
|
||||
lualogic_send("IN;" @ %gate.getID() @ ";" @ %argc @ ";" @ %args);
|
||||
@ -244,3 +233,55 @@ function lualogic_readfile(%filename){
|
||||
|
||||
return %filestr;
|
||||
}
|
||||
|
||||
$LuaLogic::EscapeCount = 0;
|
||||
$LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\\"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "b"; $LuaLogic::EscapeCount++;
|
||||
$LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\t"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "t"; $LuaLogic::EscapeCount++;
|
||||
$LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\n"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "n"; $LuaLogic::EscapeCount++;
|
||||
$LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\r"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "r"; $LuaLogic::EscapeCount++;
|
||||
$LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\'"; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "a"; $LuaLogic::EscapeCount++;
|
||||
$LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = "\""; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "q"; $LuaLogic::EscapeCount++;
|
||||
$LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = ";" ; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "s"; $LuaLogic::EscapeCount++;
|
||||
$LuaLogic::EscapeIn[$LuaLogic::EscapeCount] = ":" ; $LuaLogic::EscapeOut[$LuaLogic::EscapeCount] = "c"; $LuaLogic::EscapeCount++;
|
||||
|
||||
function lualogic_expandescape(%str){
|
||||
%ostr = "";
|
||||
|
||||
%len = strLen(%str);
|
||||
for(%i=0; %i<%len; %i++){
|
||||
%ci = getSubStr(%str, %i, 1);
|
||||
|
||||
%co = %ci;
|
||||
for(%j=0; %j<$LuaLogic::EscapeCount; %j++){
|
||||
if(%ci$=$LuaLogic::EscapeIn[%j]){ %co = "\\" @ $LuaLogic::EscapeOut[%j]; }
|
||||
}
|
||||
|
||||
%ostr = %ostr @ %co;
|
||||
}
|
||||
|
||||
return %ostr;
|
||||
}
|
||||
|
||||
function lualogic_collapseescape(%str){
|
||||
%ostr = "";
|
||||
|
||||
%i = 0;
|
||||
%len = strLen(%str);
|
||||
while(%i<%len){
|
||||
%ci = getSubStr(%str, %i, 1);
|
||||
|
||||
%co = %ci;
|
||||
if(%ci=="\\" && %i<%len-1){
|
||||
%i++;
|
||||
%ci = getSubStr(%str, %i, 1);
|
||||
for(%j=0; %j<$LuaLogic::EscapeCount; %j++){
|
||||
if(%ci$=$LuaLogic::EscapeOut[%j]){ %co = $LuaLogic::EscapeIn[%j]; }
|
||||
}
|
||||
}
|
||||
|
||||
%ostr = %ostr @ %co;
|
||||
%i++;
|
||||
}
|
||||
|
||||
return %ostr;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user