Giter Club home page Giter Club logo

dmlua's Introduction

dmlua

Copyright (c) 2013-2018 brinkqiang ([email protected])

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

[email protected]

dmlua's People

Contributors

brinkqiang avatar wendyqiang avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

meowboy326

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.