Skip to content

Commit

Permalink
update olua
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongfq committed Jun 5, 2024
1 parent d1c04f4 commit ee3a91b
Show file tree
Hide file tree
Showing 26 changed files with 4,044 additions and 1,437 deletions.
2 changes: 1 addition & 1 deletion frameworks/cclua/src/box2d/box2d-2dx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

NS_BOX2D_BEGIN

typedef olua::array<b2Vec2> Vec2Array;
typedef olua::pointer<b2Vec2> Vec2Array;

class DestructionListener : public b2DestructionListener
{
Expand Down
2 changes: 1 addition & 1 deletion frameworks/cclua/src/cclua/cclua-extend.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef olua::pointer<std::vector<std::string>> VectorString;
typedef olua::pointer<std::vector<int>> VectorInt;
typedef olua::pointer<cocos2d::ValueMap> ValueMap;
typedef olua::pointer<cocos2d::TMXTileFlags> TMXTileFlags;
typedef olua::array<cocos2d::Vec2> Vec2Array;
typedef olua::pointer<cocos2d::Vec2> Vec2Array;
}

struct Bounds {
Expand Down
6 changes: 3 additions & 3 deletions frameworks/cclua/src/cclua/luauser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ template <class K, class V>
void olua_insert_map(cocos2d::Map<K, V> &map, const K &key, const V &value);

template <class T>
void olua_insert_vector(cocos2d::Vector<T> &array, const T &value);
void olua_insert_array(cocos2d::Vector<T> &array, const T &value);

// spine
#ifdef CCLUA_BUILD_SPINE
#include "spine/Vector.h"
template <class T>
void olua_insert_vector(spine::Vector<T> &array, const T &value);
void olua_insert_array(spine::Vector<T> &array, const T &value);

template <class T>
void olua_foreach_vector(const spine::Vector<T> &array, const std::function<void(T &)> &callback);
void olua_foreach_array(const spine::Vector<T> &array, const std::function<void(T &)> &callback);
#endif // CCLUA_BUILD_SPINE

#endif // __cplusplus
Expand Down
102 changes: 77 additions & 25 deletions frameworks/cclua/src/lua-bindings/lua_box2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,26 @@ static int _box2d_Vec2Array___olua_move(lua_State *L)
return 1;
}

static int _box2d_Vec2Array_assign(lua_State *L)
{
olua_startinvoke(L);

box2d::Vec2Array *self = nullptr;
const char *arg1 = nullptr; /** data */
size_t arg2 = 0; /** len */

olua_to_object(L, 1, &self, "b2.Vec2Array");
olua_check_string(L, 2, &arg1);
olua_check_integer(L, 3, &arg2);

// void assign(const char *data, size_t len)
self->assign(arg1, arg2);

olua_endinvoke(L);

return 0;
}

static int _box2d_Vec2Array_create$1(lua_State *L)
{
olua_startinvoke(L);
Expand Down Expand Up @@ -2478,23 +2498,72 @@ static int _box2d_Vec2Array_create(lua_State *L)
return 0;
}

static int _box2d_Vec2Array_setstring(lua_State *L)
static int _box2d_Vec2Array_slice$1(lua_State *L)
{
olua_startinvoke(L);

box2d::Vec2Array *self = nullptr;
const char *arg1 = nullptr; /** data */
size_t arg2 = 0; /** len */
size_t arg1 = 0; /** from */
size_t arg2 = 0; /** to */

olua_to_object(L, 1, &self, "b2.Vec2Array");
olua_check_string(L, 2, &arg1);
olua_check_integer(L, 2, &arg1);
olua_check_integer(L, 3, &arg2);

// void setstring(const char *data, size_t len)
self->setstring(arg1, arg2);
// @postnew box2d::Vec2Array *slice(size_t from, @optional size_t to)
box2d::Vec2Array *ret = self->slice(arg1, arg2);
int num_ret = olua_push_object(L, ret, "b2.Vec2Array");

// insert code after call
olua_postnew(L, ret);

olua_endinvoke(L);

return num_ret;
}

