Tomasu / LuaGlue

C++11 Lua 5.2 Binding Library
zlib License
79 stars 22 forks source link

return type of std::function #54

Closed DominikMS closed 10 years ago

DominikMS commented 10 years ago

Works only void. Engine is crashed.

        void testFunc(std::function<std::string(int)> f)
        {
            std::cout << "[testFunc]" << std::endl;
            f(5);
        }
A:testFunc(function(x) print("hello std::function: ".. x) return "called" end)
Tomasu commented 10 years ago

I have to admit, the std::function support hasn't been widely tested. I'll try and look at this today.

Oh, and can you give me your actual C++/lua code that triggers that?

DominikMS commented 10 years ago
class ClassA {

    public:
        ClassA()
        {
            m_str = "default";
        }

        ClassA(std::string str)
        {
            m_str = str;
        }

        ~ClassA()
        {
        }

        bool test()
        {
            std::cout << "ClassA->test() : " << m_str << std::endl;
            return true;
        }

        void testFunc(std::function<void(int)> f)
        {
            std::cout << "[testFunc]" << std::endl;
            f(5);
        }

    private:
        std::string m_str;
};

int main(int argc, char *argv[])
{
    LuaGlue state;

    state.
        Class<ClassA>("ClassA").
            ctor<std::string>("new").
            method("test", &ClassA::test).
            method("testFunc", &ClassA::testFunc).
        end();

    state.open().glue();

    if(!state.doFile("script.lua"))
        std::cout << "failed to dofile [script.lua]: " << state.lastError() << std::endl;

    Sleep(1000 * 100);
    return 0;
}
    local A = ClassA:new("in lua")
    A:test()
    A:testFunc(function(x) print("hello std::function: ".. x) return "called" end)
Tomasu commented 10 years ago

I believe this one is fixed. If it isn't, please reopen.