Skip to content

Conversation

@AmyrAhmady
Copy link
Member

Info

The natives that were not used in a script were not able to be called (because they weren't actually registered, when amx_Register was called) so now we're keeping a container of all natives. Also introducing a new function to IPawnScript, named IPawnScript::CallNative so SDK users are able to call those globally stored natives using this function which handles argument types (both values and refs)

Examples:

Normal arguments:

auto result = script.CallNative("SetPlayerPos", playerid, 1352.0f, 363.0f, 200.0f);

// float return value
float result = script.CallNative<float>("GetPlayerGravity", playerid);

Reference arguments:

PawnRef<float> x, y, z;
script.CallNative("GetPlayerPos", 0, x, y, z);
printf("Pos: x = %f, y = %f, z = %f\n", x.get(), y.get(), z.get());

// String ref
PawnRef<String> playerName(24);
script.CallNative("GetPlayerName", playerid, playerName, playerName.size());
printf("Player %d name is %s\n", playerid, playerName.c_str());

// Array ref
PawnRef<DynamicArray<int>> players(100);
script.CallNative("GetPlayers", players, players.size());
for (int playerid : players.get())
{
    printf("Player %d is in server\n", playerid);
}

The PawnRef wrapper:

  1. Allocates a cell in AMX heap memory
  2. Writes the initial value to that cell
  3. Passes the AMX address to the native
  4. Reads back the modified value after the native returns
  5. Automatically cleans up allocated memory

@AmyrAhmady AmyrAhmady requested a review from Hual October 16, 2025 08:47
@AmyrAhmady
Copy link
Member Author

AmyrAhmady commented Oct 16, 2025

@github-copilot review

fuck off

@Southclaws Southclaws requested a review from Copilot October 16, 2025 10:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a global registry of Pawn natives and exposes a way to invoke them from the SDK, even if a script doesn’t reference them directly.

  • Introduces GlobalNativeRegistry and registers natives during amx_Register
  • Implements PawnScript::CallNativeArray to marshal arguments (including refs) and read back results
  • Updates the SDK submodule

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
Server/Components/Pawn/Script/Script.hpp Adds global native registry and the CallNativeArray implementation with full arg/ref marshalling.
Server/Components/Pawn/Script/Script.cpp Hooks amx_Register_impl to populate the global native registry.
SDK Bumps submodule to new commit (SDK changes not reviewed here).

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Hual Hual merged commit faf5db1 into master Oct 18, 2025
12 of 13 checks passed
@AmyrAhmady AmyrAhmady deleted the amir/native-caller branch October 18, 2025 09:37
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

Successfully merging this pull request may close these issues.

3 participants