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