kt_beginInit(bool)

This commit is contained in:
Timerix22 2024-01-03 16:58:20 +06:00
parent 791ffe8633
commit 7ba15b208f
2 changed files with 13 additions and 8 deletions

View File

@ -52,9 +52,14 @@ ktid ktid_last=-1;
ENUM(ktDescriptorsState, ENUM(ktDescriptorsState,
NotInitialized, Initializing, Initialized NotInitialized, Initializing, Initialized
) )
ktDescriptorsState initState=NotInitialized; ktDescriptorsState initState=NotInitialized;
void kt_beginInit(){ bool _printDebugMessages = false;
void kt_beginInit(bool printDebugMessages){
_printDebugMessages = printDebugMessages;
if(printDebugMessages)
kprintf("\e[94mtype descriptors initializing...\n"); kprintf("\e[94mtype descriptors initializing...\n");
__descriptorPointers=Autoarr_create(Pointer, 256, 256); __descriptorPointers=Autoarr_create(Pointer, 256, 256);
} }
@ -65,6 +70,7 @@ void kt_endInit(){
typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers); typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers);
Autoarr_free(__descriptorPointers,true); Autoarr_free(__descriptorPointers,true);
if(typeDescriptors==NULL) throw(ERR_NULLPTR); if(typeDescriptors==NULL) throw(ERR_NULLPTR);
if(_printDebugMessages)
kprintf("\e[92minitialized %u type descriptors\n", ktid_last); kprintf("\e[92minitialized %u type descriptors\n", ktid_last);
} }
@ -74,10 +80,9 @@ void __kt_register(ktDescriptor* descriptor){
} }
ktDescriptor* ktDescriptor_get(ktid id){ ktDescriptor* ktDescriptor_get(ktid id){
if(id>ktid_last || id==ktid_undefined) { if(id>ktid_last || id==ktid_undefined)
kprintf("\ntype id: %u\n",id); throw(cptr_concat("invalid type id ", toString_i64(id)));
throw("invalid type id");
}
return typeDescriptors[id]; return typeDescriptors[id];
} }

View File

@ -17,7 +17,7 @@ void __kt_register(ktDescriptor* descriptor);
__kt_register(&ktDescriptor_##TYPE##_Ptr); \ __kt_register(&ktDescriptor_##TYPE##_Ptr); \
ktid_##TYPE##_Ptr=ktid_last; ktid_##TYPE##_Ptr=ktid_last;
void kt_beginInit(); void kt_beginInit(bool printDebugMessages);
void kt_endInit(); void kt_endInit();
/// @param id id of registered type /// @param id id of registered type