2
0
mirror of https://github.com/raylib-cs/raylib-cs synced 2025-04-05 11:19:39 -04:00

Created CBool's ctors, fixed casting issue (#142)

This commit is contained in:
Fall 2022-12-27 14:26:32 -03:00 committed by GitHub
parent 8c72abb141
commit 21c010438b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,10 +18,20 @@ namespace Raylib_cs
* on explicit motivation than to blindly trust the runtime judgement on its memory * on explicit motivation than to blindly trust the runtime judgement on its memory
* management. * management.
* *
* 'value' is visible and constructable, but impossible to modify or access. * 'value' is visible and constructable (if necessary), but impossible to modify or access.
*/ */
public sbyte value { init; private get; } public sbyte value { init; private get; }
// Constructors for easier usage.
public CBool(bool value)
{
this.value = (sbyte)(value ? 1 : 0);
}
public CBool(Int64 value)
{
this.value = (sbyte)(value != 0 ? 1 : 0);
}
// CBool -> Native // CBool -> Native
// Allows for arithmetic between CBools and for assignment to greater integer variables. // Allows for arithmetic between CBools and for assignment to greater integer variables.
public static implicit operator sbyte(CBool x) public static implicit operator sbyte(CBool x)
@ -29,7 +39,7 @@ namespace Raylib_cs
return x.value; return x.value;
} }
// Allows for CBools to be implicitely assigned to a native boolean variable // Allows for CBools to be implicitely assigned to a native boolean variable.
public static implicit operator bool(CBool x) public static implicit operator bool(CBool x)
{ {
return x.value != 0 ? true : false; return x.value != 0 ? true : false;
@ -45,7 +55,7 @@ namespace Raylib_cs
// Same goes for integer numeric values (any value, so an Int64 is used). // Same goes for integer numeric values (any value, so an Int64 is used).
public static implicit operator CBool(Int64 x) public static implicit operator CBool(Int64 x)
{ {
return new CBool { value = (sbyte)x }; return new CBool { value = (sbyte)(x != 0 ? 1 : 0) };
} }
/* Arithmetic overloads /* Arithmetic overloads