First, I have a custom array:
// my Array
namespace luabridge {
/**
* @brief Stack specialization for `dl::Array`.
*/
template <class T, std::size_t Size>
struct Stack<dl::Array<T, Size>>
{
using Type = dl::Array<T, Size>;
[[nodiscard]] static Result push(lua_State* L, const Type& array)
{
#if LUABRIDGE_SAFE_STACK_CHECKS
if (!lua_checkstack(L, 3))
return makeErrorCode(ErrorCode::LuaStackOverflow);
#endif
StackRestore stackRestore(L);
lua_createtable(L, static_cast<int>(Size), 0);
for (std::size_t i = 0; i < Size; ++i)
{
lua_pushinteger(L, static_cast<lua_Integer>(i + 1));
auto result = Stack<T>::push(L, array[i]);
if (!result)
return result;
lua_settable(L, -3);
}
stackRestore.reset();
return {};
}
[[nodiscard]] static TypeResult<Type> get(lua_State* L, int index)
{
if (!lua_istable(L, index))
return makeErrorCode(ErrorCode::InvalidTypeCast);
if (get_length(L, index) != Size)
return makeErrorCode(ErrorCode::InvalidTableSizeInCast);
const StackRestore stackRestore(L);
Type array;
int absIndex = lua_absindex(L, index);
lua_pushnil(L);
int arrayIndex = 0;
while (lua_next(L, absIndex) != 0)
{
auto item = Stack<T>::get(L, -1);
if (!item)
return makeErrorCode(ErrorCode::InvalidTypeCast);
array[arrayIndex++] = *item;
lua_pop(L, 1);
}
return array;
}
[[nodiscard]] static bool isInstance(lua_State* L, int index)
{
return lua_istable(L, index) && get_length(L, index) == Size;
}
};
} // namespace luabridge
now Array is work.
Other definitions:
using Color = Array<float, 4>;
class Sprite
{
void SetColor(const Color& col);
void SetColor(const Color& col, size_t index);
}
when i bind:
luabridge::getGlobalNamespace(L)
.beginClass<Sprite>("Sprite")
.addFunction("SetColor",
luabridge::overload<const Color&>(&Sprite::SetColor),
luabridge::overload<const Color&, size_t>(&Sprite::SetColor))
.endClass();
will compile error:
D:\dl\third\LuaBridge3\Source\LuaBridge\detail\Stack.h(1494): error C2903: “isInstance”: symbol is not class template, and not function template
First, I have a custom array:
now Array is work.
Other definitions:
when i bind:
will compile error:
D:\dl\third\LuaBridge3\Source\LuaBridge\detail\Stack.h(1494): error C2903: “isInstance”: symbol is not class template, and not function template