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

LUA native parameters does not fits the RAW declaration #884

Open
Mathu-lmn opened this issue Jun 3, 2023 · 4 comments
Open

LUA native parameters does not fits the RAW declaration #884

Mathu-lmn opened this issue Jun 3, 2023 · 4 comments

Comments

@Mathu-lmn
Copy link
Contributor

Hello,

For example with the RemoveBlip native, the function takes 1 parameter (the blip) but for the LUA and JS part, the blip is shown as a return and not a parameter.
My guess is that in the RAW declaration, the type is not a standard one (Blip*) and the conversion is not done properly

@Mathu-lmn
Copy link
Contributor Author

Okay after looking at it again, when the type is an adress (int * / char * / any *), lua / js part sees it as a return value when it's not always the case

@4mmonium
Copy link
Contributor

4mmonium commented Jul 6, 2023

Lua doesn't return by reference parameters, but C# can do that by using out parameters. It seems to me, that you may be confused about how Lua returns values. Lua can only return values via the return statement i.e.

In Lua

function getCoordinates()
  local x = 10
  local y = 20
  return x, y
end

local result1, result2 = getCoordinates()
print(result1, result2) -- Outputs: 10   20

In C#

public void GetCoordinates(out int x, out int y)
{
    x = 10;
    y = 20;
}

int result1, result2;
GetCoordinates(out result1, out result2);
Console.WriteLine($"{result1}, {result2}"); // Outputs: 10, 20

Perhaps the current RemoveBlip example for Lua is a bit confusing, but it's basically:

local coords = vector3(200.0, 200.0, 5.0)
local blip = AddBlipForCoord(coords)

-- When you want to remove it
local removedBlipHandle = RemoveBlip(blip)
Citizen.Trace('Removed blip: ' .. removedBlipHandle)

I haven't tested the code above, it's only for illustration purposes.

Hope that cleared your doubts 🙂

@Mathu-lmn
Copy link
Contributor Author

Hey, thanks for the clear explanations. I do know that lua functions need the return statement to return values and that there is no pointers that can be used like in C#. My concern was mainly for your example, the RemoveBlip needs the blip to remove to be a parameter, but if you look in the natives website :

-- REMOVE_BLIP
local blip --[[ Blip ]] = RemoveBlip()

It's not explicit that you need to use RemoveBlip(ThisBlip).

@PsychoShock
Copy link
Contributor

Hey,

Thanks for the report @Mathu-lmn. I push a PR in #1095 to "fix" the issue. We just need to wait now!

Big love :)

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

3 participants