static int _box2d_Vec2Array_slice$2(lua_State *L)
{
olua_startinvoke(L);

box2d::Vec2Array *self = nullptr;
size_t arg1 = 0; /** from */

olua_to_object(L, 1, &self, "b2.Vec2Array");
olua_check_integer(L, 2, &arg1);

// @postnew box2d::Vec2Array *slice(size_t from, @optional size_t to)
box2d::Vec2Array *ret = self->slice(arg1);
int num_ret = olua_push_object(L, ret, "b2.Vec2Array");

// insert code after call
olua_postnew(L, ret);

olua_endinvoke(L);

return num_ret;
}

static int _box2d_Vec2Array_slice(lua_State *L)
{
int num_args = lua_gettop(L) - 1;

if (num_args == 1) {
// if ((olua_is_integer(L, 2))) {
// @postnew box2d::Vec2Array *slice(size_t from, @optional size_t to)
return _box2d_Vec2Array_slice$2(L);
// }
}

if (num_args == 2) {
// if ((olua_is_integer(L, 2)) && (olua_is_integer(L, 3))) {
// @postnew box2d::Vec2Array *slice(size_t from, @optional size_t to)
return _box2d_Vec2Array_slice$1(L);
// }
}

luaL_error(L, "method 'box2d::Vec2Array::slice' not support '%d' arguments", num_args);

return 0;
}

Expand Down Expand Up @@ -2602,23 +2671,6 @@ static int _box2d_Vec2Array_tostring(lua_State *L)
return (int)ret;
}

static int _box2d_Vec2Array_data(lua_State *L)
{
olua_startinvoke(L);

box2d::Vec2Array *self = nullptr;

olua_to_object(L, 1, &self, "b2.Vec2Array");

// @getter @name(data) b2Vec2 *data()
b2Vec2 *ret = self->data();
int num_ret = olua_push_object(L, ret, "b2.Vec2");

olua_endinvoke(L);

return num_ret;
}

static int _box2d_Vec2Array_length(lua_State *L)
{
olua_startinvoke(L);
Expand Down Expand Up @@ -2695,12 +2747,12 @@ OLUA_LIB int luaopen_box2d_Vec2Array(lua_State *L)
oluacls_func(L, "__index", _box2d_Vec2Array___index);
oluacls_func(L, "__newindex", _box2d_Vec2Array___newindex);
oluacls_func(L, "__olua_move", _box2d_Vec2Array___olua_move);
oluacls_func(L, "assign", _box2d_Vec2Array_assign);
oluacls_func(L, "new", _box2d_Vec2Array_create);
oluacls_func(L, "setstring", _box2d_Vec2Array_setstring);
oluacls_func(L, "slice", _box2d_Vec2Array_slice);
oluacls_func(L, "sub", _box2d_Vec2Array_sub);
oluacls_func(L, "take", _box2d_Vec2Array_take);
oluacls_func(L, "tostring", _box2d_Vec2Array_tostring);
oluacls_prop(L, "data", _box2d_Vec2Array_data, nullptr);
oluacls_prop(L, "length", _box2d_Vec2Array_length, _box2d_Vec2Array_length);
oluacls_prop(L, "rawdata", _box2d_Vec2Array_rawdata, nullptr);
oluacls_prop(L, "sizeof", _box2d_Vec2Array_size, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion frameworks/cclua/src/lua-bindings/lua_cclua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ static int _cclua_runtime_getArgs(lua_State *L)

// static const std::vector<std::string> &getArgs()
const std::vector<std::string> &ret = cclua::runtime::getArgs();
int num_ret = olua_push_vector<std::string>(L, ret, [L](std::string &arg1) {
int num_ret = olua_push_array<std::string>(L, ret, [L](std::string &arg1) {
olua_push_string(L, arg1);
});

Expand Down
Loading

0 comments on commit ee3a91b

Please sign in to comment.