package cs
Available on csPlatform-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 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 ():VoidChanges 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
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...)
static inline checked<V> (block:V ):VoidCreates 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.
static inline fixed<V> (block:V ):VoidMarks 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.
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.
static inline getNativeType (obj:Dynamic):TypeGets the native System.Type from the supplied object. Will throw an exception in case of null being passed.
static inline lock<O, V> (obj:O, block:V ):VoidEnsures 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.
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.
static inline nativeType (obj:Dynamic):TypeGets the native System.Type from the supplied object. Will throw an exception in case of null being passed. [deprecated] - use getNativeType instead
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.
static inline rethrow (e:Dynamic):VoidRethrow an exception. This is useful when manually filtering an exception in order to keep the previous exception stack.
static revertDefaultCulture ():VoidReverts the culture changes to the default settings.
static inline sizeof (struct:Class<Dynamic>):IntReturns the byte size of the given struct. Only works with structs and basic types.
static inline toNativeEnum (cl:Enum<Dynamic>):TypeReturns a System.Type equivalent to the Haxe Enum<> type.
static inline toNativeType (cl:Class<Dynamic>):TypeReturns 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.
static inline unsafe<V> (block:V ):VoidMarks 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.
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