20 Star 60 Fork 12

brinkqiang / dmlua

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

dmlua

Copyright (c) 2013-2018 brinkqiang (brink.qiang@gmail.com)

dmlua License blog Open Source Love GitHub stars GitHub forks

Build status

Linux Mac Windows
lin-badge mac-badge win-badge

Intro

Lua fully automated engine, based on tolua++, support lua 5.1-5.4

#include "role/rolemgr.h"
#include "role/role.h"
#include "gtest/gtest.h"
#include "dmlua.h"
#include "dmutil.h"
#include "script/interface.h"

#define DMLUA_TEST_COUNT 10000

TEST(luabasetest, luabasetest)
{
    CDMLuaEngine oDMLuaEngine;
    /// The default search path is to search the root directory with the exe program /../ relative path (because cmake will add the $BUILD_TYPE directory to the generated bin directory.)
    /// If you need to modify to other paths, please set your own search path

    std::string strScriptRootPath = DMGetRootPath();
    oDMLuaEngine.SetRootPath(strScriptRootPath + PATH_DELIMITER_STR + ".." + PATH_DELIMITER_STR);

    oDMLuaEngine.AddModule(tolua_interface_open);

    if (!oDMLuaEngine.ReloadScript())
    {
        ASSERT_TRUE(0);
        return;
    }

    oDMLuaEngine.DoString(R"(
        function addtest()
           local a = 100000000
           local b = 100000000
           local c = a * b
           print(c)
        end
        )");
    {
        for (int i = 0; i < 1; ++i)
        {
            int r = oDMLuaEngine.Call("addtest");
        }
    }

    if (!oDMLuaEngine.ReloadScript())
    {
        ASSERT_TRUE(0);
        return;
    }

    oDMLuaEngine.DoString(R"(
        function addex(first, second)
            print("overflow -> " .. first * second)
            return first * second
        end
        )");
    {
        for (int i = 0; i < 1; ++i)
        {
            uint64_t r = oDMLuaEngine.CallT<uint64_t>("addex", 4294967295ULL,
                         4294967295ULL);

            if (r >= 0)
            {
                std::cout << r << std::endl;
            }
        }
    }
    {
        oDMLuaEngine.DoString(R"(
            function script.task.taskinfo()
               local task = STaskInfo:new()
               task.nTaskID = 1002
               task.nTaskState = 2
               task.nTaskCondition = 2
               return task
            end
            )");

        STaskInfo sInfo = oDMLuaEngine.CallT<STaskInfo>("script.task.taskinfo");

        std::cout << sInfo.nTaskID << std::endl;
    }
    {
        oDMLuaEngine.DoString(R"(
            function script.task.taskinfo(task)
               task.nTaskID = 1003
               task.nTaskState = 1
               task.nTaskCondition = 0
            end
            )");
        STaskInfo sInfo;
        int r = oDMLuaEngine.Call("script.task.taskinfo", &sInfo);

        if (r >= 0)
        {
            std::cout << sInfo.nTaskID << std::endl;
        }
    }
    {
        oDMLuaEngine.DoString(R"(
            function bintest(data)
               print(string.len(data))
            print(data)
            end
            )");
        std::string strData = "12345";
        strData.append("\0", 1);
        strData.append("ABCDE", 5);
        int r = oDMLuaEngine.Call("bintest", strData);

        if (r >= 0)
        {
            ;
        }
    }

    CRole* poRole = CRoleMgr::Instance()->CreateRole();
    poRole->SetName("andy");
    poRole->SetHp(9999);
    poRole->SetMp(9999);
    unsigned int dwTaskID = 100;

    LResultINT oResult(-1);
    oDMLuaEngine.Call("script.task.task.AcceptTask", poRole, dwTaskID, &oResult);

    oDMLuaEngine.Call("script.task.task.FinishTask", poRole, dwTaskID);
    std::vector<std::string> vecData;
    vecData.push_back("hello");
    oDMLuaEngine.Call("script.common.test.main_vector", &vecData);
    oDMLuaEngine.Call("script.common.test.main");
    CRoleMgr::Instance()->ReleaseRole(poRole);
}

Contacts

Thanks

gavingqf@126.com

MIT License Copyright (c) 2018 brinkqiang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

dmlua 是一个 C++ & Lua 自动化引擎,无需编写额外代码实现 C++ 调用 Lua 和 Lua 调用 C++. windows & linux & mac环境编译通过. 展开 收起
C++ 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/brinkqiang/dmlua.git
git@gitee.com:brinkqiang/dmlua.git
brinkqiang
dmlua
dmlua
master

搜索帮助