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 CommentConfig def_comment = { nullptr, "--", nullptr };
33 const char * Indent = " ";
34 const char * Comment = "-- ";
35 const char * End = "end\n";
36 const char * EndFunc = "end\n";
37 const char * SelfData = "self.view";
38 const char * SelfDataPos = "self.view.pos";
39 const char * SelfDataBytes = "self.view.bytes";
41 class LuaGenerator : public BaseGenerator {
43 LuaGenerator(const Parser &parser, const std::string &path,
44 const std::string &file_name)
45 : BaseGenerator(parser, path, file_name, "" /* not used */,
47 static const char * const keywords[] = {
71 keywords_.insert(std::begin(keywords), std::end(keywords));
74 // Most field accessors need to retrieve and test the field offset first,
75 // this is the prefix code for that.
76 std::string OffsetPrefix(const FieldDef &field) {
77 return std::string(Indent) +
78 "local o = " + SelfData + ":Offset(" + NumToString(field.value.offset) + ")\n" +
79 Indent + "if o ~= 0 then\n";
82 // Begin a class declaration.
83 void BeginClass(const StructDef &struct_def, std::string *code_ptr) {
84 std::string &code = *code_ptr;
85 code += "local " + NormalizedName(struct_def) + " = {} -- the module\n";
86 code += "local " + NormalizedMetaName(struct_def) + " = {} -- the class metatable\n";
90 // Begin enum code with a class declaration.
91 void BeginEnum(const std::string &class_name, std::string *code_ptr) {
92 std::string &code = *code_ptr;
93 code += "local " + class_name + " = {\n";
96 std::string EscapeKeyword(const std::string &name) const {
97 return keywords_.find(name) == keywords_.end() ? name : "_" + name;
100 std::string NormalizedName(const Definition &definition) const {
101 return EscapeKeyword(definition.name);
104 std::string NormalizedName(const EnumVal &ev) const {
105 return EscapeKeyword(ev.name);
108 std::string NormalizedMetaName(const Definition &definition) const {
109 return EscapeKeyword(definition.name) + "_mt";
112 // A single enum member.
113 void EnumMember(const EnumDef &enum_def, const EnumVal &ev, std::string *code_ptr) {
114 std::string &code = *code_ptr;
115 code += std::string(Indent) + NormalizedName(ev) + " = " +
116 enum_def.ToString(ev) + ",\n";
120 void EndEnum(std::string *code_ptr) {
121 std::string &code = *code_ptr;
125 void GenerateNewObjectPrototype(const StructDef &struct_def,
126 std::string *code_ptr) {
127 std::string &code = *code_ptr;
129 code += "function " + NormalizedName(struct_def) + ".New()\n";
130 code += std::string(Indent) + "local o = {}\n";
131 code += std::string(Indent) + "setmetatable(o, {__index = " + NormalizedMetaName(struct_def) + "})\n";
132 code += std::string(Indent) + "return o\n";
136 // Initialize a new struct or table from existing data.
137 void NewRootTypeFromBuffer(const StructDef &struct_def,
138 std::string *code_ptr) {
139 std::string &code = *code_ptr;
141 code += "function " + NormalizedName(struct_def) + ".GetRootAs" + NormalizedName(struct_def) + "(buf, offset)\n";
142 code += std::string(Indent) + "local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)\n";
143 code += std::string(Indent) + "local o = " + NormalizedName(struct_def) + ".New()\n";
144 code += std::string(Indent) + "o:Init(buf, n + offset)\n";
145 code += std::string(Indent) + "return o\n";
149 // Initialize an existing object with other data, to avoid an allocation.
150 void InitializeExisting(const StructDef &struct_def,
151 std::string *code_ptr) {
152 std::string &code = *code_ptr;
154 GenReceiver(struct_def, code_ptr);
155 code += "Init(buf, pos)\n";
156 code += std::string(Indent) + SelfData + " = flatbuffers.view.New(buf, pos)\n";
160 // Get the length of a vector.
161 void GetVectorLen(const StructDef &struct_def, const FieldDef &field,
162 std::string *code_ptr) {
163 std::string &code = *code_ptr;
165 GenReceiver(struct_def, code_ptr);
166 code += MakeCamel(NormalizedName(field)) + "Length()\n";
167 code += OffsetPrefix(field);
168 code += std::string(Indent) + Indent + "return " + SelfData + ":VectorLen(o)\n";
169 code += std::string(Indent) + End;
170 code += std::string(Indent) + "return 0\n";
174 // Get the value of a struct's scalar.
175 void GetScalarFieldOfStruct(const StructDef &struct_def,
176 const FieldDef &field,
177 std::string *code_ptr) {
178 std::string &code = *code_ptr;
179 std::string getter = GenGetter(field.value.type);
180 GenReceiver(struct_def, code_ptr);
181 code += MakeCamel(NormalizedName(field));
183 code += std::string(Indent) + "return " + getter;
184 code += std::string(SelfDataPos) + " + " + NumToString(field.value.offset) + ")\n";
188 // Get the value of a table's scalar.
189 void GetScalarFieldOfTable(const StructDef &struct_def,
190 const FieldDef &field,
191 std::string *code_ptr) {
192 std::string &code = *code_ptr;
193 std::string getter = GenGetter(field.value.type);
194 GenReceiver(struct_def, code_ptr);
195 code += MakeCamel(NormalizedName(field));
197 code += OffsetPrefix(field);
198 getter += std::string("o + ") + SelfDataPos + ")";
199 auto is_bool = field.value.type.base_type == BASE_TYPE_BOOL;
201 getter = "(" + getter + " ~= 0)";
203 code += std::string(Indent) + Indent + "return " + getter + "\n";
204 code += std::string(Indent) + End;
205 std::string default_value;
207 default_value = field.value.constant == "0" ? "false" : "true";
210 default_value = field.value.constant;
212 code += std::string(Indent) + "return " + default_value + "\n";
216 // Get a struct by initializing an existing struct.
217 // Specific to Struct.
218 void GetStructFieldOfStruct(const StructDef &struct_def,
219 const FieldDef &field,
220 std::string *code_ptr) {
221 std::string &code = *code_ptr;
222 GenReceiver(struct_def, code_ptr);
223 code += MakeCamel(NormalizedName(field));
225 code += std::string(Indent) + "obj:Init(" + SelfDataBytes + ", " + SelfDataPos + " + ";
226 code += NumToString(field.value.offset) + ")\n";
227 code += std::string(Indent) + "return obj\n";
231 // Get a struct by initializing an existing struct.
232 // Specific to Table.
233 void GetStructFieldOfTable(const StructDef &struct_def,
234 const FieldDef &field,
235 std::string *code_ptr) {
236 std::string &code = *code_ptr;
237 GenReceiver(struct_def, code_ptr);
238 code += MakeCamel(NormalizedName(field));
240 code += OffsetPrefix(field);
241 if (field.value.type.struct_def->fixed) {
242 code += std::string(Indent) + Indent + "local x = o + " + SelfDataPos + "\n";
245 code += std::string(Indent) + Indent + "local x = " + SelfData + ":Indirect(o + " + SelfDataPos + ")\n";
247 code += std::string(Indent) + Indent + "local obj = require('" + TypeNameWithNamespace(field) + "').New()\n";
248 code += std::string(Indent) + Indent + "obj:Init(" + SelfDataBytes + ", x)\n";
249 code += std::string(Indent) + Indent + "return obj\n";
250 code += std::string(Indent) + End;
254 // Get the value of a string.
255 void GetStringField(const StructDef &struct_def, const FieldDef &field,
256 std::string *code_ptr) {
257 std::string &code = *code_ptr;
258 GenReceiver(struct_def, code_ptr);
259 code += MakeCamel(NormalizedName(field));
261 code += OffsetPrefix(field);
262 code += std::string(Indent) + Indent + "return " + GenGetter(field.value.type);
263 code += std::string("o + ") + SelfDataPos + ")\n";
264 code += std::string(Indent) + End;
268 // Get the value of a union from an object.
269 void GetUnionField(const StructDef &struct_def, const FieldDef &field,
270 std::string *code_ptr) {
271 std::string &code = *code_ptr;
272 GenReceiver(struct_def, code_ptr);
273 code += MakeCamel(NormalizedName(field)) + "()\n";
274 code += OffsetPrefix(field);
276 // TODO(rw): this works and is not the good way to it:
277 //bool is_native_table = TypeName(field) == "*flatbuffers.Table";
278 //if (is_native_table) {
279 // code += std::string(Indent) + Indent + "from flatbuffers.table import Table\n";
281 // code += std::string(Indent) + Indent +
282 // code += "from ." + TypeName(field) + " import " + TypeName(field) + "\n";
284 code += std::string(Indent) + Indent + "local obj = flatbuffers.view.New(require('flatbuffers.binaryarray').New(0), 0)\n";
285 code += std::string(Indent) + Indent + GenGetter(field.value.type) + "obj, o)\n";
286 code += std::string(Indent) + Indent + "return obj\n";
287 code += std::string(Indent) + End;
291 // Get the value of a vector's struct member.
292 void GetMemberOfVectorOfStruct(const StructDef &struct_def,
293 const FieldDef &field,
294 std::string *code_ptr) {
295 std::string &code = *code_ptr;
296 auto vectortype = field.value.type.VectorType();
298 GenReceiver(struct_def, code_ptr);
299 code += MakeCamel(NormalizedName(field));
301 code += OffsetPrefix(field);
302 code += std::string(Indent) + Indent + "local x = " + SelfData + ":Vector(o)\n";
303 code += std::string(Indent) + Indent + "x = x + ((j-1) * ";
304 code += NumToString(InlineSize(vectortype)) + ")\n";
305 if (!(vectortype.struct_def->fixed)) {
306 code += std::string(Indent) + Indent + "x = " + SelfData + ":Indirect(x)\n";
308 code += std::string(Indent) + Indent + "local obj = require('" + TypeNameWithNamespace(field) + "').New()\n";
309 code += std::string(Indent) + Indent + "obj:Init(" + SelfDataBytes + ", x)\n";
310 code += std::string(Indent) + Indent + "return obj\n";
311 code += std::string(Indent) + End;
315 // Get the value of a vector's non-struct member. Uses a named return
316 // argument to conveniently set the zero value for the result.
317 void GetMemberOfVectorOfNonStruct(const StructDef &struct_def,
318 const FieldDef &field,
319 std::string *code_ptr) {
320 std::string &code = *code_ptr;
321 auto vectortype = field.value.type.VectorType();
323 GenReceiver(struct_def, code_ptr);
324 code += MakeCamel(NormalizedName(field));
326 code += OffsetPrefix(field);
327 code += std::string(Indent) + Indent + "local a = " + SelfData + ":Vector(o)\n";
328 code += std::string(Indent) + Indent;
329 code += "return " + GenGetter(field.value.type);
330 code += "a + ((j-1) * ";
331 code += NumToString(InlineSize(vectortype)) + "))\n";
332 code += std::string(Indent) + End;
333 if (vectortype.base_type == BASE_TYPE_STRING) {
334 code += std::string(Indent) + "return ''\n";
337 code += std::string(Indent) + "return 0\n";
342 // Begin the creator function signature.
343 void BeginBuilderArgs(const StructDef &struct_def,
344 std::string *code_ptr) {
345 std::string &code = *code_ptr;
347 code += "function " + NormalizedName(struct_def) + ".Create" + NormalizedName(struct_def);
351 // Recursively generate arguments for a constructor, to deal with nested
353 void StructBuilderArgs(const StructDef &struct_def,
354 const char *nameprefix, std::string *code_ptr) {
355 for (auto it = struct_def.fields.vec.begin();
356 it != struct_def.fields.vec.end(); ++it) {
358 if (IsStruct(field.value.type)) {
359 // Generate arguments for a struct inside a struct. To ensure names
360 // don't clash, and to make it obvious these arguments are constructing
361 // a nested struct, prefix the name with the field name.
362 StructBuilderArgs(*field.value.type.struct_def,
363 (nameprefix + (NormalizedName(field) + "_")).c_str(), code_ptr);
366 std::string &code = *code_ptr;
367 code += std::string(", ") + nameprefix;
368 code += MakeCamel(NormalizedName(field), false);
373 // End the creator function signature.
374 void EndBuilderArgs(std::string *code_ptr) {
375 std::string &code = *code_ptr;
379 // Recursively generate struct construction statements and instert manual
381 void StructBuilderBody(const StructDef &struct_def,
382 const char *nameprefix, std::string *code_ptr) {
383 std::string &code = *code_ptr;
384 code += std::string(Indent) + "builder:Prep(" + NumToString(struct_def.minalign) + ", ";
385 code += NumToString(struct_def.bytesize) + ")\n";
386 for (auto it = struct_def.fields.vec.rbegin();
387 it != struct_def.fields.vec.rend(); ++it) {
390 code += std::string(Indent) + "builder:Pad(" + NumToString(field.padding) + ")\n";
391 if (IsStruct(field.value.type)) {
392 StructBuilderBody(*field.value.type.struct_def,
393 (nameprefix + (NormalizedName(field) + "_")).c_str(), code_ptr);
396 code += std::string(Indent) + "builder:Prepend" + GenMethod(field) + "(";
397 code += nameprefix + MakeCamel(NormalizedName(field), false) + ")\n";
402 void EndBuilderBody(std::string *code_ptr) {
403 std::string &code = *code_ptr;
404 code += std::string(Indent) + "return builder:Offset()\n";
408 // Get the value of a table's starting offset.
409 void GetStartOfTable(const StructDef &struct_def,
410 std::string *code_ptr) {
411 std::string &code = *code_ptr;
412 code += "function " + NormalizedName(struct_def) + ".Start";
413 code += "(builder) ";
414 code += "builder:StartObject(";
415 code += NumToString(struct_def.fields.vec.size());
419 // Set the value of a table's field.
420 void BuildFieldOfTable(const StructDef &struct_def,
421 const FieldDef &field, const size_t offset,
422 std::string *code_ptr) {
423 std::string &code = *code_ptr;
424 code += "function " + NormalizedName(struct_def) + ".Add" + MakeCamel(NormalizedName(field));
425 code += "(builder, ";
426 code += MakeCamel(NormalizedName(field), false);
428 code += "builder:Prepend";
429 code += GenMethod(field) + "Slot(";
430 code += NumToString(offset) + ", ";
431 // todo: i don't need to cast in Lua, but am I missing something?
432 // if (!IsScalar(field.value.type.base_type) && (!struct_def.fixed)) {
433 // code += "flatbuffers.N.UOffsetTFlags.py_type";
435 // code += MakeCamel(NormalizedName(field), false) + ")";
437 code += MakeCamel(NormalizedName(field), false);
439 code += ", " + field.value.constant;
443 // Set the value of one of the members of a table's vector.
444 void BuildVectorOfTable(const StructDef &struct_def,
445 const FieldDef &field, std::string *code_ptr) {
446 std::string &code = *code_ptr;
447 code += "function " + NormalizedName(struct_def) + ".Start";
448 code += MakeCamel(NormalizedName(field));
449 code += "Vector(builder, numElems) return builder:StartVector(";
450 auto vector_type = field.value.type.VectorType();
451 auto alignment = InlineAlignment(vector_type);
452 auto elem_size = InlineSize(vector_type);
453 code += NumToString(elem_size);
454 code += ", numElems, " + NumToString(alignment);
458 // Get the offset of the end of a table.
459 void GetEndOffsetOnTable(const StructDef &struct_def,
460 std::string *code_ptr) {
461 std::string &code = *code_ptr;
462 code += "function " + NormalizedName(struct_def) + ".End";
463 code += "(builder) ";
464 code += "return builder:EndObject() end\n";
467 // Generate the receiver for function signatures.
468 void GenReceiver(const StructDef &struct_def, std::string *code_ptr) {
469 std::string &code = *code_ptr;
470 code += "function " + NormalizedMetaName(struct_def) + ":";
473 // Generate a struct field, conditioned on its child type(s).
474 void GenStructAccessor(const StructDef &struct_def,
475 const FieldDef &field, std::string *code_ptr) {
476 GenComment(field.doc_comment, code_ptr, &def_comment);
477 if (IsScalar(field.value.type.base_type)) {
478 if (struct_def.fixed) {
479 GetScalarFieldOfStruct(struct_def, field, code_ptr);
482 GetScalarFieldOfTable(struct_def, field, code_ptr);
486 switch (field.value.type.base_type) {
487 case BASE_TYPE_STRUCT:
488 if (struct_def.fixed) {
489 GetStructFieldOfStruct(struct_def, field, code_ptr);
492 GetStructFieldOfTable(struct_def, field, code_ptr);
495 case BASE_TYPE_STRING: GetStringField(struct_def, field, code_ptr); break;
496 case BASE_TYPE_VECTOR: {
497 auto vectortype = field.value.type.VectorType();
498 if (vectortype.base_type == BASE_TYPE_STRUCT) {
499 GetMemberOfVectorOfStruct(struct_def, field, code_ptr);
502 GetMemberOfVectorOfNonStruct(struct_def, field, code_ptr);
506 case BASE_TYPE_UNION: GetUnionField(struct_def, field, code_ptr); break;
507 default: FLATBUFFERS_ASSERT(0);
510 if (field.value.type.base_type == BASE_TYPE_VECTOR) {
511 GetVectorLen(struct_def, field, code_ptr);
515 // Generate table constructors, conditioned on its members' types.
516 void GenTableBuilders(const StructDef &struct_def,
517 std::string *code_ptr) {
518 GetStartOfTable(struct_def, code_ptr);
520 for (auto it = struct_def.fields.vec.begin();
521 it != struct_def.fields.vec.end(); ++it) {
523 if (field.deprecated) continue;
525 auto offset = it - struct_def.fields.vec.begin();
526 BuildFieldOfTable(struct_def, field, offset, code_ptr);
527 if (field.value.type.base_type == BASE_TYPE_VECTOR) {
528 BuildVectorOfTable(struct_def, field, code_ptr);
532 GetEndOffsetOnTable(struct_def, code_ptr);
535 // Generate struct or table methods.
536 void GenStruct(const StructDef &struct_def, std::string *code_ptr) {
537 if (struct_def.generated) return;
539 GenComment(struct_def.doc_comment, code_ptr, &def_comment);
540 BeginClass(struct_def, code_ptr);
542 GenerateNewObjectPrototype(struct_def, code_ptr);
544 if (!struct_def.fixed) {
545 // Generate a special accessor for the table that has been declared as
547 NewRootTypeFromBuffer(struct_def, code_ptr);
550 // Generate the Init method that sets the field in a pre-existing
551 // accessor object. This is to allow object reuse.
552 InitializeExisting(struct_def, code_ptr);
553 for (auto it = struct_def.fields.vec.begin();
554 it != struct_def.fields.vec.end(); ++it) {
556 if (field.deprecated) continue;
558 GenStructAccessor(struct_def, field, code_ptr);
561 if (struct_def.fixed) {
562 // create a struct constructor function
563 GenStructBuilder(struct_def, code_ptr);
566 // Create a set of functions that allow table construction.
567 GenTableBuilders(struct_def, code_ptr);
571 // Generate enum declarations.
572 void GenEnum(const EnumDef &enum_def, std::string *code_ptr) {
573 if (enum_def.generated) return;
575 GenComment(enum_def.doc_comment, code_ptr, &def_comment);
576 BeginEnum(NormalizedName(enum_def), code_ptr);
577 for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end();
580 GenComment(ev.doc_comment, code_ptr, &def_comment, Indent);
581 EnumMember(enum_def, ev, code_ptr);
586 // Returns the function name that is able to read a value of the given type.
587 std::string GenGetter(const Type &type) {
588 switch (type.base_type) {
589 case BASE_TYPE_STRING: return std::string(SelfData) + ":String(";
590 case BASE_TYPE_UNION: return std::string(SelfData) + ":Union(";
591 case BASE_TYPE_VECTOR: return GenGetter(type.VectorType());
593 return std::string(SelfData) + ":Get(flatbuffers.N." +
594 MakeCamel(GenTypeGet(type)) + ", ";
598 // Returns the method name for use with add/put calls.
599 std::string GenMethod(const FieldDef &field) {
600 return IsScalar(field.value.type.base_type)
601 ? MakeCamel(GenTypeBasic(field.value.type))
602 : (IsStruct(field.value.type) ? "Struct" : "UOffsetTRelative");
605 std::string GenTypeBasic(const Type &type) {
606 static const char *ctypename[] = {
608 #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
609 CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE) \
611 FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
612 #undef FLATBUFFERS_TD
615 return ctypename[type.base_type];
618 std::string GenTypePointer(const Type &type) {
619 switch (type.base_type) {
620 case BASE_TYPE_STRING: return "string";
621 case BASE_TYPE_VECTOR: return GenTypeGet(type.VectorType());
622 case BASE_TYPE_STRUCT: return type.struct_def->name;
623 case BASE_TYPE_UNION:
625 default: return "*flatbuffers.Table";
629 std::string GenTypeGet(const Type &type) {
630 return IsScalar(type.base_type) ? GenTypeBasic(type) : GenTypePointer(type);
633 std::string GetNamespace(const Type &type) {
634 return type.struct_def->defined_namespace->GetFullyQualifiedName(type.struct_def->name);
637 std::string TypeName(const FieldDef &field) {
638 return GenTypeGet(field.value.type);
641 std::string TypeNameWithNamespace(const FieldDef &field) {
642 return GetNamespace(field.value.type);
645 // Create a struct with a builder and the struct's arguments.
646 void GenStructBuilder(const StructDef &struct_def,
647 std::string *code_ptr) {
648 BeginBuilderArgs(struct_def, code_ptr);
649 StructBuilderArgs(struct_def, "", code_ptr);
650 EndBuilderArgs(code_ptr);
652 StructBuilderBody(struct_def, "", code_ptr);
653 EndBuilderBody(code_ptr);
657 if (!generateEnums()) return false;
658 if (!generateStructs()) return false;
663 bool generateEnums() {
664 for (auto it = parser_.enums_.vec.begin(); it != parser_.enums_.vec.end();
666 auto &enum_def = **it;
667 std::string enumcode;
668 GenEnum(enum_def, &enumcode);
669 if (!SaveType(enum_def, enumcode, false)) return false;
674 bool generateStructs() {
675 for (auto it = parser_.structs_.vec.begin();
676 it != parser_.structs_.vec.end(); ++it) {
677 auto &struct_def = **it;
678 std::string declcode;
679 GenStruct(struct_def, &declcode);
680 if (!SaveType(struct_def, declcode, true)) return false;
685 // Begin by declaring namespace and imports.
686 void BeginFile(const std::string &name_space_name, const bool needs_imports,
687 std::string *code_ptr) {
688 std::string &code = *code_ptr;
689 code += std::string(Comment) + FlatBuffersGeneratedWarning() + "\n\n";
690 code += std::string(Comment) + "namespace: " + name_space_name + "\n\n";
692 code += "local flatbuffers = require('flatbuffers')\n\n";
696 // Save out the generated code for a Lua Table type.
697 bool SaveType(const Definition &def, const std::string &classcode,
698 bool needs_imports) {
699 if (!classcode.length()) return true;
701 std::string namespace_dir = path_;
702 auto &namespaces = def.defined_namespace->components;
703 for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
704 if (it != namespaces.begin()) namespace_dir += kPathSeparator;
705 namespace_dir += *it;
706 //std::string init_py_filename = namespace_dir + "/__init__.py";
707 //SaveFile(init_py_filename.c_str(), "", false);
710 std::string code = "";
711 BeginFile(LastNamespacePart(*def.defined_namespace), needs_imports, &code);
714 code += "return " + NormalizedName(def) + " " + Comment + "return the module";
715 std::string filename =
716 NamespaceDir(*def.defined_namespace) + NormalizedName(def) + ".lua";
717 return SaveFile(filename.c_str(), code, false);
720 std::unordered_set<std::string> keywords_;
725 bool GenerateLua(const Parser &parser, const std::string &path,
726 const std::string &file_name) {
727 lua::LuaGenerator generator(parser, path, file_name);
728 return generator.generate();
731 } // namespace flatbuffers