Skip to content

Commit

Permalink
fix param index for non-member function.
Browse files Browse the repository at this point in the history
  • Loading branch information
gengyong committed Oct 30, 2021
1 parent 9e802dd commit 285ee46
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions luaaa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ namespace LUAAA_NS
template<typename FTYPE, typename ...ARGS, std::size_t... Ns>
void LuaInvokeVoidImpl(lua_State* state, void* calleePtr, size_t skip, indices<Ns...>)
{
(*(FTYPE*)(calleePtr))(LuaStack<ARGS>::get(state, Ns + 2 + skip)...);
LUAAA_DUMP(state, "3");
(*(FTYPE*)(calleePtr))(LuaStack<ARGS>::get(state, Ns + 1 + skip)...);
}

template<typename FTYPE, typename ...ARGS>
Expand All @@ -466,7 +467,8 @@ namespace LUAAA_NS
template<typename TRET, typename FTYPE, typename ...ARGS, std::size_t... Ns>
TRET LuaInvokeImpl(lua_State* state, void* calleePtr, size_t skip, indices<Ns...>)
{
return (*(FTYPE*)(calleePtr))(LuaStack<ARGS>::get(state, Ns + 2 + skip)...);
LUAAA_DUMP(state, "4");
return (*(FTYPE*)(calleePtr))(LuaStack<ARGS>::get(state, Ns + 1 + skip)...);
}

template<typename TRET, typename FTYPE, typename ...ARGS>
Expand Down Expand Up @@ -570,6 +572,7 @@ namespace LUAAA_NS
template<typename TCLASS, typename TRET, typename FTYPE, typename ...ARGS, std::size_t... Ns>
TRET LuaInvokeInstanceMemberImpl(lua_State* state, void* calleePtr, indices<Ns...>)
{
LUAAA_DUMP(state, "1");
return (LuaStack<TCLASS>::get(state, 1).**(FTYPE*)(calleePtr))(LuaStack<ARGS>::get(state, Ns + 2)...);
}

Expand All @@ -582,6 +585,7 @@ namespace LUAAA_NS
template<typename TCLASS, typename FTYPE, typename ...ARGS, std::size_t... Ns>
void LuaInvokeInstanceMemberVoidImpl(lua_State* state, void* calleePtr, indices<Ns...>)
{
LUAAA_DUMP(state, "2");
(LuaStack<TCLASS>::get(state, 1).**(FTYPE*)(calleePtr))(LuaStack<ARGS>::get(state, Ns + 2)...);
}

Expand Down Expand Up @@ -786,7 +790,7 @@ namespace LUAAA_NS
TCLASS ** objPtr = (TCLASS **)lua_newuserdata(state, sizeof(TCLASS*) + sizeof(TCLASS));
if (objPtr)
{
TCLASS * obj = PlacementConstructorCaller<TCLASS, ARGS...>(state, (void*)(objPtr + 1));
TCLASS * obj = PlacementConstructorCaller<TCLASS, ARGS...>::Invoke(state, (void*)(objPtr + 1));

*objPtr = obj;
luaL_Reg destructor[] = { { "__gc", HelperClass::f_gc },{ nullptr, nullptr } };
Expand Down

0 comments on commit 285ee46

Please sign in to comment.