LUA和C/C++交互-注册回调函数

130 篇文章 1 订阅


//这里是需要注册的回调函数

class LUA_Func
{
protected:
static MProcessIO* m_spHost;
public:
static void SetHost(MProcessIO* pHost)
{
m_spHost = pHost;
}

static int IsLastTradeDate(lua_State* L)
{
long ParCount = lua_gettop(L);
if(ParCount<2)
{
//WriteLog(INFO, 0, "LUA_Func", "IsLastTradeDate参数个数少于2个,应该是IsLastTradeDate(Date, IsIF)");
lua_pushinteger(L,0);
return 1;
}
int ret = m_spHost->IsLastTradeDate(lua_tointeger(L,1),lua_toboolean(L,2));
lua_pushinteger(L,ret);
return 1;
}
static int AddKind(lua_State* L)
{
long ParCount = lua_gettop(L);
if(ParCount<4)
{
//WriteLog(INFO, 0, "LUA_Func", "AddKind参数个数少于4个,应该是AddKind(Name, PriceRate, LotSize, WareCount)");
lua_pushinteger(L,0);
return 1;
}
long ret = m_spHost->AddKind(lua_tostring(L,1),lua_tointeger(L,2),lua_tointeger(L,3),lua_tointeger(L,4));
lua_pushinteger(L,ret);
return 1;
}
static int AddCode(lua_State* L)
{
long ParCount = lua_gettop(L);
if(ParCount<6)
{
//WriteLog(INFO, 0, "LUA_Func", "AddCode参数个数少于6个,应该是AddKind(Code, Name, ContractMult, ExFlag, ObjectMId, ObjectCode)");
lua_pushinteger(L,0);
return 1;
}
long ret = m_spHost->AddCode(lua_tostring(L,1),lua_tostring(L,2),lua_tointeger(L,3),lua_tointeger(L,4),lua_tointeger(L,5),lua_tostring(L,6));
lua_pushinteger(L,ret);
return 1;
}
};

MProcessIO* LUA_Func::m_spHost = &Global_Process;



//lua 脚本注册回调函数

lua_State *L = luaL_newstate(); 
if (L) {
luaopen_base(L);
luaL_openlibs(L);


lua_register(L, "IsLastTradeDate", LUA_Func::IsLastTradeDate);
lua_register(L, "AddKind", LUA_Func::AddKind);
lua_register(L, "AddCode", LUA_Func::AddCode);


lua_pushunsigned(L, date);
lua_setglobal(L, "date");


lua_pushunsigned(L, time);
lua_setglobal(L, "time");


err = luaL_dofile(L, "cffhq.lua");
if (err) {
//WriteLog(ERR, 0, "MProcessIO", "%s", lua_tostring(L, -1));

//lua_pop(L, 1);

}

        }

lua_close(L);
L = NULL;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值