2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
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:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2022-07-12 21:31:54 +08:00
|
|
|
#include "scripting/lua-bindings/manual/ui/lua_axis_webview_manual.hpp"
|
2015-04-17 14:08:47 +08:00
|
|
|
|
2019-03-08 15:24:47 +08:00
|
|
|
#include "ui/UIWebView/UIWebView.h"
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "scripting/lua-bindings/manual/tolua_fix.h"
|
|
|
|
#include "scripting/lua-bindings/manual/LuaBasicConversions.h"
|
|
|
|
#include "scripting/lua-bindings/manual/CCLuaValue.h"
|
|
|
|
#include "scripting/lua-bindings/manual/CCLuaEngine.h"
|
2015-04-17 14:08:47 +08:00
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
static int lua_axis_WebView_setOnShouldStartLoading(lua_State* L)
|
2015-04-17 14:08:47 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
int argc = 0;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::ui::WebView* self = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
#if COCOS2D_DEBUG >= 1
|
|
|
|
tolua_Error tolua_err;
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertype(L, 1, "axui.WebView", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
2015-04-17 14:08:47 +08:00
|
|
|
#endif
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
self = static_cast<axis::ui::WebView*>(tolua_tousertype(L, 1, 0));
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
#if COCOS2D_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
if (nullptr == self)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid 'self' in function 'lua_axis_WebView_setOnShouldStartLoading'\n", nullptr);
|
2021-12-25 10:04:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-17 14:08:47 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
argc = lua_gettop(L) - 1;
|
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
#if COCOS2D_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!toluafix_isfunction(L, 2, "LUA_FUNCTION", 0, &tolua_err))
|
2015-04-17 14:08:47 +08:00
|
|
|
{
|
|
|
|
goto tolua_lerror;
|
|
|
|
}
|
|
|
|
#endif
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
LUA_FUNCTION handler = (toluafix_ref_function(L, 2, 0));
|
2021-12-26 23:26:34 +08:00
|
|
|
std::function<bool(ui::WebView * sender, std::string_view url)> callback =
|
|
|
|
[L, handler](ui::WebView* sender, std::string_view url) -> bool {
|
2022-07-12 21:31:54 +08:00
|
|
|
toluafix_pushusertype_ccobject(L, sender->_ID, &(sender->_luaID), (void*)sender, "axui.WebView");
|
2022-01-04 09:40:27 +08:00
|
|
|
tolua_pushsv(L, url);
|
2015-04-17 14:08:47 +08:00
|
|
|
return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler);
|
|
|
|
self->setOnShouldStartLoading(callback);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "axui.WebView:setOnShouldStartLoading",
|
2021-12-25 10:04:45 +08:00
|
|
|
argc, 1);
|
2015-04-17 14:08:47 +08:00
|
|
|
return 0;
|
|
|
|
#if COCOS2D_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_WebView_setOnShouldStartLoading'.", &tolua_err);
|
2015-04-17 14:08:47 +08:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
static int lua_axis_WebView_setOnDidFinishLoading(lua_State* L)
|
2015-04-17 14:08:47 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
int argc = 0;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::ui::WebView* self = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
#if COCOS2D_DEBUG >= 1
|
|
|
|
tolua_Error tolua_err;
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertype(L, 1, "axui.WebView", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
2015-04-17 14:08:47 +08:00
|
|
|
#endif
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
self = static_cast<axis::ui::WebView*>(tolua_tousertype(L, 1, 0));
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
#if COCOS2D_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
if (nullptr == self)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid 'self' in function 'lua_axis_WebView_setOnDidFinishLoading'\n", nullptr);
|
2015-04-17 14:08:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
argc = lua_gettop(L) - 1;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
#if COCOS2D_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!toluafix_isfunction(L, 2, "LUA_FUNCTION", 0, &tolua_err))
|
2015-04-17 14:08:47 +08:00
|
|
|
{
|
|
|
|
goto tolua_lerror;
|
|
|
|
}
|
|
|
|
#endif
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-28 11:00:34 +08:00
|
|
|
LUA_FUNCTION handler = (toluafix_ref_function(L, 2, 0));
|
|
|
|
std::function<void(ui::WebView * sender, std::string_view url)> callback = [L, handler](ui::WebView* sender,
|
|
|
|
std::string_view url) {
|
2022-07-12 21:31:54 +08:00
|
|
|
toluafix_pushusertype_ccobject(L, sender->_ID, &(sender->_luaID), (void*)sender, "axui.WebView");
|
2022-01-04 09:40:27 +08:00
|
|
|
tolua_pushsv(L, url);
|
2021-12-28 11:00:34 +08:00
|
|
|
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler);
|
|
|
|
self->setOnDidFinishLoading(callback);
|
|
|
|
return 0;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "axui.WebView:setOnDidFinishLoading",
|
2021-12-25 10:04:45 +08:00
|
|
|
argc, 1);
|
2015-04-17 14:08:47 +08:00
|
|
|
return 0;
|
|
|
|
#if COCOS2D_DEBUG >= 1
|
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_WebView_setOnDidFinishLoading'.", &tolua_err);
|
2015-04-17 14:08:47 +08:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
static int lua_axis_WebView_setOnDidFailLoading(lua_State* L)
|
2015-04-17 14:08:47 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
int argc = 0;
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::ui::WebView* self = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
#if COCOS2D_DEBUG >= 1
|
|
|
|
tolua_Error tolua_err;
|
2022-07-12 21:31:54 +08:00
|
|
|
if (!tolua_isusertype(L, 1, "axui.WebView", 0, &tolua_err))
|
2021-12-25 10:04:45 +08:00
|
|
|
goto tolua_lerror;
|
2015-04-17 14:08:47 +08:00
|
|
|
#endif
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
self = static_cast<axis::ui::WebView*>(tolua_tousertype(L, 1, 0));
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
#if COCOS2D_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
if (nullptr == self)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "invalid 'self' in function 'lua_axis_WebView_setOnDidFailLoading'\n", nullptr);
|
2015-04-17 14:08:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
argc = lua_gettop(L) - 1;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
#if COCOS2D_DEBUG >= 1
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!toluafix_isfunction(L, 2, "LUA_FUNCTION", 0, &tolua_err))
|
2015-04-17 14:08:47 +08:00
|
|
|
{
|
|
|
|
goto tolua_lerror;
|
|
|
|
}
|
|
|
|
#endif
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-28 11:00:34 +08:00
|
|
|
LUA_FUNCTION handler = (toluafix_ref_function(L, 2, 0));
|
|
|
|
std::function<void(ui::WebView * sender, std::string_view url)> callback = [L, handler](ui::WebView* sender,
|
|
|
|
std::string_view url) {
|
2022-07-12 21:31:54 +08:00
|
|
|
toluafix_pushusertype_ccobject(L, sender->_ID, &(sender->_luaID), (void*)sender, "axui.WebView");
|
2022-01-04 09:40:27 +08:00
|
|
|
tolua_pushsv(L, url);
|
2021-12-28 11:00:34 +08:00
|
|
|
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2);
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler);
|
2015-09-17 10:52:17 +08:00
|
|
|
self->setOnDidFailLoading(callback);
|
2015-04-17 14:08:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-12 21:31:54 +08:00
|
|
|
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "axui.WebView:setOnDidFailLoading", argc,
|
2021-12-25 10:04:45 +08:00
|
|
|
1);
|
2015-04-17 14:08:47 +08:00
|
|
|
return 0;
|
|
|
|
#if COCOS2D_DEBUG >= 1
|
|
|
|
tolua_lerror:
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_error(L, "#ferror in function 'lua_axis_WebView_setOnDidFailLoading'.", &tolua_err);
|
2015-04-17 14:08:47 +08:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extendWebView(lua_State* L)
|
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
lua_pushstring(L, "axui.WebView");
|
2015-04-17 14:08:47 +08:00
|
|
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (lua_istable(L, -1))
|
2015-04-17 14:08:47 +08:00
|
|
|
{
|
2022-07-12 21:31:54 +08:00
|
|
|
tolua_function(L, "setOnShouldStartLoading", lua_axis_WebView_setOnShouldStartLoading);
|
|
|
|
tolua_function(L, "setOnDidFinishLoading", lua_axis_WebView_setOnDidFinishLoading);
|
|
|
|
tolua_function(L, "setOnDidFailLoading", lua_axis_WebView_setOnDidFailLoading);
|
2015-04-17 14:08:47 +08:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2022-07-12 21:31:54 +08:00
|
|
|
int register_all_axis_webview_manual(lua_State* L)
|
2015-04-17 14:08:47 +08:00
|
|
|
{
|
|
|
|
if (nullptr == L)
|
|
|
|
return 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
extendWebView(L);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-17 14:08:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|