修改loadLib用法,准备更换联网模块
This commit is contained in:
@@ -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"
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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,22 +19,16 @@ 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
|
else
|
||||||
LOG.print("NETlib error: "..err,"warn")
|
function httpRequest()
|
||||||
|
LOG.print("[NO NETlib for "..SYSTEM.."]",5,COLOR.yellow)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
TASK.netTaskCount=TASK.netTaskCount+1
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,11 +44,3 @@ if client then
|
|||||||
LOG.print(text.wsNoConn,"warn")
|
LOG.print(text.wsNoConn,"warn")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
local function noNetLib()
|
|
||||||
LOG.print("[NO NETlib for "..SYSTEM.."]",5,COLOR.yellow)
|
|
||||||
end
|
|
||||||
httpRequest=noNetLib
|
|
||||||
wsConnect=noNetLib
|
|
||||||
wsWrite=noNetLib
|
|
||||||
end
|
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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={
|
||||||
|
|||||||
Reference in New Issue
Block a user