Use common function to add record binding

depth-refraction
elsid 2 years ago
parent 33a59a9342
commit ca9c55ac26
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -23,13 +23,8 @@ namespace MWLua
{
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Activator>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Activator>();
activator["record"] = sol::overload(
[](const Object& obj) -> const ESM::Activator* { return obj.ptr().get<ESM::Activator>()->mBase; },
[store](const std::string& recordId) -> const ESM::Activator* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Activator>(activator);
sol::usertype<ESM::Activator> record = context.mLua->sol().new_usertype<ESM::Activator>("ESM3_Activator");
record[sol::meta_function::to_string]
= [](const ESM::Activator& rec) { return "ESM3_Activator[" + rec.mId.toDebugString() + "]"; };

@ -30,13 +30,8 @@ namespace MWLua
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Apparatus>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Apparatus>();
apparatus["record"] = sol::overload(
[](const Object& obj) -> const ESM::Apparatus* { return obj.ptr().get<ESM::Apparatus>()->mBase; },
[store](const std::string& recordId) -> const ESM::Apparatus* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Apparatus>(apparatus);
sol::usertype<ESM::Apparatus> record = context.mLua->sol().new_usertype<ESM::Apparatus>("ESM3_Apparatus");
record[sol::meta_function::to_string]
= [](const ESM::Apparatus& rec) { return "ESM3_Apparatus[" + rec.mId.toDebugString() + "]"; };

@ -37,12 +37,8 @@ namespace MWLua
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Armor>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Armor>();
armor["record"]
= sol::overload([](const Object& obj) -> const ESM::Armor* { return obj.ptr().get<ESM::Armor>()->mBase; },
[store](const std::string& recordId) -> const ESM::Armor* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Armor>(armor);
sol::usertype<ESM::Armor> record = context.mLua->sol().new_usertype<ESM::Armor>("ESM3_Armor");
record[sol::meta_function::to_string]
= [](const ESM::Armor& rec) -> std::string { return "ESM3_Armor[" + rec.mId.toDebugString() + "]"; };

@ -32,12 +32,8 @@ namespace MWLua
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Book>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Book>();
book["record"]
= sol::overload([](const Object& obj) -> const ESM::Book* { return obj.ptr().get<ESM::Book>()->mBase; },
[store](const std::string& recordId) -> const ESM::Book* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Book>(book);
sol::usertype<ESM::Book> record = context.mLua->sol().new_usertype<ESM::Book>("ESM3_Book");
record[sol::meta_function::to_string]
= [](const ESM::Book& rec) { return "ESM3_Book[" + rec.mId.toDebugString() + "]"; };

@ -36,13 +36,8 @@ namespace MWLua
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Clothing>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Clothing>();
clothing["record"] = sol::overload(
[](const Object& obj) -> const ESM::Clothing* { return obj.ptr().get<ESM::Clothing>()->mBase; },
[store](const std::string& recordId) -> const ESM::Clothing* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Clothing>(clothing);
sol::usertype<ESM::Clothing> record = context.mLua->sol().new_usertype<ESM::Clothing>("ESM3_Clothing");
record[sol::meta_function::to_string]
= [](const ESM::Clothing& rec) -> std::string { return "ESM3_Clothing[" + rec.mId.toDebugString() + "]"; };

@ -48,13 +48,8 @@ namespace MWLua
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Container>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Container>();
container["record"] = sol::overload(
[](const Object& obj) -> const ESM::Container* { return obj.ptr().get<ESM::Container>()->mBase; },
[store](const std::string& recordId) -> const ESM::Container* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Container>(container);
sol::usertype<ESM::Container> record = context.mLua->sol().new_usertype<ESM::Container>("ESM3_Container");
record[sol::meta_function::to_string] = [](const ESM::Container& rec) -> std::string {
return "ESM3_Container[" + rec.mId.toDebugString() + "]";

@ -23,13 +23,8 @@ namespace MWLua
{
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Creature>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>();
creature["record"] = sol::overload(
[](const Object& obj) -> const ESM::Creature* { return obj.ptr().get<ESM::Creature>()->mBase; },
[store](const std::string& recordId) -> const ESM::Creature* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Creature>(creature);
sol::usertype<ESM::Creature> record = context.mLua->sol().new_usertype<ESM::Creature>("ESM3_Creature");
record[sol::meta_function::to_string]
= [](const ESM::Creature& rec) { return "ESM3_Creature[" + rec.mId.toDebugString() + "]"; };

@ -44,12 +44,8 @@ namespace MWLua
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Door>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Door>();
door["record"]
= sol::overload([](const Object& obj) -> const ESM::Door* { return obj.ptr().get<ESM::Door>()->mBase; },
[store](const std::string& recordId) -> const ESM::Door* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Door>(door);
sol::usertype<ESM::Door> record = context.mLua->sol().new_usertype<ESM::Door>("ESM3_Door");
record[sol::meta_function::to_string]
= [](const ESM::Door& rec) -> std::string { return "ESM3_Door[" + rec.mId.toDebugString() + "]"; };

@ -24,13 +24,8 @@ namespace MWLua
{
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Ingredient>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Ingredient>();
ingredient["record"] = sol::overload(
[](const Object& obj) -> const ESM::Ingredient* { return obj.ptr().get<ESM::Ingredient>()->mBase; },
[store](const std::string& recordID) -> const ESM::Ingredient* {
return store->find(ESM::RefId::stringRefId(recordID));
});
addRecordFunctionBinding<ESM::Ingredient>(ingredient);
sol::usertype<ESM::Ingredient> record = context.mLua->sol().new_usertype<ESM::Ingredient>(("ESM3_Ingredient"));
record[sol::meta_function::to_string]
= [](const ESM::Ingredient& rec) { return "ESM3_Ingredient[" + rec.mId.toDebugString() + "]"; };

@ -23,12 +23,8 @@ namespace MWLua
{
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Light>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Light>();
light["record"]
= sol::overload([](const Object& obj) -> const ESM::Light* { return obj.ptr().get<ESM::Light>()->mBase; },
[store](const std::string& recordId) -> const ESM::Light* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Light>(light);
sol::usertype<ESM::Light> record = context.mLua->sol().new_usertype<ESM::Light>("ESM3_Light");
record[sol::meta_function::to_string]
= [](const ESM::Light& rec) -> std::string { return "ESM3_Light[" + rec.mId.toDebugString() + "]"; };

@ -23,13 +23,8 @@ namespace MWLua
{
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Lockpick>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Lockpick>();
lockpick["record"] = sol::overload(
[](const Object& obj) -> const ESM::Lockpick* { return obj.ptr().get<ESM::Lockpick>()->mBase; },
[store](const std::string& recordId) -> const ESM::Lockpick* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Lockpick>(lockpick);
sol::usertype<ESM::Lockpick> record = context.mLua->sol().new_usertype<ESM::Lockpick>("ESM3_Lockpick");
record[sol::meta_function::to_string]
= [](const ESM::Lockpick& rec) { return "ESM3_Lockpick[" + rec.mId.toDebugString() + "]"; };

@ -23,13 +23,8 @@ namespace MWLua
{
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Miscellaneous>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Miscellaneous>();
miscellaneous["record"] = sol::overload(
[](const Object& obj) -> const ESM::Miscellaneous* { return obj.ptr().get<ESM::Miscellaneous>()->mBase; },
[store](const std::string& recordId) -> const ESM::Miscellaneous* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Miscellaneous>(miscellaneous);
sol::usertype<ESM::Miscellaneous> record
= context.mLua->sol().new_usertype<ESM::Miscellaneous>("ESM3_Miscellaneous");
record[sol::meta_function::to_string]

@ -25,12 +25,8 @@ namespace MWLua
{
addNpcStatsBindings(npc, context);
const MWWorld::Store<ESM::NPC>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::NPC>();
npc["record"]
= sol::overload([](const Object& obj) -> const ESM::NPC* { return obj.ptr().get<ESM::NPC>()->mBase; },
[store](const std::string& recordId) -> const ESM::NPC* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::NPC>(npc);
sol::usertype<ESM::NPC> record = context.mLua->sol().new_usertype<ESM::NPC>("ESM3_NPC");
record[sol::meta_function::to_string]
= [](const ESM::NPC& rec) { return "ESM3_NPC[" + rec.mId.toDebugString() + "]"; };

@ -21,13 +21,7 @@ namespace MWLua
{
void addPotionBindings(sol::table potion, const Context& context)
{
const MWWorld::Store<ESM::Potion>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Potion>();
potion["record"]
= sol::overload([](const Object& obj) -> const ESM::Potion* { return obj.ptr().get<ESM::Potion>()->mBase; },
[store](const std::string& recordId) -> const ESM::Potion* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Potion>(potion);
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
sol::usertype<ESM::Potion> record = context.mLua->sol().new_usertype<ESM::Potion>("ESM3_Potion");

@ -23,12 +23,8 @@ namespace MWLua
{
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Probe>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Probe>();
probe["record"]
= sol::overload([](const Object& obj) -> const ESM::Probe* { return obj.ptr().get<ESM::Probe>()->mBase; },
[store](const std::string& recordId) -> const ESM::Probe* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Probe>(probe);
sol::usertype<ESM::Probe> record = context.mLua->sol().new_usertype<ESM::Probe>("ESM3_Probe");
record[sol::meta_function::to_string]
= [](const ESM::Probe& rec) { return "ESM3_Probe[" + rec.mId.toDebugString() + "]"; };

@ -23,13 +23,8 @@ namespace MWLua
{
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Repair>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Repair>();
repair["record"]
= sol::overload([](const Object& obj) -> const ESM::Repair* { return obj.ptr().get<ESM::Repair>()->mBase; },
[store](const std::string& recordId) -> const ESM::Repair* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Repair>(repair);
sol::usertype<ESM::Repair> record = context.mLua->sol().new_usertype<ESM::Repair>("ESM3_Repair");
record[sol::meta_function::to_string]
= [](const ESM::Repair& rec) { return "ESM3_Repair[" + rec.mId.toDebugString() + "]"; };

@ -23,13 +23,8 @@ namespace MWLua
{
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Static>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>();
stat["record"]
= sol::overload([](const Object& obj) -> const ESM::Static* { return obj.ptr().get<ESM::Static>()->mBase; },
[store](const std::string& recordId) -> const ESM::Static* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Static>(stat);
sol::usertype<ESM::Static> record = context.mLua->sol().new_usertype<ESM::Static>("ESM3_Static");
record[sol::meta_function::to_string]
= [](const ESM::Static& rec) -> std::string { return "ESM3_Static[" + rec.mId.toDebugString() + "]"; };

@ -5,6 +5,11 @@
#include <components/esm/defs.hpp>
#include "apps/openmw/mwbase/environment.hpp"
#include "apps/openmw/mwbase/world.hpp"
#include "apps/openmw/mwworld/esmstore.hpp"
#include "apps/openmw/mwworld/store.hpp"
#include "../context.hpp"
namespace MWLua
@ -45,6 +50,16 @@ namespace MWLua
void addClothingBindings(sol::table clothing, const Context& context);
void addStaticBindings(sol::table stat, const Context& context);
void addLightBindings(sol::table light, const Context& context);
template <class T>
void addRecordFunctionBinding(sol::table table)
{
const MWWorld::Store<T>& store = MWBase::Environment::get().getWorld()->getStore().get<T>();
table["record"] = sol::overload([](const Object& obj) -> const T* { return obj.ptr().get<T>()->mBase; },
[&store](
const std::string& recordId) -> const T* { return store.find(ESM::RefId::stringRefId(recordId)); });
}
}
#endif // MWLUA_TYPES_H

@ -40,13 +40,8 @@ namespace MWLua
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Weapon>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Weapon>();
weapon["record"]
= sol::overload([](const Object& obj) -> const ESM::Weapon* { return obj.ptr().get<ESM::Weapon>()->mBase; },
[store](const std::string& recordId) -> const ESM::Weapon* {
return store->find(ESM::RefId::stringRefId(recordId));
});
addRecordFunctionBinding<ESM::Weapon>(weapon);
sol::usertype<ESM::Weapon> record = context.mLua->sol().new_usertype<ESM::Weapon>("ESM3_Weapon");
record[sol::meta_function::to_string]
= [](const ESM::Weapon& rec) -> std::string { return "ESM3_Weapon[" + rec.mId.toDebugString() + "]"; };

Loading…
Cancel
Save