[Lua] GetRootAs can accept strings. Made Luatest Benchmarks optional (#6593)

This commit is contained in:
Derek Bailey
2021-04-27 13:02:13 -07:00
committed by GitHub
parent 16836ff95a
commit 14725d6c3b
13 changed files with 71 additions and 0 deletions

View File

@@ -124,6 +124,10 @@ class LuaGenerator : public BaseGenerator {
code += "function " + NormalizedName(struct_def) + ".GetRootAs" +
NormalizedName(struct_def) + "(buf, offset)\n";
code += std::string(Indent) + "if type(buf) == \"string\" then\n";
code += std::string(Indent) + Indent +
"buf = flatbuffers.binaryArray.New(buf)\n";
code += std::string(Indent) + "end\n";
code += std::string(Indent) +
"local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)\n";
code += std::string(Indent) + "local o = " + NormalizedName(struct_def) +