zoukankan      html  css  js  c++  java
  • lua开发

    1:安装luaBridge

      

    git地址  https://github.com/vinniefalco/LuaBridge.git
    

      

    2:编写程序

      

    #include <lua.hpp>
    #include <LuaBridge/LuaBridge.h>
    
    #include <iostream>
    #include <string>
    
    class A
    {
    public:
            void action()
            {
                    std::cout<<"Hello I am A
    ";
            }
    
            virtual void doPrint(int a,int b)
            {
                    std::cout<<"in A a:"<<a<<"b:"<<b<<std::endl;
            }
    
            std::string goodMan() const
            {
                    return "goodman";
            }
    };
    
    class B : public A
    {
    public:
            void hello(const std::string& info) const
            {
                    std::cout<<"hello:"<<info<<std::endl;
            }
    
            virtual void doPrint(int a, int b) override
            {
                    std::cout<<"in B just"<<(a + b) <<std::endl;
            }
    };
    
    void globalFunction()
    {
            std::cout<<"hello this is a global func
    ";
    }
    
    bool reloadLuaScript(lua_State* L, const std::string& luafile)
    {
            int state = luaL_dofile(L, luafile.c_str());
            if(state != LUA_OK)
            {
                    return false;
            }
            return true;
    }
    
    int main(int argc, char** argv)
    {
            lua_State* L = luaL_newstate();
    
            luaL_openlibs(L);
            std::cout<<"try load file"<<argv[1]<<std::endl;
    
            auto ok = reloadLuaScript(L, argv[1]);
            if(!ok)
            {
                    std::cout<<"load lua file failed
    ";
            }
            else
            {
            }
            lua_close(L);
            L = nullptr;
    }
    

      

    3:编译程序

      

    g++ -std=c++11 -o testlua testLua.cpp -llua -ldl
    

      

    4:编写Lua文件

      

    //abc.lua
    print("hello");
    print("This is myWorld!
    ");
    

      

    5:运行

      

    ./testlua abc.lua
    

      

      运行结果:     

    try load fileabc.lua
    hello
    This is myWorld!
    

      

     

  • 相关阅读:
    pandas中expand的作用
    pandas中DataFrame的stack()、unstack()和pivot()方法的对比
    Django在windows下用Apache 部署
    pandas分组统计
    DataFrame中的空值处理
    Django signals 监控模型对象字段值的变化
    django+uwsgi+daphne+supervisor生产环境部署
    Django-Channels使用和部署
    Django使用Channels实现WebSocket的方法
    python 操作es
  • 原文地址:https://www.cnblogs.com/zhaohu/p/9406524.html
Copyright © 2011-2022 走看看