Something went wrong. Try again.
Monorepo for PackTools - tooling for Minecraft Modpacks!
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// pw.toml (ABI 8): TOML read the way the host reads its own settings, as data. Pure: the text came// through a capability already. AI-authored (Claude).
#include "../json.hpp"#include "bindings.hpp"#include "host.hpp"#include "lua.h"#include "lualib.h"
#include <string_view>
namespace packluau::bindings {
namespace {
/// `pw.toml.decode(text)`: the document as a read-only table (a date as its text), or nil and/// `{kind, message}` saying why `text` is not TOML.int decode(lua_State *state) { const std::string_view text = check_string(state, 1); RunContext &run = context(state); pl_str json{}; check(state, run, run.host->toml_decode(run.host->ctx, str(text), &json), "pw.toml.decode"); if (auto pushed = push_json(state, view(json)); !pushed) { luaL_error(state, "pw.toml.decode: the host sent %s", pushed.error().c_str()); } if (!lua_istable(state, -1)) { luaL_error(state, "pw.toml.decode: the host sent no object"); } lua_getfield(state, -1, "document"); if (lua_istable(state, -1)) { return 1; } lua_pop(state, 1); lua_pushnil(state); lua_getfield(state, -2, "error"); if (!lua_istable(state, -1)) { luaL_error(state, "pw.toml.decode: the host sent neither a document nor an error"); } return 2;}
} // namespace
void install_toml(lua_State *state) { lua_createtable(state, 0, 1); lua_pushcfunction(state, &decode, "pw.toml.decode"); lua_setfield(state, -2, "decode"); seal(state);}
} // namespace packluau::bindings