AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Enum Struct in Natives (https://forums.alliedmods.net/showthread.php?t=322746)

Ludak 04-03-2020 13:46

Enum Struct in Natives
 
Is it possible for a native to somehow return Enum Struct or to pass it by the reference?

MAGNAT2645 04-03-2020 19:56

Re: Enum Struct in Natives
 
https://github.com/alliedmodders/sou...ment-445578252

Since enum struct is basically an array you can use something like that:
Code:

native void MyNative(const any[] enumStructObject); // just replace your enum struct with array if you use it for natives

Bacardi 04-03-2020 20:49

Re: Enum Struct in Natives
 
Does this wiki tell same ? Because, I don't know :)

https://wiki.alliedmods.net/SourcePa...x#Enum_Structs

RumbleFrog 04-03-2020 21:11

Re: Enum Struct in Natives
 
Be aware of casting, this is UB and if compiled with different ES internals, it may cause problems.

Ludak 04-04-2020 14:35

Re: Enum Struct in Natives
 
Quote:

Originally Posted by MAGNAT2645 (Post 2690477)
https://github.com/alliedmodders/sou...ment-445578252

Since enum struct is basically an array you can use something like that:
Code:

native void MyNative(const any[] enumStructObject); // just replace your enum struct with array if you use it for natives

Thank you.

JoinedSenses 04-06-2020 13:50

Re: Enum Struct in Natives
 
Plugin
Code:

#include <sourcemod>
#include <test>

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
    RegPluginLibrary("test");
    CreateNative("Test_PassStruct", Native_PassStruct);
}

public any Native_PassStruct(Handle plugin, int numParams) {
    TestStruct test;
    test.x = 1;
    test.y = 2;
    SetNativeArray(1, test, sizeof(TestStruct));
    return 1;
}

Include
Code:

#if defined _test_included_
  #endinput
#endif
#define _test_included_

enum struct TestStruct {
    int x;
    int y;
}

native void Test_PassStruct(any teststruct[sizeof(TestStruct)]);

public SharedPlugin __pl_test = {
    name = "test",
    file = "test.smx",
#if defined REQUIRE_PLUGIN
    required = 1,
#else
    required = 0,
#endif
};



All times are GMT -4. The time now is 12:19.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.