示例#1
0
  //-----------------------------------------------------------------------
  int BspProxyImpl::bspSendWrapper(struct lua_State * state){

    int n = lua_gettop(state);
    assert(n == 1);

    BspSend bspSend;

    bspSend.tagSize(LuaUtils::getIntFromTable(state, "tagSize"))
          .nBytes(LuaUtils::getIntFromTable(state, "nBytes"))
          .superstep(LuaUtils::getIntFromTable(state, "superstep"));


    lua_pushstring(state, "payload");
    lua_gettable(state, -2);
    bspSend.writeInMem(lua_tostring(state,-1));
    lua_pop(state, 1);
    
    lua_pushstring(state, "tag");
    lua_gettable(state, -2);
    bspSend.writeTag(lua_tostring(state,-1));
    lua_pop(state, 1);


    BspProxyImpl::singleInstance->bsmpManager_->addSend(bspSend);
    return 0;
  }
示例#2
0
  //--------------------------------------------------------------------------------
  void BspProxyStubPool::bspSend(const int & taskPid, BspSend & bspSend){

    int initialStackSize = lua_gettop(clientSideState);

    lua_getglobal(clientSideState, getTaskId(taskPid).c_str());
    lua_pushstring(clientSideState, "bspSend");
    lua_gettable(clientSideState, -2);
    lua_getglobal(clientSideState, getTaskId(taskPid).c_str());
    lua_newtable(clientSideState);


    LuaUtils::setFieldOnTable(clientSideState, "nBytes", bspSend.nBytes(), -1);
    LuaUtils::setFieldOnTable(clientSideState, "tagSize", bspSend.tagSize(), -1);
    LuaUtils::setFieldOnTable(clientSideState, "superstep", bspSend.superstep(), -1);
    lua_pushstring(clientSideState, "payload");
    const char * payload = (char *) bspSend.payload();
    lua_pushlstring(clientSideState, payload, bspSend.nBytes());
    lua_settable(clientSideState, -3);
    lua_pushstring(clientSideState, "tag");
    const char * tag = (char *) bspSend.tag();
    lua_pushlstring(clientSideState, tag, bspSend.tagSize());
    lua_settable(clientSideState, -3);




    if (lua_pcall(clientSideState, 2, 0, 0) != 0){
      cerr << "[ERROR] BspProxyStubPool::bspSend->Lua error: "
           << lua_tostring(clientSideState, -1) << endl;
      lua_pop(clientSideState, 1);
    }

    lua_pop(clientSideState, 1);//removes proxy from stack
    assert(initialStackSize == lua_gettop(clientSideState));

  }