//这里是需要注册的回调函数
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 脚本注册回调函数
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;