Name
SPVM::Native::MethodCall - Method Call
Description
The Native::MethodCall class of SPVM has methods to call methods.
Usage
use Native::MethodCall;
my $class_method_call = Native::MethodCall->new_class_method("Point", "new");
my $point = (Point)$class_method_call->call([(object)1, 2]);
say $point->x;
say $point->y;
Class Methods
new_class_method_with_env_stack
static method new_class_method_with_env_stack : Native::MethodCall ($env : Native::Env, $stack : Native::Stack, $basic_type_name : string, $method_name : string);
Creates a class method call given the runtime environment $env, the runtime stck $stack, the basic type name $basic_type_name and the method name $method_name and returns it.
If $env is not given, $env is set to the current runtime environment.
If $stack is not given, $stack is set to the current runtime environment.
new_instance_method_static_with_env_stack
static method new_instance_method_static_with_env_stack : Native::MethodCall ($env : Native::Env, $stack : Native::Stack, $basic_type_name : string, $method_name : string);
Creates a instance method call given the runtime environment $env, the runtime stck $stack, the basic type name $basic_type_name and the method name $method_name, and returns it.
If $env is not given, $env is set to the current runtime environment.
If $stack is not given, $stack is set to the current runtime environment.
new_instance_method_with_env_stack
static method new_instance_method_with_env_stack : Native::MethodCall ($env : Native::Env, $stack : Native::Stack, $instance : object, $method_name : string);
Creates a instance method call given the runtime environment $env, the runtime stck $stack, the instance $instance and the method name $method_name, and returns it.
If $env is not given, $env is set to the current runtime environment.
If $stack is not given, $stack is set to the current runtime environment.
new_class_method
static method new_class_method : Native::MethodCall ($basic_type_name : string, $method_name : string);
Calls "new_class_method_with_env_stack" method given $env to undef and $stack to undef, and returns its return value.
Creates a class method call given the basic type name $basic_type_name and the method name $method_name and returns it.
new_instance_method_static
static method new_instance_method_static : Native::MethodCall ($basic_type_name : string, $method_name : string);
Calls "new_instance_method_static_with_env_stack" method given $env to undef and $stack to undef, and returns its return value.
new_instance_method
static method new_instance_method : Native::MethodCall ($instance : object, $method_name : string);
Calls "new_instance_method_with_env_stack" method given $env to undef and $stack to undef, and returns its return value.
call_class_method
static method call_class_method : void ($basic_type_name : string, $method_name : string, $args : object[] = undef, $error_id_ref : int[] = undef);
Calls a class method given the basic type name $basic_type_name, the method name $method_name, and the arguments $args.
call_instance_method_static
static method call_instance_method_static : object ($basic_type_name : string, $method_name : string, $args : object[] = undef, $error_id_ref : int[] = undef);
Calls a instance method given the basic type name $basic_type_name, the method name $method_name, and the arguments $args.
call_instance_method
static method call_instance_method : object ($method_name : string, $args : object[] = undef, $error_id_ref : int[] = undef);
Calls a instance method given the method name $method_name, and the arguments $args. The first argument in $args must be an instance.
new_proto_with_method_name
static method new_proto_with_method_name : object ($proto : object, $method_name : string, $args : object[] = undef, $error_id_ref : int[] = undef)
Calls "call_class_method" method given the class name of $proto, the method name $method_name, $args, and $error_id_ref and its return value.
Exceptions:
The prototype object $proto must be defined. Otherwise an exception is thrown.
Exceptions thrown by "call_class_method" method could be thrown.
new_proto
static method new_proto : object ($proto : object, $args : object[] = undef, $error_id_ref : int[] = undef);
Same as "new_proto_with_method_name" method, but $method_name is set to "new"
.
Instance Methods
call
method call : object ($args : object[] = undef, $error_id_ref : int[] = undef);
Calls a method with arguments and returns the return value.
get_exception
method get_exception : string ();
Gets the excetpion on the runtime enviroment and runtime stack owned by this instance.
set_exception
method set_exception : void ($exception : string);
Sets the excetpion on the runtime enviroment and runtime stack owned by this instance to the string $exception.
Arguments
Each argument must be an object type. The following conversion is perfromed.
# Numeric types
Byte -> byte
Short -> short
Int -> int
Long -> long
Float -> float
Double -> double
# Multi-Numeric types
byte[] -> multi-numeric byte
short[] -> multi-numeric short
int[] -> multi-numeric int
long[] -> multi-numeric long
float[] -> multi-numeric float
double[] -> multi-numeric double
# Numeric reference types
byte[] -> byte*
short[] -> short*
int[] -> int*
long[] -> long*
float[] -> float*
double[] -> double*
# Multi-Numeric reference types
byte[] -> multi-numeric byte reference
short[] -> multi-numeric short reference
int[] -> multi-numeric int reference
long[] -> multi-numeric long reference
float[] -> multi-numeric float reference
double[] -> multi-numeric double reference
If the type of an argument cannot be assigned, an exception is thrown.
Return Value
If the type of the return value is a numeric type, it is converted to a numeric object.
byte -> Byte
short -> Short
int -> Int
long -> Long
float -> Float
double -> Double
If the type of the return value is a multi-numeric type, it is converted to a numeric array.
multi-numeric byte type -> byte[]
multi-numeric short type -> short[]
multi-numeric int type -> int[]
multi-numeric long type -> long[]
multi-numeric float type -> float[]
multi-numeric double type -> double[]
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License