File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -409,11 +409,17 @@ unsafe fn init_userdata_metatable_index(state: *mut ffi::lua_State) -> Result<()
409
409
}
410
410
ffi:: lua_pop ( state, 1 ) ;
411
411
412
- // Create and cache `__index` helper
412
+ // Create and cache `__index` generator
413
413
let code = cstr ! (
414
414
r#"
415
415
local error, isfunction = ...
416
416
return function (__index, field_getters, methods)
417
+ -- Fastpath to return methods table for index access
418
+ if __index == nil and field_getters == nil then
419
+ return methods
420
+ end
421
+
422
+ -- Alternatively return a function for index access
417
423
return function (self, key)
418
424
if field_getters ~= nil then
419
425
local field_getter = field_getters[key]
@@ -463,7 +469,7 @@ pub unsafe fn init_userdata_metatable_newindex(state: *mut ffi::lua_State) -> Re
463
469
}
464
470
ffi:: lua_pop ( state, 1 ) ;
465
471
466
- // Create and cache `__newindex` helper
472
+ // Create and cache `__newindex` generator
467
473
let code = cstr ! (
468
474
r#"
469
475
local error, isfunction = ...
You can’t perform that action at this time.
0 commit comments