How to differentiate witch menuItem I Clicked in Lua script ?

Sorry for my poor English.
I want to make a game packet UI with lua.
I puted a lot of CCMenuItemImage as weapons.
But the registerScriptHandler’s param is a callback function.
So I must write a lot of callback function for every menu item.
Just as callback1, callback2, callback3…
FML.
Can you tell me how to solve it ? Thanks a lot.

You can use CCSprite or CCLabel for each menu item instead of using CCMenu. Store them in a table called _allMenuButtons. Then, register a touch handler with your layer. You can then check the bounding box of the touch point for each button in the onTouchEnded event handler:

local function onTouchEnded(x, y)
for i,button in ipairs(_allMenuButtons) do
if button:boundingBox():containsPoint(CCPointMake(x,y)) then
if i 1 then
–first button logic
elseif i 2 then
—second button logic
end
break
end
end
end

local function onTouch(eventType, x, y)
if eventType CCTOUCHBEGAN then
return true
elseif eventType CCTOUCHENDED then
return onTouchEnded(x, y)
end
end

myLayer:setTouchEnabled(true)
myLayer:registerScriptTouchHandler(onTouch)

For large amounts of menu items I recommend using CCMenu and a separate callback function for each for code readability.

Yes, I do~