@@ -545,24 +545,6 @@ impl Value {
545545 ident : usize ,
546546 visited : & mut HashSet < * const c_void > ,
547547 ) -> fmt:: Result {
548- unsafe fn invoke_tostring_dbg ( vref : & ValueRef ) -> Result < Option < String > > {
549- let lua = vref. lua . lock ( ) ;
550- let state = lua. state ( ) ;
551- let _guard = StackGuard :: new ( state) ;
552- check_stack ( state, 3 ) ?;
553-
554- lua. push_ref ( vref) ;
555- protect_lua ! ( state, 1 , 1 , fn ( state) {
556- // Try `__todebugstring` metamethod first, then `__tostring`
557- if ffi:: luaL_callmeta( state, -1 , cstr!( "__todebugstring" ) ) == 0 {
558- if ffi:: luaL_callmeta( state, -1 , cstr!( "__tostring" ) ) == 0 {
559- ffi:: lua_pushnil( state) ;
560- }
561- }
562- } ) ?;
563- Ok ( lua. pop_value ( ) . as_string ( ) . map ( |s| s. to_string_lossy ( ) ) )
564- }
565-
566548 match self {
567549 Value :: Nil => write ! ( fmt, "nil" ) ,
568550 Value :: Boolean ( b) => write ! ( fmt, "{b}" ) ,
@@ -579,17 +561,7 @@ impl Value {
579561 t @ Value :: Table ( _) => write ! ( fmt, "table: {:?}" , t. to_pointer( ) ) ,
580562 f @ Value :: Function ( _) => write ! ( fmt, "function: {:?}" , f. to_pointer( ) ) ,
581563 t @ Value :: Thread ( _) => write ! ( fmt, "thread: {:?}" , t. to_pointer( ) ) ,
582- u @ Value :: UserData ( ud) => unsafe {
583- // Try converting to a (debug) string first, with fallback to `__name/__type`
584- match invoke_tostring_dbg ( & ud. 0 ) {
585- Ok ( Some ( s) ) => write ! ( fmt, "{s}" ) ,
586- _ => {
587- let name = ud. type_name ( ) . ok ( ) . flatten ( ) ;
588- let name = name. as_deref ( ) . unwrap_or ( "userdata" ) ;
589- write ! ( fmt, "{name}: {:?}" , u. to_pointer( ) )
590- }
591- }
592- } ,
564+ Value :: UserData ( ud) => ud. fmt_pretty ( fmt) ,
593565 #[ cfg( feature = "luau" ) ]
594566 buf @ Value :: Buffer ( _) => write ! ( fmt, "buffer: {:?}" , buf. to_pointer( ) ) ,
595567 Value :: Error ( e) if recursive => write ! ( fmt, "{e:?}" ) ,
0 commit comments