Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callNative not return retval with return value specifiers #31

Open
dockfries opened this issue Feb 7, 2024 · 0 comments
Open

callNative not return retval with return value specifiers #31

dockfries opened this issue Feb 7, 2024 · 0 comments

Comments

@dockfries
Copy link

dockfries commented Feb 7, 2024

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 };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant