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

Update Array.hx to have set and get methods #49

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

Just-Feeshy
Copy link
Contributor

@Just-Feeshy Just-Feeshy commented May 23, 2024

Example of how it works:

Main.hx:

package;

class Main {
		public static function main() {
		    var a = new cxx.std.Array<Int, 5>();
		    a.set(0, 5);
			a.set(1, 3);
			a.set(2, 1);

			trace("Hello, World!" + (a.get(0) + a.get(1) + a.get(2)));
		}
}

To Main.cpp:

#include "Main.h"

#include <array>
#include <memory>
#include <string>
#include "_AnonStructs.h"
#include "haxe_Log.h"

using namespace std::string_literals;

void Main::main() {
	std::shared_ptr<std::array<int, 5>> a = std::make_shared<std::array<int, 5>>();

	(*a)[0] = 5;
	(*a)[1] = 3;
	(*a)[2] = 1;
	haxe::Log::trace("Hello, World!"s + std::to_string((((*a)[0]) + ((*a)[1]) + ((*a)[2]))), haxe::shared_anon<haxe::PosInfos>("Main"s, "Main.hx"s, 10, "main"s));
}

Output:

Main.hx:10: Hello, World!9

@Just-Feeshy
Copy link
Contributor Author

I added a warning comment to let others know that these functions aren't safe.

@SomeRanDev SomeRanDev merged commit b58fc02 into SomeRanDev:main Jun 17, 2024
4 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 17, 2024
Update `Array.hx` to have `set` and `get` methods
@Just-Feeshy Just-Feeshy deleted the Array branch June 21, 2024 07:17
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