Fix some variables being non-local
Signed-off-by: Rahix <rahix@rahix.de>
This commit is contained in:
parent
9c32c826ea
commit
c3ce5b0ac8
1 changed files with 12 additions and 13 deletions
25
bc.lua
25
bc.lua
|
|
@ -1,8 +1,8 @@
|
||||||
event = require("event")
|
local event = require("event")
|
||||||
modem = require("component").modem
|
local modem = require("component").modem
|
||||||
serializer = require("serialization")
|
local serializer = require("serialization")
|
||||||
|
|
||||||
List = {last = -1}
|
local List = {last = -1}
|
||||||
|
|
||||||
function List:new()
|
function List:new()
|
||||||
local o = {}
|
local o = {}
|
||||||
|
|
@ -42,7 +42,7 @@ function List:remove(id)
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
||||||
message_type = {
|
local message_type = {
|
||||||
request_noun = 1,
|
request_noun = 1,
|
||||||
call_verb = 2,
|
call_verb = 2,
|
||||||
noun_response = 3,
|
noun_response = 3,
|
||||||
|
|
@ -54,13 +54,13 @@ message_type = {
|
||||||
listener_update = 9,
|
listener_update = 9,
|
||||||
}
|
}
|
||||||
|
|
||||||
CFG_PORT = 1234
|
local CFG_PORT = 1234
|
||||||
|
|
||||||
bc = {}
|
local bc = {}
|
||||||
|
|
||||||
function bc:init(local_nouns, local_verbs)
|
function bc:init(local_nouns, local_verbs)
|
||||||
local_nouns = local_nouns or {}
|
local local_nouns = local_nouns or {}
|
||||||
local_verbs = local_verbs or {}
|
local local_verbs = local_verbs or {}
|
||||||
local o = {}
|
local o = {}
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
@ -71,11 +71,10 @@ function bc:init(local_nouns, local_verbs)
|
||||||
o.listening_remotes = {}
|
o.listening_remotes = {}
|
||||||
-- Modem listener
|
-- Modem listener
|
||||||
function modem_listener(moden_msg, localAddress, remoteAddress, port, dist, message)
|
function modem_listener(moden_msg, localAddress, remoteAddress, port, dist, message)
|
||||||
dbg = message
|
local message = serializer.unserialize(message)
|
||||||
message = serializer.unserialize(message)
|
|
||||||
if port == CFG_PORT then
|
if port == CFG_PORT then
|
||||||
if message.ty == message_type.request_noun then
|
if message.ty == message_type.request_noun then
|
||||||
msg = {ty=message_type.noun_response,
|
local msg = {ty=message_type.noun_response,
|
||||||
noun=message.noun,
|
noun=message.noun,
|
||||||
value=o.local_nouns[message.noun]
|
value=o.local_nouns[message.noun]
|
||||||
}
|
}
|
||||||
|
|
@ -161,7 +160,7 @@ function bc:get_noun(n)
|
||||||
while i < 5 do
|
while i < 5 do
|
||||||
local _, _, remoteAddr, port, _, msg = event.pull("modem_message")
|
local _, _, remoteAddr, port, _, msg = event.pull("modem_message")
|
||||||
if port == CFG_PORT and remoteAddr == self.remote_nouns[n] then
|
if port == CFG_PORT and remoteAddr == self.remote_nouns[n] then
|
||||||
message = serializer.unserialize(msg)
|
local message = serializer.unserialize(msg)
|
||||||
if message.ty == message_type.noun_response and message.noun == n then
|
if message.ty == message_type.noun_response and message.noun == n then
|
||||||
return message.value
|
return message.value
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue