diff options
author | Jeija <norrepli@gmail.com> | 2012-08-10 10:47:40 +0200 |
---|---|---|
committer | Jeija <norrepli@gmail.com> | 2012-08-10 10:47:40 +0200 |
commit | ce72ed2babec7cfc5f650e4e240e6d94a79e704e (patch) | |
tree | 9be7f9699fa008f27a255db3d96417c847cacfb6 | |
parent | 6a524b8cdd45fc73d8aeed66347e57c81621fb78 (diff) | |
download | mesecons-ce72ed2babec7cfc5f650e4e240e6d94a79e704e.tar mesecons-ce72ed2babec7cfc5f650e4e240e6d94a79e704e.tar.gz mesecons-ce72ed2babec7cfc5f650e4e240e6d94a79e704e.tar.bz2 mesecons-ce72ed2babec7cfc5f650e4e240e6d94a79e704e.tar.xz mesecons-ce72ed2babec7cfc5f650e4e240e6d94a79e704e.zip |
Add print command print(string in quotes or condition, can be concatenated using comma)
-rw-r--r-- | mesecons_microcontroller/init.lua | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index 530a2cf..74c1366 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -141,8 +141,12 @@ end --Code Parsing function yc_code_remove_commentary(code) + is_string = false for i = 1, #code do - if code:sub(i, i) == ":" then + if code:sub(i, i) == '"' then + is_string = (is_string==false) --toggle is_string + end + if code:sub(i, i) == ":" and is_string==false then return code:sub(1, i-1) end end @@ -181,6 +185,9 @@ function parse_yccode(code, pos) L = yc_command_on (params, Lvirtual) elseif command == "off" then L = yc_command_off(params, Lvirtual) + elseif command == "print" then + su = yc_command_print(params, eeprom, yc_merge_portstates(Lreal, Lvirtual)) + if su ~= true then return nil end elseif command == "sbi" then new_eeprom, Lvirtual = yc_command_sbi (params, eeprom, yc_merge_portstates(Lreal, Lvirtual), Lvirtual) if new_eeprom == nil then return nil @@ -227,13 +234,17 @@ function parse_get_params(code, starti) i = starti s = nil local params = {} + local is_string = false while s ~= "" do s = string.sub(code, i, i) - if s == ")" then + if code:sub(i, i) == '"' then + is_string = (is_string==false) --toggle is_string + end + if s == ")" and is_string == false then table.insert(params, string.sub(code, starti, i-1)) -- i: ) i+1 after ) return params, i + 1 end - if s == "," then + if s == "," and is_string == false then table.insert(params, string.sub(code, starti, i-1)) -- i: ) i+1 after ) starti = i + 1 end @@ -315,6 +326,22 @@ function yc_command_off(params, L) return L end +function yc_command_print(params, eeprom, L) + local s = "" + for i, param in ipairs(params) do + if param:sub(1,1) == '"' and param:sub(#param, #param) == '"' then + s = s..param:sub(2, #param-1) + else + r = yc_command_parsecondition(param, L, eeprom) + if r == "1" or r == "0" then + s = s..r + else return nil end + end + end + print(s) --don't remove + return true +end + function yc_command_sbi(params, eeprom, L, Lv) if params[1]==nil or params[2]==nil or params[3] ~=nil then return nil end local status = yc_command_parsecondition(params[2], L, eeprom) |