File tree 1 file changed +21
-9
lines changed
1 file changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -229,23 +229,35 @@ end
229
229
230
230
local function remove_functions (x )
231
231
local tp = type (x )
232
- if tp == " table" then
232
+ if tp == " function" then
233
+ return nil
234
+ end
235
+
236
+ -- Make sure to not serialize the same table multiple times, otherwise
237
+ -- writing mem.test = mem in the LuaController will lead to infinite recursion
238
+ local seen = {}
239
+
240
+ local function rfuncs (x )
241
+ if seen [x ] then return end
242
+ seen [x ] = true
243
+ if type (x ) ~= " table" then return end
244
+
233
245
for key , value in pairs (x ) do
234
- local key_t , val_t = type (key ), type (value )
235
- if key_t == " function" or val_t == " function" then
246
+ if type (key ) == " function" or type (value ) == " function" then
236
247
x [key ] = nil
237
248
else
238
- if key_t == " table" then
239
- remove_functions (key )
249
+ if type ( key ) == " table" then
250
+ rfuncs (key )
240
251
end
241
- if val_t == " table" then
242
- remove_functions (value )
252
+ if type ( value ) == " table" then
253
+ rfuncs (value )
243
254
end
244
255
end
245
256
end
246
- elseif tp == " function" then
247
- return nil
248
257
end
258
+
259
+ rfuncs (x )
260
+
249
261
return x
250
262
end
251
263
You can’t perform that action at this time.
0 commit comments