zoukankan      html  css  js  c++  java
  • 超越luabind的luaBridge

    此编是引用他人的文章,这里记录下,主要为以后自己查找方便,原文地址:http://www.cppblog.com/sunicdavy/archive/2013/12/07/204648.html

    最近准备在手机项目客户端中使用lua, 以前一直在服务器使用luabind. 另外, tolua++也体验过, LuaPlus也在早年用过. 以下是本人对这些绑定库的个人感觉:

    luabind

    利用boost机制把绑定做到极致, 比较适合主c++, 弱lua的脚本框架.

    作者已经停止更新, 在windows/linux编译没问题, 但是在ios的LLVM下, 无法编译

    tolua++

    像cocos2dx使用tolua++也是可以理解的, 那么多函数需要绑定, tolua++的头文件parse及自动代码生成节约了很多手动绑定的时间.

    但是看到代码中有一部分bugfix就心存不安(纯个人感觉, 本人使用不多, 欢迎砖头伺候),另外, tolua++只能由脚本层驱动C++, 而没有将已经实例化的句柄注册到lua的功能也是煞笔啊

    LuaPlus

    接口较为简单, 适于初学者上手, 无任何的模板, 性能不高

    luaBridge

    项目地址: https://github.com/vinniefalco/LuaBridge

    手册: http://vinniefalco.com/LuaBridge/Manual.html

    纯头文件实现, 无需编译, 包含进入工程即可, 接口简洁高效

    相比luabind, 唯一不能实现的常用功能就是枚举, 但是可以支持类成员静态变量注册, 这个就无所谓了, 手写一个枚举支持也很简单

    看下演示代码:

    class A
    {
    public:
        A( )
        {
    
        }
        virtual void foo( int a )
        {
            printf("foo base
    ");
        }
    
        std::string Member;
    };
    
    class B : public A
    {
    public:
        virtual void foo( int a )
        {
            printf("foo inherited
    ");
        }
    };
    
    void foo( int b )
    {
    
    }
    
    luabridge::getGlobalNamespace(L)
            .beginClass<A>("Sobj")
                .addConstructor<void (*) (void)> ()
                .addFunction("foo", &A::foo)
                .addData("Member",&A::Member)
            .endClass()
            .deriveClass<B, A>("SSec")
                .addFunction("foo",&B::foo )
            .endClass();
    
        luabridge::getGlobalNamespace(L).addFunction("foo", foo );
    
    
        B ins;
        ins.Member = "data";
        luabridge::setGlobal(L, ins, "ins");
    lua侧的代码
    
    local a = Sobj()
    a:foo(2)
    a.Member = "hello"
    
    
    ins:foo(3)
  • 相关阅读:
    73. Set Matrix Zeroes
    289. Game of Live
    212. Word Search II
    79. Word Search
    142. Linked List Cycle II
    141. Linked List Cycle
    287. Find the Duplicate Number
    260. Single Number III
    137. Single Number II
    Oracle EBS中有关Form的触发器的执行顺序
  • 原文地址:https://www.cnblogs.com/sharestudy/p/3656230.html
Copyright © 2011-2022 走看看