Merge branch 'records' into 'master'

[Lua] Fix implementation of types.*.records

See merge request OpenMW/openmw!2918
depth-refraction
psi29a 2 years ago
commit d6d7746c9b

@ -80,17 +80,14 @@ namespace MWLua
return "{" + std::to_string(store.getSize()) + " " + std::string(T::getRecordType()) + " records}"; 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::length] = [](const StoreT& store) { return store.getSize(); };
storeT[sol::meta_function::index] = [](const StoreT& store, size_t index) -> const T& { 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.
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::pairs] = lua["ipairsForArray"].template get<sol::function>(); storeT[sol::meta_function::pairs] = lua["ipairsForArray"].template get<sol::function>();
storeT[sol::meta_function::ipairs] = lua["ipairsForArray"].template get<sol::function>(); storeT[sol::meta_function::ipairs] = lua["ipairsForArray"].template get<sol::function>();
// Provide access to the store. // Provide access to the store.
table["records"] = [&store]() { return &store; }; table["records"] = &store;
} }
} }

@ -205,11 +205,6 @@ namespace MWWorld
{ {
return mShared.end(); return mShared.end();
} }
template <typename T>
const T& TypedDynamicStore<T>::at(size_t index) const
{
return *mShared.at(index);
}
template <typename T> template <typename T>
size_t TypedDynamicStore<T>::getSize() const size_t TypedDynamicStore<T>::getSize() const

@ -209,7 +209,7 @@ namespace MWWorld
iterator begin() const; iterator begin() const;
iterator end() 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; size_t getSize() const override;
int getDynamicSize() const override; int getDynamicSize() const override;

