File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ impl Vm {
201
201
Object :: NativeFun ( native_fun) => {
202
202
let args = self . stack . iter ( ) . rev ( ) . take ( arg_count. 0 as usize ) . cloned ( ) ;
203
203
let result = native_fun. 0 ( args. collect ( ) ) ;
204
- self . stack . pop_n ( arg_count. 0 as usize ) ;
204
+ self . stack . pop_n ( arg_count. 0 as usize + 1 ) ;
205
205
self . push ( result) ?;
206
206
Ok ( ( ) )
207
207
}
@@ -935,4 +935,17 @@ mod tests {
935
935
Vm :: new ( ) . run_source ( source, & mut output) . unwrap ( ) ;
936
936
assert_eq ! ( String :: from_utf8( output) . unwrap( ) . lines( ) . collect_vec( ) , vec![ "A" , "A" ] ) ;
937
937
}
938
+
939
+ #[ test]
940
+ fn call_native_fn ( ) {
941
+ let mut vm = Vm :: new ( ) ;
942
+ vm. define_native ( "increment" , |args| Value :: Number ( args[ 0 ] . clone ( ) . unwrap_number ( ) + 1.0 ) ) ;
943
+ let source = r#"
944
+ print increment(123);
945
+ "# ;
946
+
947
+ let mut output = Vec :: new ( ) ;
948
+ vm. run_source ( source, & mut output) . unwrap ( ) ;
949
+ assert_eq ! ( String :: from_utf8( output) . unwrap( ) . lines( ) . collect_vec( ) , vec![ "124" ] ) ;
950
+ }
938
951
}
You can’t perform that action at this time.
0 commit comments