From b72034a3f65dd51a43f074d5871513463ada5c98 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Fri, 17 Apr 2015 14:08:47 +0800 Subject: [PATCH] Add Lua bindings for WebView and related test case --- build/cocos2d_tests.xcodeproj/project.pbxproj | 4 + ...lua_cocos2dx_experimental_webview_auto.cpp | 734 ++++++++++++++++++ ...lua_cocos2dx_experimental_webview_auto.hpp | 32 + ...a_cocos2dx_experimental_webview_manual.cpp | 190 +++++ ...a_cocos2dx_experimental_webview_manual.hpp | 41 + .../manual/ui/lua_cocos2dx_ui_manual.cpp | 9 + .../lua-bindings/proj.android/Android.mk | 7 +- .../project.pbxproj | 16 + .../proj.win32/libluacocos2d.vcxproj | 4 + .../proj.win32/libluacocos2d.vcxproj.filters | 12 + .../CocoStudioGUITest/CocoStudioGUITest.lua | 15 - .../lua-tests/src/WebViewTest/WebViewTest.lua | 129 +++ tests/lua-tests/src/mainMenu.lua | 8 + tools/tolua/cocos2dx_experimental_webview.ini | 62 ++ tools/tolua/genbindings.py | 1 + 15 files changed, 1246 insertions(+), 18 deletions(-) create mode 100644 cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.cpp create mode 100644 cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp create mode 100644 cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.cpp create mode 100644 cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp create mode 100644 tests/lua-tests/src/WebViewTest/WebViewTest.lua create mode 100644 tools/tolua/cocos2dx_experimental_webview.ini diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 476b8f2e3c..76639c72ce 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -42,6 +42,8 @@ 1502702E1AD3BDC90089CD03 /* TerrainTest in Resources */ = {isa = PBXBuildFile; fileRef = B603F1B31AC8FBFB00A9579C /* TerrainTest */; }; 150F918819DA409E00B89F57 /* lua_test_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150F918619DA409E00B89F57 /* lua_test_bindings.cpp */; }; 150F918919DA409F00B89F57 /* lua_test_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150F918619DA409E00B89F57 /* lua_test_bindings.cpp */; }; + 1531B2501AE013DE0075DB94 /* Test.html in Resources */ = {isa = PBXBuildFile; fileRef = 29AFEF6619ACCAA000F6B10A /* Test.html */; }; + 1531B2511AE013F00075DB94 /* Test.html in Resources */ = {isa = PBXBuildFile; fileRef = 29AFEF6619ACCAA000F6B10A /* Test.html */; }; 15427B79198B879900DC375D /* libluacocos2d iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 15EFA665198B33EE000C57D3 /* libluacocos2d iOS.a */; }; 15427B7A198B87AA00DC375D /* libcocos2d iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 46A15FBE1807A4F9005B8026 /* libcocos2d iOS.a */; }; 15427B7D198B880100DC375D /* lua_cocos2dx_controller_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15427B7B198B880100DC375D /* lua_cocos2dx_controller_manual.cpp */; }; @@ -4378,6 +4380,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1531B2501AE013DE0075DB94 /* Test.html in Resources */, 1502702E1AD3BDC90089CD03 /* TerrainTest in Resources */, 157B08EC1A90864100B7BEA4 /* Particle3D in Resources */, 15B13E5219F0FD4D008A1ADC /* Manifests in Resources */, @@ -4424,6 +4427,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1531B2511AE013F00075DB94 /* Test.html in Resources */, 1502702D1AD3BDBC0089CD03 /* TerrainTest in Resources */, 157B08ED1A90865600B7BEA4 /* Particle3D in Resources */, 15B3709A19EE5EED00ABE682 /* Manifests in Resources */, diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.cpp new file mode 100644 index 0000000000..d4aec6be7b --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.cpp @@ -0,0 +1,734 @@ +#include "lua_cocos2dx_experimental_webview_auto.hpp" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#include "UIWebView.h" +#include "tolua_fix.h" +#include "LuaBasicConversions.h" + + + +int lua_cocos2dx_experimental_webview_WebView_loadURL(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_loadURL'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:loadURL"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_loadURL'", nullptr); + return 0; + } + cobj->loadURL(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:loadURL",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_loadURL'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_canGoBack(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_canGoBack'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_canGoBack'", nullptr); + return 0; + } + bool ret = cobj->canGoBack(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:canGoBack",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_canGoBack'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_loadHTMLString(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_loadHTMLString'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:loadHTMLString"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_loadHTMLString'", nullptr); + return 0; + } + cobj->loadHTMLString(arg0); + lua_settop(tolua_S, 1); + return 1; + } + if (argc == 2) + { + std::string arg0; + std::string arg1; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:loadHTMLString"); + + ok &= luaval_to_std_string(tolua_S, 3,&arg1, "ccexp.WebView:loadHTMLString"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_loadHTMLString'", nullptr); + return 0; + } + cobj->loadHTMLString(arg0, arg1); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:loadHTMLString",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_loadHTMLString'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_goForward(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_goForward'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_goForward'", nullptr); + return 0; + } + cobj->goForward(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:goForward",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_goForward'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_goBack(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_goBack'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_goBack'", nullptr); + return 0; + } + cobj->goBack(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:goBack",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_goBack'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:setJavascriptInterfaceScheme"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme'", nullptr); + return 0; + } + cobj->setJavascriptInterfaceScheme(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:setJavascriptInterfaceScheme",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_evaluateJS(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_evaluateJS'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:evaluateJS"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_evaluateJS'", nullptr); + return 0; + } + cobj->evaluateJS(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:evaluateJS",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_evaluateJS'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_getOnJSCallback(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_getOnJSCallback'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_getOnJSCallback'", nullptr); + return 0; + } + cocos2d::experimental::ui::WebView::ccWebViewCallback ret = cobj->getOnJSCallback(); + #pragma warning NO CONVERSION FROM NATIVE FOR std::function; + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:getOnJSCallback",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_getOnJSCallback'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_reload(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_reload'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_reload'", nullptr); + return 0; + } + cobj->reload(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:reload",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_reload'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + bool arg0; + + ok &= luaval_to_boolean(tolua_S, 2,&arg0, "ccexp.WebView:setScalesPageToFit"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit'", nullptr); + return 0; + } + cobj->setScalesPageToFit(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:setScalesPageToFit",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_canGoForward(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_canGoForward'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_canGoForward'", nullptr); + return 0; + } + bool ret = cobj->canGoForward(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:canGoForward",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_canGoForward'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_loadFile(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_loadFile'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:loadFile"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_loadFile'", nullptr); + return 0; + } + cobj->loadFile(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:loadFile",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_loadFile'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_stopLoading(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_stopLoading'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_stopLoading'", nullptr); + return 0; + } + cobj->stopLoading(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:stopLoading",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_stopLoading'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_create(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_create'", nullptr); + return 0; + } + cocos2d::experimental::ui::WebView* ret = cocos2d::experimental::ui::WebView::create(); + object_to_luaval(tolua_S, "ccexp.WebView",(cocos2d::experimental::ui::WebView*)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.WebView:create",argc, 0); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_create'.",&tolua_err); +#endif + return 0; +} +static int lua_cocos2dx_experimental_webview_WebView_finalize(lua_State* tolua_S) +{ + printf("luabindings: finalizing LUA object (WebView)"); + return 0; +} + +int lua_register_cocos2dx_experimental_webview_WebView(lua_State* tolua_S) +{ + tolua_usertype(tolua_S,"ccexp.WebView"); + tolua_cclass(tolua_S,"WebView","ccexp.WebView","ccui.Widget",nullptr); + + tolua_beginmodule(tolua_S,"WebView"); + tolua_function(tolua_S,"loadURL",lua_cocos2dx_experimental_webview_WebView_loadURL); + tolua_function(tolua_S,"canGoBack",lua_cocos2dx_experimental_webview_WebView_canGoBack); + tolua_function(tolua_S,"loadHTMLString",lua_cocos2dx_experimental_webview_WebView_loadHTMLString); + tolua_function(tolua_S,"goForward",lua_cocos2dx_experimental_webview_WebView_goForward); + tolua_function(tolua_S,"goBack",lua_cocos2dx_experimental_webview_WebView_goBack); + tolua_function(tolua_S,"setJavascriptInterfaceScheme",lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme); + tolua_function(tolua_S,"evaluateJS",lua_cocos2dx_experimental_webview_WebView_evaluateJS); + tolua_function(tolua_S,"getOnJSCallback",lua_cocos2dx_experimental_webview_WebView_getOnJSCallback); + tolua_function(tolua_S,"reload",lua_cocos2dx_experimental_webview_WebView_reload); + tolua_function(tolua_S,"setScalesPageToFit",lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit); + tolua_function(tolua_S,"canGoForward",lua_cocos2dx_experimental_webview_WebView_canGoForward); + tolua_function(tolua_S,"loadFile",lua_cocos2dx_experimental_webview_WebView_loadFile); + tolua_function(tolua_S,"stopLoading",lua_cocos2dx_experimental_webview_WebView_stopLoading); + tolua_function(tolua_S,"create", lua_cocos2dx_experimental_webview_WebView_create); + tolua_endmodule(tolua_S); + std::string typeName = typeid(cocos2d::experimental::ui::WebView).name(); + g_luaType[typeName] = "ccexp.WebView"; + g_typeCast["WebView"] = "ccexp.WebView"; + return 1; +} +TOLUA_API int register_all_cocos2dx_experimental_webview(lua_State* tolua_S) +{ + tolua_open(tolua_S); + + tolua_module(tolua_S,"ccexp",0); + tolua_beginmodule(tolua_S,"ccexp"); + + lua_register_cocos2dx_experimental_webview_WebView(tolua_S); + + tolua_endmodule(tolua_S); + return 1; +} + +#endif diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp new file mode 100644 index 0000000000..89e8447ecb --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp @@ -0,0 +1,32 @@ +#include "base/ccConfig.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#ifndef __cocos2dx_experimental_webview_h__ +#define __cocos2dx_experimental_webview_h__ + +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua++.h" +#ifdef __cplusplus +} +#endif + +int register_all_cocos2dx_experimental_webview(lua_State* tolua_S); + + + + + + + + + + + + + + + + +#endif // __cocos2dx_experimental_webview_h__ +#endif //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) diff --git a/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.cpp b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.cpp new file mode 100644 index 0000000000..67de59984d --- /dev/null +++ b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.cpp @@ -0,0 +1,190 @@ +#include "lua_cocos2dx_experimental_video_manual.hpp" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + +#include "UIWebView.h" +#include "tolua_fix.h" +#include "LuaBasicConversions.h" +#include "CCLuaValue.h" +#include "CCLuaEngine.h" + + + +static int lua_cocos2dx_experimental_WebView_setOnShouldStartLoading(lua_State* L) +{ + + int argc = 0; + cocos2d::experimental::ui::WebView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_experimental_WebView_setOnShouldStartLoading'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (argc == 1) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + std::function callback = [L,handler](experimental::ui::WebView *sender, const std::string &url)->bool{ + toluafix_pushusertype_ccobject(L, sender->_ID, &(sender->_luaID), (void*)sender,"ccexp.WebView"); + tolua_pushcppstring(L, url); + return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); + }; + + ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler); + self->setOnShouldStartLoading(callback); + + return 0; + } + luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.WebView:setOnShouldStartLoading",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(L, "#ferror in function 'lua_cocos2dx_experimental_WebView_setOnShouldStartLoading'.", &tolua_err); +#endif + return 0; +} + +static int lua_cocos2dx_experimental_WebView_setOnDidFinishLoading(lua_State* L) +{ + + int argc = 0; + cocos2d::experimental::ui::WebView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_experimental_WebView_setOnDidFinishLoading'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (argc == 1) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + std::function callback = [L,handler](experimental::ui::WebView *sender, const std::string &url){ + toluafix_pushusertype_ccobject(L, sender->_ID, &(sender->_luaID), (void*)sender,"ccexp.WebView"); + tolua_pushcppstring(L, url); + LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); + }; + + ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler); + self->setOnDidFinishLoading(callback); + return 0; + } + luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.WebView:setOnDidFinishLoading",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L, "#ferror in function 'lua_cocos2dx_experimental_WebView_setOnDidFinishLoading'.", &tolua_err); +#endif + return 0; +} + +static int lua_cocos2dx_experimental_WebView_setOnDidFailLoading(lua_State* L) +{ + + int argc = 0; + cocos2d::experimental::ui::WebView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_experimental_WebView_setOnDidFailLoading'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (argc == 1) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + std::function callback = [L,handler](experimental::ui::WebView *sender, const std::string &url){ + toluafix_pushusertype_ccobject(L, sender->_ID, &(sender->_luaID), (void*)sender,"ccexp.WebView"); + tolua_pushcppstring(L, url); + LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); + }; + + ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler); + self->setOnDidFinishLoading(callback); + return 0; + } + luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.WebView:setOnDidFailLoading",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L, "#ferror in function 'lua_cocos2dx_experimental_WebView_setOnDidFailLoading'.", &tolua_err); +#endif + return 0; +} + +static void extendWebView(lua_State* L) +{ + lua_pushstring(L, "ccexp.WebView"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "setOnShouldStartLoading", lua_cocos2dx_experimental_WebView_setOnShouldStartLoading); + tolua_function(L, "setOnDidFinishLoading", lua_cocos2dx_experimental_WebView_setOnDidFinishLoading); + tolua_function(L, "setOnDidFailLoading", lua_cocos2dx_experimental_WebView_setOnDidFailLoading); + } + lua_pop(L, 1); +} + +int register_all_cocos2dx_experimental_webview_manual(lua_State* L) +{ + if (nullptr == L) + return 0; + + extendWebView(L); + + return 0; +} + +#endif diff --git a/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp new file mode 100644 index 0000000000..95b68ed7a9 --- /dev/null +++ b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp @@ -0,0 +1,41 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#include "base/ccConfig.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + +#ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_EXPERIMENTAL_WEBVIEW_MANUAL_H +#define COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_EXPERIMENTAL_WEBVIEW_MANUAL_H + +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua++.h" +#ifdef __cplusplus +} +#endif + +TOLUA_API int register_all_cocos2dx_experimental_webview_manual(lua_State* L); + +#endif //#ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_EXPERIMENTAL_WEBVIEW_MANUAL_H +#endif //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) diff --git a/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp index 0e0afe8623..b68a7c860c 100644 --- a/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp @@ -27,6 +27,10 @@ #include "lua_cocos2dx_experimental_video_auto.hpp" #include "lua_cocos2dx_experimental_video_manual.hpp" #endif +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#include "lua_cocos2dx_experimental_webview_auto.hpp" +#include "lua_cocos2dx_experimental_webview_manual.hpp" +#endif #include "cocos2d.h" #include "tolua_fix.h" #include "LuaBasicConversions.h" @@ -1046,6 +1050,11 @@ int register_ui_moudle(lua_State* L) register_all_cocos2dx_experimental_video(L); register_all_cocos2dx_experimental_video_manual(L); #endif + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS ||CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + register_all_cocos2dx_experimental_webview(L); + register_all_cocos2dx_experimental_webview_manual(L); +#endif extendEventListenerFocusEvent(L); } lua_pop(L, 1); diff --git a/cocos/scripting/lua-bindings/proj.android/Android.mk b/cocos/scripting/lua-bindings/proj.android/Android.mk index 4b34226adc..0281c3c521 100644 --- a/cocos/scripting/lua-bindings/proj.android/Android.mk +++ b/cocos/scripting/lua-bindings/proj.android/Android.mk @@ -106,11 +106,12 @@ LOCAL_SRC_FILES += ../manual/spine/lua_cocos2dx_spine_manual.cpp \ ../auto/lua_cocos2dx_spine_auto.cpp #ui -LOCAL_SRC_FILES += ../manual/ui/lua_cocos2dx_experimental_video_manual.cpp \ +LOCAL_SRC_FILES += ../manual/ui/lua_cocos2dx_experimental_webview_manual.cpp \ + ../manual/ui/lua_cocos2dx_experimental_video_manual.cpp \ ../manual/ui/lua_cocos2dx_ui_manual.cpp \ ../auto/lua_cocos2dx_experimental_video_auto.cpp \ - ../auto/lua_cocos2dx_ui_auto.cpp - + ../auto/lua_cocos2dx_ui_auto.cpp \ + ../auto/lua_cocos2dx_experimental_webview_auto.cpp #quick LOCAL_SRC_FILES += ../../../../external/lua/quick/lua_cocos2dx_quick_manual.cpp \ ../../../../external/lua/quick/LuaEventNode.cpp \ diff --git a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj index d552c61e9d..e733ea83f0 100644 --- a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj +++ b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj @@ -165,6 +165,10 @@ 15AC69E21987712500D17520 /* tolua_event.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ABCA1FA18CD8F6E0087CE3A /* tolua_event.h */; }; 15AC69E31987712500D17520 /* tolua++.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ABCA1FF18CD8F6E0087CE3A /* tolua++.h */; }; 15AC69E4198771FF00D17520 /* libluajit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ABCA1F618CD8F5F0087CE3A /* libluajit.a */; }; + 15ACDBCD1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15ACDBCB1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.cpp */; }; + 15ACDBCE1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 15ACDBCC1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.hpp */; }; + 15ACDBD11ADEBAD500BDFE09 /* lua_cocos2dx_experimental_webview_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15ACDBCF1ADEBAD500BDFE09 /* lua_cocos2dx_experimental_webview_manual.cpp */; }; + 15ACDC2D1ADFFC7E00BDFE09 /* lua_cocos2dx_experimental_webview_manual.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 15ACDC271ADFFC7E00BDFE09 /* lua_cocos2dx_experimental_webview_manual.hpp */; }; 15B5754F1A6F4D1500041C20 /* lua-cocos-studio-conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15B5754D1A6F4D1500041C20 /* lua-cocos-studio-conversions.cpp */; }; 15B575501A6F4D1500041C20 /* lua-cocos-studio-conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15B5754D1A6F4D1500041C20 /* lua-cocos-studio-conversions.cpp */; }; 15B575511A6F4D1500041C20 /* lua-cocos-studio-conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = 15B5754E1A6F4D1500041C20 /* lua-cocos-studio-conversions.h */; }; @@ -332,6 +336,10 @@ 159552391A25E1C5001E9FC9 /* lua_cocos2dx_csloader_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_csloader_auto.hpp; sourceTree = ""; }; 1595523E1A25E4B8001E9FC9 /* lua_cocos2dx_csloader_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_csloader_manual.cpp; sourceTree = ""; }; 1595523F1A25E4B8001E9FC9 /* lua_cocos2dx_csloader_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_csloader_manual.hpp; sourceTree = ""; }; + 15ACDBCB1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_experimental_webview_auto.cpp; sourceTree = ""; }; + 15ACDBCC1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_experimental_webview_auto.hpp; sourceTree = ""; }; + 15ACDBCF1ADEBAD500BDFE09 /* lua_cocos2dx_experimental_webview_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_experimental_webview_manual.cpp; sourceTree = ""; }; + 15ACDC271ADFFC7E00BDFE09 /* lua_cocos2dx_experimental_webview_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_experimental_webview_manual.hpp; sourceTree = ""; }; 15B5754D1A6F4D1500041C20 /* lua-cocos-studio-conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "lua-cocos-studio-conversions.cpp"; sourceTree = ""; }; 15B5754E1A6F4D1500041C20 /* lua-cocos-studio-conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "lua-cocos-studio-conversions.h"; sourceTree = ""; }; 15C1BCC019864D8700A46ACC /* lua_cocos2dx_cocosbuilder_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_cocosbuilder_auto.cpp; sourceTree = ""; }; @@ -566,6 +574,8 @@ 15C1BD191986526C00A46ACC /* ui */ = { isa = PBXGroup; children = ( + 15ACDC271ADFFC7E00BDFE09 /* lua_cocos2dx_experimental_webview_manual.hpp */, + 15ACDBCF1ADEBAD500BDFE09 /* lua_cocos2dx_experimental_webview_manual.cpp */, 15C1C24B1987473200A46ACC /* lua_cocos2dx_experimental_video_manual.cpp */, 15C1C24C1987473200A46ACC /* lua_cocos2dx_experimental_video_manual.hpp */, 15C1BD1A1986526C00A46ACC /* lua_cocos2dx_ui_manual.cpp */, @@ -592,6 +602,8 @@ 1AACE74818BC45C200215002 /* auto */ = { isa = PBXGroup; children = ( + 15ACDBCB1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.cpp */, + 15ACDBCC1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.hpp */, 159552381A25E1C5001E9FC9 /* lua_cocos2dx_csloader_auto.cpp */, 159552391A25E1C5001E9FC9 /* lua_cocos2dx_csloader_auto.hpp */, 3E2BDB0319C5E5FE0055CDCD /* lua_cocos2dx_audioengine_auto.cpp */, @@ -829,6 +841,7 @@ 15415AAB19A71A53004F1E71 /* buffer.h in Headers */, 15AC69DE1987711400D17520 /* lauxlib.h in Headers */, 155C7E1419A71CA800F08B25 /* Lua_web_socket.h in Headers */, + 15ACDC2D1ADFFC7E00BDFE09 /* lua_cocos2dx_experimental_webview_manual.hpp in Headers */, 15AC69DF1987711400D17520 /* lua.h in Headers */, 15AC69E01987711400D17520 /* luaconf.h in Headers */, 155C7DF819A71C4400F08B25 /* lua_cocos2dx_cocosdenshion_manual.h in Headers */, @@ -936,6 +949,7 @@ 15EFA62E198B3220000C57D3 /* lua_cocos2dx_manual.hpp in Headers */, F4FE0D7119ECD02400B8B12B /* LuaNodeManager.h in Headers */, F4FE0D6919ECD02400B8B12B /* lua_cocos2dx_quick_manual.hpp in Headers */, + 15ACDBCE1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.hpp in Headers */, 15EFA62F198B3220000C57D3 /* lua_cocos2dx_physics_manual.hpp in Headers */, 155C7E0919A71C8500F08B25 /* lua_cocos2dx_extension_manual.h in Headers */, 155C7E1919A71CB500F08B25 /* lua_xml_http_request.h in Headers */, @@ -1160,6 +1174,7 @@ 155C7E2719A71CDE00F08B25 /* lua_cocos2dx_ui_manual.cpp in Sources */, F4FE0D6B19ECD02400B8B12B /* LuaEventNode.cpp in Sources */, F4FE0D7319ECD02400B8B12B /* LuaTouchEventManager.cpp in Sources */, + 15ACDBD11ADEBAD500BDFE09 /* lua_cocos2dx_experimental_webview_manual.cpp in Sources */, 15415AB619A71A53004F1E71 /* io.c in Sources */, 155C7DF719A71C4000F08B25 /* lua_cocos2dx_cocosdenshion_manual.cpp in Sources */, 155C7DEF19A71C0900F08B25 /* lua_cocos2dx_ui_auto.cpp in Sources */, @@ -1167,6 +1182,7 @@ 15415A7119A71782004F1E71 /* lua_cocos2dx_extension_auto.cpp in Sources */, 15EFA629198B31FB000C57D3 /* lua_cocos2dx_physics_manual.cpp in Sources */, 15EFA62A198B31FB000C57D3 /* LuaScriptHandlerMgr.cpp in Sources */, + 15ACDBCD1ADE169700BDFE09 /* lua_cocos2dx_experimental_webview_auto.cpp in Sources */, 15EFA617198B2E2B000C57D3 /* lua_cocos2dx_experimental_auto.cpp in Sources */, 15EFA618198B2E2B000C57D3 /* lua_cocos2dx_auto.cpp in Sources */, 15EFA619198B2E2B000C57D3 /* lua_cocos2dx_physics_auto.cpp in Sources */, diff --git a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj index d916eba7d1..0f38136138 100644 --- a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj +++ b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj @@ -44,6 +44,7 @@ + @@ -79,6 +80,7 @@ + @@ -117,6 +119,7 @@ + @@ -152,6 +155,7 @@ + diff --git a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters index 2ec7ee30b6..1b961771b2 100644 --- a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters +++ b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters @@ -285,6 +285,12 @@ manual\cocostudio + + auto + + + manual\ui + @@ -500,6 +506,12 @@ manual\cocostudio + + auto + + + manual\ui + diff --git a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua index 640846a4fd..44626fee77 100644 --- a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua +++ b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua @@ -29,9 +29,6 @@ function UIScene:init() self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back")--getWidgetByName - back_label:setVisible(false) - local function previousCallback(sender, eventType) if eventType == ccui.TouchEventType.ended then cc.Director:getInstance():replaceScene(guiSceneManager.previousUIScene()) @@ -711,9 +708,6 @@ function UILoadingBarLeftTest:initExtend() local root = self._uiLayer:getChildByTag(81) self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back") - back_label:setVisible(false) - local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() @@ -837,9 +831,6 @@ function UILoadingBarRightTest:initExtend() local root = self._uiLayer:getChildByTag(81) self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back") - back_label:setVisible(false) - local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() @@ -964,9 +955,6 @@ function UILoadingBarLeftScale9Test:initExtend() local root = self._uiLayer:getChildByTag(81) self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back") - back_label:setVisible(false) - local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() @@ -1093,9 +1081,6 @@ function UILoadingBarRightScale9Test:initExtend() local root = self._uiLayer:getChildByTag(81) self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back") - back_label:setVisible(false) - local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() diff --git a/tests/lua-tests/src/WebViewTest/WebViewTest.lua b/tests/lua-tests/src/WebViewTest/WebViewTest.lua new file mode 100644 index 0000000000..36c432a786 --- /dev/null +++ b/tests/lua-tests/src/WebViewTest/WebViewTest.lua @@ -0,0 +1,129 @@ + +---------------------------------------- +----WebViewTest +---------------------------------------- +local WebViewTest = class("WebViewTest", function () + local layer = cc.Layer:create() + + return layer +end) + +function WebViewTest:ctor() + self:init() +end + +function WebViewTest:init() + Helper.initWithLayer(self) + Helper.titleLabel:setString(self:title()) + Helper.subtitleLabel:setString(self:subtitle()) + + local winSize = cc.Director:getInstance():getVisibleSize() + self._webView = ccexp.WebView:create() + self._webView:setPosition(winSize.width / 2, winSize.height / 2 - 40) + self._webView:setContentSize(winSize.width / 2, winSize.height / 2) + self._webView:loadURL("http://www.baidu.com") + self._webView:setScalesPageToFit(true) + + self._webView:setOnShouldStartLoading(function(sender, url) + print("onWebViewShouldStartLoading, url is ", url) + return true + end) + self._webView:setOnDidFinishLoading(function(sender, url) + print("onWebViewDidFinishLoading, url is ", url) + end) + self._webView:setOnDidFailLoading(function(sender, url) + print("onWebViewDidFinishLoading, url is ", url) + end) + + self:addChild(self._webView) + + local urlTextField = ccui.TextField:create("Input a URL here", "Arial", 20) + urlTextField:setPlaceHolderColor(cc.c4b(255, 0, 0, 255)) + urlTextField:setPosition(winSize.width/2 - 80, winSize.height/2 + self._webView:getContentSize().height/2 + urlTextField:getContentSize().height/2 + 10) + self:addChild(urlTextField) + + local httpLabel = ccui.Text:create("http:// ", "Arial", 20) + httpLabel:setTextColor(cc.c4b(0, 255, 0, 255)) + httpLabel:setAnchorPoint(cc.p(1.0,0.5)) + local x,y = urlTextField:getPosition() + httpLabel:setPosition( x - urlTextField:getContentSize().width / 2, y) + self:addChild(httpLabel) + + local resetBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + resetBtn:setTitleText("Visit URL") + resetBtn:setPosition(winSize.width / 2 + 80 , winSize.height / 2 + self._webView:getContentSize().height / 2 + resetBtn:getContentSize().height / 2 + 10) + resetBtn:addClickEventListener(function(sender) + if urlTextField:getString() ~= nil then + self._webView:loadURL("http://" .. urlTextField:getString()) + end + end) + self:addChild(resetBtn) + + local reloadBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + reloadBtn:setTitleText("Reload") + reloadBtn:setPosition(winSize.width / 2 + self._webView:getContentSize().width / 2 + reloadBtn:getContentSize().width / 2 + 10, winSize.height / 2 + 50) + reloadBtn:addClickEventListener(function(sender) + self._webView:reload() + end) + self:addChild(reloadBtn) + + local forwardBtn = ccui.Button:create("cocosui/animationbuttonnormal.png","cocosui/animationbuttonpressed.png") + forwardBtn:setTitleText("Forward") + forwardBtn:setPosition(winSize.width / 2 + self._webView:getContentSize().width / 2 + forwardBtn:getContentSize().width / 2 + 10,winSize.height / 2) + forwardBtn:addClickEventListener(function(sender) + self._webView:goForward() + end) + self:addChild(forwardBtn) + + local backBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + backBtn:setTitleText("Back") + backBtn:setPosition(winSize.width / 2 + self._webView:getContentSize().width/2 + backBtn:getContentSize().width/2 + 10, winSize.height - 50) + backBtn:addClickEventListener(function(sender) + self._webView:goBack() + end) + self:addChild(backBtn) + + local loadFileBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + loadFileBtn:setTitleText("Load FILE") + loadFileBtn:setPosition(winSize.width / 2 - self._webView:getContentSize().width/2 - loadFileBtn:getContentSize().width/2 - 30, winSize.height / 2 + 50) + loadFileBtn:addClickEventListener(function(sender) + self._webView:loadFile("Test.html") + end) + self:addChild(loadFileBtn) + + local loadHTMLBtn = ccui.Button:create("cocosui/animationbuttonnormal.png","cocosui/animationbuttonpressed.png") + loadHTMLBtn:setTitleText("Load Data") + loadHTMLBtn:setPosition(winSize.width / 2 - self._webView:getContentSize().width/2 - loadHTMLBtn:getContentSize().width/2 - 30, winSize.height / 2) + loadHTMLBtn:addClickEventListener(function(sender) + self._webView:loadHTMLString("Hello World ","Images/") + end) + self:addChild(loadHTMLBtn) + + local evalJsBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + evalJsBtn:setTitleText("Evaluate JS") + evalJsBtn:setPosition(winSize.width / 2 - self._webView:getContentSize().width/2 - evalJsBtn:getContentSize().width/2 - 30, winSize.height / 2 - 50) + evalJsBtn:addClickEventListener(function(sender) + self._webView:evaluateJS("alert(\"hello\")") + end) + self:addChild(evalJsBtn) +end + +function WebViewTest:title() + return "" +end + +function WebViewTest:subtitle() + return "" +end + +function WebViewTestMain() + Helper.createFunctionTable = + { + WebViewTest.create, + } + + local scene = cc.Scene:create() + scene:addChild(WebViewTest.create()) + scene:addChild(CreateBackMenuItem()) + return scene +end \ No newline at end of file diff --git a/tests/lua-tests/src/mainMenu.lua b/tests/lua-tests/src/mainMenu.lua index 3c20ebc779..a8d46ae35c 100644 --- a/tests/lua-tests/src/mainMenu.lua +++ b/tests/lua-tests/src/mainMenu.lua @@ -58,6 +58,7 @@ require "VideoPlayerTest/VideoPlayerTest" require "FastTiledMapTest/FastTiledMapTest" require "NewAudioEngineTest/NewAudioEngineTest" require "CocosStudio3DTest/CocosStudio3DTest" +require "WebViewTest/WebViewTest" local LINE_SPACE = 40 @@ -134,6 +135,7 @@ local _allTests = { { isSupported = true, name = "TransitionsTest" , create_func = TransitionsTest }, { isSupported = true, name = "UserDefaultTest" , create_func= UserDefaultTestMain }, { isSupported = true, name = "VideoPlayerTest" , create_func= VideoPlayerTestMain }, + { isSupported = true, name = "WebViewTest" , create_func= WebViewTestMain }, { isSupported = true, name = "XMLHttpRequestTest" , create_func = XMLHttpRequestTestMain }, { isSupported = true, name = "ZwoptexTest" , create_func = ZwoptexTestMain } } @@ -196,6 +198,12 @@ function CreateTestMenu() end end + if obj.name == "WebViewTest" then + if cc.PLATFORM_OS_IPHONE ~= targetPlatform and cc.PLATFORM_OS_ANDROID ~= targetPlatform then + testMenuItem:setEnabled(false) + end + end + testMenuItem:registerScriptTapHandler(menuCallback) testMenuItem:setPosition(cc.p(s.width / 2, (s.height - (index) * LINE_SPACE))) MainMenu:addChild(testMenuItem, index + 10000, index + 10000) diff --git a/tools/tolua/cocos2dx_experimental_webview.ini b/tools/tolua/cocos2dx_experimental_webview.ini new file mode 100644 index 0000000000..be914197b5 --- /dev/null +++ b/tools/tolua/cocos2dx_experimental_webview.ini @@ -0,0 +1,62 @@ +[cocos2dx_experimental_webview] +# the prefix to be added to the generated functions. You might or might not use this in your own +# templates +prefix = cocos2dx_experimental_webview + +# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) +# all classes will be embedded in that namespace +target_namespace = ccexp + +macro_judgement = #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + +android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/include +android_flags = -D_SIZE_T_DEFINED_ + +clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ + +cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android + +cocos_flags = -DANDROID + +cxxgenerator_headers = + +# extra arguments for clang +extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s + +# what headers to parse +headers = %(cocosdir)s/cocos/ui/UIWebView.h + +# what classes to produce code for. You can use regular expressions here. When testing the regular +# expression, it will be enclosed in "^$", like this: "^Menu*$". +classes = WebView + +# what should we skip? in the format ClassName::[function function] +# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also +# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just +# add a single "*" as functions. See bellow for several examples. A special class name is "*", which +# will apply to all class names. This is a convenience wildcard to be able to skip similar named +# functions from all classes. + +skip = WebView::[(s|g)etOnShouldStartLoading (s|g)etOnDidFinishLoading (s|g)etOnDidFailLoading setOnJSCallback draw loadData] + +rename_functions = + +rename_classes = + +# for all class names, should we remove something when registering in the target VM? +remove_prefix = + +# classes for which there will be no "parent" lookup +classes_have_no_parents = + +# base classes which will be skipped when their sub-classes found them. +base_classes_to_skip = + +# classes that create no constructor +# Set is special and we will use a hand-written constructor +abstract_classes = + +# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. +script_control_cpp = no + diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index 7a7ea22ab9..abe05e5f08 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -147,6 +147,7 @@ def main(): 'cocos2dx_3d.ini': ('cocos2dx_3d', 'lua_cocos2dx_3d_auto'), \ 'cocos2dx_audioengine.ini': ('cocos2dx_audioengine', 'lua_cocos2dx_audioengine_auto'), \ 'cocos2dx_csloader.ini' : ('cocos2dx_csloader', 'lua_cocos2dx_csloader_auto'), \ + 'cocos2dx_experimental_webview.ini' : ('cocos2dx_experimental_webview', 'lua_cocos2dx_experimental_webview_auto'), \ } target = 'lua' generator_py = '%s/generator.py' % cxx_generator_root