示例#1
0
文件: luafunc.cpp 项目: skopp/rush
int JLuaServer::FnRequire( lua_State* pLua )
{
    if (lua_gettop( pLua ) != 1)
    {
        rlog.err( "LUA: Incorrect command usage: <require>. "
            "Function takes 1 string argument, but %d is provided", lua_gettop( pLua ) );
        lua_settop( pLua, 0 );
        lua_pushnil( pLua );
        return 1;
    }
    if (!lua_isstring( pLua, -1 ))
    {
        rlog.err( "LUA: Incorrect command usage: <require>. "
            "Function expects 1 string argument, for example: require('myfile.lua')" );
        lua_settop( pLua, 0 );
        lua_pushnil( pLua );
        return 1;
    }
    const char* pScriptName = lua_tostring( pLua, -1 );

    Path path( pScriptName );
    int scriptID = GetScriptID( path.GetFile() );
    JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata );
    assert( pThread->m_pLua == pLua );
    JObject* pRootObj = pThread->m_pRootObj;
    JString res;
    int threadID = RunScript( scriptID, pRootObj, &res );
    return 0;
} // JLuaServer::FnRequire
示例#2
0
bool ReadContactAndWrite(char *hash)
{
	__xdata static  char txcontac[512];
	if (!GetTxContacts((const unsigned char * const )hash, (void* const ) &txcontac, 512))
	{
		LogPrint("GetTxContacts error",sizeof("GetTxContacts error"),STRING);
		return false;
	}

	if(!DeleteData((const unsigned char * const )hash,32))
	{
		LogPrint("DeleteDataDB error",sizeof("DeleteDataDB error"),STRING);
		return false;
	}

	CONTRACT* pContract = (CONTRACT*)txcontac;
	VM_OPERATE ret;

	char accountid[6] = {0};
	if(GetScriptID(&accountid))
	{
		ret.type =REG_ID;
		ret.opeatortype = MINUS_FREE;
		memcpy(ret.accountid,&accountid,sizeof(ret.accountid));
		memcpy(&ret.money,&pContract->nPayMoney,sizeof(Int64));
		LogPrint(&accountid,32,HEX);
		WriteOutput(&ret,1);
	}

	char *strContace = pContract->buffer;
	unsigned short len = pContract->len;
	while(len)
	{
		ACCOUNT_INFO accountinfo;
		memcpy(&accountinfo,strContace,sizeof(ACCOUNT_INFO));
		memcpy(ret.accountid,&accountinfo.account,sizeof(ret.accountid));
		memcpy(&ret.money,&accountinfo.nReciMoney,sizeof(Int64));
		ret.opeatortype = ADD_FREE;
		len -= sizeof(ACCOUNT_INFO);
//		LogPrint(&accountinfo.account,32,HEX);
		WriteOutput(&ret,1);
		strContace = strContace +sizeof(ACCOUNT_INFO);

	}
	return true;
}