Exemplo n.º 1
0
struct game* seal_load_game_config() {
    GAME = (struct game*)s_malloc(sizeof(struct game));
    // lua modules
    lua_State* L = seal_new_lua();
    luaopen_lua_extensions(L);
    GAME->lstate = L;
    
    // load the game settings from config.lua
    seal_load_file("scripts/config.lua");
    lua_getglobal(L, "APP_NAME");
    lua_getglobal(L, "WINDOW_WIDTH");
    lua_getglobal(L, "WINDOW_HEIGHT");
    lua_getglobal(L, "NK_GUI_FONT_PATH");
    lua_getglobal(L, "NK_GUI_FONT_SIZE");
    
    struct game_config* config = &GAME->config;
    config->app_name = lua_tostring(L, 1);
    config->window_width = lua_tonumber(L, 2);
    config->window_height = lua_tonumber(L, 3);
    config->nk_gui_font_path = lua_tostring(L, 4);
    config->nk_gui_font_size = lua_tonumber(L, 5);
    
    lua_pop(L, 5);
    
    GAME->window = win_alloc();

    return GAME;
}
Exemplo n.º 2
0
bool LuaStack::init(void)
{
    _state = lua_open();
    luaL_openlibs(_state);
    toluafix_open(_state);

    // Register our version of the global "print" function
    const luaL_reg global_functions [] = {
        {"print", lua_print},
        {NULL, NULL}
    };
    luaL_register(_state, "_G", global_functions);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    luaopen_lua_extensions(_state);
#endif
    g_luaType.clear();
    register_all_cocos2dx(_state);
    register_all_cocos2dx_extension(_state);
    register_cocos2dx_extension_CCBProxy(_state);
    tolua_opengl_open(_state);
    register_all_cocos2dx_ui(_state);
    register_all_cocos2dx_studio(_state);
    register_all_cocos2dx_manual(_state);
    register_all_cocos2dx_module_manual(_state);
    register_all_cocos2dx_extension_manual(_state);
    register_all_cocos2dx_coco_studio_manual(_state);
    register_all_cocos2dx_ui_manual(_state);
    register_all_cocos2dx_spine(_state);
    register_all_cocos2dx_spine_manual(_state);
    register_glnode_manual(_state);
#if CC_USE_PHYSICS
    register_all_cocos2dx_physics(_state);
    register_all_cocos2dx_physics_manual(_state);
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    LuaObjcBridge::luaopen_luaoc(_state);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    LuaJavaBridge::luaopen_luaj(_state);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    tolua_web_socket_open(_state);
    register_web_socket_manual(_state);
#endif

    register_xml_http_request(_state);
    register_all_cocos2dx_deprecated(_state);
    register_all_cocos2dx_manual_deprecated(_state);

    tolua_script_handler_mgr_open(_state);

    // add cocos2dx loader
    addLuaLoader(cocos2dx_lua_loader);

    return true;
}
int register_network_module(lua_State* L)
{
    lua_getglobal(L, "_G");
    if (lua_istable(L,-1))//stack:...,_G,
    {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
        luaopen_lua_extensions(L);
#endif
        
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
        tolua_web_socket_open(L);
        register_web_socket_manual(L);
#endif

#if CC_USE_CURL        
        register_xml_http_request(L);
#endif
    }
    lua_pop(L, 1);
    
    return 1;
}
Exemplo n.º 4
0
bool LuaStack::init(void)
{
    _state = lua_open();
    luaL_openlibs(_state);
    toluafix_open(_state);

    // Register our version of the global "print" function
    const luaL_reg global_functions [] = {
        {"print", lua_print},
        {"LuaLoadChunksFromZIP", LuaStack::lua_loadChunksFromZIP},
        {NULL, NULL}
    };
    luaL_register(_state, "_G", global_functions);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
    luaopen_lua_extensions(_state);
#endif
    
    // register CCLuaStackSnapshot
    luaopen_snapshot(_state);
    
    g_luaType.clear();

    register_all_cocos2dx(_state);
    register_all_cocos2dx_extension(_state);


    register_all_cocos2dx_manual(_state);
    register_all_cocos2dx_extension_manual(_state);

    // add spine support
    register_all_cocos2dx_spine(_state);
    register_all_cocos2dx_spine_manual(_state);

     
#if CC_USE_EXTRA_FILTERS
    register_all_cocos2dx_extension_filter(_state);
#endif
    
    luaopen_cocos2dx_extra_luabinding(_state);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    luaopen_cocos2dx_extra_ios_iap_luabinding(_state);
#endif
    luaopen_HelperFunc_luabinding(_state);
#if CC_USE_PHYSICS
    register_all_cocos2dx_physics(_state);
    register_all_cocos2dx_physics_manual(_state);
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    LuaObjcBridge::luaopen_luaoc(_state);
#endif
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    LuaJavaBridge::luaopen_luaj(_state);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
#if CC_USE_WEBSOCKET
    tolua_web_socket_open(_state);
    register_web_socket_manual(_state);
#endif
#endif

#if ANYSDK_DEFINE > 0
    register_all_anysdk(_state);
    register_all_anysdk_manual(_state);
#endif
    
    //register_xml_http_request(_state);
    
    tolua_script_handler_mgr_open(_state);

    // add cocos2dx loader
    addLuaLoader(cocos2dx_lua_loader);

    return true;
}