Forum > Lua Binding > Bug in 0.12 lua bindings

Bug in 0.12 lua bindings

By nozomiyume Posted 2012-03-20 03:01 Comments 2
nozomiyume
  • Posts: 8

It looks like the new Lua bindings with 0.12 have introduced some issues with super classes not reporting correctly. From what I understand, as classes are registered (via tolua_cclass), all the super classes are registered as well (via mapsuper).

However, in the most recent version of LuaCocos2d, it looks like it’s not guaranteed that the parent class of certain CCObjects are registered before their children. Specifically the issue I’ve found is that

tolua_cclass(tolua_S,"CCLabelTTF","CCLabelTTF","CCSprite",NULL);

is now before

tolua_cclass(tolua_S,"CCSprite","CCSprite","CCNode",NULL);

What this means is when you try and do something like this:

label = CCLabelTTF:labelWithString("Test Label", "Marker Felt", 16.0)
layerGame:addChild(label)

The inner c code will fail checking the argument:

!tolua_isusertype(tolua_S,2,"CCNode",0,&tolua_err) ||

Because CCNode hasn’t been added in the class hierarchy. Unfortunately this makes many of the cocos objects unusable with the lua bindings :(

Is anyone else experiencing this behavior? If so, it would be great to get the LuaCocos2d.cpp file regenerated with explicit ordering as it seemed to before. At the least, git history says that these were ordered correctly before :)

https://raw.github.com/cocos2d/cocos2d-x/cocos2d-1.0.1-x-0.11.0/lua/cocos2dx\_support/LuaCocos2d.cpp

Thanks!

nozomiyume
  • Posts: 8

#1 RE: 2012-03-20 03:45

Looks like this works as a workaround, but it’s sloppy and easy to miss / cause errors…

layerGame:addChild(tolua.cast(label, "CCNode"), 0, 1)
label = layerGame:getChildByTag(1)
label = tolua.cast(label, "CCLabelTTF")

dualface
  • Posts: 61

#2 RE: 2012-03-21 02:12

thanks, i’m working for this bug :)

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps