diff --git a/apps/openmw/mwlua/types/types.hpp b/apps/openmw/mwlua/types/types.hpp index 01d0766289..c8546a699f 100644 --- a/apps/openmw/mwlua/types/types.hpp +++ b/apps/openmw/mwlua/types/types.hpp @@ -80,17 +80,14 @@ namespace MWLua return "{" + std::to_string(store.getSize()) + " " + std::string(T::getRecordType()) + " records}"; }; storeT[sol::meta_function::length] = [](const StoreT& store) { return store.getSize(); }; - storeT[sol::meta_function::index] = [](const StoreT& store, size_t index) -> const T& { - if (index > 0 && index <= store.getSize()) - return store.at(index - 1); // Translate from Lua's 1-based indexing. - else - throw std::runtime_error("Index out of range"); + storeT[sol::meta_function::index] = [](const StoreT& store, size_t index) -> const T* { + return store.at(index - 1); // Translate from Lua's 1-based indexing. }; storeT[sol::meta_function::pairs] = lua["ipairsForArray"].template get(); storeT[sol::meta_function::ipairs] = lua["ipairsForArray"].template get(); // Provide access to the store. - table["records"] = [&store]() { return &store; }; + table["records"] = &store; } } diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 8cba1467d8..79142b44f0 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -205,11 +205,6 @@ namespace MWWorld { return mShared.end(); } - template - const T& TypedDynamicStore::at(size_t index) const - { - return *mShared.at(index); - } template size_t TypedDynamicStore::getSize() const diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index d6e713207e..a3a54ac3ff 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -209,7 +209,7 @@ namespace MWWorld iterator begin() const; iterator end() const; - const T& at(size_t index) const; + const T* at(size_t index) const { return mShared.at(index); } size_t getSize() const override; int getDynamicSize() const override; diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index 14067fde16..0caecf50df 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -453,6 +453,7 @@ -- @type Creature -- @extends #Actor -- @field #Actor baseType @{#Actor} +-- @field #list<#CreatureRecord> records A read-only list of all @{#CreatureRecord}s in the world database. --- -- Whether the object is a creature. @@ -466,11 +467,6 @@ -- @param #any objectOrRecordId -- @return #CreatureRecord ---- --- Returns a read-only list of all @{#CreatureRecord}s in the world database. --- @function [parent=#Creature] records --- @return #list<#CreatureRecord> - --- -- @type CreatureRecord -- @field #string name @@ -488,6 +484,7 @@ -- @extends #Actor -- @field #Actor baseType @{#Actor} -- @field [parent=#NPC] #NpcStats stats +-- @field #list<#NpcRecord> records A read-only list of all @{#NpcRecord}s in the world database. --- -- Whether the object is an NPC or a Player. @@ -507,11 +504,6 @@ -- @param #any objectOrRecordId -- @return #NpcRecord ---- --- Returns a read-only list of all @{#NpcRecord}s in the world database. --- @function [parent=#Npc] records --- @return #list<#NpcRecord> - --- -- @type NpcRecord -- @field #string name @@ -544,6 +536,7 @@ -- @type Armor -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#ArmorRecord> records A read-only list of all @{#ArmorRecord}s in the world database. --- -- Whether the object is an Armor. @@ -574,11 +567,6 @@ -- @param #any objectOrRecordId -- @return #ArmorRecord ---- --- Returns a read-only list of all @{#ArmorRecord}s in the world database. --- @function [parent=#Armor] records --- @return #list<#ArmorRecord> - --- -- @type ArmorRecord -- @field #string id Record id @@ -603,6 +591,7 @@ -- @type Book -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#BookRecord> records A read-only list of all @{#BookRecord}s in the world database. --- -- Whether the object is a Book. @@ -649,11 +638,6 @@ -- @param #any objectOrRecordId -- @return #BookRecord ---- --- Returns a read-only list of all @{#BookRecord}s in the world database. --- @function [parent=#Book] records --- @return #list<#BookRecord> - --- -- @type BookRecord -- @field #string id The record ID of the book @@ -678,6 +662,7 @@ -- @type Clothing -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#ClothingRecord> records A read-only list of all @{#ClothingRecord}s in the world database. --- -- Whether the object is a Clothing. @@ -707,11 +692,6 @@ -- @param #any objectOrRecordId -- @return #ClothingRecord ---- --- Returns a read-only list of all @{#ClothingRecord}s in the world database. --- @function [parent=#Clothing] records --- @return #list<#ClothingRecord> - --- -- @type ClothingRecord -- @field #string id Record id @@ -735,6 +715,7 @@ -- @type Ingredient -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#IngredientRecord> records A read-only list of all @{#IngredientRecord}s in the world database. --- -- Whether the object is an Ingredient. @@ -748,11 +729,6 @@ -- @param #any objectOrRecordId -- @return #IngredientRecord ---- --- Returns a read-only list of all @{#IngredientRecord}s in the world database. --- @function [parent=#Ingredient] records --- @return #list<#IngredientRecord> - --- -- @type IngredientRecord -- @field #string id Record id @@ -772,6 +748,7 @@ -- @type Light -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#LightRecord> records A read-only list of all @{#LightRecord}s in the world database. --- -- Whether the object is a Light. @@ -785,11 +762,6 @@ -- @param #any objectOrRecordId -- @return #LightRecord ---- --- Returns a read-only list of all @{#LightRecord}s in the world database. --- @function [parent=#Light] records --- @return #list<#LightRecord> - --- -- @type LightRecord -- @field #string id Record id @@ -814,6 +786,7 @@ -- @type Miscellaneous -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#MiscellaneousRecord> records A read-only list of all @{#MiscellaneousRecord}s in the world database. --- -- Whether the object is a Miscellaneous. @@ -827,11 +800,6 @@ -- @param #any objectOrRecordId -- @return #MiscellaneousRecord ---- --- Returns a read-only list of all @{#MiscellaneousRecord}s in the world database. --- @function [parent=#Miscellaneous] records --- @return #list<#MiscellaneousRecord> - --- -- @type MiscellaneousRecord -- @field #string id The record ID of the miscellaneous item @@ -850,6 +818,7 @@ -- @type Potion -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#PotionRecord> records A read-only list of all @{#PotionRecord}s in the world database. --- -- Whether the object is a Potion. @@ -863,11 +832,6 @@ -- @param #any objectOrRecordId -- @return #PotionRecord ---- --- Returns a read-only list of all @{#PotionRecord}s in the world database. --- @function [parent=#Potion] records --- @return #list<#PotionRecord> - --- -- Creates a @{#PotionRecord} without adding it to the world database. -- Use @{openmw_world#(world).createRecord} to add the record to the world. @@ -894,6 +858,7 @@ -- @type Weapon -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#WeaponRecord> records A read-only list of all @{#WeaponRecord}s in the world database. --- -- Whether the object is a Weapon. @@ -927,11 +892,6 @@ -- @param #any objectOrRecordId -- @return #WeaponRecord ---- --- Returns a read-only list of all @{#WeaponRecord}s in the world database. --- @function [parent=#Weapon] records --- @return #list<#WeaponRecord> - --- -- @type WeaponRecord -- @field #string id Record id @@ -965,6 +925,7 @@ -- @type Apparatus -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#ApparatusRecord> records A read-only list of all @{#ApparatusRecord}s in the world database. --- -- Whether the object is an Apparatus. @@ -988,11 +949,6 @@ -- @param #any objectOrRecordId -- @return #ApparatusRecord ---- --- Returns a read-only list of all @{#ApparatusRecord}s in the world database. --- @function [parent=#Apparatus] records --- @return #list<#ApparatusRecord> - --- -- @type ApparatusRecord -- @field #string id The record ID of the apparatus @@ -1012,6 +968,7 @@ -- @type Lockpick -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#LockpickRecord> records A read-only list of all @{#LockpickRecord}s in the world database. --- -- Whether the object is a Lockpick. @@ -1025,11 +982,6 @@ -- @param #any objectOrRecordId -- @return #LockpickRecord ---- --- Returns a read-only list of all @{#LockpickRecord}s in the world database. --- @function [parent=#Lockpick] records --- @return #list<#LockpickRecord> - --- -- @type LockpickRecord -- @field #string id The record ID of the lockpick @@ -1049,6 +1001,7 @@ -- @type Probe -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#ProbeRecord> records A read-only list of all @{#ProbeRecord}s in the world database. --- -- Whether the object is a Probe. @@ -1062,11 +1015,6 @@ -- @param #any objectOrRecordId -- @return #ProbeRecord ---- --- Returns a read-only list of all @{#ProbeRecord}s in the world database. --- @function [parent=#Probe] records --- @return #list<#ProbeRecord> - --- -- @type ProbeRecord -- @field #string id The record ID of the probe @@ -1086,6 +1034,7 @@ -- @type Repair -- @extends #Item -- @field #Item baseType @{#Item} +-- @field #list<#RepairRecord> records A read-only list of all @{#RepairRecord}s in the world database. --- -- Whether the object is a Repair. @@ -1099,11 +1048,6 @@ -- @param #any objectOrRecordId -- @return #RepairRecord ---- --- Returns a read-only list of all @{#RepairRecord}s in the world database. --- @function [parent=#Repair] records --- @return #list<#RepairRecord> - --- -- @type RepairRecord -- @field #string id The record ID of the repair tool @@ -1121,6 +1065,7 @@ --- -- @type Activator +-- @field #list<#ActivatorRecord> records A read-only list of all @{#ActivatorRecord}s in the world database. --- -- Whether the object is an Activator. @@ -1134,11 +1079,6 @@ -- @param #any objectOrRecordId -- @return #ActivatorRecord ---- --- Returns a read-only list of all @{#ActivatorRecord}s in the world database. --- @function [parent=#Activator] records --- @return #list<#ActivatorRecord> - --- -- @type ActivatorRecord -- @field #string id Record id @@ -1151,6 +1091,7 @@ --- -- @type Container +-- @field #list<#ContainerRecord> records A read-only list of all @{#ContainerRecord}s in the world database. --- -- Container content. @@ -1182,11 +1123,6 @@ -- @param #any objectOrRecordId -- @return #ContainerRecord ---- --- Returns a read-only list of all @{#ContainerRecord}s in the world database. --- @function [parent=#Container] records --- @return #list<#ContainerRecord> - --- -- @type ContainerRecord -- @field #string id Record id @@ -1200,6 +1136,7 @@ --- -- @type Door +-- @field #list<#DoorRecord> records A read-only list of all @{#DoorRecord}s in the world database. --- -- Whether the object is a Door. @@ -1237,11 +1174,6 @@ -- @param #any objectOrRecordId -- @return #DoorRecord ---- --- Returns a read-only list of all @{#DoorRecord}s in the world database. --- @function [parent=#Door] records --- @return #list<#DoorRecord> - --- -- @type DoorRecord -- @field #string id Record id @@ -1258,6 +1190,7 @@ --- -- @type Static +-- @field #list<#StaticRecord> records A read-only list of all @{#StaticRecord}s in the world database. --- -- Whether the object is a Static. @@ -1271,11 +1204,6 @@ -- @param #any objectOrRecordId -- @return #StaticRecord ---- --- Returns a read-only list of all @{#StaticRecord}s in the world database. --- @function [parent=#Static] records --- @return #list<#StaticRecord> - --- -- @type StaticRecord -- @field #string id Record id