You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any example to do this? I tried this way seems not work as expected, any help would be really appreciated. Suppose I have this script:
class Italy {
var population = 60656000;
var area = 301340; // in km2
func density() {
return population/area;
}
}
var itally_obj = Itally();
I want to call itally_obj.density from host, i can get object value, and method closure, but it keeps FAIL when I try to execute gravity_vm_runclosure. Sorry to use object pascal instead of C, but I believe mostly it still readable:
var
AInstance: gravity_value_t;
AKeyVal, AMethodVal: gravity_value_t;
AParams: gravity_value_t_array;
AString: gravity_string_t;
AGClass: Pgravity_class_t;
AFunClosure: gravity_closure_t;
begin
...
...
// perform instance lookup
AInstance := gravity_vm_getvalue(FVM, 'itally_obj');
if VALUE_ISA_INSTANCE(AInstance) then
begin
// convert string to gravity_value_t
AString := STRINGIFY('density');
AKeyVal.isa := gravity_class_string;
AKeyVal.f2.p := @AString;
// perform method lookup
AGClass := VALUE_AS_INSTANCE(AInstance)^.objclass;
AMethodVal := gravity_hash_lookup(AGClass^.htable, AKeyVal);
if VALUE_ISA_CLOSURE(AMethodVal)
begin
AFunClosure := VALUE_AS_CLOSURE(AMethodVal);
SetLength(AParams, 1);
AParams[0] := AInstance; // Self
// try to run closure with self as parameter -- FAILED HERE ---
if gravity_vm_runclosure(FVM, AFunClosure, VALUE_FROM_NULL, @AParams[0], 1) then
begin
...
end
end;
end;
...
...
end;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
Is there any example to do this? I tried this way seems not work as expected, any help would be really appreciated. Suppose I have this script:
I want to call itally_obj.density from host, i can get object value, and method closure, but it keeps FAIL when I try to execute gravity_vm_runclosure. Sorry to use object pascal instead of C, but I believe mostly it still readable:
Beta Was this translation helpful? Give feedback.
All reactions