-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow natives to return structs and arrays.
Natives can now return enum structs and fixed-size arrays. The address is passed as a hidden first parameter. For example: native Struct DoStuff(int x, int y); Will have: params[0] = 3 params[1] = the address of the output struct params[2] = x params[3] = y The hidden address points to a fully initialized array or enum struct. In the case of a multi-dimensional array, the indirection vectors are already placed. All values/members are initialized to zero. The native MUST return params[1] on success, otherwise, behavior is undefined. It is recommended that when defining C++ definitions of SourcePawn structs, to use `#pragma pack(push, 1)` and `#pragma pack(pop)`. In addition, the only types that should appear are "cell_t" and "float". No other type should be used for scalars. For arrays, "char" may be used, but not as a scalar. When using char arrays, the C++ definition must be careful to convert the char size to a cell-aligned size. For example: enum struct MyStruct { int x; int y; char message[50]; } Should look like this in C++: #pragma pack(push, 1) struct MyStruct { cell_t x; cell_t y; char message[CharArraySize<50>::bytes]; }; #pragma pack(pop)
- Loading branch information
Showing
13 changed files
with
122 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
(1) : error 141: natives, forwards, and public functions cannot return arrays | ||
(2) : error 141: natives, forwards, and public functions cannot return arrays | ||
(1) : error 039: natives can only return fixed-size arrays | ||
(2) : error 141: forwards and public functions cannot return arrays |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
x: 4 | ||
y: 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <shell> | ||
|
||
public main() | ||
{ | ||
TestStruct a = {1, 2}; | ||
TestStruct b = {3, 4}; | ||
print_test_struct(add_test_structs(a, b)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6e00170
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason as to why
#pragma push(pack, 1)
andCharArraySize<n>::bytes
are used, rather than just stick to 4-byte struct alignment which can be forced by#pragma push(pack, 4)
?Otherwise, seems good! 😄
6e00170
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about this as I checked this in, but didn't have time to test. Probably works. Will adjust the shell example if so.
6e00170
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.