void LuaTest::OnResponse(uint32_t uLuaRpcId,
const std::string& sRespContent) const
{
using LuaIntf::LuaRef;
LuaRef require(m_pLuaState, "require");
try {
LuaRef handler = require.call<LuaRef>("client_rpc_response_handler");
handler.dispatchStatic("handle", uLuaRpcId, sRespContent);
}
catch (const LuaIntf::LuaException& e) {
std::cerr << "Failed to call lua client_rpc_response_handler.handle(), "
<< e.what() << std::endl;
}
}
require("client_rpc_response_handler").handle(uLuaRpcId, sRespContent)
#include <iostream>
#include <lua.hpp>
#include <LuaIntf/LuaIntf.h>
#include <string>
const char SCRIPTS_DIR[] = "../scripts";
using namespace std;
struct lua_State;
class TestLog
{
public:
static TestLog *getInstance()
{
static TestLog instance;
return &instance;
}
~TestLog();
void Log(const string &str);
void BindLua(lua_State *l);
private:
TestLog();
};
TestLog::TestLog()
{
}
TestLog::~TestLog()
{
}
void TestLog::Log(const string &str)
{
cout << str << endl;
}
namespace
{
using LuaRef = LuaIntf::LuaRef;
void LuaLog(const string &str)
{
TestLog::getInstance()->Log(str);
}
namespace LuaTestLog
{
void Bind(lua_State* L)
{
assert(L);
LuaIntf::LuaBinding(L).beginModule("c_testlog")
.addFunction("log", &LuaLog)
.endModule();
}
};
};
void TestLog::BindLua(lua_State *l)
{
LuaTestLog::Bind(l);
}
int main()
{
lua_State *l = luaL_newstate();
luaL_openlibs(l);
TestLog::getInstance()->BindLua(l);
cout << "mmmmmmmmmmm" << endl;
luaL_dofile(l, "test.lua");
system("pause");
return 0;
}
local Log = {}
local log = c_testlog.log
function Log:new(log_name)
assert("table" == type(self))
assert(not log_name or "string" == type(log_name))
local log = {}
log.log_name = log_name or "Log"
setmetatable(log, self)
self.__index = self
return log
end
function Log:set_log_name(log_name)
self.log_name = log_name
end
function Log:info(pattern, ...)
log(string.format(pattern, ...))
end
function Log:debug()
print("ssssssssssssssssssssssssss")
end
return Log
local function main()
print("dddddddddddddddddddddddd")
local p = "../testLuaIntf"
package.path = package.path ..";" .. p .. "/" .. "testLuaIntf" .. "/?.lua"
--package.path = package.path .. "E:\VSProject\?.luac"
print("bbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
local log = require("log"):new("svn_log")
log:info("%d...",1)
--:new("svc_log")
print("ssssssssssssssssssssssss")
end
xpcall(main,function(...)
local msg = {...};
for k ,v in pairs(msg) do
print("k=" .. tostring( k) .. " v=" .. tostring(v))
end
print(tostring() .. " 123")
end)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有