Closed jonstvns closed 2 years ago
Should I duplicate comments for the cf_ and namespaced functions?
When an exported struct or function uses an array<T>
, should that be replaced with a typeless_array
or a raw pointer? typeless_array
uses constructors, we'd have to make sure we add a CUTE_FREE anywhere a destructor would normally be called
This same issue will come up with priority_queue<T>
. lru_cache
won't be useable from a C api without writing a typeless version.
Ideally, the C++ API can keep the templated types, and then pass in wrapped or raw data into the C api. Idk how well that will work in practice.
Should I duplicate comments for the cf_ and namespaced functions?
We can just document the C functions and leave the C++ ones with no comments.
When an exported struct or function uses an array
, should that be replaced with a typeless_array or a raw pointer?
It should probably just be a const pointer and integer length, which would require a free function to also be called. So no constructors or anything fancy.
This same issue will come up with priority_queue
. lru_cache won't be useable from a C api without writing a typeless version.
We don't need to create C style data structures for the templated C++ ones. The only reason I have typeless array is because I actually needed it to implement the ECS, not because I wanted to provide C versions of C++ templated data structures. So the C API wouldn't have an array, prioritity_queue, or dictionary.
@RandyGaul let me know what you think of the changes in the above commit in cute_a_star.h/cpp, cute_gfx.h/cpp, and cute_defines.h. I added some comments for context.
cute_a_star.h is considered done
Finished renaming all the types, functions, and globals with a cf_
prefix
cute_gfx.h and cute_handle_table.h are considered done
Looks good!
@RandyGaul lmk your thoughts on cute_ecs.h. I left a few comments
https://github.com/SomeSoftwareDev/cute_framework/commit/a95972fefb7738e321086b074827333a31df48ab
Also, do we want extern "c"
to be defined as a block in the header or per function?
@RandyGaul I could use some feedback on the changes to cute_https.h
and .cpp
. The signature of function cf_https_response
was changed to accommodate previous usage of array<t>
inside cf_https_response_t
.
There's now a cf_internal_https_response_t
inside cute_https.cpp
, and the values in there are copied out to a cf_https_response_t
instead of directly returning a pointer to the internal response member like the C++ api does.
https://github.com/SomeSoftwareDev/cute_framework/commit/82cbfb4ba3a43a71b4b5fbf8b087f465f3ac573a
cf_https_response
can return a cf_https_response_t
rather than a bool. Otherwise looks good!
Also, do we want extern "c" to be defined as a block in the header or per function?
Blocks is good, not per function.
For ecs header, lets have all those get functions return **, instead of taking an out param. Triple pointer will confuse everyone. Let's also add a NULL
entry as the last pointer in each array, and also allow the the out count param to be NULL
.
Example:
CUTE_API const char** CUTE_CALL cf_ecs_get_entity_list(int* entities_count_out);
Then people can write a loop like this:
const char** list = cf_ecs_get_entity_list(NULL);
while (*list) {
do_stuff(*list);
++list;
}
cf_ecs_free_list(list);
Your implementation looks good otherwise!
Found small typo
Yeah, I realized the triple pointer might be confusing, hence the feedback request. Thanks!
Really good work! Ping me for more feedback as needed
@RandyGaul Are these function names good in cute_kv.h?
Looks pretty good to me
@RandyGaul The changes to cute_math.h need a thorough review.
A lot of overloaded functions were renamed, and while I tried to be consistent, sometimes it made more sense to me to postfix with full types, sometimes abbreviated types, and sometimes with numbers. It'd be great if you could help adjust any naming changes.
All the math operations inside headers were converted to use functions instead of operator overloads. I didn't see any translation errors, but it'd be good to check.
Hid cf_string_t
when compiling as C. It's only accessible in C++ mode, even when using the C api
still need to replace cf_dictionary<T>
with cf_hash_table_t
in cf_sprite_t
You did a really good job with the math naming! I added my comments in the commit you linked above. Good choice on the C++ string -- it's going to likely be deleted in the future anyways, or heavily refactored, and is a C++ only sort of thing anyways. In C we can use the strpool API which is way simpler and a better API imo.
For sprite.h, I made a small breaking change to the C++ api for cf_animation_t
and cf_animation_table_t
. I did not try to keep animation_table_t
a dictionary and I did not try to keep animation_t-frames
a cf_array
.
Supporting that would be annoying and not worth it in this case, imo. I just added the equivalent functions for mutation, so all the C++ folks have to do it adjust a few call sites.
All that's left is code review and verifying that everything still compiles for emscripten
Oh, and we need to merge the changes that were pushed since I began this task
Merging complete. Hope you don't have any local changes
What are we doing?
Converting cute_framework headers to be C compatible, while leaving an optional namespaced C++ API in place.
What work is remaining?
cf_
#ifdef CUTE_CPP
cf_
prefixed types inside namespaces with their original short nameusing
statements withtypedef
sextern "C"
#ifdef CUTE_NO_CPP
tocute_defines.h
for C-only mode when compiling as C++Per-file progress
Notes from discord chat