mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
Add Network draft. Format Vector
This commit is contained in:
parent
81d5a2a80e
commit
1d37ecf526
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.exe
|
||||
|
59
libnetwork.lua
Normal file
59
libnetwork.lua
Normal file
|
@ -0,0 +1,59 @@
|
|||
function socket() -- Allocate a new socket
|
||||
|
||||
end
|
||||
|
||||
function connect(sfd,remote_tag,port) -- Connect to a remote device
|
||||
|
||||
end
|
||||
|
||||
function bind(sfd,port) -- Bind socket at specific port
|
||||
|
||||
end
|
||||
|
||||
function listen(sfd,sz) -- Set size of queue for waiting connections
|
||||
|
||||
end
|
||||
|
||||
function accept(sfd) -- Accept Connection
|
||||
|
||||
end
|
||||
|
||||
function send(sfd,...) -- Standard Network I/O
|
||||
|
||||
end
|
||||
|
||||
function recv(sfd) -- Standard Network I/O
|
||||
|
||||
end
|
||||
|
||||
function shutdown(sfd) -- Close Socket
|
||||
|
||||
end
|
||||
|
||||
function close(sfd) -- Close Socket
|
||||
|
||||
end
|
||||
|
||||
function do_dhcp_client() -- Connect to DHCP Server and try to get a tag.
|
||||
|
||||
end
|
||||
|
||||
function do_arp_broadcast() -- ARP: Broadcast tag and uuid information of this device
|
||||
|
||||
end
|
||||
|
||||
function arp_listener() -- ARP: Listen to arp broadcast and record informations. Notice that this listener also replies to specific arp-request
|
||||
|
||||
end
|
||||
|
||||
function do_arp_query() -- ARP: Query uuid with tag, will send arp-request
|
||||
|
||||
end
|
||||
|
||||
function run_arp() -- Start ARP Services in background
|
||||
|
||||
end
|
||||
|
||||
function run_dhcp_client() -- Start DHCP Client in background
|
||||
|
||||
end
|
48
vector.lua
48
vector.lua
|
@ -29,7 +29,8 @@ self.sz=self.sz+1
|
|||
end
|
||||
|
||||
function Vector:pop_back()
|
||||
if(self:empty()) then return nil
|
||||
if (self:empty()) then
|
||||
return nil
|
||||
else
|
||||
local val = self.bus[self.sz - 1]
|
||||
self.bus[self.sz - 1] = nil
|
||||
|
@ -39,14 +40,18 @@ end
|
|||
end
|
||||
|
||||
function Vector:front()
|
||||
if(self:empty()) then return nil
|
||||
else return self.bus[0]
|
||||
if (self:empty()) then
|
||||
return nil
|
||||
else
|
||||
return self.bus[0]
|
||||
end
|
||||
end
|
||||
|
||||
function Vector:back()
|
||||
if(self:empty()) then return nil
|
||||
else return self.bus[self.sz-1]
|
||||
if (self:empty()) then
|
||||
return nil
|
||||
else
|
||||
return self.bus[self.sz - 1]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -55,11 +60,16 @@ self:_reset()
|
|||
end
|
||||
|
||||
function Vector:at(index)
|
||||
if(type(index) ~= "number") then return nil
|
||||
elseif(self:empty()) then return nil
|
||||
elseif(index<0) then return nil
|
||||
elseif(index>=self.sz) then return nil
|
||||
else return self.bus[index]
|
||||
if (type(index) ~= "number") then
|
||||
return nil
|
||||
elseif (self:empty()) then
|
||||
return nil
|
||||
elseif (index < 0) then
|
||||
return nil
|
||||
elseif (index >= self.sz) then
|
||||
return nil
|
||||
else
|
||||
return self.bus[index]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,9 +78,12 @@ return self.sz
|
|||
end
|
||||
|
||||
function Vector:insert_after(index, val)
|
||||
if(type(index) ~= "number") then return nil
|
||||
elseif(index>=self.sz) then return nil
|
||||
elseif(index<-1) then return nil
|
||||
if (type(index) ~= "number") then
|
||||
return nil
|
||||
elseif (index >= self.sz) then
|
||||
return nil
|
||||
elseif (index < -1) then
|
||||
return nil
|
||||
else
|
||||
for i = self.sz - 1, index + 1, -1 do
|
||||
self.bus[i + 1] = self.bus[i]
|
||||
|
@ -81,9 +94,12 @@ end
|
|||
end
|
||||
|
||||
function Vector:erase(index)
|
||||
if(type(index) ~= "number") then return nil
|
||||
elseif(index>=self.sz) then return nil
|
||||
elseif(index<0) then return nil
|
||||
if (type(index) ~= "number") then
|
||||
return nil
|
||||
elseif (index >= self.sz) then
|
||||
return nil
|
||||
elseif (index < 0) then
|
||||
return nil
|
||||
else
|
||||
for i = index + 1, self.sz - 1, 1 do
|
||||
self.bus[i - 1] = self.bus[i]
|
||||
|
|
Loading…
Reference in New Issue
Block a user