Added some instance checks

This commit is contained in:
2025-05-06 13:52:37 +02:00
parent d339ddf0a2
commit 13a0d4dbaf

View File

@@ -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