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

Dynamic type #46

Open
Ilir-Liburn opened this issue May 22, 2022 · 0 comments
Open

Dynamic type #46

Ilir-Liburn opened this issue May 22, 2022 · 0 comments

Comments

@Ilir-Liburn
Copy link
Contributor

Ilir-Liburn commented May 22, 2022

Hello,

I tried using Dynamic type via haxe-c-bridge and it works! The most interesting part is happening due to memory alignment ( see printDynamicType function ).

Now I wonder if there is a better way to get ValueType ( outside of the Haxe code or by reducing the Haxe code ).

Edit:

I tested this using Win32 because I don't have 64 bit version of cl, can't compile 64bit version even gcc 64 bit version is used ( see #38 )

[ add to src/Main.hx at Main class ]

	static public function getDynamicInt() {
		var val:Int = -1; 
		var dyn:Any = val;
		return dyn;
	}

	static public function getDynamicFloat() {
		var val:Float = 99234234.99234234; 
		var dyn:Any = val;
		return dyn;
	}

	static public function getDynamicType(dyn:Any) {
		var idx = Type.typeof(dyn).getIndex();
		var arr = Type.getEnumConstructs(Type.ValueType);
		trace("HaxeEnumType = " + arr[idx]);
		return idx; 
	}

[ add to App.c ]

enum HaxeValueType
{
	TNull = 0,
	TInt = 1,
	TFloat = 2,
	TBool = 3,
	TObject = 4,
	TFunction = 5,
	TClass = 6,
	TEnum = 7,
	TUnknown = 8
};

void printDynamicType(enum HaxeValueType en,HaxeObject *obj) {
	switch (en) {
		default :
			printf("HaxeDynamicValue = Unknown (temporary:)\n");
			break ;
		case TInt :
			printf("HaxeDynamicValue = %d\n",((int *)obj)[1]);
			break ;
		case TFloat :
			printf("HaxeDynamicValue = %f\n",((double *)obj)[1]);
			break ;
	}
}

	HaxeObject int_obj = HaxeLib_Main_getDynamicInt();
	enum HaxeValueType int_en = HaxeLib_Main_getDynamicType(int_obj);
	printDynamicType(int_en,int_obj);

	HaxeObject float_obj = HaxeLib_Main_getDynamicFloat();
	enum HaxeValueType float_en = HaxeLib_Main_getDynamicType(float_obj);
	printDynamicType(float_en,float_obj);
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

No branches or pull requests

1 participant