@@ -1028,27 +1028,16 @@ impl RawLua {
1028
1028
1029
1029
// Creates a Function out of a Callback containing a 'static Fn.
1030
1030
pub ( crate ) fn create_callback ( & self , func : Callback ) -> Result < Function > {
1031
+ // This is non-scoped version of the callback (upvalue is always valid)
1032
+ // TODO: add a scoped version
1031
1033
unsafe extern "C-unwind" fn call_callback ( state : * mut ffi:: lua_State ) -> c_int {
1032
- // Normal functions can be scoped and therefore destroyed,
1033
- // so we need to check that the first upvalue is valid
1034
- let ( upvalue, extra) = match ffi:: lua_type ( state, ffi:: lua_upvalueindex ( 1 ) ) {
1035
- ffi:: LUA_TUSERDATA => {
1036
- let upvalue = get_userdata :: < CallbackUpvalue > ( state, ffi:: lua_upvalueindex ( 1 ) ) ;
1037
- ( upvalue, ( * upvalue) . extra . get ( ) )
1038
- }
1039
- _ => ( ptr:: null_mut ( ) , ptr:: null_mut ( ) ) ,
1040
- } ;
1041
- callback_error_ext ( state, extra, |extra, nargs| {
1034
+ let upvalue = get_userdata :: < CallbackUpvalue > ( state, ffi:: lua_upvalueindex ( 1 ) ) ;
1035
+ callback_error_ext ( state, ( * upvalue) . extra . get ( ) , |extra, nargs| {
1042
1036
// Lua ensures that `LUA_MINSTACK` stack spaces are available (after pushing arguments)
1043
- if upvalue. is_null ( ) {
1044
- return Err ( Error :: CallbackDestructed ) ;
1045
- }
1046
-
1047
1037
// The lock must be already held as the callback is executed
1048
1038
let rawlua = ( * extra) . raw_lua ( ) ;
1049
1039
let _guard = StateGuard :: new ( rawlua, state) ;
1050
1040
let func = & * ( * upvalue) . data ;
1051
-
1052
1041
func ( rawlua, nargs)
1053
1042
} )
1054
1043
}
0 commit comments