@@ -34,7 +34,7 @@ macro_rules! wrap {
3434 // todo: potentially add a silenterror type so we can return that and it'll return a nil.
3535 // right now this would kind of leak the fact that it's an autorun function.
3636 lua. push( state, c"" ) ;
37- lua. error( state) ;
37+ lua. raw . error( state) ;
3838 } else {
3939 $func( lua, state, env)
4040 }
@@ -44,7 +44,7 @@ macro_rules! wrap {
4444
4545impl EnvHandle {
4646 pub fn push ( & self , lua : & LuaApi , state : * mut LuaState ) {
47- self . env . push ( lua , state ) ;
47+ lua . push ( state , & self . env ) ;
4848 }
4949
5050 pub fn realm ( & self ) -> Realm {
@@ -57,25 +57,25 @@ impl EnvHandle {
5757 let lj_state = state as * mut LJState ;
5858 let lj_state = unsafe { lj_state. as_ref ( ) . context ( "Failed to dereference LJState" ) ? } ;
5959
60- lua. get_fenv ( state, func_index) ;
60+ lua. raw . getfenv ( state, func_index) ;
6161 let function_env_tvalue = index2adr ( lj_state, -1 ) . context ( "Failed to get TValue for function environment" ) ?;
6262 let function_env_gcr = unsafe { ( * function_env_tvalue) . gcr } ;
6363
64- lua. pop ( state, 1 ) ;
64+ lua. raw . pop ( state, 1 ) ;
6565 Ok ( function_env_gcr == self . env_gcr )
6666 }
6767
6868 pub fn is_active ( & self , lua : & LuaApi , state : * mut LuaState ) -> bool {
69- if lua. get_info ( state, 1 , c"f" ) . is_none ( ) {
69+ if lua. raw . getinfo ( state, 1 , c"f" ) . is_none ( ) {
7070 // No function info available
7171 return false ;
7272 }
7373
74- lua. get_fenv ( state, -1 ) ;
74+ lua. raw . getfenv ( state, -1 ) ;
7575 self . push ( lua, state) ;
7676
77- let equal = lua. is_raw_equal ( state, -1 , -2 ) ;
78- lua. pop ( state, 3 ) ;
77+ let equal = lua. raw . rawequal ( state, -1 , -2 ) ;
78+ lua. raw . pop ( state, 3 ) ;
7979
8080 equal
8181 }
@@ -117,16 +117,11 @@ impl EnvHandle {
117117
118118 pub fn execute ( & self , lua : & LuaApi , state : * mut LuaState , name : & CStr , src : & [ u8 ] ) -> anyhow:: Result < ( ) > {
119119 let name = self . format_chunk_name ( name) ?;
120- if let Err ( why) = lua. load_buffer_x ( state, src, & name, c"t" ) {
121- anyhow:: bail!( "Failed to compile: {why}" ) ;
122- }
123-
124- self . push ( lua, state) ;
125- if lua. set_fenv ( state, -2 ) . is_err ( ) {
126- anyhow:: bail!( "Failed to set environment" ) ;
127- }
120+ let chunk = lua. load ( state, src, & name) ?;
121+ lua. setfenv ( state, & chunk, & self . env ) ?;
128122
129- if let Err ( why) = lua. pcall ( state, 0 , 0 , 0 ) {
123+ lua. push ( state, & chunk) ;
124+ if let Err ( why) = lua. raw . pcall ( state, 0 , 0 , 0 ) {
130125 anyhow:: bail!( "Failed to execute: {}" , why) ;
131126 }
132127
@@ -141,7 +136,7 @@ impl EnvHandle {
141136 lua. set ( state, & env, "_G" , Globals ) ;
142137
143138 // todo: refactor luajit code to not depend on the stack
144- env . push ( lua , state ) ;
139+ lua . push ( state , & env ) ;
145140
146141 // Can unwrap since we are sure there is something on the stack
147142 let lj_state = state as * mut LJState ;
@@ -150,7 +145,7 @@ impl EnvHandle {
150145 let env_gcr = unsafe { ( * env_tvalue) . gcr } ;
151146
152147 // todo: refactor luajit code to not depend on the stack
153- lua. pop ( state, 1 ) ;
148+ lua. raw . pop ( state, 1 ) ;
154149
155150 let chunk_nonce = rand:: random :: < u64 > ( ) ;
156151 Ok ( Self {
@@ -181,19 +176,19 @@ impl EnvHandle {
181176
182177 pub fn trigger ( & self , lua : & LuaApi , state : * mut LuaState , event_name : & CStr , n_args : c_int ) -> anyhow:: Result < ( ) > {
183178 lua. push ( state, event_name) ;
184- lua. insert ( state, -( n_args + 1 ) ) ;
179+ lua. raw . insert ( state, -( n_args + 1 ) ) ;
185180
186- self . autorun . push ( lua , state ) ;
187- lua. get_field ( state, -1 , c"trigger" . as_ptr ( ) ) ;
188- lua. remove ( state, -2 ) ; // remove Autorun table
181+ lua . push ( state , & self . autorun ) ;
182+ lua. raw . getfield ( state, -1 , c"trigger" . as_ptr ( ) ) ;
183+ lua. raw . remove ( state, -2 ) ; // remove Autorun table
189184
190- if lua. type_id ( state, -1 ) != autorun_lua:: LuaTypeId :: Function {
191- lua. pop ( state, 1 ) ;
185+ if lua. raw . typeid ( state, -1 ) != autorun_lua:: LuaTypeId :: Function {
186+ lua. raw . pop ( state, 1 ) ;
192187 anyhow:: bail!( "don't remove Autorun.trigger lil bro." ) ;
193188 }
194189
195- lua. insert ( state, -( n_args + 2 ) ) ;
196- lua. pcall ( state, n_args + 1 , 0 , 0 ) . map_err ( |e| anyhow:: anyhow!( e) ) ?;
190+ lua. raw . insert ( state, -( n_args + 2 ) ) ;
191+ lua. raw . pcall ( state, n_args + 1 , 0 , 0 ) . map_err ( |e| anyhow:: anyhow!( e) ) ?;
197192
198193 Ok ( ( ) )
199194 }
@@ -206,19 +201,19 @@ impl EnvHandle {
206201 n_args : c_int ,
207202 ) -> anyhow:: Result < ( ) > {
208203 lua. push ( state, event_name) ;
209- lua. insert ( state, -( n_args + 1 ) ) ;
204+ lua. raw . insert ( state, -( n_args + 1 ) ) ;
210205
211- self . autorun . push ( lua , state ) ;
212- lua. get_field ( state, -1 , c"runRemoteCallbacks" . as_ptr ( ) ) ;
213- lua. remove ( state, -2 ) ; // remove Autorun table
206+ lua . push ( state , & self . autorun ) ;
207+ lua. raw . getfield ( state, -1 , c"runRemoteCallbacks" . as_ptr ( ) ) ;
208+ lua. raw . remove ( state, -2 ) ; // remove Autorun table
214209
215- if lua. type_id ( state, -1 ) != autorun_lua:: LuaTypeId :: Function {
216- lua. pop ( state, 1 ) ;
210+ if lua. raw . typeid ( state, -1 ) != autorun_lua:: LuaTypeId :: Function {
211+ lua. raw . pop ( state, 1 ) ;
217212 anyhow:: bail!( "don't remove Autorun.runRemoteCallbacks lil bro." ) ;
218213 }
219214
220- lua. insert ( state, -( n_args + 2 ) ) ;
221- lua. pcall ( state, n_args + 1 , 0 , 0 ) . map_err ( |e| anyhow:: anyhow!( e) ) ?;
215+ lua. raw . insert ( state, -( n_args + 2 ) ) ;
216+ lua. raw . pcall ( state, n_args + 1 , 0 , 0 ) . map_err ( |e| anyhow:: anyhow!( e) ) ?;
222217
223218 Ok ( ( ) )
224219 }
0 commit comments