完善入口

This commit is contained in:
baidwwy 2021-04-05 05:46:44 +08:00
parent 5b9d5ab4e8
commit d78c306ea3
6 changed files with 41 additions and 14 deletions

View File

@ -4,8 +4,7 @@
@LastEditTime : 2021-03-20 10:21:51 @LastEditTime : 2021-03-20 10:21:51
--]] --]]
io.stdout:setvbuf('no',0) io.stdout:setvbuf('no',0)
local ggelua = require("ggelua")
local gge = assert(package.loadlib("ggelua", "luaopen_ggelua"),'加载"ggelua.dll"失败')()
local entry,data,nstate = ... local entry,data,nstate = ...
local function 分割路径(path) local function 分割路径(path)
@ -16,17 +15,21 @@ local function 分割路径(path)
end end
return t return t
end end
--lua脚本搜索
local lpath = "?.lua;lua/?.lua;lua/?/?.lua;!/lua/?.lua;!/lua/?/?.lua"
lpath = lpath:gsub('!',gge.getrunpath())
lpath_ = (lpath)
--lua模块搜索
local cpath = "?.dll;lib/?.dll;!/?.dll;!/lib/?.dll"
if gge.getplatform()=='Android' then--安卓模块加 lib?
cpath = "lib?.dll;lib/lib?.dll;!/lib?.dll;!/lib/lib?.dll"
end
cpath = cpath:gsub('!',gge.getrunpath())
local lpath,lpath_,cpath
if gge.platform=='Windows' then
--lua脚本搜索
lpath = "?.lua;lua/?.lua;lua/?/?.lua;!/lua/?.lua;!/lua/?/?.lua"
lpath = lpath:gsub('!',gge.getrunpath())
lpath_ = (lpath)
--lua模块搜索
cpath = "?.dll;lib/?.dll;!/?.dll;!/lib/?.dll"
cpath = cpath:gsub('!',gge.getrunpath())
elseif gge.platform=='Android' then
lpath = "?.lua;lua/?.lua;lua/?/?.lua"
lpath_ = (lpath)
cpath = gge.arg[1].."/lib?.so"
end
package.path = nil package.path = nil
package.cpath = nil package.cpath = nil
@ -54,6 +57,9 @@ local m_unpack = require("cmsgpack.safe").unpack
if data then if data then
data = m_unpack(data) data = m_unpack(data)
elseif gge.platform=='Android' then
error("找不到脚本")
return
end end
local function 处理路径(path) local function 处理路径(path)

View File

@ -187,7 +187,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
* @return arguments for the native application. * @return arguments for the native application.
*/ */
protected String[] getArguments() { protected String[] getArguments() {
return new String[0]; return new String[]{getApplicationInfo().nativeLibraryDir};
} }
public static void initialize() { public static void initialize() {

View File

@ -227,6 +227,9 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\lib\ggelua\ggelua.vcxproj">
<Project>{e35e2816-7594-4b05-b684-12b97e4bfd20}</Project>
</ProjectReference>
<ProjectReference Include="..\..\lua\lua.vcxproj"> <ProjectReference Include="..\..\lua\lua.vcxproj">
<Project>{8481f772-bc91-4032-8682-09809ef70942}</Project> <Project>{8481f772-bc91-4032-8682-09809ef70942}</Project>
</ProjectReference> </ProjectReference>

View File

@ -176,6 +176,9 @@
<ProjectReference Include="..\..\dep\zlib\zlib.vcxproj"> <ProjectReference Include="..\..\dep\zlib\zlib.vcxproj">
<Project>{5fca3894-feb8-4c7f-b5fa-baff2e69f619}</Project> <Project>{5fca3894-feb8-4c7f-b5fa-baff2e69f619}</Project>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\lib\ggelua\ggelua.vcxproj">
<Project>{4f7b97f6-1b8f-416c-a987-8dba9b105f5d}</Project>
</ProjectReference>
<ProjectReference Include="..\..\lua\lua.vcxproj"> <ProjectReference Include="..\..\lua\lua.vcxproj">
<Project>{0ffa55d6-c072-4ba9-a5ea-f08cffe7d641}</Project> <Project>{0ffa55d6-c072-4ba9-a5ea-f08cffe7d641}</Project>
</ProjectReference> </ProjectReference>

View File

@ -175,6 +175,9 @@
<ProjectReference Include="..\..\dep\zlib\zlib.vcxproj"> <ProjectReference Include="..\..\dep\zlib\zlib.vcxproj">
<Project>{5fca3894-feb8-4c7f-b5fa-baff2e69f619}</Project> <Project>{5fca3894-feb8-4c7f-b5fa-baff2e69f619}</Project>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\lib\ggelua\ggelua.vcxproj">
<Project>{4f7b97f6-1b8f-416c-a987-8dba9b105f5d}</Project>
</ProjectReference>
<ProjectReference Include="..\..\lua\lua.vcxproj"> <ProjectReference Include="..\..\lua\lua.vcxproj">
<Project>{0ffa55d6-c072-4ba9-a5ea-f08cffe7d641}</Project> <Project>{0ffa55d6-c072-4ba9-a5ea-f08cffe7d641}</Project>
</ProjectReference> </ProjectReference>

View File

@ -7,7 +7,10 @@
#include "SDL_rwops.h" #include "SDL_rwops.h"
#include "SDL_main.h" #include "SDL_main.h"
#include "SDL_log.h" #include "SDL_log.h"
#include "SDL_system.h"
#include "SDL_platform.h"
int luaopen_ggelua(lua_State* L);
struct INFO { struct INFO {
unsigned int signal; unsigned int signal;
unsigned int coresize; unsigned int coresize;
@ -98,11 +101,12 @@ int SDL_main(int argc, char* argv[])
luaL_getsubtable(L, LUA_REGISTRYINDEX, "_ggelua"); luaL_getsubtable(L, LUA_REGISTRYINDEX, "_ggelua");
lua_createtable(L, argc, 0); lua_createtable(L, argc, 0);
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
lua_pushstring(L, argv[i]); lua_pushstring(L, argv[i]);
lua_seti(L, -2, i); lua_seti(L, -2, i);
} }
lua_setfield(L, -2, "arg");//gge.arg lua_setfield(L, -2, "arg");//gge.arg
#ifdef _CONSOLE #ifdef _CONSOLE
lua_pushboolean(L, 1); lua_pushboolean(L, 1);
#else #else
@ -123,15 +127,23 @@ int SDL_main(int argc, char* argv[])
lua_setfield(L, -2, "entry");//gge.entry lua_setfield(L, -2, "entry");//gge.entry
lua_pushboolean(L, 1); lua_pushboolean(L, 1);
lua_setfield(L, -2, "ismain");//gge.ismain lua_setfield(L, -2, "ismain");//gge.ismain
lua_pushstring(L, SDL_GetPlatform());
lua_setfield(L, -2, "platform");//gge.platform
lua_setglobal(L, "gge"); lua_setglobal(L, "gge");
SDL_mutex **extra = (SDL_mutex **)lua_getextraspace(L);//线程锁 SDL_mutex **extra = (SDL_mutex **)lua_getextraspace(L);//线程锁
SDL_mutex*mutex = SDL_CreateMutex(); SDL_mutex*mutex = SDL_CreateMutex();
*extra = mutex; *extra = mutex;
lua_getfield(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);//package.preload
lua_pushcfunction(L, luaopen_ggelua);
lua_setfield(L, -2, "ggelua");
lua_pop(L, 1);
if (lua_getfield(L, LUA_REGISTRYINDEX, "ggelua.lua")==LUA_TSTRING){ if (lua_getfield(L, LUA_REGISTRYINDEX, "ggelua.lua")==LUA_TSTRING){
size_t coresize; size_t coresize;
const char* ggelua = lua_tolstring(L, -1, &coresize); const char* ggelua = lua_tolstring(L, -1, &coresize);
lua_pop(L, 1);
SDL_LockMutex(mutex);//ggelua.delay解锁 SDL_LockMutex(mutex);//ggelua.delay解锁
if (luaL_loadbuffer(L,ggelua,coresize,"ggelua.lua")== LUA_OK){ if (luaL_loadbuffer(L,ggelua,coresize,"ggelua.lua")== LUA_OK){