summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpsi29a <psi29a@gmail.com>2023-04-11 06:54:19 +0000
committerpsi29a <psi29a@gmail.com>2023-04-11 06:54:19 +0000
commitd6d7746c9befff077ab20106817f4bab39b0b929 (patch)
tree06214075307bc2241d196d5396d2ddc9137a9c51
parent898e43205e506bcd3dbc2669f7ccb0ce324bd733 (diff)
parent9279c3d3e1cbf9a57713f25a4d8578ed30ce90c6 (diff)
Merge branch 'records' into 'master'qt6
[Lua] Fix implementation of types.*.records See merge request OpenMW/openmw!2918
-rw-r--r--apps/openmw/mwlua/types/types.hpp9
-rw-r--r--apps/openmw/mwworld/store.cpp5
-rw-r--r--apps/openmw/mwworld/store.hpp2
-rw-r--r--files/lua_api/openmw/types.lua108
4 files changed, 22 insertions, 102 deletions
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<sol::function>();
storeT[sol::meta_function::ipairs] = lua["ipairsForArray"].template get<sol::function>();
// 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 <typename T>
- const T& TypedDynamicStore<T>::at(size_t index) const
- {
- return *mShared.at(index);
- }
template <typename T>
size_t TypedDynamicStore<T>::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 ef2237128c..6eaa809cac 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.
@@ -467,11 +468,6 @@
-- @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 id The record ID of the creature
-- @field #string name
@@ -489,6 +485,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.
@@ -509,11 +506,6 @@
-- @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 id The record ID of the NPC
-- @field #string name
@@ -546,6 +538,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.
@@ -577,11 +570,6 @@
-- @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
-- @field #string name Human-readable name
@@ -605,6 +593,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.
@@ -652,11 +641,6 @@
-- @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
-- @field #string name Name of the book
@@ -680,6 +664,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.
@@ -710,11 +695,6 @@
-- @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
-- @field #string name Name of the clothing
@@ -737,6 +717,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.
@@ -751,11 +732,6 @@
-- @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
-- @field #string name Human-readable name
@@ -774,6 +750,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.
@@ -788,11 +765,6 @@
-- @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
-- @field #string name Human-readable name
@@ -816,6 +788,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.
@@ -830,11 +803,6 @@
-- @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
-- @field #string name The name of the miscellaneous item
@@ -852,6 +820,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.
@@ -866,11 +835,6 @@
-- @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.
-- @function [parent=#Potion] createRecordDraft
@@ -896,6 +860,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.
@@ -930,11 +895,6 @@
-- @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
-- @field #string name Human-readable name
@@ -967,6 +927,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.
@@ -991,11 +952,6 @@
-- @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
-- @field #string name The name of the apparatus
@@ -1014,6 +970,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.
@@ -1028,11 +985,6 @@
-- @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
-- @field #string name The name of the lockpick
@@ -1051,6 +1003,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.
@@ -1065,11 +1018,6 @@
-- @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
-- @field #string name The name of the probe
@@ -1088,6 +1036,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.
@@ -1102,11 +1051,6 @@
-- @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
-- @field #string name The name of the repair tool
@@ -1123,6 +1067,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.
@@ -1137,11 +1082,6 @@
-- @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
-- @field #string name Human-readable name
@@ -1153,6 +1093,7 @@
---
-- @type Container
+-- @field #list<#ContainerRecord> records A read-only list of all @{#ContainerRecord}s in the world database.
---
-- Container content.
@@ -1185,11 +1126,6 @@
-- @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
-- @field #string name Human-readable name
@@ -1202,6 +1138,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.
@@ -1240,11 +1177,6 @@
-- @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
-- @field #string name Human-readable name
@@ -1260,6 +1192,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.
@@ -1274,11 +1207,6 @@
-- @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
-- @field #string model VFS path to the model