mirror of https://github.com/axmolengine/axmol.git
Merge pull request #257 from wtfdnvxk/patch-1
extend lua by register extensions
This commit is contained in:
commit
0a410dbf7f
|
@ -1,5 +1,6 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2020 c4games.com.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
|
@ -21,6 +22,7 @@
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include "lua.hpp"
|
||||
|
||||
#include "scripting/lua-bindings/manual/lua_module_register.h"
|
||||
|
||||
|
@ -33,20 +35,29 @@
|
|||
#include "scripting/lua-bindings/manual/audioengine/lua_cocos2dx_audioengine_manual.h"
|
||||
#include "scripting/lua-bindings/manual/physics3d/lua_cocos2dx_physics3d_manual.h"
|
||||
#include "scripting/lua-bindings/manual/navmesh/lua_cocos2dx_navmesh_manual.h"
|
||||
|
||||
#include "scripting/lua-bindings/lua-cjson/lua_cjson.h"
|
||||
|
||||
#if defined(CC_ENABLE_YASIO_LUA)
|
||||
#include "yasio/bindings/yasio_cclua.h"
|
||||
#endif
|
||||
|
||||
static void lua_register_extensions(lua_State* L) {
|
||||
|
||||
static luaL_Reg lua_exts[] = {
|
||||
{"yasio", luaopen_yasio_cclua},
|
||||
{"cjson", luaopen_cjson},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
lua_getglobal(L, "package");
|
||||
lua_getfield(L, -1, "preload");
|
||||
auto lib = lua_exts;
|
||||
for (; lib->func; ++lib) {
|
||||
lua_pushcfunction(L, lib->func);
|
||||
lua_setfield(L, -2, lib->name);
|
||||
}
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
int lua_module_register(lua_State* L)
|
||||
{
|
||||
luaopen_cjson(L);
|
||||
#if defined(CC_ENABLE_YASIO_LUA)
|
||||
luaopen_yasio_cclua(L);
|
||||
#endif
|
||||
// Don't change the module register order unless you know what your are doing
|
||||
register_network_module(L);
|
||||
register_cocostudio_module(L);
|
||||
|
@ -62,6 +73,9 @@ int lua_module_register(lua_State* L)
|
|||
#if CC_USE_NAVMESH
|
||||
register_navmesh_module(L);
|
||||
#endif
|
||||
|
||||
// register extensions: yaiso, lua-cjson
|
||||
lua_register_extensions(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue