mirror of https://github.com/axmolengine/axmol.git
Improve lua framework code
This commit is contained in:
parent
f6e87217bf
commit
a524d61036
|
@ -185,10 +185,6 @@ if(WINDOWS)
|
||||||
target_compile_definitions(${ENGINEX_LUA_LIB} PUBLIC _USRLUASTATIC)
|
target_compile_definitions(${ENGINEX_LUA_LIB} PUBLIC _USRLUASTATIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(${ENGINEX_LUA_LIB}
|
|
||||||
PUBLIC LUA_COMPAT_MODULE
|
|
||||||
)
|
|
||||||
|
|
||||||
set_target_properties(${ENGINEX_LUA_LIB}
|
set_target_properties(${ENGINEX_LUA_LIB}
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||||
|
|
|
@ -69,8 +69,7 @@ namespace {
|
||||||
size_t sz;
|
size_t sz;
|
||||||
s = lua_tolstring(L, -1, &sz); /* get result */
|
s = lua_tolstring(L, -1, &sz); /* get result */
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return luaL_error(L, LUA_QL("tostring") " must return a string to "
|
return luaL_error(L, "'tostring' must return a string to 'print'");
|
||||||
LUA_QL("print"));
|
|
||||||
if (i>1) out->append("\t");
|
if (i>1) out->append("\t");
|
||||||
out->append(s, sz);
|
out->append(s, sz);
|
||||||
lua_pop(L, 1); /* pop result */
|
lua_pop(L, 1); /* pop result */
|
||||||
|
@ -189,10 +188,16 @@ void LuaStack::addLuaLoader(lua_CFunction func)
|
||||||
{
|
{
|
||||||
if (!func) return;
|
if (!func) return;
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM >= 504 || (LUA_VERSION_NUM >= 502 && !defined(LUA_COMPAT_LOADERS))
|
||||||
|
const char* realname = "searchers";
|
||||||
|
#else
|
||||||
|
const char* realname = "loaders";
|
||||||
|
#endif
|
||||||
|
|
||||||
// stack content after the invoking of the function
|
// stack content after the invoking of the function
|
||||||
// get loader table
|
// get loader table
|
||||||
lua_getglobal(_state, "package"); /* L: package */
|
lua_getglobal(_state, "package"); /* L: package */
|
||||||
lua_getfield(_state, -1, "loaders"); /* L: package, loaders */
|
lua_getfield(_state, -1, realname); /* L: package, loaders */
|
||||||
|
|
||||||
// insert loader into index 2
|
// insert loader into index 2
|
||||||
lua_pushcfunction(_state, func); /* L: package, loaders, func */
|
lua_pushcfunction(_state, func); /* L: package, loaders, func */
|
||||||
|
@ -205,7 +210,7 @@ void LuaStack::addLuaLoader(lua_CFunction func)
|
||||||
lua_rawseti(_state, -2, 2); /* L: package, loaders */
|
lua_rawseti(_state, -2, 2); /* L: package, loaders */
|
||||||
|
|
||||||
// set loaders into package
|
// set loaders into package
|
||||||
lua_setfield(_state, -2, "loaders"); /* L: package */
|
lua_setfield(_state, -2, realname); /* L: package */
|
||||||
|
|
||||||
lua_pop(_state, 1);
|
lua_pop(_state, 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue