Update 'Controller/wheatController.lua'
This commit is contained in:
parent
9aef0bdabe
commit
23b1baef84
@ -1,3 +1,13 @@
|
|||||||
|
wheatController = {}
|
||||||
|
|
||||||
|
function wheatController:new(t)
|
||||||
|
t = t or {}
|
||||||
|
setmetatable(t, self)
|
||||||
|
self.__index = self
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function toMatrix(str)
|
function toMatrix(str)
|
||||||
local matrix = {}
|
local matrix = {}
|
||||||
assert(type(str) == "string")
|
assert(type(str) == "string")
|
||||||
@ -10,10 +20,27 @@ function toMatrix(str)
|
|||||||
|
|
||||||
str = str:sub(2, len - 1)
|
str = str:sub(2, len - 1)
|
||||||
len = len - 2
|
len = len - 2
|
||||||
|
if ob = 1 then
|
||||||
if(str:sub(1,1) == "{") then
|
return toArray(str)
|
||||||
|
else
|
||||||
|
local level = 0
|
||||||
|
local lastC = 0
|
||||||
|
for i = 1, len do
|
||||||
|
local c = str:sub(i,i)
|
||||||
|
if c == "{" then
|
||||||
|
level = level + 1
|
||||||
|
elseif c == "}" then
|
||||||
|
level = level - 1
|
||||||
|
elseif c == "," then
|
||||||
|
if level == 0 then
|
||||||
|
matrix[#matrix+1] = toMatrix(str:sub(lastC + 1, i - 1))
|
||||||
|
lastC = i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return matrix
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function toArray(str)
|
function toArray(str)
|
||||||
@ -30,4 +57,23 @@ function toArray(str)
|
|||||||
arr[#arr+1] = str
|
arr[#arr+1] = str
|
||||||
end
|
end
|
||||||
return arr
|
return arr
|
||||||
|
end
|
||||||
|
|
||||||
|
function wheatController:sendMessage(id, message, protocol)
|
||||||
|
rednet.send(id, message, protocol)
|
||||||
|
local id2, message2 = rednet.receive("received", 1)
|
||||||
|
return message == message2
|
||||||
|
end
|
||||||
|
|
||||||
|
function wheatController:doAction(id, message, protocol)
|
||||||
|
self:sendMessage(id, message, protocol)
|
||||||
|
local id2, message2, protocol2
|
||||||
|
repeat
|
||||||
|
id2, message2, protocol2 = rednet.receive()
|
||||||
|
until id2 == id
|
||||||
|
return protocol2 == "confirm", message2
|
||||||
|
end
|
||||||
|
|
||||||
|
function wheatController:setSlaveID(id)
|
||||||
|
self.slaveID = id
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user