bool VRSDClientLuaImplementation::UpdateDynamicProperty(const void* pUserDataParent, 
                                                             const char* szVarName, 
                                                             const char* szNewValue)
{
  VASSERT(m_pLuaState);

  lua_State* L = m_pLuaState;

  VLuaStackCleaner stackCleaner(L);

  VTypedObject* pTypedObject = LUA_ExtractFromUserData(L, pUserDataParent);

  if (pTypedObject == NULL)
  {
    return false;
  }

  LUA_LookupObjectProxy(L, pTypedObject);     // proxy or nil, TOP

  if (lua_isnil(L, -1))
  {
    return false;
  }

  LUA_FetchDynPropertyTable(L);               // proxy, dynproptable or nil, TOP

  if (lua_isnil(L, -1))
  {
    return false;
  }

  lua_pushstring(L, szVarName);               // proxy, dynproptable, key, TOP
  lua_pushvalue(L, -1);                       // proxy, dynproptable, key, key, TOP

  lua_rawget(L, -3);                          // proxy, dynproptable, key, value, TOP

  if (lua_isnil(L, -1))
  {
    return false;
  }

  int iType = lua_type(L, -1);                // proxy, dynproptable, key, value, TOP
  lua_pop(L, 1);                              // proxy, dynproptable, key, TOP

  if (!PushValue(iType, szNewValue))          // proxy, dynproptable, key, newvalue, TOP
  {
    return false;
  }

  lua_rawset(L, -3);

  return true;
}
Exemple #2
0
void LUA_RemoveWrapperFromLookupTable(lua_State* L, VTypedObject* pObj)
{
    VASSERT(pObj != NULL);

    // Fetch wrapper and set the stored pointer to NULL
    LUA_LookupObjectProxy(L, pObj);

    swig_lua_userdata* pData = (swig_lua_userdata*) lua_touserdata(L, -1);
    if(pData)
    {
        pData->ptr = NULL;
    }

    lua_pop(L, 1);

    // Remove entry by setting its value to nil.
    lua_pushlightuserdata(L, pObj);                             // ..., address(key), TOP
    lua_pushnil(L);                                             // ..., address(key), nil(value), TOP
    lua_rawset(L, LUA_REGISTRYINDEX);                           // ..., TOP
}
Exemple #3
0
void LUA_PushObjectProxy(lua_State* L, VTypedObject *pObj, VisTypedEngineObject_cl* pOwner)
{
    if (pObj==NULL)
    {
        lua_pushnil(L);                                           // ..., nil, TOP
        return;                                                   // 1 value left on the stack
    }

    LUA_LookupObjectProxy(L, pObj);

    // In case there is no wrapper created yet, we create a new one.
    if (lua_isnil(L, -1))
    {
        lua_pop(L, 1);                                            // ..., TOP
        LUA_CreateNewWrapper(L, pObj, pOwner);                    // ..., wrapper-obj(value), TOP
        lua_pushlightuserdata(L, pObj);                           // ..., wrapper-obj(value), address(key), TOP
        lua_pushvalue(L, -2);                                     // ..., wrapper-obj(value), address(key), wrapper-obj, TOP
        lua_rawset(L, LUA_REGISTRYINDEX);                         // ..., wrapper-obj, TOP

        // Make sure callback is triggered when object gets deleted, so we can remove the object from the lookup table.
        pObj->SetObjectFlag(VObjectFlag_TriggerCallbackOnDelete);
    }                                                              // 1 value left on the stack
}