2 * Copyright 2014 Google Inc. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 // independent from idl_parser, since this code is not needed for most clients
21 #include "flatbuffers/code_generators.h"
22 #include "flatbuffers/flatbuffers.h"
23 #include "flatbuffers/idl.h"
24 #include "flatbuffers/util.h"
26 #include <unordered_set>
28 namespace flatbuffers {
31 // Hardcode spaces per indentation.
32 const char * Indent = " ";
33 const char * Comment = "-- ";
34 const char * End = "end\n";
35 const char * EndFunc = "end\n";
36 const char * SelfData = "self.view";
37 const char * SelfDataPos = "self.view.pos";
38 const char * SelfDataBytes = "self.view.bytes";
40 class LuaGenerator : public BaseGenerator {
42 LuaGenerator(const Parser &parser, const std::string &path,
43 const std::string &file_name)
44 : BaseGenerator(parser, path, file_name, "" /* not used */,
46 static const char * const keywords[] = {
70 keywords_.insert(std::begin(keywords), std::end(keywords));
73 // Most field accessors need to retrieve and test the field offset first,
74 // this is the prefix code for that.
75 std::string OffsetPrefix(const FieldDef &field) {
76 return std::string(Indent) +
77 "local o = " + SelfData + ":Offset(" + NumToString(field.value.offset) + ")\n" +
78 Indent + "if o ~= 0 then\n";
81 // Begin a class declaration.
82 void BeginClass(const StructDef &struct_def, std::string *code_ptr) {
83 std::string &code = *code_ptr;
84 code += "local " + NormalizedName(struct_def) + " = {} -- the module\n";
85 code += "local " + NormalizedMetaName(struct_def) + " = {} -- the class metatable\n";
89 // Begin enum code with a class declaration.
90 void BeginEnum(const std::string class_name, std::string *code_ptr) {
91 std::string &code = *code_ptr;
92 code += "local " + class_name + " = {\n";
95 std::string EscapeKeyword(const std::string &name) const {
96 return keywords_.find(name) == keywords_.end() ? name : "_" + name;
99 std::string NormalizedName(const Definition &definition) const {
100 return EscapeKeyword(definition.name);
103 std::string NormalizedName(const EnumVal &ev) const {
104 return EscapeKeyword(ev.name);
107 std::string NormalizedMetaName(const Definition &definition) const {
108 return EscapeKeyword(definition.name) + "_mt";
111 // A single enum member.
112 void EnumMember(const EnumVal ev, std::string *code_ptr) {
113 std::string &code = *code_ptr;
114 code += std::string(Indent) + NormalizedName(ev) + " = " + NumToString(ev.value) + ",\n";
118 void EndEnum(std::string *code_ptr) {
119 std::string &code = *code_ptr;
123 void GenerateNewObjectPrototype(const StructDef &struct_def,
124 std::string *code_ptr) {
125 std::string &code = *code_ptr;
127 code += "function " + NormalizedName(struct_def) + ".New()\n";
128 code += std::string(Indent) + "local o = {}\n";
129 code += std::string(Indent) + "setmetatable(o, {__index = " + NormalizedMetaName(struct_def) + "})\n";
130 code += std::string(Indent) + "return o\n";
134 // Initialize a new struct or table from existing data.
135 void NewRootTypeFromBuffer(const StructDef &struct_def,
136 std::string *code_ptr) {
137 std::string &code = *code_ptr;
139 code += "function " + NormalizedName(struct_def) + ".GetRootAs" + NormalizedName(struct_def) + "(buf, offset)\n";
140 code += std::string(Indent) + "local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)\n";
141 code += std::string(Indent) + "local o = " + NormalizedName(struct_def) + ".New()\n";
142 code += std::string(Indent) + "o:Init(buf, n + offset)\n";
143 code += std::string(Indent) + "return o\n";
147 // Initialize an existing object with other data, to avoid an allocation.
148 void InitializeExisting(const StructDef &struct_def,
149 std::string *code_ptr) {
150 std::string &code = *code_ptr;
152 GenReceiver(struct_def, code_ptr);
153 code += "Init(buf, pos)\n";
154 code += std::string(Indent) + SelfData + " = flatbuffers.view.New(buf, pos)\n";
158 // Get the length of a vector.
159 void GetVectorLen(const StructDef &struct_def, const FieldDef &field,
160 std::string *code_ptr) {
161 std::string &code = *code_ptr;
163 GenReceiver(struct_def, code_ptr);
164 code += MakeCamel(NormalizedName(field)) + "Length()\n";
165 code += OffsetPrefix(field);
166 code += std::string(Indent) + Indent + "return " + SelfData + ":VectorLen(o)\n";
167 code += std::string(Indent) + End;
168 code += std::string(Indent) + "return 0\n";
172 // Get the value of a struct's scalar.
173 void GetScalarFieldOfStruct(const StructDef &struct_def,
174 const FieldDef &field,
175 std::string *code_ptr) {
176 std::string &code = *code_ptr;
177 std::string getter = GenGetter(field.value.type);
178 GenReceiver(struct_def, code_ptr);
179 code += MakeCamel(NormalizedName(field));
181 code += std::string(Indent) + "return " + getter;
182 code += std::string(SelfDataPos) + " + " + NumToString(field.value.offset) + ")\n";
186 // Get the value of a table's scalar.
187 void GetScalarFieldOfTable(const StructDef &struct_def,
188 const FieldDef &field,
189 std::string *code_ptr) {
190 std::string &code = *code_ptr;
191 std::string getter = GenGetter(field.value.type);
192 GenReceiver(struct_def, code_ptr);
193 code += MakeCamel(NormalizedName(field));
195 code += OffsetPrefix(field);
196 getter += std::string("o + ") + SelfDataPos + ")";
197 auto is_bool = field.value.type.base_type == BASE_TYPE_BOOL;
199 getter = "(" + getter + " ~= 0)";
201 code += std::string(Indent) + Indent + "return " + getter + "\n";
202 code += std::string(Indent) + End;
203 std::string default_value;
205 default_value = field.value.constant == "0" ? "false" : "true";
208 default_value = field.value.constant;
210 code += std::string(Indent) + "return " + default_value + "\n";
214 // Get a struct by initializing an existing struct.
215 // Specific to Struct.
216 void GetStructFieldOfStruct(const StructDef &struct_def,
217 const FieldDef &field,
218 std::string *code_ptr) {
219 std::string &code = *code_ptr;
220 GenReceiver(struct_def, code_ptr);
221 code += MakeCamel(NormalizedName(field));
223 code += std::string(Indent) + "obj:Init(" + SelfDataBytes + ", " + SelfDataPos + " + ";
224 code += NumToString(field.value.offset) + ")\n";
225 code += std::string(Indent) + "return obj\n";
229 // Get a struct by initializing an existing struct.
230 // Specific to Table.
231 void GetStructFieldOfTable(const StructDef &struct_def,
232 const FieldDef &field,
233 std::string *code_ptr) {
234 std::string &code = *code_ptr;
235 GenReceiver(struct_def, code_ptr);
236 code += MakeCamel(NormalizedName(field));
238 code += OffsetPrefix(field);
239 if (field.value.type.struct_def->fixed) {
240 code += std::string(Indent) + Indent + "local x = o + " + SelfDataPos + "\n";
243 code += std::string(Indent) + Indent + "local x = " + SelfData + ":Indirect(o + " + SelfDataPos + ")\n";
245 code += std::string(Indent) + Indent + "local obj = require('" + TypeNameWithNamespace(field) + "').New()\n";
246 code += std::string(Indent) + Indent + "obj:Init(" + SelfDataBytes + ", x)\n";
247 code += std::string(Indent) + Indent + "return obj\n";
248 code += std::string(Indent) + End;
252 // Get the value of a string.
253 void GetStringField(const StructDef &struct_def, const FieldDef &field,
254 std::string *code_ptr) {
255 std::string &code = *code_ptr;
256 GenReceiver(struct_def, code_ptr);
257 code += MakeCamel(NormalizedName(field));
259 code += OffsetPrefix(field);
260 code += std::string(Indent) + Indent + "return " + GenGetter(field.value.type);
261 code += std::string("o + ") + SelfDataPos + ")\n";
262 code += std::string(Indent) + End;
266 // Get the value of a union from an object.
267 void GetUnionField(const StructDef &struct_def, const FieldDef &field,
268 std::string *code_ptr) {
269 std::string &code = *code_ptr;
270 GenReceiver(struct_def, code_ptr);
271 code += MakeCamel(NormalizedName(field)) + "()\n";
272 code += OffsetPrefix(field);
274 // TODO(rw): this works and is not the good way to it:
275 //bool is_native_table = TypeName(field) == "*flatbuffers.Table";
276 //if (is_native_table) {
277 // code += std::string(Indent) + Indent + "from flatbuffers.table import Table\n";
279 // code += std::string(Indent) + Indent +
280 // code += "from ." + TypeName(field) + " import " + TypeName(field) + "\n";
282 code += std::string(Indent) + Indent + "local obj = flatbuffers.view.New(require('flatbuffers.binaryarray').New(0), 0)\n";
283 code += std::string(Indent) + Indent + GenGetter(field.value.type) + "obj, o)\n";
284 code += std::string(Indent) + Indent + "return obj\n";
285 code += std::string(Indent) + End;
289 // Get the value of a vector's struct member.
290 void GetMemberOfVectorOfStruct(const StructDef &struct_def,
291 const FieldDef &field,
292 std::string *code_ptr) {
293 std::string &code = *code_ptr;
294 auto vectortype = field.value.type.VectorType();
296 GenReceiver(struct_def, code_ptr);
297 code += MakeCamel(NormalizedName(field));
299 code += OffsetPrefix(field);
300 code += std::string(Indent) + Indent + "local x = " + SelfData + ":Vector(o)\n";
301 code += std::string(Indent) + Indent + "x = x + ((j-1) * ";
302 code += NumToString(InlineSize(vectortype)) + ")\n";
303 if (!(vectortype.struct_def->fixed)) {
304 code += std::string(Indent) + Indent + "x = " + SelfData + ":Indirect(x)\n";
306 code += std::string(Indent) + Indent + "local obj = require('" + TypeNameWithNamespace(field) + "').New()\n";
307 code += std::string(Indent) + Indent + "obj:Init(" + SelfDataBytes + ", x)\n";
308 code += std::string(Indent) + Indent + "return obj\n";
309 code += std::string(Indent) + End;
313 // Get the value of a vector's non-struct member. Uses a named return
314 // argument to conveniently set the zero value for the result.
315 void GetMemberOfVectorOfNonStruct(const StructDef &struct_def,
316 const FieldDef &field,
317 std::string *code_ptr) {
318 std::string &code = *code_ptr;
319 auto vectortype = field.value.type.VectorType();
321 GenReceiver(struct_def, code_ptr);
322 code += MakeCamel(NormalizedName(field));
324 code += OffsetPrefix(field);
325 code += std::string(Indent) + Indent + "local a = " + SelfData + ":Vector(o)\n";
326 code += std::string(Indent) + Indent;
327 code += "return " + GenGetter(field.value.type);
328 code += "a + ((j-1) * ";
329 code += NumToString(InlineSize(vectortype)) + "))\n";
330 code += std::string(Indent) + End;
331 if (vectortype.base_type == BASE_TYPE_STRING) {
332 code += std::string(Indent) + "return ''\n";
335 code += std::string(Indent) + "return 0\n";
340 // Begin the creator function signature.
341 void BeginBuilderArgs(const StructDef &struct_def,
342 std::string *code_ptr) {
343 std::string &code = *code_ptr;
345 code += "function " + NormalizedName(struct_def) + ".Create" + NormalizedName(struct_def);
349 // Recursively generate arguments for a constructor, to deal with nested
351 void StructBuilderArgs(const StructDef &struct_def,
352 const char *nameprefix, std::string *code_ptr) {
353 for (auto it = struct_def.fields.vec.begin();
354 it != struct_def.fields.vec.end(); ++it) {
356 if (IsStruct(field.value.type)) {
357 // Generate arguments for a struct inside a struct. To ensure names
358 // don't clash, and to make it obvious these arguments are constructing
359 // a nested struct, prefix the name with the field name.
360 StructBuilderArgs(*field.value.type.struct_def,
361 (nameprefix + (NormalizedName(field) + "_")).c_str(), code_ptr);
364 std::string &code = *code_ptr;
365 code += (std::string) ", " + nameprefix;
366 code += MakeCamel(NormalizedName(field), false);
371 // End the creator function signature.
372 void EndBuilderArgs(std::string *code_ptr) {
373 std::string &code = *code_ptr;
377 // Recursively generate struct construction statements and instert manual
379 void StructBuilderBody(const StructDef &struct_def,
380 const char *nameprefix, std::string *code_ptr) {
381 std::string &code = *code_ptr;
382 code += std::string(Indent) + "builder:Prep(" + NumToString(struct_def.minalign) + ", ";
383 code += NumToString(struct_def.bytesize) + ")\n";
384 for (auto it = struct_def.fields.vec.rbegin();
385 it != struct_def.fields.vec.rend(); ++it) {
388 code += std::string(Indent) + "builder:Pad(" + NumToString(field.padding) + ")\n";
389 if (IsStruct(field.value.type)) {
390 StructBuilderBody(*field.value.type.struct_def,
391 (nameprefix + (NormalizedName(field) + "_")).c_str(), code_ptr);
394 code += std::string(Indent) + "builder:Prepend" + GenMethod(field) + "(";
395 code += nameprefix + MakeCamel(NormalizedName(field), false) + ")\n";
400 void EndBuilderBody(std::string *code_ptr) {
401 std::string &code = *code_ptr;
402 code += std::string(Indent) + "return builder:Offset()\n";
406 // Get the value of a table's starting offset.
407 void GetStartOfTable(const StructDef &struct_def,
408 std::string *code_ptr) {
409 std::string &code = *code_ptr;
410 code += "function " + NormalizedName(struct_def) + ".Start";
411 code += "(builder) ";
412 code += "builder:StartObject(";
413 code += NumToString(struct_def.fields.vec.size());
417 // Set the value of a table's field.
418 void BuildFieldOfTable(const StructDef &struct_def,
419 const FieldDef &field, const size_t offset,
420 std::string *code_ptr) {
421 std::string &code = *code_ptr;
422 code += "function " + NormalizedName(struct_def) + ".Add" + MakeCamel(NormalizedName(field));
423 code += "(builder, ";
424 code += MakeCamel(NormalizedName(field), false);
426 code += "builder:Prepend";
427 code += GenMethod(field) + "Slot(";
428 code += NumToString(offset) + ", ";
429 // todo: i don't need to cast in Lua, but am I missing something?
430 // if (!IsScalar(field.value.type.base_type) && (!struct_def.fixed)) {
431 // code += "flatbuffers.N.UOffsetTFlags.py_type";
433 // code += MakeCamel(NormalizedName(field), false) + ")";
435 code += MakeCamel(NormalizedName(field), false);
437 code += ", " + field.value.constant;
441 // Set the value of one of the members of a table's vector.
442 void BuildVectorOfTable(const StructDef &struct_def,
443 const FieldDef &field, std::string *code_ptr) {
444 std::string &code = *code_ptr;
445 code += "function " + NormalizedName(struct_def) + ".Start";
446 code += MakeCamel(NormalizedName(field));
447 code += "Vector(builder, numElems) return builder:StartVector(";
448 auto vector_type = field.value.type.VectorType();
449 auto alignment = InlineAlignment(vector_type);
450 auto elem_size = InlineSize(vector_type);
451 code += NumToString(elem_size);
452 code += ", numElems, " + NumToString(alignment);
456 // Get the offset of the end of a table.
457 void GetEndOffsetOnTable(const StructDef &struct_def,
458 std::string *code_ptr) {
459 std::string &code = *code_ptr;
460 code += "function " + NormalizedName(struct_def) + ".End";
461 code += "(builder) ";
462 code += "return builder:EndObject() end\n";
465 // Generate the receiver for function signatures.
466 void GenReceiver(const StructDef &struct_def, std::string *code_ptr) {
467 std::string &code = *code_ptr;
468 code += "function " + NormalizedMetaName(struct_def) + ":";
471 // Generate a struct field, conditioned on its child type(s).
472 void GenStructAccessor(const StructDef &struct_def,
473 const FieldDef &field, std::string *code_ptr) {
474 GenComment(field.doc_comment, code_ptr, nullptr, Comment);
475 if (IsScalar(field.value.type.base_type)) {
476 if (struct_def.fixed) {
477 GetScalarFieldOfStruct(struct_def, field, code_ptr);
480 GetScalarFieldOfTable(struct_def, field, code_ptr);
484 switch (field.value.type.base_type) {
485 case BASE_TYPE_STRUCT:
486 if (struct_def.fixed) {
487 GetStructFieldOfStruct(struct_def, field, code_ptr);
490 GetStructFieldOfTable(struct_def, field, code_ptr);
493 case BASE_TYPE_STRING: GetStringField(struct_def, field, code_ptr); break;
494 case BASE_TYPE_VECTOR: {
495 auto vectortype = field.value.type.VectorType();
496 if (vectortype.base_type == BASE_TYPE_STRUCT) {
497 GetMemberOfVectorOfStruct(struct_def, field, code_ptr);
500 GetMemberOfVectorOfNonStruct(struct_def, field, code_ptr);
504 case BASE_TYPE_UNION: GetUnionField(struct_def, field, code_ptr); break;
505 default: FLATBUFFERS_ASSERT(0);
508 if (field.value.type.base_type == BASE_TYPE_VECTOR) {
509 GetVectorLen(struct_def, field, code_ptr);
513 // Generate table constructors, conditioned on its members' types.
514 void GenTableBuilders(const StructDef &struct_def,
515 std::string *code_ptr) {
516 GetStartOfTable(struct_def, code_ptr);
518 for (auto it = struct_def.fields.vec.begin();
519 it != struct_def.fields.vec.end(); ++it) {
521 if (field.deprecated) continue;
523 auto offset = it - struct_def.fields.vec.begin();
524 BuildFieldOfTable(struct_def, field, offset, code_ptr);
525 if (field.value.type.base_type == BASE_TYPE_VECTOR) {
526 BuildVectorOfTable(struct_def, field, code_ptr);
530 GetEndOffsetOnTable(struct_def, code_ptr);
533 // Generate struct or table methods.
534 void GenStruct(const StructDef &struct_def, std::string *code_ptr) {
535 if (struct_def.generated) return;
537 GenComment(struct_def.doc_comment, code_ptr, nullptr, Comment);
538 BeginClass(struct_def, code_ptr);
540 GenerateNewObjectPrototype(struct_def, code_ptr);
542 if (!struct_def.fixed) {
543 // Generate a special accessor for the table that has been declared as
545 NewRootTypeFromBuffer(struct_def, code_ptr);
548 // Generate the Init method that sets the field in a pre-existing
549 // accessor object. This is to allow object reuse.
550 InitializeExisting(struct_def, code_ptr);
551 for (auto it = struct_def.fields.vec.begin();
552 it != struct_def.fields.vec.end(); ++it) {
554 if (field.deprecated) continue;
556 GenStructAccessor(struct_def, field, code_ptr);
559 if (struct_def.fixed) {
560 // create a struct constructor function
561 GenStructBuilder(struct_def, code_ptr);
564 // Create a set of functions that allow table construction.
565 GenTableBuilders(struct_def, code_ptr);
569 // Generate enum declarations.
570 void GenEnum(const EnumDef &enum_def, std::string *code_ptr) {
571 if (enum_def.generated) return;
573 GenComment(enum_def.doc_comment, code_ptr, nullptr, Comment);
574 BeginEnum(NormalizedName(enum_def), code_ptr);
575 for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
578 GenComment(ev.doc_comment, code_ptr, nullptr, Comment);
579 EnumMember(ev, code_ptr);
584 // Returns the function name that is able to read a value of the given type.
585 std::string GenGetter(const Type &type) {
586 switch (type.base_type) {
587 case BASE_TYPE_STRING: return std::string(SelfData) + ":String(";
588 case BASE_TYPE_UNION: return std::string(SelfData) + ":Union(";
589 case BASE_TYPE_VECTOR: return GenGetter(type.VectorType());
591 return std::string(SelfData) + ":Get(flatbuffers.N." +
592 MakeCamel(GenTypeGet(type)) + ", ";
596 // Returns the method name for use with add/put calls.
597 std::string GenMethod(const FieldDef &field) {
598 return IsScalar(field.value.type.base_type)
599 ? MakeCamel(GenTypeBasic(field.value.type))
600 : (IsStruct(field.value.type) ? "Struct" : "UOffsetTRelative");
603 std::string GenTypeBasic(const Type &type) {
604 static const char *ctypename[] = {
606 #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
607 CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \
609 FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
610 #undef FLATBUFFERS_TD
613 return ctypename[type.base_type];
616 std::string GenTypePointer(const Type &type) {
617 switch (type.base_type) {
618 case BASE_TYPE_STRING: return "string";
619 case BASE_TYPE_VECTOR: return GenTypeGet(type.VectorType());
620 case BASE_TYPE_STRUCT: return type.struct_def->name;
621 case BASE_TYPE_UNION:
623 default: return "*flatbuffers.Table";
627 std::string GenTypeGet(const Type &type) {
628 return IsScalar(type.base_type) ? GenTypeBasic(type) : GenTypePointer(type);
631 std::string GetNamespace(const Type &type) {
632 return type.struct_def->defined_namespace->GetFullyQualifiedName(type.struct_def->name);
635 std::string TypeName(const FieldDef &field) {
636 return GenTypeGet(field.value.type);
639 std::string TypeNameWithNamespace(const FieldDef &field) {
640 return GetNamespace(field.value.type);
643 // Create a struct with a builder and the struct's arguments.
644 void GenStructBuilder(const StructDef &struct_def,
645 std::string *code_ptr) {
646 BeginBuilderArgs(struct_def, code_ptr);
647 StructBuilderArgs(struct_def, "", code_ptr);
648 EndBuilderArgs(code_ptr);
650 StructBuilderBody(struct_def, "", code_ptr);
651 EndBuilderBody(code_ptr);
655 if (!generateEnums()) return false;
656 if (!generateStructs()) return false;
661 bool generateEnums() {
662 for (auto it = parser_.enums_.vec.begin(); it != parser_.enums_.vec.end();
664 auto &enum_def = **it;
665 std::string enumcode;
666 GenEnum(enum_def, &enumcode);
667 if (!SaveType(enum_def, enumcode, false)) return false;
672 bool generateStructs() {
673 for (auto it = parser_.structs_.vec.begin();
674 it != parser_.structs_.vec.end(); ++it) {
675 auto &struct_def = **it;
676 std::string declcode;
677 GenStruct(struct_def, &declcode);
678 if (!SaveType(struct_def, declcode, true)) return false;
683 // Begin by declaring namespace and imports.
684 void BeginFile(const std::string name_space_name, const bool needs_imports,
685 std::string *code_ptr) {
686 std::string &code = *code_ptr;
687 code += std::string(Comment) + FlatBuffersGeneratedWarning() + "\n\n";
688 code += std::string(Comment) + "namespace: " + name_space_name + "\n\n";
690 code += "local flatbuffers = require('flatbuffers')\n\n";
694 // Save out the generated code for a Lua Table type.
695 bool SaveType(const Definition &def, const std::string &classcode,
696 bool needs_imports) {
697 if (!classcode.length()) return true;
699 std::string namespace_dir = path_;
700 auto &namespaces = def.defined_namespace->components;
701 for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
702 if (it != namespaces.begin()) namespace_dir += kPathSeparator;
703 namespace_dir += *it;
704 //std::string init_py_filename = namespace_dir + "/__init__.py";
705 //SaveFile(init_py_filename.c_str(), "", false);
708 std::string code = "";
709 BeginFile(LastNamespacePart(*def.defined_namespace), needs_imports, &code);
712 code += "return " + NormalizedName(def) + " " + Comment + "return the module";
713 std::string filename =
714 NamespaceDir(*def.defined_namespace) + NormalizedName(def) + ".lua";
715 return SaveFile(filename.c_str(), code, false);
718 std::unordered_set<std::string> keywords_;
723 bool GenerateLua(const Parser &parser, const std::string &path,
724 const std::string &file_name) {
725 lua::LuaGenerator generator(parser, path, file_name);
726 return generator.generate();
729 } // namespace flatbuffers