[SOLVED] Bug in PhysicsShape binding

Hi,
Lua binding for methods like PhysicsShapeEdgeBox::getPoints, PhysicsShapeEdgeChain::getPoints… doesn’t seem to work.

The getPoints function in Lua always returns nil and if I try to pass a table I get the following error.

getPoints has wrong number of arguments: 1, was expecting 1

Here is the Lua code to reproduce the issue.

local scene = cc.Scene:createWithPhysics()

scene:getPhysicsWorld():setDebugDrawMask(cc.PhysicsWorld.DEBUGDRAW_ALL)
scene:getPhysicsWorld():setGravity(cc.p(0,0))

local edgeBox= cc.Node:create()
edgeBox:setPhysicsBody(cc.PhysicsBody:createEdgeBox(cc.size(100,100)))
edgeBox:setPosition(cc.p(100,100))
scene:addChild(edgeBox)

print(edgeBox:getPhysicsBody():getFirstShape():getPointsCount()) -- ok 4
local points = edgeBox:getPhysicsBody():getFirstShape():getPoints()
print(points) -- nil

local points = {}
-- edgeBox:getPhysicsBody():getFirstShape():getPoints(points) -- KO
-- getPoints has wrong number of arguments: 1, was expecting 1 

local poly = cc.Node:create()
poly:setPhysicsBody(cc.PhysicsBody:createPolygon({cc.p(100,250),cc.p(200,300),cc.p(200,250)}))
scene:addChild(poly)

for _,shape in ipairs(poly:getPhysicsBody():getShapes()) do 
    local count = shape:getPointsCount()
    print(count) -- 3
    for i=0, count - 1 do
        local p = shape:getPoint(i)
        print(p.x,p.y) -- ok
    end
    local points = shape:getPoints()
    print(points) -- nil
end

local edgePoly = cc.Node:create()
edgePoly:setPhysicsBody(cc.PhysicsBody:createEdgePolygon({cc.p(300,150),cc.p(400,200),cc.p(400,150)}))
scene:addChild(edgePoly)

print(edgePoly:getPhysicsBody():getFirstShape():getPointsCount())
local points = edgePoly:getPhysicsBody():getFirstShape():getPoints()
print(points) -- nil

cc.Director:getInstance():replaceScene(scene)

Thanks in advance.

I figured out the bug(s) in lua_cocos2dx_physics_manual.cpp. All the lua_cocos2dx_physics***getPoints functions should return 1 instead of 0.

int lua_cocos2dx_physics_PhysicsShapeBox_getPoints(lua_State* tolua_S)
{
...
   if (argc == 0)
   { 
       cocos2d::Vec2 arg0[4];
       cobj->getPoints(arg0);
       vec2_array_to_luaval(tolua_S, arg0, 4);
       return 0; 
   }
...
}

vec2_array_to_luaval push the table to the Lua stack but since the function lua_cocos2dx_physics_PhysicsShapeBox_getPoints returns zero no value is actually returned in the Lua code. It must be changed to 1 in all the ***getPoints to fix it.

Regards,
Laurent