加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 22:06:26 所属栏目:大数据 来源:网络整理
导读://这里是需要注册的回调函数 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(ParCount2


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

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

//lua_pop(L,1);

}

? ? ? ? }

lua_close(L); L = NULL;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读