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;
@@ -1285,16 +1285,14 @@ impl RawLua {
12851285
12861286// Uses 3 stack spaces
12871287unsafe fn load_std_libs ( state : * mut ffi:: lua_State , libs : StdLib ) -> Result < ( ) > {
1288- #[ inline( always) ]
1289- pub unsafe fn requiref (
1288+ unsafe fn requiref (
12901289 state : * mut ffi:: lua_State ,
1291- modname : & str ,
1290+ modname : * const c_char ,
12921291 openf : ffi:: lua_CFunction ,
12931292 glb : c_int ,
12941293 ) -> Result < ( ) > {
1295- let modname = mlua_expect ! ( CString :: new( modname) , "modname contains nil byte" ) ;
1296- protect_lua ! ( state, 0 , 1 , |state| {
1297- ffi:: luaL_requiref( state, modname. as_ptr( ) as * const c_char, openf, glb)
1294+ protect_lua ! ( state, 0 , 0 , |state| {
1295+ ffi:: luaL_requiref( state, modname, openf, glb)
12981296 } )
12991297 }
13001298
@@ -1325,81 +1323,68 @@ unsafe fn load_std_libs(state: *mut ffi::lua_State, libs: StdLib) -> Result<()>
13251323 {
13261324 if libs. contains ( StdLib :: COROUTINE ) {
13271325 requiref ( state, ffi:: LUA_COLIBNAME , ffi:: luaopen_coroutine, 1 ) ?;
1328- ffi:: lua_pop ( state, 1 ) ;
13291326 }
13301327 }
13311328
13321329 if libs. contains ( StdLib :: TABLE ) {
13331330 requiref ( state, ffi:: LUA_TABLIBNAME , ffi:: luaopen_table, 1 ) ?;
1334- ffi:: lua_pop ( state, 1 ) ;
13351331 }
13361332
13371333 #[ cfg( not( feature = "luau" ) ) ]
13381334 if libs. contains ( StdLib :: IO ) {
13391335 requiref ( state, ffi:: LUA_IOLIBNAME , ffi:: luaopen_io, 1 ) ?;
1340- ffi:: lua_pop ( state, 1 ) ;
13411336 }
13421337
13431338 if libs. contains ( StdLib :: OS ) {
13441339 requiref ( state, ffi:: LUA_OSLIBNAME , ffi:: luaopen_os, 1 ) ?;
1345- ffi:: lua_pop ( state, 1 ) ;
13461340 }
13471341
13481342 if libs. contains ( StdLib :: STRING ) {
13491343 requiref ( state, ffi:: LUA_STRLIBNAME , ffi:: luaopen_string, 1 ) ?;
1350- ffi:: lua_pop ( state, 1 ) ;
13511344 }
13521345
13531346 #[ cfg( any( feature = "lua54" , feature = "lua53" , feature = "luau" ) ) ]
13541347 {
13551348 if libs. contains ( StdLib :: UTF8 ) {
13561349 requiref ( state, ffi:: LUA_UTF8LIBNAME , ffi:: luaopen_utf8, 1 ) ?;
1357- ffi:: lua_pop ( state, 1 ) ;
13581350 }
13591351 }
13601352
13611353 #[ cfg( any( feature = "lua52" , feature = "luau" ) ) ]
13621354 {
13631355 if libs. contains ( StdLib :: BIT ) {
13641356 requiref ( state, ffi:: LUA_BITLIBNAME , ffi:: luaopen_bit32, 1 ) ?;
1365- ffi:: lua_pop ( state, 1 ) ;
13661357 }
13671358 }
13681359
13691360 #[ cfg( feature = "luajit" ) ]
13701361 {
13711362 if libs. contains ( StdLib :: BIT ) {
13721363 requiref ( state, ffi:: LUA_BITLIBNAME , ffi:: luaopen_bit, 1 ) ?;
1373- ffi:: lua_pop ( state, 1 ) ;
13741364 }
13751365 }
13761366
13771367 #[ cfg( feature = "luau" ) ]
13781368 if libs. contains ( StdLib :: BUFFER ) {
13791369 requiref ( state, ffi:: LUA_BUFFERLIBNAME , ffi:: luaopen_buffer, 1 ) ?;
1380- ffi:: lua_pop ( state, 1 ) ;
13811370 }
13821371
13831372 #[ cfg( feature = "luau" ) ]
13841373 if libs. contains ( StdLib :: VECTOR ) {
13851374 requiref ( state, ffi:: LUA_VECLIBNAME , ffi:: luaopen_vector, 1 ) ?;
1386- ffi:: lua_pop ( state, 1 ) ;
13871375 }
13881376
13891377 if libs. contains ( StdLib :: MATH ) {
13901378 requiref ( state, ffi:: LUA_MATHLIBNAME , ffi:: luaopen_math, 1 ) ?;
1391- ffi:: lua_pop ( state, 1 ) ;
13921379 }
13931380
13941381 if libs. contains ( StdLib :: DEBUG ) {
13951382 requiref ( state, ffi:: LUA_DBLIBNAME , ffi:: luaopen_debug, 1 ) ?;
1396- ffi:: lua_pop ( state, 1 ) ;
13971383 }
13981384
13991385 #[ cfg( not( feature = "luau" ) ) ]
14001386 if libs. contains ( StdLib :: PACKAGE ) {
14011387 requiref ( state, ffi:: LUA_LOADLIBNAME , ffi:: luaopen_package, 1 ) ?;
1402- ffi:: lua_pop ( state, 1 ) ;
14031388 }
14041389 #[ cfg( feature = "luau" ) ]
14051390 if libs. contains ( StdLib :: PACKAGE ) {
@@ -1410,13 +1395,11 @@ unsafe fn load_std_libs(state: *mut ffi::lua_State, libs: StdLib) -> Result<()>
14101395 #[ cfg( feature = "luajit" ) ]
14111396 if libs. contains ( StdLib :: JIT ) {
14121397 requiref ( state, ffi:: LUA_JITLIBNAME , ffi:: luaopen_jit, 1 ) ?;
1413- ffi:: lua_pop ( state, 1 ) ;
14141398 }
14151399
14161400 #[ cfg( feature = "luajit" ) ]
14171401 if libs. contains ( StdLib :: FFI ) {
14181402 requiref ( state, ffi:: LUA_FFILIBNAME , ffi:: luaopen_ffi, 1 ) ?;
1419- ffi:: lua_pop ( state, 1 ) ;
14201403 }
14211404
14221405 Ok ( ( ) )
0 commit comments