From 405d96c66f8d849f6bc76aec75518738659049ff Mon Sep 17 00:00:00 2001 From: Alex May Date: Sun, 3 May 2020 00:30:06 +0100 Subject: [PATCH] Fixed some issues with PropIndex that was causing various problems --- ServerCore/lua_object.cpp | 2 +- ServerCore/lua_prop.cpp | 13 ++++++++----- ServerCore/lua_prop.h | 5 +++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ServerCore/lua_object.cpp b/ServerCore/lua_object.cpp index 157cd22..1692c10 100644 --- a/ServerCore/lua_object.cpp +++ b/ServerCore/lua_object.cpp @@ -545,7 +545,7 @@ int lua_object::luaGet( lua_State *L ) { if( P->type() == QVariant::Map ) { - return( lua_prop::lua_pushpropindex( L, P ) ); + return( lua_prop::lua_pushpropindex( L, O->id(), P ) ); } else { diff --git a/ServerCore/lua_prop.cpp b/ServerCore/lua_prop.cpp index a8e73fe..eb4cb55 100644 --- a/ServerCore/lua_prop.cpp +++ b/ServerCore/lua_prop.cpp @@ -18,6 +18,7 @@ #include "changeset/propertysetwrite.h" #include "changeset/propertysetchange.h" #include "changeset/connectionnotify.h" +#include "changeset/objectsetproperty.h" const char *lua_prop::mLuaName = "moo.prop"; const char *lua_prop::mLuaPropIndexName = "moo.propindex"; @@ -689,7 +690,7 @@ int lua_prop::luaValue( lua_State *L ) // Property Index -int lua_prop::lua_pushpropindex( lua_State *L, Property *pProperty ) +int lua_prop::lua_pushpropindex( lua_State *L, ObjectId pObjectId, Property *pProperty ) { luaPropIndex *P = reinterpret_cast( lua_newuserdata( L, sizeof( luaPropIndex ) ) ); @@ -701,6 +702,7 @@ int lua_prop::lua_pushpropindex( lua_State *L, Property *pProperty ) } P->mProperty = pProperty; + P->mObjectId = pObjectId; P->mIndex = Q_NULLPTR; luaL_getmetatable( L, mLuaPropIndexName ); @@ -709,7 +711,7 @@ int lua_prop::lua_pushpropindex( lua_State *L, Property *pProperty ) return( 1 ); } -int lua_prop::lua_pushpropindex( lua_State *L, Property *pProperty, const lua_prop::luaPropIndexPath &pPath ) +int lua_prop::lua_pushpropindex( lua_State *L, ObjectId pObjectId, Property *pProperty, const lua_prop::luaPropIndexPath &pPath ) { luaPropIndex *P = reinterpret_cast( lua_newuserdata( L, sizeof( luaPropIndex ) ) ); @@ -721,6 +723,7 @@ int lua_prop::lua_pushpropindex( lua_State *L, Property *pProperty, const lua_pr } P->mProperty = pProperty; + P->mObjectId = pObjectId; P->mIndex = new luaPropIndexPath( pPath ); luaL_getmetatable( L, mLuaPropIndexName ); @@ -819,7 +822,7 @@ int lua_prop::luaPropIndexGet( lua_State *L ) if( V.type() == QVariant::Map || V.type() == QVariant::List ) { - return( lua_pushpropindex( L, P, Path ) ); + return( lua_pushpropindex( L, LP->mObjectId, P, Path ) ); } return( luaL_pushvariant( L, V ) ); @@ -895,7 +898,7 @@ int lua_prop::luaPropIndexSet( lua_State *L ) NewV = Index.first; } - P->setValue( NewV ); + Command->changeAdd( new change::ObjectSetProperty( ObjectManager::o( LP->mObjectId ), P->name(), NewV ) ); } catch( const mooException &e ) { @@ -969,7 +972,7 @@ int lua_prop::luaPropIndexClear(lua_State *L) NewV = Index.first; } - P->setValue( NewV ); + Command->changeAdd( new change::ObjectSetProperty( ObjectManager::o( LP->mObjectId ), P->name(), NewV ) ); } catch( const mooException &e ) { diff --git a/ServerCore/lua_prop.h b/ServerCore/lua_prop.h index d059701..e925648 100644 --- a/ServerCore/lua_prop.h +++ b/ServerCore/lua_prop.h @@ -30,12 +30,13 @@ class lua_prop typedef struct luaPropIndex { Property *mProperty; + ObjectId mObjectId; luaPropIndexPath *mIndex; } luaPropIndex; - static int lua_pushpropindex( lua_State *L, Property *pProperty ); + static int lua_pushpropindex( lua_State *L, ObjectId pObjectId, Property *pProperty ); - static int lua_pushpropindex( lua_State *L, Property *pProperty, const luaPropIndexPath &pPath ); + static int lua_pushpropindex( lua_State *L, ObjectId pObjectId, Property *pProperty, const luaPropIndexPath &pPath ); static luaPropIndex *propindex( lua_State *L, int pIndex = 1 );