satoren / kaguya

C++ binding to Lua
Boost Software License 1.0
345 stars 70 forks source link

How to handle Lua function in c++ #25

Closed ghost closed 8 years ago

ghost commented 8 years ago

Thanks for the great Lua binding !!

But I meet a problem:

class prototype

class Node : public Ref
{
public:
    void scheduleOnce(const std::function<void(float)>& callback, float delay, const std::string &key);
}

register code:

cc["Node"].setClass(kaguya::ClassMetatable<Node, Ref>()
                    .addMemberFunction("scheduleOnce", static_cast<void(Node::*)(const std::function<void(float)>& callback, float delay, const std::string &key)>(&Node::scheduleOnce))
                    );

Lua test code:

node:scheduleOnce(function(dt) print ("scheduleOnce") end, 1.0, "test")

error:

__luadraw__ error: maybe...Argument mismatch:PN7cocos2d6SpriteE,function,number,string   candidate is:
        PN7cocos2d4NodeE,NSt3__18functionIFvfEEE,f,NSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE,

Am I missing something?

satoren commented 8 years ago

It's is not supported for current version.but i can support it.

current version can write like below.

 void scheduleOnce(LuaFunction callback, float delay, const std::string &key);
ghost commented 8 years ago

It works. Thanks for your hard work.