2024-03-05 06:07:35 +00:00
|
|
|
#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)
|
|
|
|
{
|
2024-08-22 20:22:28 +00:00
|
|
|
sol::state_view lua = context.sol();
|
|
|
|
sol::table api(lua, sol::create);
|
2024-03-05 06:07:35 +00:00
|
|
|
|
|
|
|
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
|
|
|
|
2024-08-22 20:22:28 +00:00
|
|
|
api["loadYaml"] = [lua, vfs](std::string_view fileName) {
|
2024-03-16 13:22:07 +00:00
|
|
|
Files::IStreamPtr file = vfs->get(VFS::Path::Normalized(fileName));
|
2024-08-22 20:22:28 +00:00
|
|
|
return LuaUtil::loadYaml(*file, lua);
|
2024-03-05 06:07:35 +00:00
|
|
|
};
|
2024-08-22 20:22:28 +00:00
|
|
|
api["decodeYaml"]
|
|
|
|
= [lua](std::string_view inputData) { return LuaUtil::loadYaml(std::string(inputData), lua); };
|
2024-03-05 06:07:35 +00:00
|
|
|
|
|
|
|
return LuaUtil::makeReadOnly(api);
|
|
|
|
}
|
|
|
|
}
|