@@ -567,10 +567,20 @@ pub(super) fn create_require_function<R: Require + MaybeSend + 'static>(
567567 1
568568 }
569569
570- let ( error, r#type) = unsafe {
571- lua. exec_raw :: < ( Function , Function ) > ( ( ) , move |state| {
570+ unsafe extern "C-unwind" fn to_lowercase ( state : * mut ffi:: lua_State ) -> c_int {
571+ let s = ffi:: luaL_checkstring ( state, 1 ) ;
572+ let s = CStr :: from_ptr ( s) ;
573+ callback_error_ext ( state, ptr:: null_mut ( ) , true , |extra, _| {
574+ let s = s. to_string_lossy ( ) . to_lowercase ( ) ;
575+ ( * extra) . raw_lua ( ) . push ( s) . map ( |_| 1 )
576+ } )
577+ }
578+
579+ let ( error, r#type, to_lowercase) = unsafe {
580+ lua. exec_raw :: < ( Function , Function , Function ) > ( ( ) , move |state| {
572581 ffi:: lua_pushcfunctiond ( state, error, cstr ! ( "error" ) ) ;
573582 ffi:: lua_pushcfunctiond ( state, r#type, cstr ! ( "type" ) ) ;
583+ ffi:: lua_pushcfunctiond ( state, to_lowercase, cstr ! ( "to_lowercase" ) ) ;
574584 } )
575585 } ?;
576586
@@ -583,6 +593,7 @@ pub(super) fn create_require_function<R: Require + MaybeSend + 'static>(
583593 env. raw_set ( "LOADER_CACHE" , loader_cache) ?;
584594 env. raw_set ( "error" , error) ?;
585595 env. raw_set ( "type" , r#type) ?;
596+ env. raw_set ( "to_lowercase" , to_lowercase) ?;
586597
587598 lua. load (
588599 r#"
@@ -592,7 +603,7 @@ pub(super) fn create_require_function<R: Require + MaybeSend + 'static>(
592603 end
593604
594605 -- Check if the module (path) is explicitly registered
595- local maybe_result = REGISTERED_MODULES[path]
606+ local maybe_result = REGISTERED_MODULES[to_lowercase( path) ]
596607 if maybe_result ~= nil then
597608 return maybe_result
598609 end
0 commit comments