Skip to content

Commit

Permalink
Optional filename in flexbuffers_json_to_binary for better errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aardappel committed Oct 25, 2023
1 parent 0abbc00 commit 8078de3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dev/src/lobsterreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,16 @@ nfr("flexbuffers_binary_to_json", "flex,field_quotes,indent_string", "SBS", "S?S
}
});

nfr("flexbuffers_json_to_binary", "json", "S", "SS?",
nfr("flexbuffers_json_to_binary", "json,filename_for_errors", "SS?", "SS?",
"turns a JSON string into a flexbuffer, second value is error, if any",
[](StackPtr &sp, VM &vm, Value &json) {
[](StackPtr &sp, VM &vm, Value &json, Value &filename) {
flexbuffers::Builder builder;
flatbuffers::Parser parser;
auto err = NilVal();
if (!parser.ParseFlexBuffer(json.sval()->strv().data(), "(flexbuffers_json_to_binary)",
auto fn = filename.True()
? filename.sval()->strvnt()
: string_view_nt("{flexbuffers_json_to_binary}");
if (!parser.ParseFlexBuffer(json.sval()->strv().data(), fn.c_str(),
&builder)) {
err = vm.NewString(parser.error_);
Push(sp, vm.NewString(""));
Expand Down

0 comments on commit 8078de3

Please sign in to comment.