GithubHelp home page GithubHelp logo

brinkqiang2cpp / dmlua Goto Github PK

View Code? Open in Web Editor NEW

This project forked from linecode/dmlua

0.0 1.0 0.0 7.12 MB

Lua fully automated engine. C++ call Lua(pcall) 200W/s. pb2, pb3 support.

License: MIT License

CMake 0.24% Lua 3.82% Batchfile 0.02% Shell 0.02% C++ 95.90%

dmlua's Introduction

dmlua

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

dmlua License blog Open Source Love GitHub stars GitHub forks

Build status

Linux MacOSX Windows
lin-badge osx-badge win-badge

Intro

Lua fully automated engine, based on tolua++, support lua 5.3

#include "test/role/rolemgr.h"
#include "test/role/role.h"
#include "dmlua.h"
#include "gtest/gtest.h"

TEST( luatest, luatest ) {
    CDMLuaEngine oDMLuaEngine;

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

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

    if ( !oDMLuaEngine.ReloadScript() ) {
        return;
    }
    
    oDMLuaEngine.DoString(
        "function addex(first, second)\n"
        "   return first * second\n"
        "end\n" );
    {
        for ( int i = 0; i < 1; ++i ) {
            uint64_t r = oDMLuaEngine.CallT<uint64_t>("addex", 100000000LL, 100000000LL);

            if ( r >= 0 ) {
                std::cout << r << std::endl;
            }
        }
    }
    
    oDMLuaEngine.DoString(
        "function addex(first, second, res)\n"
        "   res.value = first * second\n"
        "end\n" );
    {
        LResultINT64 resAdd( -1 );

        for ( int i = 0; i < 1; ++i ) {
            int r = oDMLuaEngine.Call( "addex", 100000000LL, 100000000LL, &resAdd );

            if ( r >= 0 ) {
                std::cout << resAdd.value << std::endl;
            }
        }
    }
    {
        oDMLuaEngine.DoString(
            "function script.task.taskinfo(task)\n"
            "   task.nTaskID = 1002\n"
            "   task.nTaskState = 2\n"
            "   task.nTaskCondition = 2\n"
            "end\n" );
        STaskInfo sInfo;
        int r = oDMLuaEngine.Call( "script.task.taskinfo", &sInfo );

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

        if ( r >= 0 ) {
            std::cout << sInfo.nTaskID << std::endl;
        }
    }
    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", &vecData );
    oDMLuaEngine.Call( "script.config.loadcsv.main" );
    CRoleMgr::Instance()->ReleaseRole( poRole );
}
-- lua script
module (..., package.seeall)

pb.import("net.proto")

function main()
  local msg = pb.new("net.tb_Person")
  msg.number = "13615632545"
  msg.email = "[email protected]"
  msg.age = 28
  msg.ptype = 2
  msg.desc:add("first")
  msg.desc:add("second")
  msg.desc:add("three")
  
  local debugstr = pb.tostring(msg)
  local binstr = pb.serializeToString(msg)

  print("msgdebug:\n" .. debugstr)
  print("msgbin:\n" .. binstr)

  local msg2 = pb.new("net.tb_Person")
  pb.parseFromString(msg2, binstr)

  print("msg2debug:\n" .. pb.tostring(msg2))
  print("msg2bin:\n" .. pb.serializeToString(msg2))
end

Contacts

Join the chat

Thanks

[email protected]

dmlua's People

Contributors

brinkqiang avatar wendyqiang avatar

Watchers

James Cloos avatar

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.