Raised This Month: $12 Target: $400
 3% 

Solved Enum Struct in Natives


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ludak
Member
Join Date: Oct 2014
Old 04-03-2020 , 13:46   Enum Struct in Natives
Reply With Quote #1

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

Last edited by Ludak; 04-04-2020 at 14:35.
Ludak is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 04-03-2020 , 19:56   Re: Enum Struct in Natives
Reply With Quote #2

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
__________________
MAGNAT2645 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-03-2020 , 20:49   Re: Enum Struct in Natives
Reply With Quote #3

Does this wiki tell same ? Because, I don't know

https://wiki.alliedmods.net/SourcePa...x#Enum_Structs
__________________
Do not Private Message @me

Last edited by Bacardi; 04-03-2020 at 20:50.
Bacardi is offline
RumbleFrog
Great Tester of Whatever
Join Date: Dec 2016
Location: Fish Tank
Old 04-03-2020 , 21:11   Re: Enum Struct in Natives
Reply With Quote #4

Be aware of casting, this is UB and if compiled with different ES internals, it may cause problems.
__________________
RumbleFrog is offline
Ludak
Member
Join Date: Oct 2014
Old 04-04-2020 , 14:35   Re: Enum Struct in Natives
Reply With Quote #5

Quote:
Originally Posted by MAGNAT2645 View Post
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.
Ludak is offline
JoinedSenses
Senior Member
Join Date: Sep 2013
Old 04-06-2020 , 13:50   Re: Enum Struct in Natives
Reply With Quote #6

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
};
__________________
JoinedSenses is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:37.


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