修改loadLib用法,准备更换联网模块

This commit is contained in:
MrZ626
2021-02-16 16:54:30 +08:00
parent 35f62f1636
commit 5943970312
5 changed files with 36 additions and 73 deletions

View File

@@ -2,11 +2,11 @@ SCR= require"Zframework/screen"
COLOR= require"Zframework/color" COLOR= require"Zframework/color"
SCN= require"Zframework/scene" SCN= require"Zframework/scene"
LOG= require"Zframework/log" LOG= require"Zframework/log"
WS= require"Zframework/websocket"
require"Zframework/loadLib" loadLib=require"Zframework/loadLib"
require"Zframework/wheelScroll" require"Zframework/wheelScroll"
require"Zframework/network" require"Zframework/network"
-- require"Zframework/websocket"
require"Zframework/setFont" require"Zframework/setFont"
require"Zframework/mDraw" require"Zframework/mDraw"

View File

@@ -1,19 +1,4 @@
local libs={ return function(name,libName)
CC={
Windows="CCloader",
Linux="CCloader",
Android="libCCloader.so",
libFunc="luaopen_CCloader",
},
NETlib={
Windows="client",
Linux="client",
Android="client.so",
libFunc="luaopen_client",
},
}
function loadLib(name)
local libName=libs[name]
if SYSTEM=="Windows"or SYSTEM=="Linux"then if SYSTEM=="Windows"or SYSTEM=="Linux"then
local r1,r2,r3=pcall(require,libName[SYSTEM]) local r1,r2,r3=pcall(require,libName[SYSTEM])
if r1 and r2 then if r1 and r2 then

View File

@@ -1,4 +1,9 @@
client=loadLib("NETlib") client=loadLib("NETlib",{
Windows="client",
Linux="client",
Android="client.so",
libFunc="luaopen_client",
})
if client then if client then
function httpRequest(tick,path,method,header,body) function httpRequest(tick,path,method,header,body)
local task,err=client.httpraw{ local task,err=client.httpraw{
@@ -14,42 +19,28 @@ if client then
end end
TASK.netTaskCount=TASK.netTaskCount+1 TASK.netTaskCount=TASK.netTaskCount+1
end end
function wsConnect(tick,path,header)
if TASK.wsConnecting then
LOG.print(text.waitNetTask,"message")
return
end
local task,err=client.wsraw{
url="ws://"..PATH.url..":"..PATH.port..path,
origin=PATH.url,
header=header,
}
if task then
TASK.newWS(tick,task)
else
LOG.print("NETlib error: "..err,"warn")
end
TASK.netTaskCount=TASK.netTaskCount+1
end
function wsWrite(data)
if WSCONN then
local writeErr=client.write(WSCONN,data)
if writeErr then
LOG.print(writeErr,"error")
return
end
return true
else
LOG.print(text.wsNoConn,"warn")
end
end
else else
local function noNetLib() function httpRequest()
LOG.print("[NO NETlib for "..SYSTEM.."]",5,COLOR.yellow) LOG.print("[NO NETlib for "..SYSTEM.."]",5,COLOR.yellow)
end end
httpRequest=noNetLib end
wsConnect=noNetLib
wsWrite=noNetLib function wsConnect(path,body)
local ws=WS.new()
ws:settimeout(6.26)
ws:connect(PATH.url..":"..PATH.port,path,body)
TASK.netTaskCount=TASK.netTaskCount+1
end
function wsWrite(data)
if WSCONN then
local writeErr=client.write(WSCONN,data)
if writeErr then
LOG.print(writeErr,"error")
return
end
return true
else
LOG.print(text.wsNoConn,"warn")
end
end end

View File

@@ -5,7 +5,6 @@ local tasks={}
local TASK={ local TASK={
netTaskCount=0, netTaskCount=0,
wsConnecting=false,
} }
function TASK.getCount() function TASK.getCount()
return #tasks return #tasks
@@ -18,9 +17,6 @@ function TASK.update()
if T.net then if T.net then
TASK.netTaskCount=TASK.netTaskCount-1 TASK.netTaskCount=TASK.netTaskCount-1
end end
if T.ws then
TASK.wsConnecting=false
end
rem(tasks,i) rem(tasks,i)
end end
end end
@@ -48,20 +44,6 @@ function TASK.newNet(code,...)
} }
end end
end end
function TASK.newWS(code,...)
TASK.wsConnecting=true
local thread=ct.create(code)
ct.resume(thread,...)
if ct.status(thread)~="dead"then
tasks[#tasks+1]={
thread=thread,
code=code,
args={...},
net=true,
ws=true,
}
end
end
function TASK.removeTask_code(code) function TASK.removeTask_code(code)
for i=#tasks,1,-1 do for i=#tasks,1,-1 do
if tasks[i].code==code then if tasks[i].code==code then

View File

@@ -14,7 +14,12 @@ local ins,rem=table.insert,table.remove
-- 11~13:LL,RR,DD -- 11~13:LL,RR,DD
local blockPos={4,4,4,4,4,5,4} local blockPos={4,4,4,4,4,5,4}
-------------------------------------------------Cold clear -------------------------------------------------Cold clear
local _CC=loadLib("CC")cc=nil local _CC=loadLib("CC",{
Windows="CCloader",
Linux="CCloader",
Android="libCCloader.so",
libFunc="luaopen_CCloader",
})cc=nil
if _CC then if _CC then
local CCblockID={6,5,4,3,2,1,0} local CCblockID={6,5,4,3,2,1,0}
CC={ CC={