@ -453,6 +453,7 @@
-- @type Creature -- @type Creature
-- @extends #Actor -- @extends #Actor
-- @field #Actor baseType @{#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. -- Whether the object is a creature.
@ -466,11 +467,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #CreatureRecord -- @return #CreatureRecord
---
-- Returns a read-only list of all @{#CreatureRecord}s in the world database.
-- @function [parent=#Creature] records
-- @return #list<#CreatureRecord>
--- ---
-- @type CreatureRecord -- @type CreatureRecord
-- @field #string id The record ID of the creature -- @field #string id The record ID of the creature
@ -489,6 +485,7 @@
-- @extends #Actor -- @extends #Actor
-- @field #Actor baseType @{#Actor} -- @field #Actor baseType @{#Actor}
-- @field [parent=#NPC] #NpcStats stats -- @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. -- Whether the object is an NPC or a Player.
@ -508,11 +505,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #NpcRecord -- @return #NpcRecord
---
-- Returns a read-only list of all @{#NpcRecord}s in the world database.
-- @function [parent=#Npc] records
-- @return #list<#NpcRecord>
--- ---
-- @type NpcRecord -- @type NpcRecord
-- @field #string id The record ID of the NPC -- @field #string id The record ID of the NPC
@ -546,6 +538,7 @@
-- @type Armor -- @type Armor
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is an Armor.
@ -576,11 +569,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #ArmorRecord -- @return #ArmorRecord
---
-- Returns a read-only list of all @{#ArmorRecord}s in the world database.
-- @function [parent=#Armor] records
-- @return #list<#ArmorRecord>
--- ---
-- @type ArmorRecord -- @type ArmorRecord
-- @field #string id Record id -- @field #string id Record id
@ -605,6 +593,7 @@
-- @type Book -- @type Book
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is a Book.
@ -651,11 +640,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #BookRecord -- @return #BookRecord
---
-- Returns a read-only list of all @{#BookRecord}s in the world database.
-- @function [parent=#Book] records
-- @return #list<#BookRecord>
--- ---
-- @type BookRecord -- @type BookRecord
-- @field #string id The record ID of the book -- @field #string id The record ID of the book
@ -680,6 +664,7 @@
-- @type Clothing -- @type Clothing
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is a Clothing.
@ -709,11 +694,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #ClothingRecord -- @return #ClothingRecord
---
-- Returns a read-only list of all @{#ClothingRecord}s in the world database.
-- @function [parent=#Clothing] records
-- @return #list<#ClothingRecord>
--- ---
-- @type ClothingRecord -- @type ClothingRecord
-- @field #string id Record id -- @field #string id Record id
@ -737,6 +717,7 @@
-- @type Ingredient -- @type Ingredient
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is an Ingredient.
@ -750,11 +731,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #IngredientRecord -- @return #IngredientRecord
---
-- Returns a read-only list of all @{#IngredientRecord}s in the world database.
-- @function [parent=#Ingredient] records
-- @return #list<#IngredientRecord>
--- ---
-- @type IngredientRecord -- @type IngredientRecord
-- @field #string id Record id -- @field #string id Record id
@ -774,6 +750,7 @@
-- @type Light -- @type Light
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is a Light.
@ -787,11 +764,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #LightRecord -- @return #LightRecord
---
-- Returns a read-only list of all @{#LightRecord}s in the world database.
-- @function [parent=#Light] records
-- @return #list<#LightRecord>
--- ---
-- @type LightRecord -- @type LightRecord
-- @field #string id Record id -- @field #string id Record id
@ -816,6 +788,7 @@
-- @type Miscellaneous -- @type Miscellaneous
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is a Miscellaneous.
@ -829,11 +802,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #MiscellaneousRecord -- @return #MiscellaneousRecord
---
-- Returns a read-only list of all @{#MiscellaneousRecord}s in the world database.
-- @function [parent=#Miscellaneous] records
-- @return #list<#MiscellaneousRecord>
--- ---
-- @type MiscellaneousRecord -- @type MiscellaneousRecord
-- @field #string id The record ID of the miscellaneous item -- @field #string id The record ID of the miscellaneous item
@ -852,6 +820,7 @@
-- @type Potion -- @type Potion
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is a Potion.
@ -865,11 +834,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #PotionRecord -- @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. -- Creates a @{#PotionRecord} without adding it to the world database.
-- Use @{openmw_world#(world).createRecord} to add the record to the world. -- Use @{openmw_world#(world).createRecord} to add the record to the world.
@ -896,6 +860,7 @@
-- @type Weapon -- @type Weapon
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is a Weapon.
@ -929,11 +894,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #WeaponRecord -- @return #WeaponRecord
---
-- Returns a read-only list of all @{#WeaponRecord}s in the world database.
-- @function [parent=#Weapon] records
-- @return #list<#WeaponRecord>
--- ---
-- @type WeaponRecord -- @type WeaponRecord
-- @field #string id Record id -- @field #string id Record id
@ -967,6 +927,7 @@
-- @type Apparatus -- @type Apparatus
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is an Apparatus.
@ -990,11 +951,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #ApparatusRecord -- @return #ApparatusRecord
---
-- Returns a read-only list of all @{#ApparatusRecord}s in the world database.
-- @function [parent=#Apparatus] records
-- @return #list<#ApparatusRecord>
--- ---
-- @type ApparatusRecord -- @type ApparatusRecord
-- @field #string id The record ID of the apparatus -- @field #string id The record ID of the apparatus
@ -1014,6 +970,7 @@
-- @type Lockpick -- @type Lockpick
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is a Lockpick.
@ -1027,11 +984,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #LockpickRecord -- @return #LockpickRecord
---
-- Returns a read-only list of all @{#LockpickRecord}s in the world database.
-- @function [parent=#Lockpick] records
-- @return #list<#LockpickRecord>
--- ---
-- @type LockpickRecord -- @type LockpickRecord
-- @field #string id The record ID of the lockpick -- @field #string id The record ID of the lockpick
@ -1051,6 +1003,7 @@
-- @type Probe -- @type Probe
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is a Probe.
@ -1064,11 +1017,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #ProbeRecord -- @return #ProbeRecord
---
-- Returns a read-only list of all @{#ProbeRecord}s in the world database.
-- @function [parent=#Probe] records
-- @return #list<#ProbeRecord>
--- ---
-- @type ProbeRecord -- @type ProbeRecord
-- @field #string id The record ID of the probe -- @field #string id The record ID of the probe
@ -1088,6 +1036,7 @@
-- @type Repair -- @type Repair
-- @extends #Item -- @extends #Item
-- @field #Item baseType @{#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. -- Whether the object is a Repair.
@ -1101,11 +1050,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #RepairRecord -- @return #RepairRecord
---
-- Returns a read-only list of all @{#RepairRecord}s in the world database.
-- @function [parent=#Repair] records
-- @return #list<#RepairRecord>
--- ---
-- @type RepairRecord -- @type RepairRecord
-- @field #string id The record ID of the repair tool -- @field #string id The record ID of the repair tool
@ -1123,6 +1067,7 @@
--- ---
-- @type Activator -- @type Activator
-- @field #list<#ActivatorRecord> records A read-only list of all @{#ActivatorRecord}s in the world database.
--- ---
-- Whether the object is an Activator. -- Whether the object is an Activator.
@ -1136,11 +1081,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #ActivatorRecord -- @return #ActivatorRecord
---
-- Returns a read-only list of all @{#ActivatorRecord}s in the world database.
-- @function [parent=#Activator] records
-- @return #list<#ActivatorRecord>
--- ---
-- @type ActivatorRecord -- @type ActivatorRecord
-- @field #string id Record id -- @field #string id Record id
@ -1153,6 +1093,7 @@
--- ---
-- @type Container -- @type Container
-- @field #list<#ContainerRecord> records A read-only list of all @{#ContainerRecord}s in the world database.
--- ---
-- Container content. -- Container content.
@ -1184,11 +1125,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #ContainerRecord -- @return #ContainerRecord
---
-- Returns a read-only list of all @{#ContainerRecord}s in the world database.
-- @function [parent=#Container] records
-- @return #list<#ContainerRecord>
--- ---
-- @type ContainerRecord -- @type ContainerRecord
-- @field #string id Record id -- @field #string id Record id
@ -1202,6 +1138,7 @@
--- ---
-- @type Door -- @type Door
-- @field #list<#DoorRecord> records A read-only list of all @{#DoorRecord}s in the world database.
--- ---
-- Whether the object is a Door. -- Whether the object is a Door.
@ -1239,11 +1176,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #DoorRecord -- @return #DoorRecord
---
-- Returns a read-only list of all @{#DoorRecord}s in the world database.
-- @function [parent=#Door] records
-- @return #list<#DoorRecord>
--- ---
-- @type DoorRecord -- @type DoorRecord
-- @field #string id Record id -- @field #string id Record id
@ -1260,6 +1192,7 @@
--- ---
-- @type Static -- @type Static
-- @field #list<#StaticRecord> records A read-only list of all @{#StaticRecord}s in the world database.
--- ---
-- Whether the object is a Static. -- Whether the object is a Static.
@ -1273,11 +1206,6 @@
-- @param #any objectOrRecordId -- @param #any objectOrRecordId
-- @return #StaticRecord -- @return #StaticRecord
---
-- Returns a read-only list of all @{#StaticRecord}s in the world database.
-- @function [parent=#Static] records
-- @return #list<#StaticRecord>
--- ---
-- @type StaticRecord -- @type StaticRecord
-- @field #string id Record id -- @field #string id Record id

Loading…
Cancel
Save