MCPcopy Create free account
hub / github.com/OpenMW/openmw / initLuaBindings

Method initLuaBindings

components/lua/storage.cpp:127–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125 }
126
127 void LuaStorage::initLuaBindings(LuaUtil::LuaView& view)
128 {
129 sol::usertype<SectionView> sview = view.sol().new_usertype<SectionView>("Section");
130 sview["get"] = [](sol::this_state s, const SectionView& section, std::string_view key) {
131 return section.mSection->get(key).getReadOnly(s);
132 };
133 sview["getCopy"] = [](sol::this_state s, const SectionView& section, std::string_view key) {
134 return section.mSection->get(key).getCopy(s);
135 };
136 sview["asTable"]
137 = [](sol::this_state lua, const SectionView& section) { return section.mSection->asTable(lua); };
138 sview["subscribe"] = [](const SectionView& section, const sol::table& callback) {
139 std::vector<Callback>& callbacks
140 = section.mForMenuScripts ? section.mSection->mMenuScriptsCallbacks : section.mSection->mCallbacks;
141 if (!callbacks.empty() && callbacks.size() == callbacks.capacity())
142 {
143 callbacks.erase(
144 std::remove_if(callbacks.begin(), callbacks.end(), [&](const Callback& c) { return !c.isValid(); }),
145 callbacks.end());
146 }
147 callbacks.push_back(Callback::fromLua(callback));
148 };
149 sview["reset"] = [](const SectionView& section, const sol::optional<sol::table>& newValues) {
150 if (section.mReadOnly)
151 throw std::runtime_error("Access to storage is read only");
152 section.mSection->setAll(newValues);
153 };
154 sview["removeOnExit"] = [](const SectionView& section) {
155 if (section.mReadOnly)
156 throw std::runtime_error("Access to storage is read only");
157 section.mSection->mLifeTime = Section::Temporary;
158 };
159 sview["setLifeTime"] = [](const SectionView& section, Section::LifeTime lifeTime) {
160 if (section.mReadOnly)
161 throw std::runtime_error("Access to storage is read only");
162 section.mSection->mLifeTime = lifeTime;
163 };
164 sview["set"] = [](const SectionView& section, std::string_view key, const sol::object& value) {
165 if (section.mReadOnly)
166 throw std::runtime_error("Access to storage is read only");
167 section.mSection->set(key, value);
168 };
169 }
170
171 sol::table LuaStorage::initGlobalPackage(LuaUtil::LuaView& view, LuaStorage* globalStorage)
172 {

Callers

nothing calls this directly

Calls 14

solMethod · 0.80
getReadOnlyMethod · 0.80
getCopyMethod · 0.80
asTableMethod · 0.80
capacityMethod · 0.80
setAllMethod · 0.80
getMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected