W3cubDocs

/Haxe C#

Lib

package cs

Available on cs

Platform-specific C# Library. Provides some platform-specific functions for the C# target, such as conversion from haxe types to native types and vice-versa.

Static methods

@:has_untyped @:extern static inline addressOf<T> (variable:T ):Pointer<T>

Gets the pointer to the address of current local. Equivalent to the "&" operator in C# Usage:

var x:Int = 0;
cs.Lib.unsafe({
	var addr = cs.Lib.addressOf(x);
	x[0] = 42;
});
trace(x); //42

This method only exists at compile-time, so it can't be called via reflection. Warning: This method will only work if a local variable is passed as an argument.

static applyCultureChanges ():Void

Changes the current culture settings to allow a consistent cross-target behavior. Currently the only change made is in regard to the decimal separator, which is always set to "."

static inline array<T> (native:NativeArray<T>):Array<T>

Returns a Haxe Array of a native Array. Unless erase_generics is defined, it won't copy the contents of the native array, so unless any operation triggers an array resize, all changes made to the Haxe array will affect the native array argument.

static inline arrayAlloc<T> (size:Int):Array<T>

Allocates a new Haxe Array with a predetermined size

@:has_untyped @:extern static inline as<T> (obj:Dynamic, cl:Class<T>):T

Provides support for the "as" keyword in C#. If the object is not of the supplied type "T", it will return null instead of rasing an exception.

This function will not work with Value Types (such as Int, Float, Bool...)

@:has_untyped @:extern static inline checked<V> (block:V ):Void

Creates a "checked" block, which throws exceptions for overflows.

Usage:

cs.Lib.checked({
	var x = 1000;
	while(true)
	{
		x *= x;
	}
});

This method only exists at compile-time, so it can't be called via reflection.

@:has_untyped @:extern static inline fixed<V> (block:V ):Void

Marks its parameters as fixed objects inside the defined block. The first variable declarations that use cs.Lib.pointerOfArray() will be the fixed definitions. Usage:

cs.Lib.fixed({
	var obj1 = cs.Lib.pointerOfArray(someArray);
	var obj2 = cs.Lib.pointerOfArray(someArray2);
	var obj3 = cs.Lib.pointerOfArray(someArray3);
	//from now on, obj1, obj2 and obj3 are fixed
	//we cannot change obj1, obj2 or obj3 variables like this:
	//obj1++;
});

This method only exists at compile-time, so it can't be called via reflection.

@:has_untyped static inline fromNativeType (t:Type):Class<Dynamic>

Returns a Class<> equivalent to the native System.Type type.

Currently Haxe's Class<> is equivalent to System.Type, but this is an implementation detail. This may change in the future, so use this function whenever you need to perform such conversion.

@:has_untyped static inline getNativeType (obj:Dynamic):Type

Gets the native System.Type from the supplied object. Will throw an exception in case of null being passed.

@:has_untyped @:extern static inline lock<O, V> (obj:O, block:V ):Void

Ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread attempts to enter a locked code, it will wait, block, until the object is released.

This method only exists at compile-time, so it can't be called via reflection.

@:extern static inline nativeArray<T> (arr:Array<T>, equalLengthRequired:Bool):NativeArray<T>

Returns a native array from the supplied Array. This native array is unsafe to be written on, as it may or may not be linked to the actual Array implementation.

If equalLengthRequired is true, the result might be a copy of an array with the correct size.

@:has_untyped static inline nativeType (obj:Dynamic):Type

Deprecated: "The function `nativeType` is deprecated and will be removed in later versions. Please use `getNativeType` instead"

Gets the native System.Type from the supplied object. Will throw an exception in case of null being passed. [deprecated] - use getNativeType instead

@:has_untyped @:extern static inline pointerOfArray<T> (array:NativeArray<T>):Pointer<T>

Transforms a managed native array into a Pointer. Must be inside a fixed statement Usage:

var x:cs.NativeArray<Int> = new cs.NativeArray(1);
cs.Lib.unsafe({
	cs.Lib.fixed({
		var addr = cs.Lib.pointerOfArray(x);
		trace(cs.Lib.valueOf(addr)); //0
		addr[0] = 42;
		trace(cs.Lib.valueOf(addr)); //42
	});
});
trace(x[0]); //42

This method only exists at compile-time, so it can't be called via reflection.

@:has_untyped @:extern static inline rethrow (e:Dynamic):Void

Rethrow an exception. This is useful when manually filtering an exception in order to keep the previous exception stack.

static revertDefaultCulture ():Void

Reverts the culture changes to the default settings.

@:has_untyped @:extern static inline sizeof (struct:Class<Dynamic>):Int

Returns the byte size of the given struct. Only works with structs and basic types.

@:has_untyped static inline toNativeEnum (cl:Enum<Dynamic>):Type

Returns a System.Type equivalent to the Haxe Enum<> type.

@:has_untyped static inline toNativeType (cl:Class<Dynamic>):Type

Returns a System.Type equivalent to the Haxe Class<> type.

Currently Haxe's Class<> is equivalent to System.Type, but this is an implementation detail. This may change in the future, so use this function whenever you need to perform such conversion.

@:has_untyped @:extern static inline unsafe<V> (block:V ):Void

Marks the contained block as an unsafe block, meaning that it can contain unsafe code. Usage:

cs.Lib.unsafe({
	//unsafe code is allowed inside here
});

This method only exists at compile-time, so it can't be called via reflection.

@:has_untyped @:extern static inline valueOf<T> (pointer:Pointer<T>):T

Gets the value of the pointer address. Usage:

var x:Int = 0;
cs.Lib.unsafe({
	var addr = cs.Lib.addressOf(x);
	trace(cs.Lib.valueOf(addr)); //0
	addr[0] = 42;
	trace(cs.Lib.valueOf(addr)); //42
});
trace(x); //42

This method only exists at compile-time, so it can't be called via reflection.

© 2005–2018 Haxe Foundation
Licensed under a MIT license.
https://api.haxe.org/cs/Lib.html