Added some instance checks
This commit is contained in:
18
core.lua
18
core.lua
@@ -8,6 +8,10 @@ function Core:new()
|
||||
end
|
||||
|
||||
function Core:connect()
|
||||
if not self then
|
||||
error("No instance!")
|
||||
end
|
||||
|
||||
ws, err = assert(http.websocket("ws://192.168.5.162:8080"));
|
||||
|
||||
if not ws then
|
||||
@@ -20,6 +24,10 @@ function Core:connect()
|
||||
end
|
||||
|
||||
function Core:send(package)
|
||||
if not self then
|
||||
error("No instance!")
|
||||
end
|
||||
|
||||
if not package then
|
||||
return false, "Missing package";
|
||||
end
|
||||
@@ -32,14 +40,22 @@ function Core:send(package)
|
||||
end
|
||||
|
||||
function Core:read()
|
||||
if not self then
|
||||
error("No instance!")
|
||||
end
|
||||
|
||||
if not self.ws then
|
||||
return false, "Websocket not initiated";
|
||||
end
|
||||
|
||||
return true, textutils.unserialiseJSON(self.ws.read())
|
||||
return true, textutils.unserialiseJSON(self.ws.receive())
|
||||
end
|
||||
|
||||
function Core:download(file)
|
||||
if not self then
|
||||
error("No instance!")
|
||||
end
|
||||
|
||||
if not self.ws then
|
||||
return false, "Websocket not initiated";
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user