axmol/tests/lua-tests/Source/lua_test_bindings.cpp

715 lines
19 KiB
C++
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
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:
2019-11-23 20:27:39 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2019-11-23 20:27:39 +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.
****************************************************************************/
#include "lua_test_bindings.h"
#include "cocos2d.h"
#include "scripting/lua-bindings/manual/LuaBasicConversions.h"
NS_AX_BEGIN
2019-11-23 20:27:39 +08:00
/**
* Copy DrawNode for 3D geometry drawing.
*/
class DrawNode3D : public Node
2019-11-23 20:27:39 +08:00
{
public:
/** creates and initialize a DrawNode3D node */
static DrawNode3D* create();
2019-11-23 20:27:39 +08:00
/**
* Draw 3D Line
*/
void drawLine(const Vec3& from, const Vec3& to, const Color4F& color);
2019-11-23 20:27:39 +08:00
/**
* Draw 3D cube
* @param point to a vertex array who has 8 element.
* vertices[0]:Left-top-front,
* vertices[1]:Left-bottom-front,
* vertices[2]:Right-bottom-front,
* vertices[3]:Right-top-front,
* vertices[4]:Right-top-back,
* vertices[5]:Right-bottom-back,
* vertices[6]:Left-bottom-back,
* vertices[7]:Left-top-back.
* @param color
*/
void drawCube(Vec3* vertices, const Color4F& color);
2019-11-23 20:27:39 +08:00
/** Clear the geometry in the node's buffer. */
void clear();
2019-11-23 20:27:39 +08:00
/**
* @js NA
* @lua NA
*/
const BlendFunc& getBlendFunc() const;
2019-11-23 20:27:39 +08:00
/**
* @code
* When this function bound into js or lua,the parameter will be changed
* In js: var setBlendFunc(var src, var dst)
* @endcode
* @lua NA
*/
void setBlendFunc(const BlendFunc& blendFunc);
2019-11-23 20:27:39 +08:00
// Overrides
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
DrawNode3D();
2019-11-23 20:27:39 +08:00
virtual ~DrawNode3D();
virtual bool init() override;
2019-11-23 20:27:39 +08:00
protected:
struct V3F_C4B
{
Vec3 vertices;
Color4B colors;
2019-11-23 20:27:39 +08:00
};
void ensureCapacity(int count);
std::vector<V3F_C4B> _buffer;
BlendFunc _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
CustomCommand _customCommand;
backend::ProgramState* _programState = nullptr;
bool _dirty = false;
backend::UniformLocation _locMVPMatrix;
2019-11-23 20:27:39 +08:00
private:
2022-07-16 10:43:05 +08:00
AX_DISALLOW_COPY_AND_ASSIGN(DrawNode3D);
2019-11-23 20:27:39 +08:00
bool _rendererDepthTestEnabled = false;
2019-11-23 20:27:39 +08:00
void onBeforeDraw();
void onAfterDraw();
};
DrawNode3D::DrawNode3D() {}
2019-11-23 20:27:39 +08:00
DrawNode3D::~DrawNode3D()
{
2022-07-16 10:43:05 +08:00
AX_SAFE_RELEASE_NULL(_programState);
2019-11-23 20:27:39 +08:00
}
DrawNode3D* DrawNode3D::create()
{
2021-12-08 00:11:53 +08:00
DrawNode3D* ret = new DrawNode3D();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
2019-11-23 20:27:39 +08:00
return ret;
}
void DrawNode3D::ensureCapacity(int count)
{
2022-07-16 10:43:05 +08:00
AXASSERT(count >= 0, "capacity must be >= 0");
if (_buffer.size() + count > _buffer.capacity())
2019-11-23 20:27:39 +08:00
{
auto newSize = MAX(_buffer.capacity() + (_buffer.capacity() >> 1), count + _buffer.size());
2019-11-23 20:27:39 +08:00
_buffer.reserve(newSize);
}
2019-11-23 20:27:39 +08:00
}
bool DrawNode3D::init()
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
auto program = backend::Program::getBuiltinProgram(backend::ProgramType::LINE_COLOR_3D);
2019-11-23 20:27:39 +08:00
_programState = new backend::ProgramState(program);
_locMVPMatrix = _programState->getUniformLocation("u_MVPMatrix");
#define INITIAL_VERTEX_BUFFER_LENGTH 512
ensureCapacity(INITIAL_VERTEX_BUFFER_LENGTH);
_customCommand.setDrawType(CustomCommand::DrawType::ARRAY);
_customCommand.setPrimitiveType(CustomCommand::PrimitiveType::LINE);
const auto& attributeInfo = _programState->getProgram()->getActiveAttributes();
auto iter = attributeInfo.find("a_position");
if (iter != attributeInfo.end())
{
2023-08-31 18:07:23 +08:00
_programState->setVertexAttrib(iter->first, iter->second.location, backend::VertexFormat::FLOAT3, 0, false);
2019-11-23 20:27:39 +08:00
}
iter = attributeInfo.find("a_color");
if (iter != attributeInfo.end())
{
2023-08-31 18:07:23 +08:00
_programState->setVertexAttrib(iter->first, iter->second.location, backend::VertexFormat::UBYTE4, sizeof(Vec3), true);
2019-11-23 20:27:39 +08:00
}
2023-08-31 18:07:23 +08:00
_programState->setVertexStride(sizeof(V3F_C4B));
2019-11-23 20:27:39 +08:00
_customCommand.createVertexBuffer(sizeof(V3F_C4B), INITIAL_VERTEX_BUFFER_LENGTH,
CustomCommand::BufferUsage::DYNAMIC);
2019-11-23 20:27:39 +08:00
_customCommand.getPipelineDescriptor().programState = _programState;
_dirty = true;
2022-07-16 10:43:05 +08:00
_customCommand.setBeforeCallback(AX_CALLBACK_0(DrawNode3D::onBeforeDraw, this));
_customCommand.setAfterCallback(AX_CALLBACK_0(DrawNode3D::onAfterDraw, this));
2019-11-23 20:27:39 +08:00
2022-07-16 10:43:05 +08:00
#if AX_ENABLE_CACHE_TEXTURE_DATA
2019-11-23 20:27:39 +08:00
// Need to listen the event only when not use batchnode, because it will use VBO
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event) {
2019-11-23 20:27:39 +08:00
/** listen the event that coming to foreground on Android */
this->init();
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
return true;
}
void DrawNode3D::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
2019-11-23 20:27:39 +08:00
{
_customCommand.init(_globalZOrder);
// update mvp matrix
auto& matrixP = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
auto mvp = matrixP * transform;
2019-11-23 20:27:39 +08:00
_programState->setUniform(_locMVPMatrix, mvp.m, sizeof(mvp.m));
if (_customCommand.getVertexCapacity() < _buffer.size())
{
2019-11-23 20:27:39 +08:00
auto s = _buffer.size();
_customCommand.createVertexBuffer(sizeof(V3F_C4B), s + s / 2, CustomCommand::BufferUsage::DYNAMIC);
2019-11-23 20:27:39 +08:00
}
if (_dirty && !_buffer.empty())
{
_customCommand.updateVertexBuffer(_buffer.data(), (unsigned int)(_buffer.size() * sizeof(_buffer[0])));
_customCommand.setVertexDrawInfo(0, _buffer.size());
_dirty = false;
}
setBlendFunc(_blendFunc);
if (!_buffer.empty())
{
renderer->addCommand(&_customCommand);
}
}
void DrawNode3D::drawLine(const Vec3& from, const Vec3& to, const Color4F& color)
2019-11-23 20:27:39 +08:00
{
unsigned int vertex_count = 2;
ensureCapacity(vertex_count);
2019-11-23 20:27:39 +08:00
Color4B col = Color4B(color);
V3F_C4B a = {Vec3(from.x, from.y, from.z), col};
V3F_C4B b = {
Vec3(to.x, to.y, to.z),
col,
};
2019-11-23 20:27:39 +08:00
_buffer.emplace_back(a);
_buffer.emplace_back(b);
_dirty = true;
}
void DrawNode3D::drawCube(Vec3* vertices, const Color4F& color)
2019-11-23 20:27:39 +08:00
{
// front face
drawLine(vertices[0], vertices[1], color);
drawLine(vertices[1], vertices[2], color);
drawLine(vertices[2], vertices[3], color);
drawLine(vertices[3], vertices[0], color);
2019-11-23 20:27:39 +08:00
// back face
drawLine(vertices[4], vertices[5], color);
drawLine(vertices[5], vertices[6], color);
drawLine(vertices[6], vertices[7], color);
drawLine(vertices[7], vertices[4], color);
2019-11-23 20:27:39 +08:00
// edge
drawLine(vertices[0], vertices[7], color);
drawLine(vertices[1], vertices[6], color);
drawLine(vertices[2], vertices[5], color);
drawLine(vertices[3], vertices[4], color);
}
void DrawNode3D::clear()
{
_dirty = true;
_buffer.clear();
}
const BlendFunc& DrawNode3D::getBlendFunc() const
{
return _blendFunc;
}
void DrawNode3D::setBlendFunc(const BlendFunc& blendFunc)
2019-11-23 20:27:39 +08:00
{
_blendFunc = blendFunc;
// update blend mode
auto& blend = _customCommand.getPipelineDescriptor().blendDescriptor;
blend.blendEnabled = true;
2019-11-23 20:27:39 +08:00
blend.sourceRGBBlendFactor = blend.sourceAlphaBlendFactor = _blendFunc.src;
blend.destinationRGBBlendFactor = blend.destinationAlphaBlendFactor = _blendFunc.dst;
}
void DrawNode3D::onBeforeDraw()
{
auto* renderer = Director::getInstance()->getRenderer();
2019-11-23 20:27:39 +08:00
_rendererDepthTestEnabled = renderer->getDepthTest();
renderer->setDepthTest(true);
}
void DrawNode3D::onAfterDraw()
{
auto* renderer = Director::getInstance()->getRenderer();
2019-11-23 20:27:39 +08:00
renderer->setDepthTest(_rendererDepthTestEnabled);
}
/**
@since v3.3rc1
This class is used to check if the the value type judgement in table is correct or not.
eg:
If call `create` by passing {index1 = 111, index2 = 112, index3 = 113} from lua,
the type 111,112,113 would be judged as string type before 3.3rc1
**/
class ValueTypeJudgeInTable : public Node
2019-11-23 20:27:39 +08:00
{
public:
static ValueTypeJudgeInTable* create(ValueMap valueMap);
};
ValueTypeJudgeInTable* ValueTypeJudgeInTable::create(ValueMap valueMap)
{
2021-12-08 00:11:53 +08:00
ValueTypeJudgeInTable* ret = new ValueTypeJudgeInTable();
ret->autorelease();
2019-11-23 20:27:39 +08:00
int index = 0;
for (const auto& iter : valueMap)
{
2021-11-09 14:29:15 +08:00
Value::Type type = iter.second.getTypeFamily();
if (type == Value::Type::STRING)
{
2022-07-16 10:43:05 +08:00
AXLOG("The type of index %d is string", index);
2019-11-23 20:27:39 +08:00
}
if (type == Value::Type::INTEGER || type == Value::Type::DOUBLE || type == Value::Type::FLOAT)
{
2022-07-16 10:43:05 +08:00
AXLOG("The type of index %d is number", index);
2019-11-23 20:27:39 +08:00
}
2019-11-23 20:27:39 +08:00
++index;
}
2019-11-23 20:27:39 +08:00
return ret;
}
NS_AX_END
2019-11-23 20:27:39 +08:00
int lua_cocos2dx_DrawNode3D_getBlendFunc(lua_State* L)
{
int argc = 0;
2022-10-18 19:17:36 +08:00
ax::DrawNode3D* cobj = nullptr;
bool ok = true;
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
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.DrawNode3D", 0, &tolua_err))
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-10-18 19:17:36 +08:00
cobj = (ax::DrawNode3D*)tolua_tousertype(L, 1, 0);
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!cobj)
{
tolua_error(L, "invalid 'cobj' in function 'lua_cocos2dx_DrawNode3D_getBlendFunc'", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
argc = lua_gettop(L) - 1;
2019-11-23 20:27:39 +08:00
if (argc == 0)
{
if (!ok)
2019-11-23 20:27:39 +08:00
return 0;
2022-10-18 19:17:36 +08:00
const ax::BlendFunc& ret = cobj->getBlendFunc();
2019-11-23 20:27:39 +08:00
blendfunc_to_luaval(L, ret);
return 1;
}
2022-07-16 10:43:05 +08:00
AXLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ax.DrawNode3D:getBlendFunc", argc, 0);
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:
tolua_error(L, "#ferror in function 'lua_cocos2dx_DrawNode3D_getBlendFunc'.", &tolua_err);
2019-11-23 20:27:39 +08:00
#endif
2019-11-23 20:27:39 +08:00
return 0;
}
int lua_cocos2dx_DrawNode3D_setBlendFunc(lua_State* L)
{
int argc = 0;
2022-10-18 19:17:36 +08:00
ax::DrawNode3D* cobj = nullptr;
bool ok = true;
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
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.DrawNode3D", 0, &tolua_err))
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-10-18 19:17:36 +08:00
cobj = (ax::DrawNode3D*)tolua_tousertype(L, 1, 0);
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!cobj)
{
tolua_error(L, "invalid 'cobj' in function 'lua_cocos2dx_DrawNode3D_setBlendFunc'", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
argc = lua_gettop(L) - 1;
2019-11-23 20:27:39 +08:00
if (argc == 1)
{
2022-10-18 19:17:36 +08:00
ax::BlendFunc arg0;
2022-07-12 21:31:54 +08:00
ok &= luaval_to_blendfunc(L, 2, &arg0, "ax.Sprite3D:setBlendFunc");
if (!ok)
2019-11-23 20:27:39 +08:00
{
tolua_error(L, "invalid arguments in function 'lua_cocos2dx_DrawNode3D_setBlendFunc'", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
cobj->setBlendFunc(arg0);
return 0;
}
2022-07-16 10:43:05 +08:00
AXLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ax.DrawNode3D:setBlendFunc", argc, 1);
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:
tolua_error(L, "#ferror in function 'lua_cocos2dx_DrawNode3D_setBlendFunc'.", &tolua_err);
2019-11-23 20:27:39 +08:00
#endif
2019-11-23 20:27:39 +08:00
return 0;
}
int lua_cocos2dx_DrawNode3D_drawLine(lua_State* L)
{
int argc = 0;
2022-10-18 19:17:36 +08:00
ax::DrawNode3D* cobj = nullptr;
bool ok = true;
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
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.DrawNode3D", 0, &tolua_err))
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-10-18 19:17:36 +08:00
cobj = (ax::DrawNode3D*)tolua_tousertype(L, 1, 0);
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!cobj)
{
tolua_error(L, "invalid 'cobj' in function 'lua_cocos2dx_DrawNode3D_drawLine'", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
argc = lua_gettop(L) - 1;
2019-11-23 20:27:39 +08:00
if (argc == 3)
{
2022-10-18 19:17:36 +08:00
ax::Vec3 arg0;
ax::Vec3 arg1;
ax::Color4F arg2;
2022-07-12 21:31:54 +08:00
ok &= luaval_to_vec3(L, 2, &arg0, "ax.DrawNode3D:drawLine");
2022-07-12 21:31:54 +08:00
ok &= luaval_to_vec3(L, 3, &arg1, "ax.DrawNode3D:drawLine");
2022-07-12 21:31:54 +08:00
ok &= luaval_to_color4f(L, 4, &arg2, "ax.DrawNode3D:drawLine");
if (!ok)
2019-11-23 20:27:39 +08:00
return 0;
cobj->drawLine(arg0, arg1, arg2);
return 0;
}
2022-07-16 10:43:05 +08:00
AXLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ax.DrawNode3D:drawLine", argc, 3);
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:
tolua_error(L, "#ferror in function 'lua_cocos2dx_DrawNode3D_drawLine'.", &tolua_err);
2019-11-23 20:27:39 +08:00
#endif
2019-11-23 20:27:39 +08:00
return 0;
}
int lua_cocos2dx_DrawNode3D_clear(lua_State* L)
{
int argc = 0;
2022-10-18 19:17:36 +08:00
ax::DrawNode3D* cobj = nullptr;
bool ok = true;
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
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.DrawNode3D", 0, &tolua_err))
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-10-18 19:17:36 +08:00
cobj = (ax::DrawNode3D*)tolua_tousertype(L, 1, 0);
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!cobj)
{
tolua_error(L, "invalid 'cobj' in function 'lua_cocos2dx_DrawNode3D_clear'", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
argc = lua_gettop(L) - 1;
2019-11-23 20:27:39 +08:00
if (argc == 0)
{
if (!ok)
2019-11-23 20:27:39 +08:00
return 0;
cobj->clear();
return 0;
}
2022-07-16 10:43:05 +08:00
AXLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ax.DrawNode3D:clear", argc, 0);
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:
tolua_error(L, "#ferror in function 'lua_cocos2dx_DrawNode3D_clear'.", &tolua_err);
2019-11-23 20:27:39 +08:00
#endif
2019-11-23 20:27:39 +08:00
return 0;
}
int lua_cocos2dx_DrawNode3D_drawCube(lua_State* L)
{
int argc = 0;
2022-10-18 19:17:36 +08:00
ax::DrawNode3D* cobj = nullptr;
bool ok = true;
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
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2022-07-12 21:31:54 +08:00
if (!tolua_isusertype(L, 1, "ax.DrawNode3D", 0, &tolua_err))
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2022-10-18 19:17:36 +08:00
cobj = (ax::DrawNode3D*)tolua_tousertype(L, 1, 0);
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!cobj)
{
tolua_error(L, "invalid 'cobj' in function 'lua_cocos2dx_DrawNode3D_drawCube'", nullptr);
2019-11-23 20:27:39 +08:00
return 0;
}
#endif
argc = lua_gettop(L) - 1;
2019-11-23 20:27:39 +08:00
if (argc == 2)
{
2022-10-18 19:17:36 +08:00
std::vector<ax::Vec3> arg0;
ax::Color4F arg1;
2019-11-23 20:27:39 +08:00
Vec3 vec3;
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!tolua_istable(L, 2, 0, &tolua_err))
goto tolua_lerror;
#endif
size_t size = lua_objlen(L, 2);
for (int i = 0; i < size; i++)
{
lua_pushnumber(L, i + 1);
lua_gettable(L, 2);
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!tolua_istable(L, -1, 0, &tolua_err))
{
lua_pop(L, 1);
goto tolua_lerror;
}
#endif
ok &= luaval_to_vec3(L, lua_gettop(L), &vec3);
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2019-11-23 20:27:39 +08:00
if (!ok)
{
lua_pop(L, 1);
goto tolua_lerror;
}
#endif
// arg0[i] = vec3;
arg0.emplace_back(vec3);
2019-11-23 20:27:39 +08:00
lua_pop(L, 1);
}
2022-07-12 21:31:54 +08:00
ok &= luaval_to_color4f(L, 3, &arg1, "ax.DrawNode3D:drawCube");
if (!ok)
2019-11-23 20:27:39 +08:00
return 0;
cobj->drawCube(&arg0[0], arg1);
return 0;
}
2022-07-16 10:43:05 +08:00
AXLOG("%s has wrong number of arguments: %d, was expecting %d \n", "ax.DrawNode3D:drawCube", 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:
tolua_error(L, "#ferror in function 'lua_cocos2dx_DrawNode3D_drawCube'.", &tolua_err);
2019-11-23 20:27:39 +08:00
#endif
2019-11-23 20:27:39 +08:00
return 0;
}
int lua_cocos2dx_DrawNode3D_create(lua_State* L)
{
int argc = 0;
bool ok = true;
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
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2022-07-12 21:31:54 +08:00
if (!tolua_isusertable(L, 1, "ax.DrawNode3D", 0, &tolua_err))
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2019-11-23 20:27:39 +08:00
argc = lua_gettop(L) - 1;
2019-11-23 20:27:39 +08:00
if (argc == 0)
{
if (!ok)
2019-11-23 20:27:39 +08:00
return 0;
2022-10-18 19:17:36 +08:00
ax::DrawNode3D* ret = ax::DrawNode3D::create();
object_to_luaval<ax::DrawNode3D>(L, "ax.DrawNode3D", (ax::DrawNode3D*)ret);
2019-11-23 20:27:39 +08:00
return 1;
}
2022-07-16 10:43:05 +08:00
AXLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "ax.DrawNode3D:create", argc, 0);
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:
tolua_error(L, "#ferror in function 'lua_cocos2dx_DrawNode3D_create'.", &tolua_err);
2019-11-23 20:27:39 +08:00
#endif
return 0;
}
int lua_register_cocos2dx_DrawNode3D(lua_State* L)
{
2022-07-12 21:31:54 +08:00
tolua_usertype(L, "ax.DrawNode3D");
tolua_cclass(L, "DrawNode3D", "ax.DrawNode3D", "ax.Node", nullptr);
tolua_beginmodule(L, "DrawNode3D");
tolua_function(L, "getBlendFunc", lua_cocos2dx_DrawNode3D_getBlendFunc);
tolua_function(L, "drawLine", lua_cocos2dx_DrawNode3D_drawLine);
tolua_function(L, "clear", lua_cocos2dx_DrawNode3D_clear);
tolua_function(L, "drawCube", lua_cocos2dx_DrawNode3D_drawCube);
tolua_function(L, "create", lua_cocos2dx_DrawNode3D_create);
2019-11-23 20:27:39 +08:00
tolua_endmodule(L);
2022-10-18 19:17:36 +08:00
auto typeName = typeid(ax::DrawNode3D).name();
2022-07-12 21:31:54 +08:00
g_luaType[reinterpret_cast<uintptr_t>(typeName)] = "ax.DrawNode3D";
g_typeCast[typeName] = "ax.DrawNode3D";
2019-11-23 20:27:39 +08:00
return 1;
}
int lua_cocos2dx_ValueTypeJudgeInTable_create(lua_State* L)
{
int argc = 0;
bool ok = true;
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
2022-08-08 18:02:17 +08:00
#if _AX_DEBUG >= 1
2022-07-12 21:31:54 +08:00
if (!tolua_isusertable(L, 1, "ax.ValueTypeJudgeInTable", 0, &tolua_err))
goto tolua_lerror;
2019-11-23 20:27:39 +08:00
#endif
2019-11-23 20:27:39 +08:00
argc = lua_gettop(L) - 1;
2019-11-23 20:27:39 +08:00
if (argc == 1)
{
2022-10-18 19:17:36 +08:00
ax::ValueMap arg0;
2022-07-12 21:31:54 +08:00
ok &= luaval_to_ccvaluemap(L, 2, &arg0, "ax.ValueTypeJudgeInTable:create");
if (!ok)
2019-11-23 20:27:39 +08:00
return 0;
2022-10-18 19:17:36 +08:00
ax::ValueTypeJudgeInTable* ret = ax::ValueTypeJudgeInTable::create(arg0);
object_to_luaval<ax::ValueTypeJudgeInTable>(L, "ax.ValueTypeJudgeInTable",
(ax::ValueTypeJudgeInTable*)ret);
2019-11-23 20:27:39 +08:00
return 1;
}
2022-07-16 10:43:05 +08:00
AXLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "ax.ValueTypeJudgeInTable:create", argc, 1);
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:
tolua_error(L, "#ferror in function 'lua_cocos2dx_ValueTypeJudgeInTable_create'.", &tolua_err);
2019-11-23 20:27:39 +08:00
#endif
return 0;
}
int lua_register_cocos2dx_ValueTypeJudgeInTable(lua_State* L)
{
2022-07-12 21:31:54 +08:00
tolua_usertype(L, "ax.ValueTypeJudgeInTable");
tolua_cclass(L, "ValueTypeJudgeInTable", "ax.ValueTypeJudgeInTable", "ax.Node", nullptr);
tolua_beginmodule(L, "ValueTypeJudgeInTable");
tolua_function(L, "create", lua_cocos2dx_ValueTypeJudgeInTable_create);
2019-11-23 20:27:39 +08:00
tolua_endmodule(L);
2022-10-18 19:17:36 +08:00
auto typeName = typeid(ax::ValueTypeJudgeInTable).name();
2022-07-12 21:31:54 +08:00
g_luaType[reinterpret_cast<uintptr_t>(typeName)] = "ax.ValueTypeJudgeInTable";
g_typeCast[typeName] = "ax.ValueTypeJudgeInTable";
2019-11-23 20:27:39 +08:00
return 1;
}
int register_test_binding(lua_State* L)
{
tolua_open(L);
2022-07-12 21:31:54 +08:00
tolua_module(L, "ax", 0);
tolua_beginmodule(L, "ax");
lua_register_cocos2dx_DrawNode3D(L);
lua_register_cocos2dx_ValueTypeJudgeInTable(L);
2019-11-23 20:27:39 +08:00
tolua_endmodule(L);
return 0;
}