High-level wrapper around Flecs, a powerful ECS (Entity Component System) library, written in Zig language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.5 KiB

const c = @import("./c.zig");
pub const FlecsError = error{
InvalidOperation,
InvalidParameter,
ConstraintViolated,
OutOfMemory,
OutOfRange,
Unsupported,
InternalError,
AlreadyDefined,
MissingOsApi,
OperationFailed,
InvalidConversion,
IdInUse,
CycleDetected,
LeakDetected,
DoubleFree,
InconsistentName,
NameInUse,
NotAComponent,
InvalidComponentSize,
InvalidComponentAlignment,
ComponentNotRegistered,
InconsistentComponentId,
InconsistentComponentAction,
ModuleUndefined,
MissingSymbol,
AlreadyInUse,
AccessViolation,
ColumnIndexOutOfRange,
ColumnIsNotShared,
ColumnIsShared,
ColumnTypeMismatch,
InvalidWhileReadonly,
LockedStorage,
InvalidFromWorker,
/// An unexpected error occurred in Flecs,
/// but we're not exactly sure what happened.
Unknown,
};
/// Gets the last logged error that occurred in Flecs.
/// Calling this function resets the error code.
pub fn getLastError() ?FlecsError {
return intToFlecsError(c.ecs_log_last_error());
}
/// Gets the last logged error that occurred in Flecs.
/// Calling this function resets the error code.
pub fn getLastErrorOrUnknown() FlecsError {
return getLastError() orelse FlecsError.Unknown;
}
pub fn intToFlecsError(i: i32) ?FlecsError {
return switch (i) {
c.ECS_INVALID_OPERATION => FlecsError.InvalidOperation,
c.ECS_INVALID_PARAMETER => FlecsError.InvalidParameter,
c.ECS_CONSTRAINT_VIOLATED => FlecsError.ConstraintViolated,
c.ECS_OUT_OF_MEMORY => FlecsError.OutOfMemory,
c.ECS_OUT_OF_RANGE => FlecsError.OutOfRange,
c.ECS_UNSUPPORTED => FlecsError.Unsupported,
c.ECS_INTERNAL_ERROR => FlecsError.InternalError,
c.ECS_ALREADY_DEFINED => FlecsError.AlreadyDefined,
c.ECS_MISSING_OS_API => FlecsError.MissingOsApi,
c.ECS_OPERATION_FAILED => FlecsError.OperationFailed,
c.ECS_INVALID_CONVERSION => FlecsError.InvalidConversion,
c.ECS_ID_IN_USE => FlecsError.IdInUse,
c.ECS_CYCLE_DETECTED => FlecsError.CycleDetected,
c.ECS_LEAK_DETECTED => FlecsError.LeakDetected,
c.ECS_DOUBLE_FREE => FlecsError.DoubleFree,
c.ECS_INCONSISTENT_NAME => FlecsError.InconsistentName,
c.ECS_NAME_IN_USE => FlecsError.NameInUse,
c.ECS_NOT_A_COMPONENT => FlecsError.NotAComponent,
c.ECS_INVALID_COMPONENT_SIZE => FlecsError.InvalidComponentSize,
c.ECS_INVALID_COMPONENT_ALIGNMENT => FlecsError.InvalidComponentAlignment,
c.ECS_COMPONENT_NOT_REGISTERED => FlecsError.ComponentNotRegistered,
c.ECS_INCONSISTENT_COMPONENT_ID => FlecsError.InconsistentComponentId,
c.ECS_INCONSISTENT_COMPONENT_ACTION => FlecsError.InconsistentComponentAction,
c.ECS_MODULE_UNDEFINED => FlecsError.ModuleUndefined,
c.ECS_MISSING_SYMBOL => FlecsError.MissingSymbol,
c.ECS_ALREADY_IN_USE => FlecsError.AlreadyInUse,
c.ECS_ACCESS_VIOLATION => FlecsError.AccessViolation,
c.ECS_COLUMN_INDEX_OUT_OF_RANGE => FlecsError.ColumnIndexOutOfRange,
c.ECS_COLUMN_IS_NOT_SHARED => FlecsError.ColumnIsNotShared,
c.ECS_COLUMN_IS_SHARED => FlecsError.ColumnIsShared,
c.ECS_COLUMN_TYPE_MISMATCH => FlecsError.ColumnTypeMismatch,
c.ECS_INVALID_WHILE_READONLY => FlecsError.InvalidWhileReadonly,
c.ECS_LOCKED_STORAGE => FlecsError.LockedStorage,
c.ECS_INVALID_FROM_WORKER => FlecsError.InvalidFromWorker,
else => null,
};
}