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

Y_Inline - How to directly call inline function #696

Open
leamir opened this issue Jan 24, 2025 · 0 comments
Open

Y_Inline - How to directly call inline function #696

leamir opened this issue Jan 24, 2025 · 0 comments

Comments

@leamir
Copy link

leamir commented Jan 24, 2025

I'm programming part of my gamemode, and realised I can prevent code repetition if I use a function, however, I prefer using inline functions to keep everything together.

The problem i'm facing is I can't find how to directly call a inline function that was defined on the same stack.

Example:

stock SomeStock()
{
    inline const SomeFunction(value) 
    {
        printf("Argument: %d", value);
    }

    print("Reached Before"); //Prints correctly

    //Call code here (see below my attempts)

    print("Reached After"); // Never Prints
}

All tested on the following environment:

[2025-01-24T16:13:06-0300] [Info]  |                                        | 
[2025-01-24T16:13:06-0300] [Info]  | Server:      open.mp 1.4.0.2783 (L)    | 
[2025-01-24T16:13:06-0300] [Info]  | Started:     24 Jan 2025 - 16:13:06    | 
[2025-01-24T16:13:06-0300] [Info]  |                                        | 
[2025-01-24T16:13:06-0300] [Info]  | Compiler:    3.10.10 (Linux)           | 
[2025-01-24T16:13:06-0300] [Info]  | Includes:    open.mp v037030           | 
[2025-01-24T16:13:06-0300] [Info]  | Codepage:    <none>                    | 
[2025-01-24T16:13:06-0300] [Info]  | Built:       24 Jan 2025 - 16:13:02    | 
[2025-01-24T16:13:06-0300] [Info]  |                                        | 
[2025-01-24T16:13:06-0300] [Info]  | YSI:         v05.10.0006               | 
[2025-01-24T16:13:06-0300] [Info]  | Master:      1                         | 
[2025-01-24T16:13:06-0300] [Info]  |                                        | 
[2025-01-24T16:13:06-0300] [Info]  | JIT:         <none>                    | 
[2025-01-24T16:13:06-0300] [Info]  | Crashdetect: <none>                    | 
[2025-01-24T16:13:06-0300] [Info]  |                                        | 
[2025-01-24T16:13:06-0300] [Info]  ==========================================

Attempts (Copy directly to the line with the comment):
@.SomeFunction(1);

  • Hangs, never calls function

Callback_Call(using inline SomeFunction, 1);

  • Compiler warning: argument type mismatch (argument 1)
  • YSI doesn't even load

Indirect_Call(_:(using inline SomeFunction), _:0, 1);

  • Hangs, never calls function

CallStoredFunction(using inline SomeFunction, 1);

  • Works
  • Compiler warning: function is deprecated (symbol "CallStoredFunction") Use '@.func(params);'.
  • Compiler warning: warning 213: tag mismatch: expected tag "F@_@", but found "F@_@i"

Also the implementation contains some Inline_Call functions, all of which are also deprecated. Maybe this is a use for them?

I did see the FAQ issue for warning 234: function is deprecated (symbol "CallStoredFunction") Use '@.func(params);'.

Which is about what I want, but it still isn't a one-liner. And also doesn't work:
Attempt 1:

new Func:f<i> = GetLocalFunction(&SomeFunction<i>);
@.f(1);
  • Compiler warning: warning 204: symbol is assigned a value that is never used: "SomeFunction" (on the inline const SomeFunction line)
  • Function is never called, but doesn't hang

Attempt 2:

new Func:f<i> = GetLocalFunction(using inline SomeFunction);
@.f(1);
  • Compiler error: error 035: argument type mismatch (argument 1)
  • Compiler error: warning 213: tag mismatch: expected tag "F@_@i", but found "F@_@"

How can I make that direct call, without having to pass the inline to a different top-level function (as shown in all the examples), is this currently something that can be achieved in y_inline without warnings?

@Y-Less (sorry for the mention, but I belive you're the only one who can answer this)

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