samp-node icon indicating copy to clipboard operation
samp-node copied to clipboard

callNative not return retval with return value specifiers

Open dockfries opened this issue 1 year ago • 0 comments

callNative and callNativeFloat

retval is still important to return value specifiers, but it has been discarded so far and only value has been returned.

This means that when the native function thinks something wrong and returns such as 0 or -1 instead of the expected result, assuming that "FFF" is passed, you will get three wrong arrays of float values.

I can't think of any good plan at the moment, such as push retval to the last item of the value array. But it can also lead to breaking changes.

see specifiers. see retval. see natives.cpp.

			if (vars == 1)
			{
				v8::Local<v8::Value> jsval = arr->Get(_context, 0).ToLocalChecked();
				args.GetReturnValue().Set(jsval);
			}
			else if (vars > 1)
				args.GetReturnValue().Set(arr);
			else
				args.GetReturnValue().Set(retval);

see CA_RayCastLine. Take the function of colandreas as an example

function rayCastLine(
  startX: number,
  startY: number,
  startZ: number,
  endX: number,
  endY: number,
  endZ: number
) {
  

  const [x, y, z] = samp.callNative(
    "CA_RayCastLine",
    "ffffffFFF",
    startX,
    startY,
    startZ,
    endX,
    endY,
    endZ
  ) as number[];

 // cannot get retval 
// if (retval === 0) return null;

// so if retval === 0 returned native, "FFF" get wrong value

  return { x, y, z };
}

dockfries avatar Feb 07 '24 16:02 dockfries