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
From Issue: #296 I know all arguments are passed by reference, question: what is the safe way (GC friendly) to replace value referenced by args into something else? ex: from int to string, from unknown to int. Is there any example I can use for
In my case, I need to write a function that returns multiple return values which this cannot be done using conventional function structure, so i want to use parameter as output argument.
for example in gravity:
func main() {
var date_today = SysUtils.Today(); // 12-12-2023
var year, month, day;
SysUtils.DecodeDate(date_today, year, month, day); // output: year = 2023, month = 12, day = 12
}
The decodedate function in native (object pascal language):
function gravity_decodedate(vm: Pgravity_vm; args: Pgravity_value_t; nargs: UInt16; rindex: UInt32): Boolean; cdecl;
procedure REPLACE_TO_INT(AVal: Pgravity_value_t; value: Int64);
begin
AVal^.isa := GravityEng.gravity_class_int;
AVal^.f2.n := value;
end;
var
Year, Month, Day: Pgravity_value_t; // gravity_value_t*
AYear, AMonth, ADay: Word;
begin
with GravityEng do
begin
if (nargs <> 5) then
Result := RETURN_ERROR(vm, 'Incorrect number of arguments.', rindex)
else
begin
// Get the reference pointer to year, month, day in args
Year := Pgravity_value_t(NativeUInt(args) + 2 * SizeOf(gravity_value_t));
Month := Pgravity_value_t(NativeUInt(args) + 3 * SizeOf(gravity_value_t));
Day := Pgravity_value_t(NativeUInt(args) + 4 * SizeOf(gravity_value_t));
// perform decoding date
DecodeDate(VALUE_AS_FLOAT(GET_VALUE(args, 1)), AYear, AMonth, ADay);
// replace value on reference params
REPLACE_TO_INT(Year, AYear);
REPLACE_TO_INT(Month, AMonth);
REPLACE_TO_INT(Day, ADay);
Result := RETURN_NOVALUE;
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,
From Issue: #296 I know all arguments are passed by reference, question: what is the safe way (GC friendly) to replace value referenced by args into something else? ex: from int to string, from unknown to int. Is there any example I can use for
In my case, I need to write a function that returns multiple return values which this cannot be done using conventional function structure, so i want to use parameter as output argument.
for example in gravity:
The decodedate function in native (object pascal language):
Regards,
-Jaimy.
Beta Was this translation helpful? Give feedback.
All reactions