加载外部库模块化
This commit is contained in:
@@ -2,6 +2,66 @@ local gc=love.graphics
|
||||
local int=math.floor
|
||||
local sub,find,format=string.sub,string.find,string.format
|
||||
|
||||
do--LOADLIB
|
||||
local libName={
|
||||
CC={
|
||||
Windows="CCloader",
|
||||
Linux="CCloader",
|
||||
Android="libCCloader.so",
|
||||
libFunc="luaopen_CCloader",
|
||||
},
|
||||
NETlib={
|
||||
Windows="client",
|
||||
Linux="client",
|
||||
Android="client.so",
|
||||
libFunc="client",
|
||||
},
|
||||
}
|
||||
function LOADLIB(name)
|
||||
local libName=libName[name]
|
||||
if system=="Windows"or system=="Linux"then
|
||||
local success,message=require(libName[system])
|
||||
if success then
|
||||
LOG.print(name.." load successfully","warn",color.green)
|
||||
else
|
||||
LOG.print("Cannot load "..name..": "..message,"warn",color.red)
|
||||
end
|
||||
elseif system=="Android"then
|
||||
local fs=love.filesystem
|
||||
local platform={"arm64-v8a","armeabi-v7a"}
|
||||
local libFunc
|
||||
for i=1,#platform do
|
||||
local soFile,size=fs.read("data","libAndroid/"..platform[i].."/"..libName.Android)
|
||||
if soFile then
|
||||
local success,message=fs.write(libName.Android,soFile,size)
|
||||
if success then
|
||||
libFunc,message=package.loadlib(table.concat({fs.getSaveDirectory(),libName.Android},"/"),libName.libFunc)
|
||||
if libFunc then
|
||||
LOG.print(name.." lib loaded","warn",color.green)
|
||||
break
|
||||
else
|
||||
LOG.print("Cannot load "..name..": "..message,"warn",color.red)
|
||||
end
|
||||
else
|
||||
LOG.print("Write "..name.."-"..platform[i].." to saving failed: "..message,"warn",color.red)
|
||||
end
|
||||
else
|
||||
LOG.print("Read "..name.."-"..platform[i].." failed","warn",color.red)
|
||||
end
|
||||
end
|
||||
if not libFunc then
|
||||
LOG.print("failed to load "..name,"warn",color.red)
|
||||
return
|
||||
end
|
||||
LOG.print(name.." load successfully","warn",color.green)
|
||||
libFunc()
|
||||
else
|
||||
LOG.print("No "..name.." for "..system,"warn",color.red)
|
||||
return
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
do--setFont
|
||||
local newFont=gc.setNewFont
|
||||
local setNewFont=gc.setFont
|
||||
@@ -25,7 +85,6 @@ do--setFont
|
||||
end
|
||||
else
|
||||
function setFont(s)
|
||||
local f=fontCache[s]
|
||||
if s~=currentFontSize then
|
||||
if not fontCache[s]then
|
||||
fontCache[s]=newFont(s)
|
||||
@@ -92,17 +151,34 @@ do--dumpTable
|
||||
end
|
||||
do--HTTPrequest
|
||||
local http=require("socket.http")
|
||||
function HTTPrequest(url)
|
||||
function HTTPrequest(url,method)
|
||||
local data={}
|
||||
local res,code,response_headers,response_body=http.request{
|
||||
url=url,
|
||||
sink=ltn12.sink.table(data)
|
||||
sink=ltn12.sink.table(data),
|
||||
method=method or"GET",
|
||||
}
|
||||
if code~=200 then
|
||||
LOG.print("NET ERROR: code="..(code or"nil"))
|
||||
end
|
||||
return data[1]
|
||||
end
|
||||
--[[
|
||||
LOADLIB("NETlib")
|
||||
function HTTPrequest(url,method)
|
||||
local task,err=client.httpraw{
|
||||
url=url,
|
||||
method=method,
|
||||
-- header={},
|
||||
-- body="",
|
||||
}
|
||||
if not err then
|
||||
TASK.new(TICK.httpRequest,{code=task,time=0})
|
||||
else
|
||||
LOG.print("NET error: "..err,"error")
|
||||
end
|
||||
end
|
||||
]]
|
||||
end
|
||||
do--json
|
||||
--
|
||||
|
||||
55
parts/ai.lua
55
parts/ai.lua
@@ -16,59 +16,7 @@ local Timer=love.timer.getTime
|
||||
local blockPos={4,4,4,4,4,5,4}
|
||||
local scs={{0,1},{0,1},{0,1},{0,1},{0,1},{.5,.5},{-.5,1.5}}
|
||||
-------------------------------------------------Cold clear
|
||||
do
|
||||
local fs=love.filesystem
|
||||
if system=="Windows"then
|
||||
local success,message=require("CCloader")
|
||||
if success then
|
||||
LOG.print("CC load successfully","warn",color.green)
|
||||
else
|
||||
LOG.print("Cannot load CC: "..message,"warn",color.red)
|
||||
end
|
||||
if fs.getInfo("CCloader.dll")then
|
||||
NOGAME="delCC"
|
||||
end
|
||||
elseif system=="Linux"then
|
||||
local success,message=require("CCloader")
|
||||
if success then
|
||||
LOG.print("CC load successfully","warn",color.green)
|
||||
else
|
||||
LOG.print("Cannot load CC: "..message,"warn",color.red)
|
||||
end
|
||||
elseif system=="Android"then
|
||||
local armList={"arm64-v8a","armeabi-v7a"}
|
||||
local libFunc,success,message
|
||||
for i=1,#armList do
|
||||
local CCloader_f,size=fs.read("data","libAndroid/"..armList[i].."/libCCloader.so")
|
||||
if CCloader_f then
|
||||
LOG.print("Read CC-"..armList[i].." successfully","warn",color.green)
|
||||
success,message=fs.write("libCCloader.so",CCloader_f,size)
|
||||
if success then
|
||||
LOG.print("Write CC-"..armList[i].." to saving successfully","warn",color.green)
|
||||
libFunc,message=package.loadlib(table.concat({fs.getSaveDirectory(),"libCCloader.so"},"/"),"luaopen_CCloader")
|
||||
if libFunc then
|
||||
LOG.print("CC lib loaded","warn",color.green)
|
||||
break
|
||||
else
|
||||
LOG.print("Cannot load CC: "..message,"warn",color.red)
|
||||
end
|
||||
else
|
||||
LOG.print("Write CC-"..armList[i].." to saving failed","warn",color.red)
|
||||
end
|
||||
else
|
||||
LOG.print("Read CC-"..armList[i].." failed","warn",color.red)
|
||||
end
|
||||
end
|
||||
if not libFunc then
|
||||
LOG.print("failed to load CC","warn",color.red)
|
||||
goto FAILED
|
||||
end
|
||||
LOG.print("CC load successfully","warn",color.green)
|
||||
libFunc()
|
||||
else
|
||||
LOG.print("No CC for "..system,"warn",color.red)
|
||||
goto FAILED
|
||||
end
|
||||
if LOADLIB("CC")then
|
||||
local CCblockID={6,5,4,3,2,1,0}
|
||||
CC={
|
||||
getConf= cc.get_default_config ,--()options,weights
|
||||
@@ -135,7 +83,6 @@ do
|
||||
collectgarbage()
|
||||
end
|
||||
end
|
||||
::FAILED::
|
||||
-------------------------------------------------9 Stack setup
|
||||
local dirCount={1,1,3,3,3,0,1}
|
||||
local spinOffset={
|
||||
|
||||
Reference in New Issue
Block a user