11use std:: any:: TypeId ;
22use std:: cell:: { Cell , UnsafeCell } ;
3- use std:: ffi:: { CStr , CString } ;
3+ use std:: ffi:: CStr ;
44use std:: mem;
55use std:: os:: raw:: { c_char, c_int, c_void} ;
66use std:: panic:: resume_unwind;
@@ -1351,16 +1351,14 @@ impl RawLua {
13511351
13521352// Uses 3 stack spaces
13531353unsafe fn load_std_libs ( state : * mut ffi:: lua_State , libs : StdLib ) -> Result < ( ) > {
1354- #[ inline( always) ]
1355- pub unsafe fn requiref (
1354+ unsafe fn requiref (
13561355 state : * mut ffi:: lua_State ,
1357- modname : & str ,
1356+ modname : * const c_char ,
13581357 openf : ffi:: lua_CFunction ,
13591358 glb : c_int ,
13601359 ) -> Result < ( ) > {
1361- let modname = mlua_expect ! ( CString :: new( modname) , "modname contains nil byte" ) ;
1362- protect_lua ! ( state, 0 , 1 , |state| {
1363- ffi:: luaL_requiref( state, modname. as_ptr( ) as * const c_char, openf, glb)
1360+ protect_lua ! ( state, 0 , 0 , |state| {
1361+ ffi:: luaL_requiref( state, modname, openf, glb)
13641362 } )
13651363 }
13661364
@@ -1391,81 +1389,68 @@ unsafe fn load_std_libs(state: *mut ffi::lua_State, libs: StdLib) -> Result<()>
13911389 {
13921390 if libs. contains ( StdLib :: COROUTINE ) {
13931391 requiref ( state, ffi:: LUA_COLIBNAME , ffi:: luaopen_coroutine, 1 ) ?;
1394- ffi:: lua_pop ( state, 1 ) ;
13951392 }
13961393 }
13971394
13981395 if libs. contains ( StdLib :: TABLE ) {
13991396 requiref ( state, ffi:: LUA_TABLIBNAME , ffi:: luaopen_table, 1 ) ?;
1400- ffi:: lua_pop ( state, 1 ) ;
14011397 }
14021398
14031399 #[ cfg( not( feature = "luau" ) ) ]
14041400 if libs. contains ( StdLib :: IO ) {
14051401 requiref ( state, ffi:: LUA_IOLIBNAME , ffi:: luaopen_io, 1 ) ?;
1406- ffi:: lua_pop ( state, 1 ) ;
14071402 }
14081403
14091404 if libs. contains ( StdLib :: OS ) {
14101405 requiref ( state, ffi:: LUA_OSLIBNAME , ffi:: luaopen_os, 1 ) ?;
1411- ffi:: lua_pop ( state, 1 ) ;
14121406 }
14131407
14141408 if libs. contains ( StdLib :: STRING ) {
14151409 requiref ( state, ffi:: LUA_STRLIBNAME , ffi:: luaopen_string, 1 ) ?;
1416- ffi:: lua_pop ( state, 1 ) ;
14171410 }
14181411
14191412 #[ cfg( any( feature = "lua54" , feature = "lua53" , feature = "luau" ) ) ]
14201413 {
14211414 if libs. contains ( StdLib :: UTF8 ) {
14221415 requiref ( state, ffi:: LUA_UTF8LIBNAME , ffi:: luaopen_utf8, 1 ) ?;
1423- ffi:: lua_pop ( state, 1 ) ;
14241416 }
14251417 }
14261418
14271419 #[ cfg( any( feature = "lua52" , feature = "luau" ) ) ]
14281420 {
14291421 if libs. contains ( StdLib :: BIT ) {
14301422 requiref ( state, ffi:: LUA_BITLIBNAME , ffi:: luaopen_bit32, 1 ) ?;
1431- ffi:: lua_pop ( state, 1 ) ;
14321423 }
14331424 }
14341425
14351426 #[ cfg( feature = "luajit" ) ]
14361427 {
14371428 if libs. contains ( StdLib :: BIT ) {
14381429 requiref ( state, ffi:: LUA_BITLIBNAME , ffi:: luaopen_bit, 1 ) ?;
1439- ffi:: lua_pop ( state, 1 ) ;
14401430 }
14411431 }
14421432
14431433 #[ cfg( feature = "luau" ) ]
14441434 if libs. contains ( StdLib :: BUFFER ) {
14451435 requiref ( state, ffi:: LUA_BUFFERLIBNAME , ffi:: luaopen_buffer, 1 ) ?;
1446- ffi:: lua_pop ( state, 1 ) ;
14471436 }
14481437
14491438 #[ cfg( feature = "luau" ) ]
14501439 if libs. contains ( StdLib :: VECTOR ) {
14511440 requiref ( state, ffi:: LUA_VECLIBNAME , ffi:: luaopen_vector, 1 ) ?;
1452- ffi:: lua_pop ( state, 1 ) ;
14531441 }
14541442
14551443 if libs. contains ( StdLib :: MATH ) {
14561444 requiref ( state, ffi:: LUA_MATHLIBNAME , ffi:: luaopen_math, 1 ) ?;
1457- ffi:: lua_pop ( state, 1 ) ;
14581445 }
14591446
14601447 if libs. contains ( StdLib :: DEBUG ) {
14611448 requiref ( state, ffi:: LUA_DBLIBNAME , ffi:: luaopen_debug, 1 ) ?;
1462- ffi:: lua_pop ( state, 1 ) ;
14631449 }
14641450
14651451 #[ cfg( not( feature = "luau" ) ) ]
14661452 if libs. contains ( StdLib :: PACKAGE ) {
14671453 requiref ( state, ffi:: LUA_LOADLIBNAME , ffi:: luaopen_package, 1 ) ?;
1468- ffi:: lua_pop ( state, 1 ) ;
14691454 }
14701455 #[ cfg( feature = "luau" ) ]
14711456 if libs. contains ( StdLib :: PACKAGE ) {
@@ -1476,13 +1461,11 @@ unsafe fn load_std_libs(state: *mut ffi::lua_State, libs: StdLib) -> Result<()>
14761461 #[ cfg( feature = "luajit" ) ]
14771462 if libs. contains ( StdLib :: JIT ) {
14781463 requiref ( state, ffi:: LUA_JITLIBNAME , ffi:: luaopen_jit, 1 ) ?;
1479- ffi:: lua_pop ( state, 1 ) ;
14801464 }
14811465
14821466 #[ cfg( feature = "luajit" ) ]
14831467 if libs. contains ( StdLib :: FFI ) {
14841468 requiref ( state, ffi:: LUA_FFILIBNAME , ffi:: luaopen_ffi, 1 ) ?;
1485- ffi:: lua_pop ( state, 1 ) ;
14861469 }
14871470
14881471 Ok ( ( ) )
0 commit comments