1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-28 18:18:52 +00:00
OpenMW/apps/openmw/mwlua/markupbindings.cpp
2024-03-17 18:15:23 +04:00

32 lines
964 B
C++

#include "markupbindings.hpp"
#include <components/lua/luastate.hpp>
#include <components/lua/yamlloader.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/vfs/manager.hpp>
#include <components/vfs/pathutil.hpp>
#include "../mwbase/environment.hpp"
#include "context.hpp"
namespace MWLua
{
sol::table initMarkupPackage(const Context& context)
{
sol::table api(context.mLua->sol(), sol::create);
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
api["loadYaml"] = [lua = context.mLua, vfs](std::string_view fileName) {
Files::IStreamPtr file = vfs->get(VFS::Path::Normalized(fileName));
return LuaUtil::loadYaml(*file, lua->sol());
};
api["decodeYaml"] = [lua = context.mLua](std::string_view inputData) {
return LuaUtil::loadYaml(std::string(inputData), lua->sol());
};
return LuaUtil::makeReadOnly(api);
}
}