@@ -81,17 +81,7 @@ def gen_mod_decl(self, decl):
81
81
82
82
self .cur_block = LuaBlock ()
83
83
self .gen_decls (decl .decls )
84
-
85
- module_fields = []
86
- for sym in decl .sym .scope .syms :
87
- if sym .access_modifier .is_public ():
88
- module_fields .append (
89
- LuaTableField (LuaIdent (sym .name ), LuaIdent (sym .name ))
90
- )
91
- self .cur_block .add_stmt (
92
- LuaAssignment ([LuaIdent (decl .name )], [LuaTable (module_fields )],
93
- False )
94
- )
84
+ self .export_public_symbols (decl .sym )
95
85
96
86
mod_decls = self .cur_block
97
87
self .cur_block = old_block
@@ -113,26 +103,30 @@ def gen_const_decl(self, decl):
113
103
self .cur_block .add_stmt (lua_assign )
114
104
115
105
def gen_enum_decl (self , decl ):
116
- fields = []
106
+ self .cur_block .add_stmt (LuaAssignment ([LuaIdent (decl .sym .name )], []))
107
+ old_block = self .cur_block
108
+ self .cur_block = LuaBlock ()
117
109
for i , f in enumerate (decl .fields ):
118
- fields . append ( LuaTableField ( LuaIdent ( f . name ), LuaNumberLit ( str ( i ))))
119
- self . cur_block . add_stmt (
120
- LuaAssignment ([ LuaIdent ( decl . sym . name )], [ LuaTable ( fields )], False )
121
- )
110
+ self . cur_block . add_stmt (
111
+ LuaAssignment ([ LuaSelector ( LuaIdent ( decl . name ), f . name )],
112
+ [ LuaNumberLit ( str ( i ) )], False )
113
+ )
122
114
self .switch_cur_sym (decl .sym )
123
115
self .gen_decls (decl .decls )
116
+ self .export_public_symbols (decl .sym )
124
117
self .switch_cur_sym ()
118
+ old_block .add_stmt (self .cur_block )
119
+ self .cur_block = old_block
125
120
126
121
def gen_fn_decl (self , decl ):
127
122
if not decl .has_body : return
128
123
old_block = self .cur_block
129
124
args = []
125
+ if decl .is_method :
126
+ args .append (LuaIdent ("self" ))
130
127
for arg in decl .args :
131
128
args .append (LuaIdent (arg .name ))
132
- luafn = LuaFunction (
133
- decl .sym .cg_method_qualname (), args ,
134
- is_static = decl .sym .is_static ()
135
- )
129
+ luafn = LuaFunction (args , is_static = decl .sym .is_static ())
136
130
for arg in decl .args :
137
131
if arg .default_value != None :
138
132
left = LuaIdent (arg .name )
@@ -148,7 +142,9 @@ def gen_fn_decl(self, decl):
148
142
self .gen_stmts (decl .stmts )
149
143
self .cur_fn = None
150
144
self .cur_block = old_block
151
- self .cur_block .add_stmt (luafn )
145
+ self .cur_block .add_stmt (
146
+ LuaAssignment ([LuaIdent (decl .sym .name )], [luafn ])
147
+ )
152
148
153
149
## == Statements ============================================
154
150
@@ -269,3 +265,15 @@ def gen_expr(self, expr):
269
265
ret_expr = self .gen_expr (expr .expr )
270
266
self .cur_block .add_stmt (LuaReturn (ret_expr ))
271
267
return LuaSkip ()
268
+
269
+ def export_public_symbols (self , decl_sym ):
270
+ exported_fields = []
271
+ for sym in decl_sym .scope .syms :
272
+ if sym .access_modifier .is_public ():
273
+ exported_fields .append (
274
+ LuaTableField (LuaIdent (sym .name ), LuaIdent (sym .name ))
275
+ )
276
+ self .cur_block .add_stmt (
277
+ LuaAssignment ([LuaIdent (decl_sym .name )],
278
+ [LuaTable (exported_fields )], False )
279
+ )
0 commit comments