Lua 没办法调用 c++ 静态变量

可以调用静态方法,

但不可以调用静态变量,
发现是2.2.3里把tolua里面代码修改了,
我试着回到2.2.1版本,的确可以调用了,
但是,requie(“framework.init”)
报lua stack overflow

请把调用静态变量的代码发出来看一下呢

我估计 你是 用的 2.2.1的 c++
用的 2.2.3的 quick framework

C++ 代码
/**
* The AnimationEvent provides and defines all events dispatched during an animation.
*
* @see dragonBones.Armature
* @see dragonBones.animation.Animation
/
class AnimationEvent : public Event
{
public:
/
*
* Dispatched when the playback of an animation fade in.
*/
static const String MOVEMENT_CHANGE;

    /**
     * Dispatched when the playback of an animation fade in.
     */
    static const String FADE_IN;
    
    /**
     * Dispatched when the playback of an animation fade out.
     */
    static const String FADE_OUT;
    
    /**
     * Dispatched when the playback of an animation starts.
     */
    static const String START;
    
    /**
     * Dispatched when the playback of a animation stops.
     */
    static const String COMPLETE;
    
    /**
     * Dispatched when the playback of a animation completes a loop.
     */
    static const String LOOP_COMPLETE;
    
    /**
     * Dispatched when the playback of an animation fade in complete.
     */
    static const String FADE_IN_COMPLETE;
    
    /**
     * Dispatched when the playback of an animation fade out complete.
     */
    static const String FADE_OUT_COMPLETE;
    
    /**
     * The animationState instance.
     */
    AnimationState *animationState;
    
    Armature *armature;

    const String &getMovementID();
    
    /**
     * Creates a new AnimationEvent instance.
     * @param    type
     * @param    cancelable
     */
    AnimationEvent(const String &type)
        : Event(type)
        , armature(0)
        , animationState(0)
    {
        
    }
    
};

LuaCocos2d.cpp

tolua_cclass(tolua_S,“AnimationEvent”,“AnimationEvent”,“Event”,NULL);
tolua_beginmodule(tolua_S,“AnimationEvent”);
tolua_variable(tolua_S,“MOVEMENT_CHANGE”,tolua_get_AnimationEvent_MOVEMENT_CHANGE,NULL);
tolua_variable(tolua_S,“FADE_IN”,tolua_get_AnimationEvent_FADE_IN,NULL);
tolua_variable(tolua_S,“FADE_OUT”,tolua_get_AnimationEvent_FADE_OUT,NULL);
tolua_variable(tolua_S,“START”,tolua_get_AnimationEvent_START,NULL);
tolua_variable(tolua_S,“COMPLETE”,tolua_get_AnimationEvent_COMPLETE,NULL);
tolua_variable(tolua_S,“LOOP_COMPLETE”,tolua_get_AnimationEvent_LOOP_COMPLETE,NULL);
tolua_variable(tolua_S,“FADE_IN_COMPLETE”,tolua_get_AnimationEvent_FADE_IN_COMPLETE,NULL);
tolua_variable(tolua_S,“FADE_OUT_COMPLETE”,tolua_get_AnimationEvent_FADE_OUT_COMPLETE,NULL);
tolua_function(tolua_S,“getMovementID”,tolua_Cocos2d_AnimationEvent_getMovementID00);
tolua_endmodule(tolua_S);

print(AnimationEvent.START) 输出 nil
我在这个方法 tolua_get_AnimationEvent_START 里加了打印根本就没有进入这方法

然后我把
tolua_event.c
tolua_is.c
tolua_map.c
回到2.2.1就没问题
print(tolua.type(CCDirector)) --输出class

我知道2.2.3加入了一些代码
并且现在用print(tolua.type(CCDirector)) --输出table
输出的是:table 不是class

微微 你和我说的不是一个问题,
我问的静态变量无法调用,
我知道2.2.3改了这三个文件 估计是为了对2.2.3 的framework的支持, 但是的确影响的静态变量的调用,
tolua_event.c
tolua_is.c
tolua_map.c

2.2.3里面没有你所贴的代码,你再看看?

关于这块,2.2.1 和2.2.3 官方的改动比较多

了解了,我查一下原因

问题已经修改,我已经递交了PR。如果你不想等合并到官方版本里再用的话,可以用下面的文件替换你现在的文件:
https://github.com/SunLightJuly/quick-cocos2d-x/blob/fix_tolua/lib/cocos2d-x/scripting/lua/tolua/tolua_event.c

谢谢7月, 这几天忙没来论坛上看,明天试试。

修改的PR已经合并,你直接用最新的master版本就可以了

MARKMARK~~