axmol/extensions/scripting/lua-bindings/manual/audioengine/axlua_audioengine_manual.cpp

326 lines
8.8 KiB
C++
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2014-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2022-10-01 16:24:52 +08:00
https://axmolengine.github.io/
2019-11-23 20:27:39 +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:
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.
****************************************************************************/
2022-08-08 18:02:17 +08:00
#include "scripting/lua-bindings/manual/audioengine/axlua_audioengine_manual.h"
#include "scripting/lua-bindings/auto/axlua_audioengine_auto.hpp"
2019-11-23 20:27:39 +08:00
#include "scripting/lua-bindings/manual/tolua_fix.h"
#include "scripting/lua-bindings/manual/LuaBasicConversions.h"
#include "scripting/lua-bindings/manual/CCLuaEngine.h"
2022-01-03 11:34:58 +08:00
#include "audio/AudioEngine.h"
2019-11-23 20:27:39 +08:00
static int lua_get_AudioProfile_name(lua_State* L)
{
2022-08-08 18:02:17 +08:00
ax::AudioProfile* self = nullptr;
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_Error tolua_err;
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.AudioProfile", 0, &tolua_err))
2021-12-25 10:04:45 +08:00
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-08-08 18:02:17 +08:00
self = (ax::AudioProfile*)tolua_tousertype(L, 1, 0);
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (nullptr == self)
{
2021-12-25 10:04:45 +08:00
tolua_error(L, "invalid 'self' in function 'lua_get_AudioProfile_name'\n", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
lua_pushstring(L, self->name.c_str());
return 1;
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_lerror:
2021-12-25 10:04:45 +08:00
tolua_error(L, "#ferror in function 'lua_get_AudioProfile_name'.", &tolua_err);
2019-11-23 20:27:39 +08:00
return 0;
#endif
}
static int lua_set_AudioProfile_name(lua_State* L)
{
2021-12-25 10:04:45 +08:00
int argc = 0;
2022-08-08 18:02:17 +08:00
ax::AudioProfile* self = nullptr;
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_Error tolua_err;
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.AudioProfile", 0, &tolua_err))
2021-12-25 10:04:45 +08:00
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-08-08 18:02:17 +08:00
self = (ax::AudioProfile*)tolua_tousertype(L, 1, 0);
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (nullptr == self)
{
2021-12-25 10:04:45 +08:00
tolua_error(L, "invalid 'self' in function 'lua_set_AudioProfile_name'\n", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
argc = lua_gettop(L) - 1;
if (1 == argc)
{
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!tolua_isstring(L, 2, 0, &tolua_err))
goto tolua_lerror;
#endif
self->name = tolua_tostring(L, 2, 0);
return 0;
}
return 0;
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_lerror:
2021-12-25 10:04:45 +08:00
tolua_error(L, "#ferror in function 'lua_set_AudioProfile_name'.", &tolua_err);
2019-11-23 20:27:39 +08:00
return 0;
#endif
}
static int lua_get_AudioProfile_maxInstances(lua_State* L)
{
2022-08-08 18:02:17 +08:00
ax::AudioProfile* self = nullptr;
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_Error tolua_err;
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.AudioProfile", 0, &tolua_err))
2021-12-25 10:04:45 +08:00
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-08-08 18:02:17 +08:00
self = (ax::AudioProfile*)tolua_tousertype(L, 1, 0);
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (nullptr == self)
{
2021-12-25 10:04:45 +08:00
tolua_error(L, "invalid 'self' in function 'lua_get_AudioProfile_maxInstances'\n", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
tolua_pushnumber(L, (lua_Number)self->maxInstances);
return 1;
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_lerror:
2021-12-25 10:04:45 +08:00
tolua_error(L, "#ferror in function 'lua_get_AudioProfile_maxInstances'.", &tolua_err);
2019-11-23 20:27:39 +08:00
return 0;
#endif
}
static int lua_set_AudioProfile_maxInstances(lua_State* L)
{
2021-12-25 10:04:45 +08:00
int argc = 0;
2022-08-08 18:02:17 +08:00
ax::AudioProfile* self = nullptr;
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_Error tolua_err;
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.AudioProfile", 0, &tolua_err))
2021-12-25 10:04:45 +08:00
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-08-08 18:02:17 +08:00
self = (ax::AudioProfile*)tolua_tousertype(L, 1, 0);
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (nullptr == self)
{
2021-12-25 10:04:45 +08:00
tolua_error(L, "invalid 'self' in function 'lua_set_AudioProfile_maxInstances'\n", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
argc = lua_gettop(L) - 1;
if (1 == argc)
{
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!tolua_isnumber(L, 2, 0, &tolua_err))
goto tolua_lerror;
#endif
self->maxInstances = (unsigned)tolua_tonumber(L, 2, 0);
return 0;
}
return 0;
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_lerror:
2021-12-25 10:04:45 +08:00
tolua_error(L, "#ferror in function 'lua_set_AudioProfile_maxInstances'.", &tolua_err);
2019-11-23 20:27:39 +08:00
return 0;
#endif
}
static int lua_get_AudioProfile_minDelay(lua_State* L)
{
2022-08-08 18:02:17 +08:00
ax::AudioProfile* self = nullptr;
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_Error tolua_err;
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.AudioProfile", 0, &tolua_err))
2021-12-25 10:04:45 +08:00
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-08-08 18:02:17 +08:00
self = (ax::AudioProfile*)tolua_tousertype(L, 1, 0);
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (nullptr == self)
{
2021-12-25 10:04:45 +08:00
tolua_error(L, "invalid 'self' in function 'lua_get_AudioProfile_minDelay'\n", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
tolua_pushnumber(L, (lua_Number)self->minDelay);
return 1;
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_lerror:
2021-12-25 10:04:45 +08:00
tolua_error(L, "#ferror in function 'lua_get_AudioProfile_minDelay'.", &tolua_err);
2019-11-23 20:27:39 +08:00
return 0;
#endif
}
static int lua_set_AudioProfile_minDelay(lua_State* L)
{
2021-12-25 10:04:45 +08:00
int argc = 0;
2022-08-08 18:02:17 +08:00
ax::AudioProfile* self = nullptr;
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_Error tolua_err;
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.AudioProfile", 0, &tolua_err))
2021-12-25 10:04:45 +08:00
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-08-08 18:02:17 +08:00
self = (ax::AudioProfile*)tolua_tousertype(L, 1, 0);
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (nullptr == self)
{
2021-12-25 10:04:45 +08:00
tolua_error(L, "invalid 'self' in function 'lua_set_AudioProfile_minDelay'\n", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
argc = lua_gettop(L) - 1;
if (1 == argc)
{
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!tolua_isnumber(L, 2, 0, &tolua_err))
goto tolua_lerror;
#endif
self->minDelay = tolua_tonumber(L, 2, 0);
return 0;
}
return 0;
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_lerror:
2021-12-25 10:04:45 +08:00
tolua_error(L, "#ferror in function 'lua_set_AudioProfile_minDelay'.", &tolua_err);
2019-11-23 20:27:39 +08:00
return 0;
#endif
}
2022-08-08 18:02:17 +08:00
int axlua_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S)
2019-11-23 20:27:39 +08:00
{
int argc = 0;
bool ok = true;
2021-12-25 10:04:45 +08:00
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_Error tolua_err;
#endif
2021-12-25 10:04:45 +08:00
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2022-07-12 21:31:54 +08:00
if (!tolua_isusertable(tolua_S, 1, "ax.AudioEngine", 0, &tolua_err))
2021-12-25 10:04:45 +08:00
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
argc = lua_gettop(tolua_S) - 1;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
if (argc == 2)
{
int arg0;
2022-07-12 21:31:54 +08:00
ok &= luaval_to_int32(tolua_S, 2, (int*)&arg0, "ax.AudioEngine:setFinishCallback");
2021-12-25 10:04:45 +08:00
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2021-12-25 10:04:45 +08:00
if (!toluafix_isfunction(tolua_S, 3, "LUA_FUNCTION", 0, &tolua_err))
2019-11-23 20:27:39 +08:00
{
goto tolua_lerror;
}
#endif
2021-12-25 10:04:45 +08:00
LUA_FUNCTION handler = (toluafix_ref_function(tolua_S, 3, 0));
2022-08-08 18:02:17 +08:00
ax::AudioEngine::setFinishCallback(arg0, [=](int audioID, std::string_view filePath) {
2019-11-23 20:27:39 +08:00
LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
stack->pushInt(audioID);
stack->pushString(filePath);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
stack->executeFunctionByHandler(handler, 2);
2021-12-25 10:04:45 +08:00
2022-07-20 18:41:33 +08:00
stack->removeScriptHandler(handler);
2019-11-23 20:27:39 +08:00
});
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
return 0;
}
2022-07-12 21:31:54 +08:00
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.AudioEngine:setFinishCallback",
2021-12-25 10:04:45 +08:00
argc, 2);
2019-11-23 20:27:39 +08:00
return 0;
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
tolua_lerror:
2022-08-08 18:02:17 +08:00
tolua_error(tolua_S, "#ferror in function 'axlua_audioengine_AudioEngine_setFinishCallback'.", &tolua_err);
2019-11-23 20:27:39 +08:00
#endif
return 0;
}
int register_audioengine_module(lua_State* L)
{
lua_getglobal(L, "_G");
2021-12-25 10:04:45 +08:00
if (lua_istable(L, -1)) // stack:...,_G,
2019-11-23 20:27:39 +08:00
{
register_all_ax_audioengine(L);
2019-11-23 20:27:39 +08:00
if (L)
{
2022-07-12 21:31:54 +08:00
lua_pushstring(L, "ax.AudioProfile");
2019-11-23 20:27:39 +08:00
lua_rawget(L, LUA_REGISTRYINDEX);
2021-12-25 10:04:45 +08:00
if (lua_istable(L, -1))
2019-11-23 20:27:39 +08:00
{
tolua_variable(L, "name", lua_get_AudioProfile_name, lua_set_AudioProfile_name);
tolua_variable(L, "maxInstances", lua_get_AudioProfile_maxInstances, lua_set_AudioProfile_maxInstances);
tolua_variable(L, "minDelay", lua_get_AudioProfile_minDelay, lua_set_AudioProfile_minDelay);
}
lua_pop(L, 1);
2021-12-25 10:04:45 +08:00
2022-07-12 21:31:54 +08:00
lua_pushstring(L, "ax.AudioEngine");
2019-11-23 20:27:39 +08:00
lua_rawget(L, LUA_REGISTRYINDEX);
2021-12-25 10:04:45 +08:00
if (lua_istable(L, -1))
2019-11-23 20:27:39 +08:00
{
2022-08-08 18:02:17 +08:00
tolua_function(L, "setFinishCallback", axlua_audioengine_AudioEngine_setFinishCallback);
2019-11-23 20:27:39 +08:00
}
lua_pop(L, 1);
}
}
lua_pop(L, 1);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
return 1;
}