@@ -8,8 +8,8 @@ use std::sync::Arc;
88use std:: { error, f32, f64, fmt} ;
99
1010use mlua:: {
11- ChunkMode , Error , ExternalError , Function , Lua , LuaOptions , Nil , Result , StdLib , String , Table , UserData ,
12- Value , Variadic ,
11+ ffi , ChunkMode , Error , ExternalError , Function , Lua , LuaOptions , Nil , Result , StdLib , String , Table ,
12+ UserData , Value , Variadic ,
1313} ;
1414
1515#[ cfg( not( feature = "luau" ) ) ]
@@ -1425,3 +1425,23 @@ fn test_gc_drop_ref_thread() -> Result<()> {
14251425
14261426 Ok ( ( ) )
14271427}
1428+
1429+ #[ cfg( not( feature = "luau" ) ) ]
1430+ #[ test]
1431+ fn test_get_or_init_from_ptr ( ) -> Result < ( ) > {
1432+ // This would not work with Luau, the state must be init by mlua internally
1433+ let state = unsafe { ffi:: luaL_newstate ( ) } ;
1434+
1435+ let mut lua = unsafe { Lua :: get_or_init_from_ptr ( state) } ;
1436+ lua. globals ( ) . set ( "hello" , "world678" ) ?;
1437+
1438+ // The same Lua instance must be returned
1439+ lua = unsafe { Lua :: get_or_init_from_ptr ( state) } ;
1440+ assert_eq ! ( lua. globals( ) . get:: <String >( "hello" ) ?, "world678" ) ;
1441+
1442+ unsafe { ffi:: lua_close ( state) } ;
1443+
1444+ // Lua must not be accessed after closing
1445+
1446+ Ok ( ( ) )
1447+ }
0 commit comments