diff --git a/.github/workflows/release-rust.yml b/.github/workflows/release-rust.yml index 6d2f0897f..d2a0c31a4 100644 --- a/.github/workflows/release-rust.yml +++ b/.github/workflows/release-rust.yml @@ -6,6 +6,7 @@ on: push: branches: [ master, develop ] paths: + - '.github/workflows/release-rust.yml' - 'source/ports/rs_port/**' concurrency: @@ -22,7 +23,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest] # TODO: , windows-latest] steps: - name: Check out the repo uses: actions/checkout@v4 @@ -34,22 +35,26 @@ jobs: - name: Install MetaCall Windows if: matrix.os == 'windows-latest' run: powershell -NoProfile -ExecutionPolicy Unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://raw.githubusercontent.com/metacall/install/master/install.ps1')))" + - name: Install Rust uses: actions-rs/toolchain@v1 with: toolchain: stable override: true - - name: Build and Test the Rust Port + + - name: Build the Rust Port working-directory: source/ports/rs_port - run: | - cargo build --verbose - cargo test --verbose + run: cargo build --verbose + + - name: Test the Rust Port + working-directory: source/ports/rs_port + run: cargo test --verbose release: name: Release Rust Port runs-on: ubuntu-latest needs: test - if: ${{ github.event_name != 'workflow_dispatch' && github.event_name != 'pull_request' }} + if: ${{ github.event_name != 'pull_request' }} steps: - name: Check out the repo uses: actions/checkout@v4 diff --git a/VERSION b/VERSION index 69010fa5b..6f16bd325 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.14 \ No newline at end of file +0.9.15 \ No newline at end of file diff --git a/source/environment/include/environment/environment_variable_path.h b/source/environment/include/environment/environment_variable_path.h index d5492d8f6..5f3a17ba4 100644 --- a/source/environment/include/environment/environment_variable_path.h +++ b/source/environment/include/environment/environment_variable_path.h @@ -52,7 +52,29 @@ extern "C" { /* -- Methods -- */ -ENVIRONMENT_API char *environment_variable_path_create(const char *name, const char *default_path, size_t default_path_size, size_t *env_size); +/** + * @brief + * If the value of @name exists as an environment variable, return a live string of its value, otherwise return a live value of @default_path or "/". + * @name should not be NULL. + * If @default_path is not NULL, @default_path_size must be set to <= the length (including null-terminator) of the @default_path string. + * If @env_size is not NULL, the length (including null-terminator) of the returned string will be set to it. + * + * @param[in] name + * The environment variable name to look up. + * + * @param[in] default_path + * If the environment variable value is not found, the value to return instead. + * + * @param[in] default_path_size + * The length (including null-terminator) of @default_path in chars. + * + * @param[out] env_size + * Pointer to a size_t to write the length of the returned string to (optional). + * + * @return + * The allocated string containing the environment variable value or the default or "/". + */ +ENVIRONMENT_API char *environment_variable_path_create(const char *const name, const char *const default_path, const size_t default_path_size, size_t *const env_size); ENVIRONMENT_API void environment_variable_path_destroy(char *variable_path); diff --git a/source/environment/source/environment_variable_path.c b/source/environment/source/environment_variable_path.c index 53f492dc3..813112a80 100644 --- a/source/environment/source/environment_variable_path.c +++ b/source/environment/source/environment_variable_path.c @@ -43,59 +43,53 @@ /* -- Methods -- */ -char *environment_variable_path_create(const char *name, const char *default_path, size_t default_path_size, size_t *env_size) +char *environment_variable_path_create(const char *const name, const char *const default_path, const size_t default_path_size, size_t *const env_size) { - const char *path_ptr = getenv(name); + const char *env_variable = getenv(name); char *path; - size_t length, size, last, end; + size_t size, alloc_size; - if (path_ptr == NULL) + if (env_variable) { - if (default_path == NULL) - { - static const char empty_path[] = ""; - - default_path = empty_path; - default_path_size = sizeof(empty_path); - } - - path_ptr = default_path; - length = default_path_size - 1; + size = strlen(env_variable) + 1; + } + else if (default_path) + { + env_variable = default_path; + size = default_path_size; } else { - length = strlen(path_ptr); + env_variable = ENVIRONMENT_VARIABLE_PATH_SEPARATOR_STR; + size = sizeof(ENVIRONMENT_VARIABLE_PATH_SEPARATOR_STR); } - last = length - 1; + alloc_size = size; - if (ENVIRONMENT_VARIABLE_PATH_SEPARATOR(path_ptr[last])) - { - end = length; - size = length + 1; - } - else + if (size > 1) { - last = length; - end = length + 1; - size = length + 2; + alloc_size += !ENVIRONMENT_VARIABLE_PATH_SEPARATOR(env_variable[size - 2]); } - path = malloc(sizeof(char) * size); + path = malloc(sizeof(char) * alloc_size); if (path == NULL) { return NULL; } - strncpy(path, path_ptr, length); + memcpy(path, env_variable, sizeof(char) * size); + + if (size > 1) + { + path[alloc_size - 2] = ENVIRONMENT_VARIABLE_PATH_SEPARATOR_C; + } - path[last] = ENVIRONMENT_VARIABLE_PATH_SEPARATOR_C; - path[end] = '\0'; + path[alloc_size - 1] = '\0'; - if (env_size != NULL) + if (env_size) { - *env_size = size; + *env_size = alloc_size; } return path; diff --git a/source/loader/source/loader_impl.c b/source/loader/source/loader_impl.c index 260a787af..ac35595f5 100644 --- a/source/loader/source/loader_impl.c +++ b/source/loader/source/loader_impl.c @@ -1150,7 +1150,8 @@ int loader_impl_load_from_file(plugin_manager manager, plugin p, loader_impl imp { loader_handle handle; loader_path path; - size_t init_order; + size_t init_order = 0; + int init_order_not_initialized = !(handle_ptr != NULL && *handle_ptr != NULL); if (loader_impl_initialize(manager, p, impl) != 0) { @@ -1164,9 +1165,12 @@ int loader_impl_load_from_file(plugin_manager manager, plugin p, loader_impl imp return 1; } - init_order = vector_size(impl->handle_impl_init_order); + if (init_order_not_initialized) + { + init_order = vector_size(impl->handle_impl_init_order); - vector_push_back_empty(impl->handle_impl_init_order); + vector_push_back_empty(impl->handle_impl_init_order); + } handle = iface->load_from_file(impl, paths, size); @@ -1192,7 +1196,10 @@ int loader_impl_load_from_file(plugin_manager manager, plugin p, loader_impl imp { if (loader_impl_handle_register(manager, impl, path, handle_impl, handle_ptr) == 0) { - vector_set_var(impl->handle_impl_init_order, init_order, handle_impl); + if (init_order_not_initialized) + { + vector_set_var(impl->handle_impl_init_order, init_order, handle_impl); + } return 0; } @@ -1204,7 +1211,10 @@ int loader_impl_load_from_file(plugin_manager manager, plugin p, loader_impl imp set_remove(impl->handle_impl_path_map, handle_impl->path); } + if (init_order_not_initialized) { + /* Here we delete all the subsequent loaded scripts because this script can load others, + and once it is destroyed it must clear all of them */ size_t iterator; for (iterator = init_order + 1; iterator < vector_size(impl->handle_impl_init_order); ++iterator) @@ -1224,16 +1234,21 @@ int loader_impl_load_from_file(plugin_manager manager, plugin p, loader_impl imp } else { - size_t iterator; - - for (iterator = init_order + 1; iterator < vector_size(impl->handle_impl_init_order); ++iterator) + if (init_order_not_initialized) { - loader_handle_impl iterator_handle_impl = vector_at_type(impl->handle_impl_init_order, iterator, loader_handle_impl); + /* Here we delete all the subsequent loaded scripts because this script can load others, + and once it is destroyed it must clear all of them */ + size_t iterator; - loader_impl_destroy_handle(iterator_handle_impl); - } + for (iterator = init_order + 1; iterator < vector_size(impl->handle_impl_init_order); ++iterator) + { + loader_handle_impl iterator_handle_impl = vector_at_type(impl->handle_impl_init_order, iterator, loader_handle_impl); + + loader_impl_destroy_handle(iterator_handle_impl); + } - vector_pop_back(impl->handle_impl_init_order); + vector_pop_back(impl->handle_impl_init_order); + } } } } @@ -1276,7 +1291,8 @@ int loader_impl_load_from_memory(plugin_manager manager, plugin p, loader_impl i { loader_name name; loader_handle handle = NULL; - size_t init_order; + size_t init_order = 0; + int init_order_not_initialized = !(handle_ptr != NULL && *handle_ptr != NULL); if (loader_impl_initialize(manager, p, impl) != 0) { @@ -1297,9 +1313,12 @@ int loader_impl_load_from_memory(plugin_manager manager, plugin p, loader_impl i return 1; } - init_order = vector_size(impl->handle_impl_init_order); + if (init_order_not_initialized) + { + init_order = vector_size(impl->handle_impl_init_order); - vector_push_back_empty(impl->handle_impl_init_order); + vector_push_back_empty(impl->handle_impl_init_order); + } handle = iface->load_from_memory(impl, name, buffer, size); @@ -1322,7 +1341,10 @@ int loader_impl_load_from_memory(plugin_manager manager, plugin p, loader_impl i { if (loader_impl_handle_register(manager, impl, name, handle_impl, handle_ptr) == 0) { - vector_set_var(impl->handle_impl_init_order, init_order, handle_impl); + if (init_order_not_initialized) + { + vector_set_var(impl->handle_impl_init_order, init_order, handle_impl); + } return 0; } @@ -1334,7 +1356,10 @@ int loader_impl_load_from_memory(plugin_manager manager, plugin p, loader_impl i set_remove(impl->handle_impl_path_map, handle_impl->path); } + if (init_order_not_initialized) { + /* Here we delete all the subsequent loaded scripts because this script can load others, + and once it is destroyed it must clear all of them */ size_t iterator; for (iterator = init_order + 1; iterator < vector_size(impl->handle_impl_init_order); ++iterator) @@ -1354,16 +1379,21 @@ int loader_impl_load_from_memory(plugin_manager manager, plugin p, loader_impl i } else { - size_t iterator; - - for (iterator = init_order + 1; iterator < vector_size(impl->handle_impl_init_order); ++iterator) + if (init_order_not_initialized) { - loader_handle_impl iterator_handle_impl = vector_at_type(impl->handle_impl_init_order, iterator, loader_handle_impl); + /* Here we delete all the subsequent loaded scripts because this script can load others, + and once it is destroyed it must clear all of them */ + size_t iterator; - loader_impl_destroy_handle(iterator_handle_impl); - } + for (iterator = init_order + 1; iterator < vector_size(impl->handle_impl_init_order); ++iterator) + { + loader_handle_impl iterator_handle_impl = vector_at_type(impl->handle_impl_init_order, iterator, loader_handle_impl); + + loader_impl_destroy_handle(iterator_handle_impl); + } - vector_pop_back(impl->handle_impl_init_order); + vector_pop_back(impl->handle_impl_init_order); + } } } } @@ -1377,7 +1407,8 @@ int loader_impl_load_from_package(plugin_manager manager, plugin p, loader_impl { loader_impl_interface iface = loader_iface(p); loader_path subpath; - size_t init_order; + size_t init_order = 0; + int init_order_not_initialized = !(handle_ptr != NULL && *handle_ptr != NULL); if (iface != NULL && loader_impl_handle_name(manager, path, subpath) > 1) { @@ -1395,9 +1426,12 @@ int loader_impl_load_from_package(plugin_manager manager, plugin p, loader_impl return 1; } - init_order = vector_size(impl->handle_impl_init_order); + if (init_order_not_initialized) + { + init_order = vector_size(impl->handle_impl_init_order); - vector_push_back_empty(impl->handle_impl_init_order); + vector_push_back_empty(impl->handle_impl_init_order); + } handle = iface->load_from_package(impl, path); @@ -1420,7 +1454,10 @@ int loader_impl_load_from_package(plugin_manager manager, plugin p, loader_impl { if (loader_impl_handle_register(manager, impl, subpath, handle_impl, handle_ptr) == 0) { - vector_set_var(impl->handle_impl_init_order, init_order, handle_impl); + if (init_order_not_initialized) + { + vector_set_var(impl->handle_impl_init_order, init_order, handle_impl); + } return 0; } @@ -1432,7 +1469,10 @@ int loader_impl_load_from_package(plugin_manager manager, plugin p, loader_impl set_remove(impl->handle_impl_path_map, handle_impl->path); } + if (init_order_not_initialized) { + /* Here we delete all the subsequent loaded scripts because this script can load others, + and once it is destroyed it must clear all of them */ size_t iterator; for (iterator = init_order + 1; iterator < vector_size(impl->handle_impl_init_order); ++iterator) @@ -1452,16 +1492,21 @@ int loader_impl_load_from_package(plugin_manager manager, plugin p, loader_impl } else { - size_t iterator; - - for (iterator = init_order + 1; iterator < vector_size(impl->handle_impl_init_order); ++iterator) + if (init_order_not_initialized) { - loader_handle_impl iterator_handle_impl = vector_at_type(impl->handle_impl_init_order, iterator, loader_handle_impl); + /* Here we delete all the subsequent loaded scripts because this script can load others, + and once it is destroyed it must clear all of them */ + size_t iterator; - loader_impl_destroy_handle(iterator_handle_impl); - } + for (iterator = init_order + 1; iterator < vector_size(impl->handle_impl_init_order); ++iterator) + { + loader_handle_impl iterator_handle_impl = vector_at_type(impl->handle_impl_init_order, iterator, loader_handle_impl); - vector_pop_back(impl->handle_impl_init_order); + loader_impl_destroy_handle(iterator_handle_impl); + } + + vector_pop_back(impl->handle_impl_init_order); + } } } } diff --git a/source/loaders/py_loader/source/py_loader_impl.c b/source/loaders/py_loader/source/py_loader_impl.c index d5a11d618..77fc87016 100644 --- a/source/loaders/py_loader/source/py_loader_impl.c +++ b/source/loaders/py_loader/source/py_loader_impl.c @@ -58,7 +58,7 @@ * and threading flow for improving the debug of memory leaks and async bugs. * Set it to 0 in order to remove all the noise. */ -#define DEBUG_PRINT_ENABLED 1 +#define DEBUG_PRINT_ENABLED 0 typedef struct loader_impl_py_function_type { diff --git a/source/portability/include/portability/portability_path.h b/source/portability/include/portability/portability_path.h index 79ff0761b..38e743fbf 100644 --- a/source/portability/include/portability/portability_path.h +++ b/source/portability/include/portability/portability_path.h @@ -109,9 +109,58 @@ extern "C" { /* -- Methods -- */ -PORTABILITY_API size_t portability_path_get_name(const char *path, size_t path_size, char *name, size_t name_size); +/** + * @brief + * Get the file name portion out of a path and strip away the file extension if any. + * If @path is NULL this will return an empty string. + * If @name is NULL or @name_size is 0 this will return the size it requires in order to write @name. + * If @path or @name are not NULL, then @path_size or @name_size, respectively, must be set to <= the length (including null-terminator) of the memory regions pointed to by @path and @name. + * + * @param[in] path + * The full path to extract the name from. + * + * @param[in] path_size + * The length (including null-terminator) of @path in chars. + * + * @param[out] name + * The memory location to write the extracted name to. If NULL the size required will be returned instead of the size written. + * + * @param[in] name_size + * The size of the memory location pointed to by @name. + * + * @return + * The size of the name. + */ +PORTABILITY_API size_t portability_path_get_name(const char *const path, const size_t path_size, char *const name, const size_t name_size); -PORTABILITY_API size_t portability_path_get_name_canonical(const char *path, size_t path_size, char *name, size_t name_size); +/** + * @brief + * Get the file name portion out of a path and strip away any amount of file extensions. + * When called with `"/foo/bar.baz.qux"`: + * + * - `portability_path_get_name` will produce the string `"bar.baz"` + * - `portability_path_get_name_canonical` will produce the string `"bar"` + * + * If @path is NULL this will return an empty string. + * If @name is NULL or @name_size is 0 this will return the size it requires in order to write @name. + * If @path or @name are not NULL, then @path_size or @name_size, respectively, must be set to <= the length (including null-terminator) of the memory regions pointed to by @path and @name. + * + * @param[in] path + * The full path to extract the name from. + * + * @param[in] path_size + * The length (including null-terminator) of @path in chars. + * + * @param[out] name + * The memory location to write the extracted name to. If NULL the size required will be returned instead of the size written. + * + * @param[in] name_size + * The size of the memory location pointed to by @name. + * + * @return + * The size of the name. + */ +PORTABILITY_API size_t portability_path_get_name_canonical(const char *const path, const size_t path_size, char *const name, const size_t name_size); PORTABILITY_API size_t portability_path_get_fullname(const char *path, size_t path_size, char *name, size_t name_size); diff --git a/source/portability/source/portability_path.c b/source/portability/source/portability_path.c index 9606a7d69..207a9cf29 100644 --- a/source/portability/source/portability_path.c +++ b/source/portability/source/portability_path.c @@ -25,107 +25,136 @@ /* Define separator checking for any platform */ #define PORTABILITY_PATH_SEPARATOR_ALL(chr) (chr == '\\' || chr == '/') -size_t portability_path_get_name(const char *path, size_t path_size, char *name, size_t name_size) +static size_t portability_path_basename_offset(const char *const path, const size_t path_size) { - size_t i, count, last; + size_t offset = path_size; - if (path == NULL || name == NULL) + while (offset > 0 && !PORTABILITY_PATH_SEPARATOR(path[offset - 1])) { - return 0; + --offset; } - for (i = 0, count = 0, last = 0; path[i] != '\0' && i < path_size && count < name_size; ++i) - { - name[count++] = path[i]; + return offset; +} - if (PORTABILITY_PATH_SEPARATOR(path[i])) - { - count = 0; - } - else if (path[i] == '.') +size_t portability_path_get_name(const char *const path, const size_t path_size, char *const name, const size_t name_size) +{ + size_t name_start, rightmost_dot, length, size; + + if (path == NULL) + { + if (name == NULL || name_size == 0) { - if (i > 0 && path[i - 1] == '.') - { - last = 0; - count = 0; - } - else - { - if (count > 0) - { - last = count - 1; - } - else - { - last = 0; - } - } + return 0; } + + name[0] = '\0'; + + return 1; + } + + /* Find rightmost path separator */ + name_start = portability_path_basename_offset(path, path_size); + + /* Find rightmost dot */ + rightmost_dot = path_size; + + while (rightmost_dot != name_start && path[rightmost_dot - 1] != '.') + { + --rightmost_dot; } - if ((last == 0 && count > 1) || last > count) + /* No dots found, or name starts with dot and is non-empty, use whole name */ + if (rightmost_dot == name_start || (rightmost_dot == name_start + 1 && rightmost_dot != path_size - 1)) { - last = count; + rightmost_dot = path_size - 1; } - name[last] = '\0'; + /* Remove all consecutive dots at the end */ + while (rightmost_dot != name_start && path[rightmost_dot - 1] == '.') + { + --rightmost_dot; + } - return last + 1; + length = rightmost_dot - name_start; + size = length + 1; + + /* Return required size */ + if (name == NULL || size > name_size) + { + return size; + } + + if (length > 0) + { + memcpy(name, path + name_start, length); + } + + name[length] = '\0'; + + return size; } -size_t portability_path_get_name_canonical(const char *path, size_t path_size, char *name, size_t name_size) +size_t portability_path_get_name_canonical(const char *const path, const size_t path_size, char *const name, const size_t name_size) { - if (path == NULL || name == NULL) + size_t name_start, leftmost_dot, length, size; + + if (path == NULL) { - return 0; + if (name == NULL || name_size == 0) + { + return 0; + } + + name[0] = '\0'; + + return 1; } - size_t i, count, last; + /* Find rightmost path separator */ + name_start = portability_path_basename_offset(path, path_size); + + /* Find leftmost dot */ + leftmost_dot = name_start; - for (i = 0, count = 0, last = 0; path[i] != '\0' && i < path_size && count < name_size; ++i) + while (leftmost_dot < path_size && path[leftmost_dot] != '.') { - name[count++] = path[i]; + ++leftmost_dot; + } - if (PORTABILITY_PATH_SEPARATOR(path[i])) - { - count = 0; - } - else if (path[i] == '.') + /* No dots found, use whole name */ + if (leftmost_dot == path_size) + { + --leftmost_dot; + } + + /* Name starts with dot, use the following dot instead */ + if (leftmost_dot == name_start) + { + do { - if (i > 0 && path[i - 1] == '.') - { - last = 0; - count = 0; - } - else - { - if (count > 0) - { - last = count - 1; - } - else - { - last = 0; - } + ++leftmost_dot; - /* This function is the same as portability_path_get_name but - returns the name of the file without any extension, for example: - - portability_path_get_name of libnode.so.72 is libnode.so - - portability_path_get_name_canonical of libnode.so.72 is libnode - */ - break; - } - } + } while (leftmost_dot < path_size && path[leftmost_dot] != '.'); + } + + length = leftmost_dot - name_start; + size = length + 1; + + /* Return required size */ + if (name == NULL || size > name_size) + { + return size; } - if (last == 0 && count > 1) + if (length > 0) { - last = count; + memcpy(name, path + name_start, length); } - name[last] = '\0'; + name[length] = '\0'; - return last + 1; + return size; } size_t portability_path_get_fullname(const char *path, size_t path_size, char *name, size_t name_size) diff --git a/source/ports/cxx_port/CMakeLists.txt b/source/ports/cxx_port/CMakeLists.txt index bc450a068..13657ce94 100644 --- a/source/ports/cxx_port/CMakeLists.txt +++ b/source/ports/cxx_port/CMakeLists.txt @@ -9,17 +9,14 @@ endif() # Target name set(target cxx_port) -string(TOLOWER ${META_PROJECT_NAME} target_name) - -set(target_export "${META_PROJECT_NAME}-cxx") # Exit here if required dependencies are not met message(STATUS "Port ${target}") # Set API export file and macro -string(TOUPPER ${target_name} target_name_upper) -set(export_file "include/${target_name}/${target_name}_api.hpp") -set(export_macro "${target_name_upper}_API") +string(TOUPPER ${target} target_upper) +set(export_file "include/${target}/${target}_api.h") +set(export_macro "${target_upper}_API") # # Compiler warnings @@ -37,30 +34,29 @@ include(SecurityFlags) # Sources # -set(inline_path "${CMAKE_CURRENT_SOURCE_DIR}/inline/${target_name}") -set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target_name}") +set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/metacall") set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source") -set(inlines - ${inline_path}/metacall.inl -) - set(headers ${include_path}/metacall.hpp ) +set(inline + ${include_path}/metacall.inl +) + set(sources ${source_path}/metacall.cpp ) # Group source files -set(inline_group "Inline Files") set(header_group "Header Files (API)") +set(inline_group "Inline Files") set(source_group "Source Files") -source_group_by_path(${inline_path} "\\\\.inl$" - ${inline_group} ${inlines}) source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$" ${header_group} ${headers}) +source_group_by_path(${include_path} "\\\\.inl$" + ${inline_group} ${inlines}) source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$" ${source_group} ${sources}) @@ -70,16 +66,16 @@ source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$" # Build library add_library(${target} - ${inlines} ${sources} ${headers} + ${inline} ) # Create namespaced alias add_library(${META_PROJECT_NAME}::${target} ALIAS ${target}) # Export library for downstream projects -export(TARGETS ${target} NAMESPACE ${META_PROJECT_NAME}:: FILE ${PROJECT_BINARY_DIR}/cmake/${target_name}/${target_export}-export.cmake) +export(TARGETS ${target} NAMESPACE ${META_PROJECT_NAME}:: FILE ${PROJECT_BINARY_DIR}/cmake/${target}/${target}-export.cmake) # Create API export header generate_export_header(${target} @@ -100,12 +96,12 @@ set_target_properties(${target} # # Include directories # + target_include_directories(${target} PRIVATE ${PROJECT_BINARY_DIR}/source/include ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/inline PUBLIC ${DEFAULT_INCLUDE_DIRECTORIES} @@ -116,15 +112,31 @@ target_include_directories(${target} $ ) +# +# Libraries +# + +target_link_libraries(${target} + PRIVATE + ${META_PROJECT_NAME}::metacall + + PUBLIC + ${DEFAULT_LIBRARIES} + + INTERFACE + ${META_PROJECT_NAME}::metacall +) + # # Compile definitions # target_compile_definitions(${target} PRIVATE + ${target_upper}_EXPORTS # Export API PUBLIC - $<$>:${target_name_upper}_STATIC_DEFINE> + $<$>:${target_upper}_STATIC_DEFINE> ${DEFAULT_COMPILE_DEFINITIONS} INTERFACE @@ -143,6 +155,15 @@ target_compile_options(${target} INTERFACE ) +# +# Compile features +# + +target_compile_features(${target} + PRIVATE + cxx_std_17 +) + # # Linker options # @@ -160,67 +181,8 @@ target_link_options(${target} # Deployment # -# Library -install(TARGETS ${target} - EXPORT "${target_export}-export" COMPONENT dev - RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT runtime - LIBRARY DESTINATION ${INSTALL_SHARED} COMPONENT runtime - ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT dev -) - -# Inline files -install(DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR}/inline/${target_name} DESTINATION ${INSTALL_INCLUDE} - COMPONENT dev -) - # Header files install(DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR}/include/${target_name} DESTINATION ${INSTALL_INCLUDE} - COMPONENT dev -) - -# Generated header files -install(DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR}/include/${target_name} DESTINATION ${INSTALL_INCLUDE} + ${CMAKE_CURRENT_SOURCE_DIR}/include/metacall DESTINATION ${INSTALL_INCLUDE} COMPONENT dev ) - -# CMake config -install(EXPORT ${target_export}-export - NAMESPACE ${META_PROJECT_NAME}:: - DESTINATION ${INSTALL_CMAKE}/${target_name} - COMPONENT dev -) - -# TODO - -# # -# # Configure test -# # - -# set(metacall_cxx_test "${target}_test") -# set(metacall_cxx_test_path "${CMAKE_CURRENT_BINARY_DIR}/${metacall_cxx_test}.cpp") - -# # -# # Define test -# # - -# add_test(NAME ${metacall_cxx_test} -# COMMAND $ -# ) - -# # -# # Define test labels -# # - -# set_property(TEST ${metacall_cxx_test} -# PROPERTY LABELS ${metacall_cxx_test} -# ) - -# include(TestEnvironmentVariables) - -# test_environment_variables(${metacall_cxx_test} -# "" -# ${TESTS_ENVIRONMENT_VARIABLES} -# ) diff --git a/source/ports/cxx_port/include/metacall/metacall.hpp b/source/ports/cxx_port/include/metacall/metacall.hpp index 7995efa3e..593b472ea 100644 --- a/source/ports/cxx_port/include/metacall/metacall.hpp +++ b/source/ports/cxx_port/include/metacall/metacall.hpp @@ -23,17 +23,568 @@ /* -- Headers -- */ -#include - +#include +#include +#include +#include #include +#include +#include namespace metacall { -template -METACALL_API int metacall(std::string name, Ts... ts); +#include + +class value_base +{ +public: + // Non-copyable, but movable + value_base(const value_base &) = delete; + value_base &operator=(const value_base &) = delete; + + value_base(value_base &&) noexcept = default; + value_base &operator=(value_base &&) noexcept = default; + + // Access the raw value + void *to_raw() const + { + return value_ptr.get(); + } + +protected: + std::unique_ptr value_ptr; + + explicit value_base(void *value_ptr, void (*destructor)(void *) = &metacall_value_destroy) : + value_ptr(value_ptr, destructor) {} + + static void noop_destructor(void *) {} +}; + +template +class value : public value_base +{ +public: + explicit value(const T &v, void (*destructor)(void *) = &metacall_value_destroy) : + value_base(create(v), destructor) + { + if (value_ptr == nullptr) + { + throw std::runtime_error("Failed to create MetaCall value"); + } + } + + explicit value(void *value_ptr, void (*destructor)(void *) = &value_base::noop_destructor) : + value_base(value_ptr, destructor) + { + if (metacall_value_id(value_ptr) != id()) + { + throw std::runtime_error("Failed to create MetaCall value, the received MetaCall value type does not match with the value class type"); + } + } + + T to_value() const + { + throw std::runtime_error("Unsupported MetaCall value"); + } + + // Type-specific creation (calls specialized version below) + static void *create(const T &v); + + // Type-specific type id + static enum metacall_value_id id(); +}; + +template <> +inline void *value::create(const bool &v) +{ + return metacall_value_create_bool(v); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_BOOL; +} + +template <> +inline bool value::to_value() const +{ + return metacall_value_to_bool(value_ptr.get()); +} + +template <> +inline void *value::create(const char &v) +{ + return metacall_value_create_char(v); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_CHAR; +} + +template <> +inline char value::to_value() const +{ + return metacall_value_to_char(value_ptr.get()); +} + +template <> +inline void *value::create(const short &v) +{ + return metacall_value_create_short(v); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_SHORT; +} + +template <> +inline short value::to_value() const +{ + return metacall_value_to_short(value_ptr.get()); +} + +template <> +inline void *value::create(const int &v) +{ + return metacall_value_create_int(v); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_INT; +} + +template <> +inline int value::to_value() const +{ + return metacall_value_to_int(value_ptr.get()); +} + +template <> +inline void *value::create(const long &v) +{ + return metacall_value_create_long(v); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_LONG; +} + +template <> +inline long value::to_value() const +{ + return metacall_value_to_long(value_ptr.get()); +} + +template <> +inline void *value::create(const float &v) +{ + return metacall_value_create_float(v); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_FLOAT; +} + +template <> +inline float value::to_value() const +{ + return metacall_value_to_float(value_ptr.get()); +} + +template <> +inline void *value::create(const double &v) +{ + return metacall_value_create_double(v); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_DOUBLE; +} + +template <> +inline double value::to_value() const +{ + return metacall_value_to_double(value_ptr.get()); +} + +template <> +inline void *value::create(const std::string &v) +{ + return metacall_value_create_string(v.c_str(), v.size()); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_STRING; +} + +template <> +inline std::string value::to_value() const +{ + return metacall_value_to_string(value_ptr.get()); +} + +template <> +inline void *value::create(const char *const &v) +{ + return metacall_value_create_string(v, std::strlen(v)); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_STRING; +} + +template <> +inline const char *value::to_value() const +{ + return metacall_value_to_string(value_ptr.get()); +} + +template <> +inline void *value>::create(const std::vector &v) +{ + return metacall_value_create_buffer(v.data(), v.size()); +} + +template <> +inline enum metacall_value_id value>::id() +{ + return METACALL_BUFFER; +} + +template <> +inline std::vector value>::to_value() const +{ + void *ptr = value_ptr.get(); + char *buffer = static_cast(metacall_value_to_buffer(ptr)); + std::vector buffer_vector(buffer, buffer + metacall_value_count(ptr)); + + return buffer_vector; +} + +template <> +inline void *value>::create(const std::vector &v) +{ + return metacall_value_create_buffer(v.data(), v.size()); +} + +template <> +inline enum metacall_value_id value>::id() +{ + return METACALL_BUFFER; +} + +template <> +inline std::vector value>::to_value() const +{ + void *ptr = value_ptr.get(); + unsigned char *buffer = static_cast(metacall_value_to_buffer(ptr)); + std::vector buffer_vector(buffer, buffer + metacall_value_count(ptr)); + + return buffer_vector; +} + +template <> +inline void *value::create(void *const &v) +{ + return metacall_value_create_ptr(v); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_PTR; +} + +template <> +inline void *value::to_value() const +{ + return metacall_value_to_ptr(value_ptr.get()); +} + +template <> +inline void *value::create(const std::nullptr_t &) +{ + return metacall_value_create_null(); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_NULL; +} + +template <> +inline std::nullptr_t value::to_value() const +{ + return nullptr; +} + +// TODO: Future, Function, Class, Object, Exception, Throwable... + +class value_ref +{ +public: + explicit value_ref(void *ptr) : + ptr(ptr) {} + + template + T as() const + { + return value(ptr).to_value(); + } + +private: + void *ptr; +}; + +class array : public value_base +{ +public: + template + explicit array(Args &&...args) : + value_base(create(std::forward(args)...), &metacall_value_destroy) + { + if (value_ptr == nullptr) + { + throw std::runtime_error("Failed to create MetaCall array"); + } + } + + explicit array(void *array_value) : + value_base(array_value, &value_base::noop_destructor) {} + + void **to_value() const + { + void **array_ptr = metacall_value_to_array(value_ptr.get()); + + if (array_ptr == NULL) + { + throw std::runtime_error("Invalid MetaCall array"); + } + + return array_ptr; + } + + template + T get(std::size_t index) const + { + void **array_ptr = to_value(); + + return value(array_ptr[index]).to_value(); + } + + value_ref operator[](std::size_t index) const + { + void **array_ptr = to_value(); + + return value_ref(array_ptr[index]); + } + + static enum metacall_value_id id() + { + return METACALL_ARRAY; + } + +private: + // Recursive function to create and fill the MetaCall array + template + static void *create(Args &&...args) + { + constexpr std::size_t size = sizeof...(Args); + + // Create the array with null data initially + void *array_value = metacall_value_create_array(NULL, size); + + if (array_value == NULL) + { + throw std::runtime_error("Failed to create MetaCall value array"); + } + + // Get the internal C array + void **array_ptr = metacall_value_to_array(array_value); + + // Helper to unpack the args into array + create_array(array_ptr, 0, std::forward(args)...); + + return array_value; + } + + // Recursive unpacking using fold expression (C++17+) + template + static void create_array(void **array_ptr, std::size_t index, Args &&...args) + { + // Use initializer list trick to expand the pack + (( + array_ptr[index++] = value>::create(std::forward(args))), + ...); + } +}; + +template <> +inline void *value::create(const array &v) +{ + return metacall_value_copy(v.to_raw()); +} + +template <> +inline enum metacall_value_id value::id() +{ + return METACALL_ARRAY; +} + +template <> +inline array value::to_value() const +{ + return array(to_raw()); +} + +template +class map : public value_base +{ +public: + using pair_type = std::pair; + using pair_value_type = std::pair, value>; + + map(std::initializer_list list) : + value_base(metacall_value_create_map(NULL, list.size())) + { + if (value_ptr == nullptr) + { + throw std::runtime_error("Failed to create MetaCall map value"); + } + + void **map_array = metacall_value_to_map(value_ptr.get()); + size_t index = 0; + + for (const auto &pair : list) + { + void *tuple = metacall_value_create_array(nullptr, 2); + void **tuple_array = metacall_value_to_array(tuple); + + // Create the pair + auto value_pair = std::make_pair(value(pair.first, &value_base::noop_destructor), value(pair.second, &value_base::noop_destructor)); + + // Insert into metacall value map + tuple_array[0] = value_pair.first.to_raw(); + tuple_array[1] = value_pair.second.to_raw(); + + map_array[index++] = tuple; + + // Store into the map + m.emplace(pair.first, std::move(value_pair)); + } + } + + explicit map(void *value_ptr) : + value_base(value_ptr, &value_base::noop_destructor) + { + if (metacall_value_id(value_ptr) != METACALL_MAP) + { + throw std::runtime_error("MetaCall map initialized with a MetaCall value which is not of type map"); + } + + rehash(); + } + + V operator[](const K &key) const + { + return m.at(key).second.to_value(); + } + + static enum metacall_value_id id() + { + return METACALL_MAP; + } + +protected: + void rehash() + { + void *ptr = value_ptr.get(); + void **map_array = metacall_value_to_map(ptr); + const size_t size = metacall_value_count(ptr); + + m.clear(); + + for (size_t index = 0; index < size; ++index) + { + void **tuple_array = metacall_value_to_array(map_array[index]); + + // Create the values + auto pair = std::make_pair(value(tuple_array[0]), value(tuple_array[1])); + + // Store into the map + m.emplace(pair.first.to_value(), std::move(pair)); + } + } + +private: + std::unordered_map m; +}; + +namespace detail +{ +template +constexpr bool is_value_base = std::is_base_of_v>>; + +template +value_base to_value_base(T &&arg) +{ + if constexpr (is_value_base) + { + return std::move(arg); + } + else + { + return value>(std::forward(arg)); + } +} + +} /* namespace detail */ + +template +Ret metacall(std::string name, Args &&...args) +{ + constexpr std::size_t size = sizeof...(Args); + std::array value_args = { { detail::to_value_base(std::forward(args))... } }; + void *raw_args[size]; + + for (std::size_t i = 0; i < size; ++i) + { + raw_args[i] = value_args[i].to_raw(); + } + + void *ret = metacallv_s(name.c_str(), raw_args, size); + + if (ret == NULL) + { + throw std::runtime_error("MetaCall invokation to '" + name + "' has failed by returning NULL"); + } + + value result(ret, &metacall_value_destroy); + + return result.to_value(); +} } /* namespace metacall */ +// TODO: Move implementations to metacall.inl #include #endif /* METACALL_HPP */ diff --git a/source/ports/cxx_port/inline/metacall/metacall.inl b/source/ports/cxx_port/include/metacall/metacall.inl similarity index 82% rename from source/ports/cxx_port/inline/metacall/metacall.inl rename to source/ports/cxx_port/include/metacall/metacall.inl index 7789dff86..9a36cec3a 100644 --- a/source/ports/cxx_port/inline/metacall/metacall.inl +++ b/source/ports/cxx_port/include/metacall/metacall.inl @@ -1,40 +1,30 @@ -/* - * Format Library by Parra Studios - * A cross-platform library for supporting formatted input / output. - * - * Copyright (C) 2016 - 2025 Vicente Eduardo Ferrer Garcia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef METACALL_INL -#define METACALL_INL 1 - -/* -- Headers -- */ - -#include - -#include - -namespace metacall -{ -template -METACALL_API int metacall(std::string name, Ts... ts) -{ - return 0; -} - -} /* namespace metacall */ - -#endif /* METACALL_INL */ +/* + * Format Library by Parra Studios + * A cross-platform library for supporting formatted input / output. + * + * Copyright (C) 2016 - 2025 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef METACALL_INL +#define METACALL_INL 1 + +/* -- Headers -- */ + +namespace metacall +{ +} /* namespace metacall */ + +#endif /* METACALL_INL */ diff --git a/source/ports/rs_port/.vscode/launch.json b/source/ports/rs_port/.vscode/launch.json index 684cfc347..838674c31 100644 --- a/source/ports/rs_port/.vscode/launch.json +++ b/source/ports/rs_port/.vscode/launch.json @@ -103,6 +103,26 @@ "args": [], "envFile": "${workspaceFolder}${/}.vscode${/}.env", "cwd": "${workspaceFolder}" - } + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'metacall_handle_test'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=metacall_handle_test", + "--package=metacall" + ], + "filter": { + "name": "metacall_handle_test", + "kind": "test" + } + }, + "args": [], + "envFile": "${workspaceFolder}${/}.vscode${/}.env", + "cwd": "${workspaceFolder}" + }, ] } \ No newline at end of file diff --git a/source/ports/rs_port/Cargo.toml b/source/ports/rs_port/Cargo.toml index 4779e08f0..51428b033 100644 --- a/source/ports/rs_port/Cargo.toml +++ b/source/ports/rs_port/Cargo.toml @@ -7,7 +7,7 @@ license = "Apache-2.0" name = "metacall" readme = "README.md" repository = "https://github.com/metacall/core/tree/develop/source/ports/rs_port" -version = "0.4.4" +version = "0.5.4" [lib] crate-type = ["lib"] @@ -17,4 +17,13 @@ name = "metacall" path = "src/lib.rs" [dependencies] -metacall-inline = { path = "./inline", version = "0.2.0" } +metacall-inline = { version = "0.2.0", path = "./inline" } + +[build-dependencies] +metacall-sys = { version = "0.1.2", path = "./sys" } + +[workspace] +members = [ + "inline", + "sys", +] diff --git a/source/ports/rs_port/README.md b/source/ports/rs_port/README.md index 06f77ab06..1cce7dd4b 100644 --- a/source/ports/rs_port/README.md +++ b/source/ports/rs_port/README.md @@ -15,6 +15,24 @@ MetaCall is a C plugin based library. This crate wraps the C library into Rust, curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | sh ``` +# Linking + +If your project uses MetaCall in a folder that is not in the system path, we encourage to use [`metacall-sys`](https://crates.io/crates/metacall-sys) crate as a [`build-dependecy`](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#build-dependencies). By this way you will be able to locate and link MetaCall directly in your build system. For example: + +`Cargo.toml`: +```toml +[build-dependencies] +metacall-sys = "0.1.2" +``` + +`build.rs`: +```rust +fn main() { + // Find MetaCall library + metacall_sys::build(); +} +``` + # Example `sum.ts` @@ -26,14 +44,14 @@ export function sum(a: number, b: number): number { `main.rs` ``` rust -use metacall::{switch, metacall, loaders}; +use metacall::{initialize, metacall, load}; fn main() { // Initialize MetaCall at the top - let _metacall = switch::initialize().unwrap(); + let _metacall = initialize().unwrap(); // Load the file - load::from_single_file("ts", "sum.ts").unwrap(); + load::from_single_file(load::Tag::TypeScript, "sum.ts").unwrap(); // Call the sum function let sum = metacall::("sum", [1.0, 2.0]).unwrap(); diff --git a/source/ports/rs_port/build.rs b/source/ports/rs_port/build.rs index 3ad13b15d..efb09e8f6 100644 --- a/source/ports/rs_port/build.rs +++ b/source/ports/rs_port/build.rs @@ -1,232 +1,4 @@ -use std::{ - env, fs, - path::{Path, PathBuf}, - vec, -}; - -// Search for MetaCall libraries in platform-specific locations -// Handle custom installation paths via environment variables -// Find configuration files recursively -// Provide helpful error messages when things aren't found - -/// Represents the install paths for a platform -struct InstallPath { - paths: Vec, - names: Vec<&'static str>, -} - -/// Represents the match of a library when it's found -struct LibraryPath { - path: PathBuf, - library: String, -} - -/// Find files recursively in a directory matching a pattern -fn find_files_recursively>( - root_dir: P, - filename: &str, - max_depth: Option, -) -> Result, Box> { - let mut matches = Vec::new(); - let mut stack = vec![(root_dir.as_ref().to_path_buf(), 0)]; - - while let Some((current_dir, depth)) = stack.pop() { - if let Some(max) = max_depth { - if depth > max { - continue; - } - } - - if let Ok(entries) = fs::read_dir(¤t_dir) { - for entry in entries.flatten() { - let path = entry.path(); - - if path.is_file() { - // Simple filename comparison instead of regex - if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) { - if file_name == filename { - matches.push(path); - } - } - } else if path.is_dir() { - stack.push((path, depth + 1)); - } - } - } - } - - Ok(matches) -} - -fn platform_install_paths() -> Result> { - if cfg!(target_os = "windows") { - // Defaults to path: C:\Users\Default\AppData\Local - let local_app_data = env::var("LOCALAPPDATA") - .unwrap_or_else(|_| String::from("C:\\Users\\Default\\AppData\\Local")); - - Ok(InstallPath { - paths: vec![PathBuf::from(local_app_data) - .join("MetaCall") - .join("metacall")], - names: vec!["metacall.lib"], - }) - } else if cfg!(target_os = "macos") { - Ok(InstallPath { - paths: vec![ - PathBuf::from("/opt/homebrew/lib/"), - PathBuf::from("/usr/local/lib/"), - ], - names: vec!["libmetacall.dylib"], - }) - } else if cfg!(target_os = "linux") { - Ok(InstallPath { - paths: vec![PathBuf::from("/usr/local/lib/"), PathBuf::from("/gnu/lib/")], - names: vec!["libmetacall.so"], - }) - } else { - Err(format!("Platform {} not supported", env::consts::OS).into()) - } -} - -/// Get search paths, checking for custom installation path first -fn get_search_config() -> Result> { - // First, check if user specified a custom path - if let Ok(custom_path) = env::var("METACALL_INSTALL_PATH") { - // For custom paths, we need to search for any metacall library variant - return Ok(InstallPath { - paths: vec![PathBuf::from(custom_path)], - names: vec![ - "libmetacall.so", - "libmetacalld.so", - "libmetacall.dylib", - "libmetacalld.dylib", - "metacall.lib", - "metacalld.lib", - ], - }); - } - - // Fall back to platform-specific paths - platform_install_paths() -} - -/// Get the parent path and library name -fn get_parent_and_library(path: &Path) -> Option<(PathBuf, String)> { - let parent = path.parent()?.to_path_buf(); - - // Get the file stem (filename without extension) - let stem = path.file_stem()?.to_str()?; - - // Remove "lib" prefix if present - let cleaned_stem = stem.strip_prefix("lib").unwrap_or(stem).to_string(); - - Some((parent, cleaned_stem)) -} - -/// Find the MetaCall library -/// This orchestrates the search process -fn find_metacall_library() -> Result> { - let search_config = get_search_config()?; - - // Search in each configured path - for search_path in &search_config.paths { - for name in &search_config.names { - // Search with no limit in depth - match find_files_recursively(search_path, name, None) { - Ok(files) if !files.is_empty() => { - let found_lib = fs::canonicalize(&files[0])?; - - match get_parent_and_library(&found_lib) { - Some((parent, name)) => { - return Ok(LibraryPath { - path: parent, - library: name, - }) - } - None => continue, - }; - } - Ok(_) => { - // No files found in this path, continue searching - continue; - } - Err(e) => { - eprintln!("Error searching in {}: {}", search_path.display(), e); - continue; - } - } - } - } - - // If we get here, library wasn't found - let search_paths: Vec = search_config - .paths - .iter() - .map(|p| p.display().to_string()) - .collect(); - - Err(format!( - "MetaCall library not found. Searched in: {}. \ - If you have it installed elsewhere, set METACALL_INSTALL_PATH environment variable.", - search_paths.join(", ") - ) - .into()) -} - fn main() { - // When running tests from CMake - if let Ok(val) = env::var("PROJECT_OUTPUT_DIR") { - // Link search path to build folder - println!("cargo:rustc-link-search=native={val}"); - - // Link against correct version of metacall - match env::var("CMAKE_BUILD_TYPE") { - Ok(val) => { - if val == "Debug" { - // Try to link the debug version when running tests - println!("cargo:rustc-link-lib=dylib=metacalld"); - } else { - println!("cargo:rustc-link-lib=dylib=metacall"); - } - } - Err(_) => { - println!("cargo:rustc-link-lib=dylib=metacall"); - } - } - } else { - // When building from Cargo, try to find MetaCall - match find_metacall_library() { - Ok(lib_path) => { - // Define linker flags - println!("cargo:rustc-link-search=native={}", lib_path.path.display()); - println!("cargo:rustc-link-lib=dylib={}", lib_path.library); - - // Set the runtime environment variable for finding the library during tests - #[cfg(target_os = "linux")] - println!( - "cargo:rustc-env=LD_LIBRARY_PATH={}", - lib_path.path.display() - ); - - #[cfg(target_os = "macos")] - println!( - "cargo:rustc-env=DYLD_LIBRARY_PATH={}", - lib_path.path.display() - ); - - #[cfg(target_os = "windows")] - println!("cargo:rustc-env=PATH={}", lib_path.path.display()); - } - Err(e) => { - // Print the error - eprintln!( - "Failed to find MetaCall library with: {e} \ - Still trying to link in case the library is in system paths" - ); - - // Still try to link in case the library is in system paths - println!("cargo:rustc-link-lib=dylib=metacall") - } - } - } + // Find MetaCall library + metacall_sys::build(); } diff --git a/source/ports/rs_port/inline/src/lib.rs b/source/ports/rs_port/inline/src/lib.rs index bb9358d5a..094386890 100644 --- a/source/ports/rs_port/inline/src/lib.rs +++ b/source/ports/rs_port/inline/src/lib.rs @@ -2,7 +2,7 @@ use proc_macro::TokenStream; use quote::quote; macro_rules! gen_inline_macro { - ($($name:ident),*) => ( + ($($name:ident => $tag:ident),*) => ( $( #[proc_macro] pub fn $name(input: TokenStream) -> TokenStream { @@ -10,7 +10,7 @@ macro_rules! gen_inline_macro { let buffer = token_stream_input.to_string(); let result = quote! {{ - ::metacall::load::from_memory(stringify!($name), #buffer.to_string()).unwrap() + ::metacall::load::from_memory(::metacall::load::Tag::$tag, #buffer.to_string(), None).unwrap() }}; result.into() @@ -19,4 +19,14 @@ macro_rules! gen_inline_macro { ) } -gen_inline_macro!(py, node, ts, cs, rb, cob, rpc, java, wasm); +gen_inline_macro!( + py => Python, + node => NodeJS, + ts => TypeScript, + cs => CSharp, + rb => Ruby, + cob => Cobol, + rpc => RPC, + java => Java, + wasm => Wasm +); diff --git a/source/ports/rs_port/src/bindings.rs b/source/ports/rs_port/src/bindings.rs index 7222ae744..04c9be017 100644 --- a/source/ports/rs_port/src/bindings.rs +++ b/source/ports/rs_port/src/bindings.rs @@ -1,3 +1,1440 @@ /* automatically generated by rust-bindgen 0.71.1 */ -pub type __pid_t = :: std :: os :: raw :: c_int ; pub type pid_t = __pid_t ; # [repr (u32)] # [derive (Debug , Copy , Clone , Hash , PartialEq , Eq)] pub enum metacall_allocator_id { METACALL_ALLOCATOR_STD = 0 , METACALL_ALLOCATOR_NGINX = 1 , } unsafe extern "C" { # [doc = " @brief\n Create an allocator instance\n\n @param[in] allocator_id\n Type of allocator to be created\n\n @param[in] ctx\n Context of the allocator\n\n @return\n Pointer to allocator if success, null otherwise"] pub fn metacall_allocator_create (allocator_id : metacall_allocator_id , ctx : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Reserve memory from an allocator instance\n\n @param[in] allocator\n Pointer to allocator instance\n\n @param[in] size\n Size in bytes to be allocated\n\n @return\n Pointer to allocated data on success, null otherwise"] pub fn metacall_allocator_alloc (allocator : * mut :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Reallocate memory from an allocator instance\n\n @param[in] allocator\n Pointer to allocator instance\n\n @param[in] data\n Original pointer to data\n\n @param[in] size\n Original size in bytes\n\n @param[in] new_size\n New size in bytes to be reallocated\n\n @return\n Pointer to new reallocated data on success, null otherwise"] pub fn metacall_allocator_realloc (allocator : * mut :: std :: os :: raw :: c_void , data : * mut :: std :: os :: raw :: c_void , size : usize , new_size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Free memory from an allocator instance\n\n @param[in] allocator\n Pointer to allocator instance\n\n @param[in] data\n Pointer to data to be freed"] pub fn metacall_allocator_free (allocator : * mut :: std :: os :: raw :: c_void , data : * mut :: std :: os :: raw :: c_void) ; } unsafe extern "C" { # [doc = " @brief\n Destroy an allocator instance\n\n @param[in] allocator\n Pointer to allocator instance"] pub fn metacall_allocator_destroy (allocator : * mut :: std :: os :: raw :: c_void) ; } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct metacall_exception_type { pub message : * const :: std :: os :: raw :: c_char , pub label : * const :: std :: os :: raw :: c_char , pub code : i64 , pub stacktrace : * const :: std :: os :: raw :: c_char , } # [allow (clippy :: unnecessary_operation , clippy :: identity_op)] const _ : () = { ["Size of metacall_exception_type"] [:: std :: mem :: size_of :: < metacall_exception_type > () - 32usize] ; ["Alignment of metacall_exception_type"] [:: std :: mem :: align_of :: < metacall_exception_type > () - 8usize] ; ["Offset of field: metacall_exception_type::message"] [:: std :: mem :: offset_of ! (metacall_exception_type , message) - 0usize] ; ["Offset of field: metacall_exception_type::label"] [:: std :: mem :: offset_of ! (metacall_exception_type , label) - 8usize] ; ["Offset of field: metacall_exception_type::code"] [:: std :: mem :: offset_of ! (metacall_exception_type , code) - 16usize] ; ["Offset of field: metacall_exception_type::stacktrace"] [:: std :: mem :: offset_of ! (metacall_exception_type , stacktrace) - 24usize] ; } ; pub type metacall_exception = * mut metacall_exception_type ; unsafe extern "C" { # [doc = " @brief\n Create an throwable value from an exception with a simple API in a single instruction\n\n @param[in] label\n Label of the exception\n\n @param[in] code\n Error code of the exception\n\n @param[in] stacktrace\n Stack trace of the exception\n\n @param[in] message\n Message of the exception to be formatted with the variable arguments\n\n @param[in] va_args\n Arguments for formatting the message\n\n @return\n The value of type throwable containing the exception created"] pub fn metacall_error_throw (label : * const :: std :: os :: raw :: c_char , code : i64 , stacktrace : * const :: std :: os :: raw :: c_char , message : * const :: std :: os :: raw :: c_char , ...) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Retrieve the exception from a value, it can be either a throwable value with an exception inside or an exception itself\n\n @param[in] v\n Value that represents the exception to be retrieved\n\n @param[out] ex\n Exception that will be used as out parameter, the lifetime of the struct fields is attached to @v\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_error_from_value (v : * mut :: std :: os :: raw :: c_void , ex : metacall_exception) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Retrieve last error that has happened after a call to any API from MetaCall\n\n @param[out] ex\n Exception that will be used as out parameter, the lifetime of the struct fields is attached to the internal MetaCall exception\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_error_last (ex : metacall_exception) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Clear last error that has happened after a call to any API from MetaCall"] pub fn metacall_error_clear () ; } unsafe extern "C" { # [doc = " @brief\n Initialize link detours and allocate shared memory\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_link_initialize () -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Register a function pointer in order to allow function\n interposition when loading a library, if you register a\n function @symbol called 'foo', when you try to dlsym (or the equivalent\n on every platform), you will get the pointer to @fn, even if\n the symbol does not exist in the library, it will work.\n Function interposition is required in order to hook into runtimes\n and dynamically interpose our functions.\n\n @param[in] tag\n Name of the loader which the @library belongs to\n\n @param[in] library\n Name of the library that is going to be hooked\n\n @param[in] symbol\n Name of the function to be interposed\n\n @param[in] fn\n Function pointer that will be returned by dlsym (or equivalent) when accessing to @symbol\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_link_register (tag : * const :: std :: os :: raw :: c_char , library : * const :: std :: os :: raw :: c_char , symbol : * const :: std :: os :: raw :: c_char , fn_ : :: std :: option :: Option < unsafe extern "C" fn () >) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Register a function pointer in order to allow function\n interposition when loading a library, if you register a\n function @symbol called 'foo', when you try to dlsym (or the equivalent\n on every platform), you will get the pointer to @fn, even if\n the symbol does not exist in the library, it will work.\n Function interposition is required in order to hook into runtimes\n and dynamically interpose our functions.\n\n @param[in] loader\n Pointer to the loader which the @library belongs to\n\n @param[in] library\n Name of the library that is going to be hooked\n\n @param[in] symbol\n Name of the function to be interposed\n\n @param[in] fn\n Function pointer that will be returned by dlsym (or equivalent) when accessing to @symbol\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_link_register_loader (loader : * mut :: std :: os :: raw :: c_void , library : * const :: std :: os :: raw :: c_char , symbol : * const :: std :: os :: raw :: c_char , fn_ : :: std :: option :: Option < unsafe extern "C" fn () >) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Remove the hook previously registered\n\n @param[in] tag\n Name of the loader which the @library belongs to\n\n @param[in] library\n Name of the library that is going to be hooked\n\n @param[in] symbol\n Name of the function to be interposed\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_link_unregister (tag : * const :: std :: os :: raw :: c_char , library : * const :: std :: os :: raw :: c_char , symbol : * const :: std :: os :: raw :: c_char) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Unregister link detours and destroy shared memory"] pub fn metacall_link_destroy () ; } # [repr (u32)] # [derive (Debug , Copy , Clone , Hash , PartialEq , Eq)] pub enum metacall_log_id { METACALL_LOG_STDIO = 0 , METACALL_LOG_FILE = 1 , METACALL_LOG_SOCKET = 2 , METACALL_LOG_SYSLOG = 3 , METACALL_LOG_NGINX = 4 , METACALL_LOG_CUSTOM = 5 , } unsafe extern "C" { # [doc = " @brief\n Create a log instance\n\n @param[in] log_id\n Type of log to be created\n\n @param[in] ctx\n Context of the log (a pointer to metacall_log_{stdio, file, socket, syslog, nginx, custom}_type)\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_log (log_id : metacall_log_id , ctx : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } # [repr (u32)] # [derive (Debug , Copy , Clone , Hash , PartialEq , Eq)] pub enum metacall_value_id { METACALL_BOOL = 0 , METACALL_CHAR = 1 , METACALL_SHORT = 2 , METACALL_INT = 3 , METACALL_LONG = 4 , METACALL_FLOAT = 5 , METACALL_DOUBLE = 6 , METACALL_STRING = 7 , METACALL_BUFFER = 8 , METACALL_ARRAY = 9 , METACALL_MAP = 10 , METACALL_PTR = 11 , METACALL_FUTURE = 12 , METACALL_FUNCTION = 13 , METACALL_NULL = 14 , METACALL_CLASS = 15 , METACALL_OBJECT = 16 , METACALL_EXCEPTION = 17 , METACALL_THROWABLE = 18 , METACALL_SIZE = 19 , METACALL_INVALID = 20 , } unsafe extern "C" { # [doc = " @brief\n Create a value from boolean @b\n\n @param[in] b\n Boolean will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_bool (b : :: std :: os :: raw :: c_uchar) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from char @c\n\n @param[in] c\n Character will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_char (c : :: std :: os :: raw :: c_char) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from short @s\n\n @param[in] s\n Short will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_short (s : :: std :: os :: raw :: c_short) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from integer @i\n\n @param[in] i\n Integer will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_int (i : :: std :: os :: raw :: c_int) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from long @l\n\n @param[in] l\n Long integer will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_long (l : :: std :: os :: raw :: c_long) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from single precision floating point number @f\n\n @param[in] f\n Float will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_float (f : f32) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from double precision floating point number @d\n\n @param[in] d\n Double will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_double (d : f64) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from a C string @str\n\n @param[in] str\n Constant string will be copied into value (needs to be null terminated)\n\n @param[in] length\n Length of the constant string\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_string (str_ : * const :: std :: os :: raw :: c_char , length : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value buffer from array @buffer\n\n @param[in] buffer\n Constant memory block will be copied into value array\n\n @param[in] size\n Size in bytes of data contained in the array\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_buffer (buffer : * const :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value array from array of values @values\n\n @param[in] values\n Constant array of values will be copied into value list\n\n @param[in] size\n Number of elements contained in the array\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_array (values : * mut * const :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value map from array of tuples @map\n\n @param[in] tuples\n Constant array of tuples will be copied into value map\n\n @param[in] size\n Number of elements contained in the map\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_map (tuples : * mut * const :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from pointer @ptr\n\n @param[in] ptr\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_ptr (ptr : * const :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from future @f\n\n @param[in] f\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_future (f : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from function @f\n\n @param[in] f\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_function (f : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from function @f binding a closure @c to it\n\n @param[in] f\n Pointer to constant data will be copied into value\n\n @param[in] c\n Pointer to closure that will be binded into function @f\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_function_closure (f : * mut :: std :: os :: raw :: c_void , c : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value of type null\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_null () -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from class @c\n\n @param[in] c\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_class (c : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from object @o\n\n @param[in] o\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_object (o : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from exception @ex\n\n @param[in] ex\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_exception (ex : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a value from throwable @th\n\n @param[in] th\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] pub fn metacall_value_create_throwable (th : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Returns the size of the value\n\n @param[in] v\n Reference to the value\n\n @return\n Size in bytes of the value"] pub fn metacall_value_size (v : * mut :: std :: os :: raw :: c_void) -> usize ; } unsafe extern "C" { # [doc = " @brief\n Returns the amount of values this value contains\n\n @param[in] v\n Reference to the value\n\n @return\n Number of values @v represents"] pub fn metacall_value_count (v : * mut :: std :: os :: raw :: c_void) -> usize ; } unsafe extern "C" { # [doc = " @brief\n Provide type id of value\n\n @param[in] v\n Reference to the value\n\n @return\n Return type id assigned to value"] pub fn metacall_value_id (v : * mut :: std :: os :: raw :: c_void) -> metacall_value_id ; } unsafe extern "C" { # [doc = " @brief\n Provide type id in a readable form (as string) of a type id\n\n @param[in] id\n Value type identifier\n\n @return\n Return string related to the type id"] pub fn metacall_value_id_name (id : metacall_value_id) -> * const :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Provide type id in a readable form (as string) of value\n\n @param[in] v\n Reference to the value\n\n @return\n Return string related to the type id assigned to value"] pub fn metacall_value_type_name (v : * mut :: std :: os :: raw :: c_void) -> * const :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Deep copies the value @v, the result copy resets\n the reference counter and ownership, including the finalizer\n\n @param[in] v\n Reference to the value to be copied\n\n @return\n Copy of the value @v on success, null otherwhise"] pub fn metacall_value_copy (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Creates a new pointer value, with a reference to the\n data contained inside the value @v. For example:\n\n void *v = metacall_value_create_int(20);\n void *ptr = metacall_value_reference(v);\n\n In this case, void *ptr is a value equivalent to int*,\n and it points directly to the integer contained in void *v.\n Note that if we destroy the value @v, the reference will\n point to already freed memory, causing use-after-free when used.\n\n @param[in] v\n Reference to the value to be referenced\n\n @return\n A new value of type pointer, pointing to the @v data"] pub fn metacall_value_reference (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n If you pass a reference previously created (i.e a value of\n type pointer, pointing to another value), it returns the\n original value. It does not modify the memory of the values\n neither allocates anything. If the value @v is pointing to\n has been deleted, it will cause an use-after-free. For example:\n\n void *v = metacall_value_create_int(20);\n void *ptr = metacall_value_reference(v);\n void *w = metacall_value_dereference(ptr);\n assert(v == w); // Both are the same value\n\n @param[in] v\n Reference to the value to be dereferenced\n\n @return\n The value containing the data which ptr is pointing to"] pub fn metacall_value_dereference (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Copies the ownership from @src to @dst, including the finalizer,\n and resets the owner and finalizer of @src\n\n @param[in] src\n Source value which will lose the ownership\n\n @param[in] dst\n Destination value which will recieve the ownership"] pub fn metacall_value_move (src : * mut :: std :: os :: raw :: c_void , dest : * mut :: std :: os :: raw :: c_void) ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to boolean\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to boolean"] pub fn metacall_value_to_bool (v : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_uchar ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to char\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to char"] pub fn metacall_value_to_char (v : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to short\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to short"] pub fn metacall_value_to_short (v : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_short ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to integer\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to integer"] pub fn metacall_value_to_int (v : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to long integer\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to long integer"] pub fn metacall_value_to_long (v : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_long ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to single precision floating point\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to float"] pub fn metacall_value_to_float (v : * mut :: std :: os :: raw :: c_void) -> f32 ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to double precision floating point\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to dobule"] pub fn metacall_value_to_double (v : * mut :: std :: os :: raw :: c_void) -> f64 ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to string\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to C string (null terminated)"] pub fn metacall_value_to_string (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to buffer\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to memory block"] pub fn metacall_value_to_buffer (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to array of values\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to array of values"] pub fn metacall_value_to_array (v : * mut :: std :: os :: raw :: c_void) -> * mut * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to map\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to map (array of tuples (array of values))"] pub fn metacall_value_to_map (v : * mut :: std :: os :: raw :: c_void) -> * mut * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to pointer\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to pointer"] pub fn metacall_value_to_ptr (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to future\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to future"] pub fn metacall_value_to_future (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to function\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to function"] pub fn metacall_value_to_function (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to null\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to null"] pub fn metacall_value_to_null (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to class\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to class"] pub fn metacall_value_to_class (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to object\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to object"] pub fn metacall_value_to_object (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to exception\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to exception"] pub fn metacall_value_to_exception (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v to throwable\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to throwable"] pub fn metacall_value_to_throwable (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign boolean @b to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] b\n Boolean to be assigned to value @v\n\n @return\n Value with boolean @b assigned to it"] pub fn metacall_value_from_bool (v : * mut :: std :: os :: raw :: c_void , b : :: std :: os :: raw :: c_uchar) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign character @c to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] c\n Character to be assigned to value @v\n\n @return\n Value with char @c assigned to it"] pub fn metacall_value_from_char (v : * mut :: std :: os :: raw :: c_void , c : :: std :: os :: raw :: c_char) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign short @s to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] s\n Short to be assigned to value @v\n\n @return\n Value with short @s assigned to it"] pub fn metacall_value_from_short (v : * mut :: std :: os :: raw :: c_void , s : :: std :: os :: raw :: c_short) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign integer @i to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] i\n Integer to be assigned to value @v\n\n @return\n Value with integer @i assigned to it"] pub fn metacall_value_from_int (v : * mut :: std :: os :: raw :: c_void , i : :: std :: os :: raw :: c_int) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign long integer @l to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] l\n Long integer to be assigned to value @v\n\n @return\n Value with long @l assigned to it"] pub fn metacall_value_from_long (v : * mut :: std :: os :: raw :: c_void , l : :: std :: os :: raw :: c_long) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign single precision floating point @f to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] f\n Float to be assigned to value @v\n\n @return\n Value with float @f assigned to it"] pub fn metacall_value_from_float (v : * mut :: std :: os :: raw :: c_void , f : f32) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign double precision floating point @d to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] d\n Double to be assigned to value @v\n\n @return\n Value with double @d assigned to it"] pub fn metacall_value_from_double (v : * mut :: std :: os :: raw :: c_void , d : f64) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign string @str to value @v, truncates to @v size if it is smaller\n than @length + 1. It does not add null terminator if truncated.\n\n @param[in] v\n Reference to the value\n\n @param[in] str\n Constant string to be assigned to value @v (it needs to be null terminated)\n\n @param[in] length\n Length of the constant string @str\n\n @return\n Value with string @str assigned to it"] pub fn metacall_value_from_string (v : * mut :: std :: os :: raw :: c_void , str_ : * const :: std :: os :: raw :: c_char , length : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign array @buffer to value buffer @v\n\n @param[in] v\n Reference to the value\n\n @param[in] buffer\n Constant array to be assigned to value @v\n\n @param[in] size\n Number of elements contained in @buffer\n\n @return\n Value with array @buffer assigned to it"] pub fn metacall_value_from_buffer (v : * mut :: std :: os :: raw :: c_void , buffer : * const :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign array of values @values to value array @v\n\n @param[in] v\n Reference to the value\n\n @param[in] values\n Constant array of values to be assigned to value array @v\n\n @param[in] size\n Number of values contained in constant array @values\n\n @return\n Value with array of values @values assigned to it"] pub fn metacall_value_from_array (v : * mut :: std :: os :: raw :: c_void , values : * mut * const :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign array of values @values to value map @v\n\n @param[in] v\n Reference to the value\n\n @param[in] tuples\n Constant array of tuples to be assigned to value map @v\n\n @param[in] size\n Number of values contained in constant array @tuples\n\n @return\n Value with array of tuples @tuples assigned to it"] pub fn metacall_value_from_map (v : * mut :: std :: os :: raw :: c_void , tuples : * mut * const :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign pointer reference @ptr to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] ptr\n Pointer to be assigned to value @v\n\n @return\n Value with pointer @ptr assigned to it"] pub fn metacall_value_from_ptr (v : * mut :: std :: os :: raw :: c_void , ptr : * const :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign future @f to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] f\n Future to be assigned to value @v\n\n @return\n Value with future @f assigned to it"] pub fn metacall_value_from_future (v : * mut :: std :: os :: raw :: c_void , f : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign function @f to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] f\n Function to be assigned to value @v\n\n @return\n Value with function @f assigned to it"] pub fn metacall_value_from_function (v : * mut :: std :: os :: raw :: c_void , f : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign null to value @v\n\n @param[in] v\n Reference to the value\n\n @return\n Value with null assigned to it"] pub fn metacall_value_from_null (v : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign class @c to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] c\n Class to be assigned to value @v\n\n @return\n Value with class @c assigned to it"] pub fn metacall_value_from_class (v : * mut :: std :: os :: raw :: c_void , c : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign object @o to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] o\n Object to be assigned to value @v\n\n @return\n Value with object @o assigned to it"] pub fn metacall_value_from_object (v : * mut :: std :: os :: raw :: c_void , o : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign exception @ex to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] ex\n Exception to be assigned to value @v\n\n @return\n Value with exception @ex assigned to it"] pub fn metacall_value_from_exception (v : * mut :: std :: os :: raw :: c_void , ex : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Assign throwable @th to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] th\n Throwable to be assigned to value @v\n\n @return\n Value with throwable @th assigned to it"] pub fn metacall_value_from_throwable (v : * mut :: std :: os :: raw :: c_void , th : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Casts a value to a new type @id\n\n @param[in] v\n Reference to the value\n\n @param[in] id\n New type id of value to be casted\n\n @return\n Casted value or reference to @v if casting is between equivalent types"] pub fn metacall_value_cast (v : * mut :: std :: os :: raw :: c_void , id : metacall_value_id) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to boolean\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to boolean"] pub fn metacall_value_cast_bool (v : * mut * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_uchar ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to char\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to char"] pub fn metacall_value_cast_char (v : * mut * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to short\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to short"] pub fn metacall_value_cast_short (v : * mut * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_short ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to int\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to int"] pub fn metacall_value_cast_int (v : * mut * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to long\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to long"] pub fn metacall_value_cast_long (v : * mut * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_long ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to float\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to float"] pub fn metacall_value_cast_float (v : * mut * mut :: std :: os :: raw :: c_void) -> f32 ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to double\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to double"] pub fn metacall_value_cast_double (v : * mut * mut :: std :: os :: raw :: c_void) -> f64 ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to string\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to a C string (null terminated)"] pub fn metacall_value_cast_string (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to buffer\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to buffer"] pub fn metacall_value_cast_buffer (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to array\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to array of values"] pub fn metacall_value_cast_array (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to map\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to map"] pub fn metacall_value_cast_map (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to ptr\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to ptr"] pub fn metacall_value_cast_ptr (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to future\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to future"] pub fn metacall_value_cast_future (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to function\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to function"] pub fn metacall_value_cast_function (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to null\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to null"] pub fn metacall_value_cast_null (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to class\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to class"] pub fn metacall_value_cast_class (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to object\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to object"] pub fn metacall_value_cast_object (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to exception\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to exception"] pub fn metacall_value_cast_exception (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert value @v implicitly to throwable\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to throwable"] pub fn metacall_value_cast_throwable (v : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Destroy a value from scope stack\n\n @param[in] v\n Reference to the value"] pub fn metacall_value_destroy (v : * mut :: std :: os :: raw :: c_void) ; } pub type metacall_pid = pid_t ; pub type metacall_pre_fork_callback_ptr = :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int > ; pub type metacall_post_fork_callback_ptr = :: std :: option :: Option < unsafe extern "C" fn (arg1 : metacall_pid , arg2 : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int > ; unsafe extern "C" { # [doc = " @brief\n Initialize fork detours and allocate shared memory\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_fork_initialize () -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Set fork hook callback\n\n @param[in] pre_callback\n Callback to be called before fork detour is executed\n\n @param[in] post_callback\n Callback to be called after fork detour is executed"] pub fn metacall_fork (pre_callback : metacall_pre_fork_callback_ptr , post_callback : metacall_post_fork_callback_ptr) ; } unsafe extern "C" { # [doc = " @brief\n Unregister fork detours and destroy shared memory"] pub fn metacall_fork_destroy () ; } # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct metacall_initialize_configuration_type { pub tag : * const :: std :: os :: raw :: c_char , pub options : * mut :: std :: os :: raw :: c_void , } # [allow (clippy :: unnecessary_operation , clippy :: identity_op)] const _ : () = { ["Size of metacall_initialize_configuration_type"] [:: std :: mem :: size_of :: < metacall_initialize_configuration_type > () - 16usize] ; ["Alignment of metacall_initialize_configuration_type"] [:: std :: mem :: align_of :: < metacall_initialize_configuration_type > () - 8usize] ; ["Offset of field: metacall_initialize_configuration_type::tag"] [:: std :: mem :: offset_of ! (metacall_initialize_configuration_type , tag) - 0usize] ; ["Offset of field: metacall_initialize_configuration_type::options"] [:: std :: mem :: offset_of ! (metacall_initialize_configuration_type , options) - 8usize] ; } ; pub type metacall_await_callback = :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > ; # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct metacall_await_callbacks_type { pub resolve : metacall_await_callback , pub reject : metacall_await_callback , } # [allow (clippy :: unnecessary_operation , clippy :: identity_op)] const _ : () = { ["Size of metacall_await_callbacks_type"] [:: std :: mem :: size_of :: < metacall_await_callbacks_type > () - 16usize] ; ["Alignment of metacall_await_callbacks_type"] [:: std :: mem :: align_of :: < metacall_await_callbacks_type > () - 8usize] ; ["Offset of field: metacall_await_callbacks_type::resolve"] [:: std :: mem :: offset_of ! (metacall_await_callbacks_type , resolve) - 0usize] ; ["Offset of field: metacall_await_callbacks_type::reject"] [:: std :: mem :: offset_of ! (metacall_await_callbacks_type , reject) - 8usize] ; } ; pub type metacall_await_callbacks = metacall_await_callbacks_type ; # [repr (C)] # [derive (Debug , Copy , Clone)] pub struct metacall_version_type { pub major : :: std :: os :: raw :: c_uint , pub minor : :: std :: os :: raw :: c_uint , pub patch : :: std :: os :: raw :: c_uint , pub revision : * const :: std :: os :: raw :: c_char , pub str_ : * const :: std :: os :: raw :: c_char , pub name : * const :: std :: os :: raw :: c_char , } # [allow (clippy :: unnecessary_operation , clippy :: identity_op)] const _ : () = { ["Size of metacall_version_type"] [:: std :: mem :: size_of :: < metacall_version_type > () - 40usize] ; ["Alignment of metacall_version_type"] [:: std :: mem :: align_of :: < metacall_version_type > () - 8usize] ; ["Offset of field: metacall_version_type::major"] [:: std :: mem :: offset_of ! (metacall_version_type , major) - 0usize] ; ["Offset of field: metacall_version_type::minor"] [:: std :: mem :: offset_of ! (metacall_version_type , minor) - 4usize] ; ["Offset of field: metacall_version_type::patch"] [:: std :: mem :: offset_of ! (metacall_version_type , patch) - 8usize] ; ["Offset of field: metacall_version_type::revision"] [:: std :: mem :: offset_of ! (metacall_version_type , revision) - 16usize] ; ["Offset of field: metacall_version_type::str_"] [:: std :: mem :: offset_of ! (metacall_version_type , str_) - 24usize] ; ["Offset of field: metacall_version_type::name"] [:: std :: mem :: offset_of ! (metacall_version_type , name) - 32usize] ; } ; unsafe extern "C" { # [doc = " @brief\n Returns default serializer used by MetaCall\n\n @return\n Name of the serializer to be used with serialization methods"] pub fn metacall_serial () -> * const :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Returns default detour used by MetaCall\n\n @return\n Name of the detour to be used with detouring methods"] pub fn metacall_detour () -> * const :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Disables MetaCall logs, must be called before @metacall_initialize.\n\n When initializing MetaCall, it initializes a default logs to stdout\n if none was defined. If you want to benchmark or simply disable this\n default logs, you can call to this function before @metacall_initialize."] pub fn metacall_log_null () ; } unsafe extern "C" { # [doc = " @brief\n Flags to be set in MetaCall library\n\n @param[in] flags\n Combination of flags referring to definitions METACALL_FLAGS_*"] pub fn metacall_flags (flags : :: std :: os :: raw :: c_int) ; } unsafe extern "C" { # [doc = " @brief\n Initialize MetaCall library\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_initialize () -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Initialize MetaCall library with configuration arguments\n\n @param[in] initialize_config\n Extension of the script to be loaded in memory with data to be injected\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_initialize_ex (initialize_config : * mut metacall_initialize_configuration_type) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Initialize MetaCall application arguments\n\n @param[in] argc\n Number of additional parameters to be passed to the runtime when initializing\n\n @param[in] argv\n Additional parameters to be passed to the runtime when initializing (when using MetaCall as an application)"] pub fn metacall_initialize_args (argc : :: std :: os :: raw :: c_int , argv : * mut * mut :: std :: os :: raw :: c_char) ; } unsafe extern "C" { # [doc = " @brief\n Get the number of arguments in which MetaCall was initialized\n\n @return\n An integer equal or greater than zero"] pub fn metacall_argc () -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Get the arguments in which MetaCall was initialized\n\n @return\n A pointer to an array of strings with the additional arguments"] pub fn metacall_argv () -> * mut * mut :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Check if script context is loaded by @tag\n\n @param[in] tag\n Extension of the script (if tag is NULL, it returns the status of the whole MetaCall instance)\n\n @return\n Zero if context is initialized, different from zero otherwise"] pub fn metacall_is_initialized (tag : * const :: std :: os :: raw :: c_char) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Amount of function call arguments supported by MetaCall\n\n @return\n Number of arguments suported"] pub fn metacall_args_size () -> usize ; } unsafe extern "C" { # [doc = " @brief\n Set a execution path defined by @path to the extension script @tag\n\n @param[in] tag\n Extension of the script\n\n @param[in] path\n Path to be loaded\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_execution_path (tag : * const :: std :: os :: raw :: c_char , path : * const :: std :: os :: raw :: c_char) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Set a execution path defined by @path to the extension script @tag with length\n\n @param[in] tag\n Extension of the script\n\n @param[in] tag_length\n Length of the extension of the tag\n\n @param[in] path\n Path to be loaded\n\n @param[in] path_length\n Length of the path\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_execution_path_s (tag : * const :: std :: os :: raw :: c_char , tag_length : usize , path : * const :: std :: os :: raw :: c_char , path_length : usize) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Loads a script from file specified by @path\n\n @param[in] tag\n Extension of the script\n\n @param[in] paths\n Path array of files\n\n @param[in] size\n Size of the array @paths\n\n @param[inout] handle\n Optional pointer to reference of loaded handle. If the parameter is NULL, the symbols loaded are\n propagated to the loader scope (i.e they will share the scope between all previously loaded files and they can collide).\n Otherwise, if we pass a void* pointer set to NULL, it will behave as output parameter, obtaining the reference to the\n created handle, which can be later on used for calling to functions of that handle. The symbols will not be propagated\n to the loader scope and they will be private (this prevents collisions). The last case is if we pass an already allocated\n handle (i.e a void* pointer pointing to an previously loaded handle), then in this case, the symbols loaded will be propagated\n to the previously allocated handle, and it will behave as a in parameter.\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_load_from_file (tag : * const :: std :: os :: raw :: c_char , paths : * mut * const :: std :: os :: raw :: c_char , size : usize , handle : * mut * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Loads a script from memory\n\n @param[in] tag\n Extension of the script\n\n @param[in] buffer\n Memory block representing the string of the script\n\n @param[in] size\n Memory block representing the string of the script\n\n @param[inout] handle\n Optional pointer to reference of loaded handle. If the parameter is NULL, the symbols loaded are\n propagated to the loader scope (i.e they will share the scope between all previously loaded files and they can collide).\n Otherwise, if we pass a void* pointer set to NULL, it will behave as output parameter, obtaining the reference to the\n created handle, which can be later on used for calling to functions of that handle. The symbols will not be propagated\n to the loader scope and they will be private (this prevents collisions). The last case is if we pass an already allocated\n handle (i.e a void* pointer pointing to an previously loaded handle), then in this case, the symbols loaded will be propagated\n to the previously allocated handle, and it will behave as a in parameter.\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_load_from_memory (tag : * const :: std :: os :: raw :: c_char , buffer : * const :: std :: os :: raw :: c_char , size : usize , handle : * mut * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Loads a package of scrips from file specified by @path into loader defined by @extension\n\n @param[in] tag\n Extension of the script\n\n @param[in] path\n Path of the package\n\n @param[inout] handle\n Optional pointer to reference of loaded handle. If the parameter is NULL, the symbols loaded are\n propagated to the loader scope (i.e they will share the scope between all previously loaded files and they can collide).\n Otherwise, if we pass a void* pointer set to NULL, it will behave as output parameter, obtaining the reference to the\n created handle, which can be later on used for calling to functions of that handle. The symbols will not be propagated\n to the loader scope and they will be private (this prevents collisions). The last case is if we pass an already allocated\n handle (i.e a void* pointer pointing to an previously loaded handle), then in this case, the symbols loaded will be propagated\n to the previously allocated handle, and it will behave as a in parameter.\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_load_from_package (tag : * const :: std :: os :: raw :: c_char , path : * const :: std :: os :: raw :: c_char , handle : * mut * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Loads a a list of scrips from configuration specified by @path into loader\n with the following format:\n {\n \"language_id\": \"\",\n \"path\": \"\",\n \"scripts\": [ \"\", \"\", ..., \"\" ]\n }\n\n @param[in] path\n Path of the configuration\n\n @param[inout] handle\n Optional pointer to reference of loaded handle. If the parameter is NULL, the symbols loaded are\n propagated to the loader scope (i.e they will share the scope between all previously loaded files and they can collide).\n Otherwise, if we pass a void* pointer set to NULL, it will behave as output parameter, obtaining the reference to the\n created handle, which can be later on used for calling to functions of that handle. The symbols will not be propagated\n to the loader scope and they will be private (this prevents collisions). The last case is if we pass an already allocated\n handle (i.e a void* pointer pointing to an previously loaded handle), then in this case, the symbols loaded will be propagated\n to the previously allocated handle, and it will behave as a in parameter.\n\n @param[in] allocator\n Pointer to allocator will allocate the configuration\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_load_from_configuration (path : * const :: std :: os :: raw :: c_char , handle : * mut * mut :: std :: os :: raw :: c_void , allocator : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by value array @args\n\n @param[in] name\n Name of the function\n\n @param[in] args\n Array of pointers to data\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallv (name : * const :: std :: os :: raw :: c_char , args : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by value array @args\n\n @param[in] name\n Name of the function\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of the call\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallv_s (name : * const :: std :: os :: raw :: c_char , args : * mut * mut :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by handle @handle value array @args\n This function allows to avoid name collisions when calling functions by name\n\n @param[in] handle\n Handle where the function belongs\n\n @param[in] name\n Name of the function\n\n @param[in] args\n Array of pointers to data\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallhv (handle : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , args : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by handle @handle value array @args\n This function allows to avoid name collisions when calling functions by name\n Includes @size in order to allow variadic arguments or safe calls\n\n @param[in] handle\n Handle where the function belongs\n\n @param[in] name\n Name of the function\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of the call\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallhv_s (handle : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , args : * mut * mut :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by variable arguments @va_args\n\n @param[in] name\n Name of the function\n\n @param[in] va_args\n Varidic function parameters\n\n @return\n Pointer to value containing the result of the call"] pub fn metacall (name : * const :: std :: os :: raw :: c_char , ...) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by type array @ids and variable arguments @va_args\n\n @param[in] name\n Name of the function\n\n @param[in] ids\n Array of types refered to @va_args\n\n @param[in] va_args\n Varidic function parameters\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallt (name : * const :: std :: os :: raw :: c_char , ids : * const metacall_value_id , ...) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by type array @ids and variable arguments @va_args\n\n @param[in] name\n Name of the function\n\n @param[in] ids\n Array of types refered to @va_args\n\n @param[in] size\n Number of elements of the call\n\n @param[in] va_args\n Varidic function parameters\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallt_s (name : * const :: std :: os :: raw :: c_char , ids : * const metacall_value_id , size : usize , ...) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by type array @ids and variable arguments @va_args\n\n @param[in] handle\n Pointer to the handle returned by metacall_load_from_{file, memory, package}\n\n @param[in] name\n Name of the function\n\n @param[in] ids\n Array of types refered to @va_args\n\n @param[in] size\n Number of elements of the call\n\n @param[in] va_args\n Varidic function parameters\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallht_s (handle : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , ids : * const metacall_value_id , size : usize , ...) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Get the function by @name\n\n @param[in] name\n Name of the function\n\n @return\n Function reference, null if the function does not exist"] pub fn metacall_function (name : * const :: std :: os :: raw :: c_char) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create an empty handler into a loader with name @name\n\n @param[in] loader\n Pointer to the loader which the handle belongs to\n\n @param[in] name\n Name of the handle\n\n @param[out] handle_ptr\n On success, returns the pointer to the handle created, otherwise NULL\n\n @return\n Return zero on success, different from zero on error"] pub fn metacall_handle_initialize (loader : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , handle_ptr : * mut * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Populate the objects of @handle_src into @handle_dest\n\n @param[inout] handle_dest\n Handle where the objects from @handle_src will be stored\n\n @param[in] handle_src\n Handle from where the objects will be copied\n\n @return\n Return zero on success, different from zero on error"] pub fn metacall_handle_populate (handle_dest : * mut :: std :: os :: raw :: c_void , handle_src : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Get the function by @name from @handle\n\n @param[in] handle\n Pointer to the handle returned by metacall_load_from_{file, memory, package}\n\n @param[in] name\n Name of the function\n\n @return\n Function reference, null if the function does not exist"] pub fn metacall_handle_function (handle : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Get the function parameter type id\n\n @param[in] func\n The pointer to the function obtained from metacall_function\n\n @param[in] parameter\n The index of the parameter to be retrieved\n\n @param[out] id\n The parameter type id that will be returned\n\n @return\n Return 0 if the @parameter index exists and @func is valid, 1 otherwhise"] pub fn metacall_function_parameter_type (func : * mut :: std :: os :: raw :: c_void , parameter : usize , id : * mut metacall_value_id) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Get the function return type id\n\n @param[in] func\n The pointer to the function obtained from metacall_function\n\n\n @param[out] id\n The value id of the return type of the function @func\n\n @return\n Return 0 if the @func is valid, 1 otherwhise"] pub fn metacall_function_return_type (func : * mut :: std :: os :: raw :: c_void , id : * mut metacall_value_id) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Get minimun mumber of arguments accepted by function @func\n\n @param[in] func\n Function reference\n\n @return\n Return mumber of arguments"] pub fn metacall_function_size (func : * mut :: std :: os :: raw :: c_void) -> usize ; } unsafe extern "C" { # [doc = " @brief\n Check if the function @func is asynchronous or synchronous\n\n @param[in] func\n Function reference\n\n @return\n Return 0 if it is syncrhonous, 1 if it is asynchronous and -1 if the function is NULL"] pub fn metacall_function_async (func : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Get the handle by @name\n\n @param[in] tag\n Extension of the script\n\n @param[in] name\n Name of the handle\n\n @return\n Handle reference, null if the function does not exist"] pub fn metacall_handle (tag : * const :: std :: os :: raw :: c_char , name : * const :: std :: os :: raw :: c_char) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Get name of a @handle\n\n @param[in] handle\n Pointer to the handle to be retrieved\n\n @return\n String that references the handle"] pub fn metacall_handle_id (handle : * mut :: std :: os :: raw :: c_void) -> * const :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Return a value representing the handle as a map of functions (or values)\n\n @param[in] handle\n Reference to the handle to be described\n\n @return\n A value of type map on success, null otherwise"] pub fn metacall_handle_export (handle : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by value array @args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to data\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallfv (func : * mut :: std :: os :: raw :: c_void , args : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by value array @args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of function arguments\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallfv_s (func : * mut :: std :: os :: raw :: c_void , args : * mut * mut :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by variable arguments @va_args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallf (func : * mut :: std :: os :: raw :: c_void , ...) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by function @func and serial @buffer of size @size\n\n @param[in] func\n Reference to function to be called\n\n @param[in] buffer\n String representing an array to be deserialized into arguments of the function\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallfs (func : * mut :: std :: os :: raw :: c_void , buffer : * const :: std :: os :: raw :: c_char , size : usize , allocator : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by value map (@keys -> @values) and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] keys\n Array of values representing argument keys\n\n @param[in] values\n Array of values representing argument values data\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallfmv (func : * mut :: std :: os :: raw :: c_void , keys : * mut * mut :: std :: os :: raw :: c_void , values : * mut * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a function anonymously by function @func and serial @buffer of size @size\n\n @param[in] func\n Reference to function to be called\n\n @param[in] buffer\n String representing a map to be deserialized into arguments of the function\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallfms (func : * mut :: std :: os :: raw :: c_void , buffer : * const :: std :: os :: raw :: c_char , size : usize , allocator : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Register a function by name @name and arguments @va_args\n\n @param[in] name\n Name of the function (if it is NULL, function is not registered into host scope)\n\n @param[in] invoke\n Pointer to function invoke interface (argc, argv, data)\n\n @param[out] func\n Will set the pointer to the function if the parameter is not null\n\n @param[in] return_type\n Type of return value\n\n @param[in] size\n Number of function arguments\n\n @param[in] va_args\n Varidic function parameter types\n\n @return\n Pointer to value containing the result of the call"] pub fn metacall_register (name : * const :: std :: os :: raw :: c_char , invoke : :: std :: option :: Option < unsafe extern "C" fn (arg1 : usize , arg2 : * mut * mut :: std :: os :: raw :: c_void , arg3 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , func : * mut * mut :: std :: os :: raw :: c_void , return_type : metacall_value_id , size : usize , ...) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Register a function by name @name and arguments @types\n\n @param[in] name\n Name of the function (if it is NULL, function is not registered into host scope)\n\n @param[in] invoke\n Pointer to function invoke interface (argc, argv, data)\n\n @param[out] func\n Will set the pointer to the function if the parameter is not null\n\n @param[in] return_type\n Type of return value\n\n @param[in] size\n Number of function arguments\n\n @param[in] types\n List of parameter types\n\n @return\n Pointer to value containing the result of the call"] pub fn metacall_registerv (name : * const :: std :: os :: raw :: c_char , invoke : :: std :: option :: Option < unsafe extern "C" fn (arg1 : usize , arg2 : * mut * mut :: std :: os :: raw :: c_void , arg3 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , func : * mut * mut :: std :: os :: raw :: c_void , return_type : metacall_value_id , size : usize , types : * mut metacall_value_id) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Obtain the loader instance by @tag\n\n @param[in] tag\n Tag in which the loader is identified, normally it is the extension of the script\n\n @return\n Pointer the loader by @tag"] pub fn metacall_loader (tag : * const :: std :: os :: raw :: c_char) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Register a function by name @name and arguments @types\n\n @param[in] loader\n Opaque pointer to the loader in which you want to register the function (this allows to register the function into a different loader than the host)\n\n @param[in] handle\n Opaque pointer to the handle in which you want to register the function (if it is NULL, it will be defined on the global scope of the loader)\n\n @param[in] name\n Name of the function (if it is NULL, function is not registered into host scope)\n\n @param[in] invoke\n Pointer to function invoke interface (argc, argv, data)\n\n @param[in] return_type\n Type of return value\n\n @param[in] size\n Number of function arguments\n\n @param[in] types\n List of parameter types\n\n @return\n Zero if the function was registered properly, distinct from zero otherwise"] pub fn metacall_register_loaderv (loader : * mut :: std :: os :: raw :: c_void , handle : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , invoke : :: std :: option :: Option < unsafe extern "C" fn (arg1 : usize , arg2 : * mut * mut :: std :: os :: raw :: c_void , arg3 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , return_type : metacall_value_id , size : usize , types : * mut metacall_value_id) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Executes an asynchronous call to the function and registers a callback to be executed when a future is resolved (it does block)\n\n @param[in] name\n The name of the function to be called asynchronously\n\n @param[in] args\n Array of pointers to the values to be passed to the function\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacall_await (name : * const :: std :: os :: raw :: c_char , args : * mut * mut :: std :: os :: raw :: c_void , resolve_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , reject_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Awaits for a promise and registers a callback to be executed when a future is resolved\n\n @param[in] f\n The pointer to the future\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacall_await_future (f : * mut :: std :: os :: raw :: c_void , resolve_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , reject_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Executes an asynchronous call to the function and registers a callback to be executed when a future is resolved (it does block)\n\n @param[in] name\n The name of the function to be called asynchronously\n\n @param[in] args\n Array of pointers to the values to be passed to the function\n\n @param[in] size\n Number of elements of the array @args\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacall_await_s (name : * const :: std :: os :: raw :: c_char , args : * mut * mut :: std :: os :: raw :: c_void , size : usize , resolve_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , reject_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call an asynchronous function anonymously by value array @args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to values\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacallfv_await (func : * mut :: std :: os :: raw :: c_void , args : * mut * mut :: std :: os :: raw :: c_void , resolve_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , reject_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call an asynchronous function anonymously by value array @args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to values\n\n @param[in] size\n Number of elements of the array @args\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacallfv_await_s (func : * mut :: std :: os :: raw :: c_void , args : * mut * mut :: std :: os :: raw :: c_void , size : usize , resolve_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , reject_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call an asynchronous function anonymously by value array @args and function @func (offered without function pointers for languages without support to function pointers)\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to values\n\n @param[in] size\n Number of elements of the array @args\n\n @param[in] cb\n Pointer to struct containing the function pointers to reject and resolve that will be executed when task completion or error\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacallfv_await_struct_s (func : * mut :: std :: os :: raw :: c_void , args : * mut * mut :: std :: os :: raw :: c_void , size : usize , cb : metacall_await_callbacks , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call an asynchronous function anonymously by value map (@keys -> @values) and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] keys\n Array of values representing argument keys\n\n @param[in] values\n Array of values representing argument values data\n\n @param[in] size\n Number of elements of the arrays @keys and @values\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacallfmv_await (func : * mut :: std :: os :: raw :: c_void , keys : * mut * mut :: std :: os :: raw :: c_void , values : * mut * mut :: std :: os :: raw :: c_void , resolve_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , reject_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call an asynchronous function anonymously by value map (@keys -> @values) and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] keys\n Array of values representing argument keys\n\n @param[in] values\n Array of values representing argument values data\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacallfmv_await_s (func : * mut :: std :: os :: raw :: c_void , keys : * mut * mut :: std :: os :: raw :: c_void , values : * mut * mut :: std :: os :: raw :: c_void , size : usize , resolve_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , reject_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call an asynchronous function anonymously by function @func and serial @buffer of size @size\n\n @param[in] func\n Reference to function to be called\n\n @param[in] buffer\n String representing an array to be deserialized into arguments of the function\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacallfs_await (func : * mut :: std :: os :: raw :: c_void , buffer : * const :: std :: os :: raw :: c_char , size : usize , allocator : * mut :: std :: os :: raw :: c_void , resolve_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , reject_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call an asynchronous function anonymously by function @func and serial @buffer of size @size\n\n @param[in] func\n Reference to function to be called\n\n @param[in] buffer\n String representing a map to be deserialized into arguments of the function\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] pub fn metacallfms_await (func : * mut :: std :: os :: raw :: c_void , buffer : * const :: std :: os :: raw :: c_char , size : usize , allocator : * mut :: std :: os :: raw :: c_void , resolve_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , reject_callback : :: std :: option :: Option < unsafe extern "C" fn (arg1 : * mut :: std :: os :: raw :: c_void , arg2 : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void > , data : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Get the class by @name\n\n @param[in] name\n Name of the class\n\n @return\n Class reference, null if the class does not exist"] pub fn metacall_class (name : * const :: std :: os :: raw :: c_char) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a class method anonymously by value array @args (this procedure assumes there's no overloaded methods and does type conversion on values)\n\n @param[in] cls\n Pointer to the class\n\n @param[in] name\n Name of the method\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of args array\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallv_class (cls : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , args : * mut * mut :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a class method anonymously by value array @args and return value type @ret (helps to resolve overloading methods)\n\n @param[in] cls\n Pointer to the class\n\n @param[in] name\n Name of the method\n\n @param[in] ret\n Type of the return value of the method\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of args array\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallt_class (cls : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , ret : metacall_value_id , args : * mut * mut :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Create a new object instance from @cls by value array @args\n\n @param[in] cls\n Pointer to the class\n\n @param[in] name\n Name of the new object\n\n @param[in] args\n Array of pointers constructor parameters\n\n @param[in] size\n Number of elements of constructor parameters\n\n @return\n Pointer to the new object value instance"] pub fn metacall_class_new (cls : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , args : * mut * mut :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Get an attribute from @cls by @key name\n\n @param[in] cls\n Pointer to the class\n\n @param[in] key\n Name of the attribute to get\n\n @return\n Pointer to the class attribute value or NULL if an error occurred"] pub fn metacall_class_static_get (cls : * mut :: std :: os :: raw :: c_void , key : * const :: std :: os :: raw :: c_char) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Set an attribute to @cls by @key name\n\n @param[in] cls\n Pointer to the class\n\n @param[in] key\n Name of the attribute to set\n\n @param[in] value\n Value to set\n\n @return\n Non-zero integer if an error ocurred"] pub fn metacall_class_static_set (cls : * mut :: std :: os :: raw :: c_void , key : * const :: std :: os :: raw :: c_char , v : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Call an object method anonymously by value array @args\n\n @param[in] obj\n Pointer to the object\n\n @param[in] name\n Name of the method\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of args array\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallv_object (obj : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , args : * mut * mut :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Call a object method anonymously by value array @args and return value type @ret (helps to resolve overloading methods)\n\n @param[in] obj\n Pointer to the object\n\n @param[in] name\n Name of the method\n\n @param[in] ret\n Type of the return value of the method\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of args array\n\n @return\n Pointer to value containing the result of the call"] pub fn metacallt_object (obj : * mut :: std :: os :: raw :: c_void , name : * const :: std :: os :: raw :: c_char , ret : metacall_value_id , args : * mut * mut :: std :: os :: raw :: c_void , size : usize) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Get an attribute from @obj by @key name\n\n @param[in] obj\n Pointer to the object\n\n @param[in] key\n Name of the attribute to get\n\n @return\n Pointer to the object attribute value or NULL if an error occurred"] pub fn metacall_object_get (obj : * mut :: std :: os :: raw :: c_void , key : * const :: std :: os :: raw :: c_char) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Set an attribute to @obj by @key name\n\n @param[in] obj\n Pointer to the object\n\n @param[in] key\n Name of the attribute to set\n\n @param[in] value\n Value to set\n\n @return\n Non-zero integer if an error ocurred"] pub fn metacall_object_set (obj : * mut :: std :: os :: raw :: c_void , key : * const :: std :: os :: raw :: c_char , v : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Get the value contained by throwable object @th\n\n @param[in] th\n Pointer to the throwable object\n\n @return\n Pointer to the value inside of the throwable or NULL in case of error"] pub fn metacall_throwable_value (th : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Provide information about all loaded objects\n\n @param[out] size\n Size in bytes of return buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the string\n\n @return\n String containing introspection information"] pub fn metacall_inspect (size : * mut usize , allocator : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Provide information about all loaded objects as a value\n\n @return\n Value containing introspection information"] pub fn metacall_inspect_value () -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Convert the value @v to serialized string\n\n @param[in] name\n Name of the serial to be used\n\n @param[in] v\n Reference to the value\n\n @param[out] size\n Size of new allocated string\n\n @param[in] allocator\n Pointer to allocator will allocate the string\n\n @return\n New allocated string containing stringified value"] pub fn metacall_serialize (name : * const :: std :: os :: raw :: c_char , v : * mut :: std :: os :: raw :: c_void , size : * mut usize , allocator : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Convert the string @buffer to value\n\n @param[in] name\n Name of the serial to be used\n\n @param[in] buffer\n String to be deserialized\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @return\n New allocated value representing the string (must be freed)"] pub fn metacall_deserialize (name : * const :: std :: os :: raw :: c_char , buffer : * const :: std :: os :: raw :: c_char , size : usize , allocator : * mut :: std :: os :: raw :: c_void) -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Clear handle from memory and unload related resources\n\n @param[in] handle\n Reference to the handle to be unloaded\n\n @return\n Zero if success, different from zero otherwise"] pub fn metacall_clear (handle : * mut :: std :: os :: raw :: c_void) -> :: std :: os :: raw :: c_int ; } unsafe extern "C" { # [doc = " @brief\n Get the plugin extension handle to be used for loading plugins\n\n @return\n Pointer to the extension handle, or null if it failed to load"] pub fn metacall_plugin_extension () -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Get the handle containing all the functionality of the plugins from core\n\n @return\n Pointer to the core plugin handle, or null if it failed to load"] pub fn metacall_plugin_core () -> * mut :: std :: os :: raw :: c_void ; } unsafe extern "C" { # [doc = " @brief\n Get the plugin extension path to be used for accessing the plugins folder\n\n @return\n String containing the core plugin path, or null if it failed to load the plugin extension"] pub fn metacall_plugin_path () -> * const :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Destroy MetaCall library"] pub fn metacall_destroy () ; } unsafe extern "C" { # [doc = " @brief\n Provide the module version struct\n\n @return\n Static struct containing unpacked version"] pub fn metacall_version () -> * const metacall_version_type ; } unsafe extern "C" { # [doc = " @brief\n Provide the module version hexadecimal value\n with format 0xMMIIPPPP where M is @major,\n I is @minor and P is @patch\n\n @param[in] major\n Unsigned integer representing major version\n\n @param[in] minor\n Unsigned integer representing minor version\n\n @param[in] patch\n Unsigned integer representing patch version\n\n @return\n Hexadecimal integer containing packed version"] pub fn metacall_version_hex_make (major : :: std :: os :: raw :: c_uint , minor : :: std :: os :: raw :: c_uint , patch : :: std :: os :: raw :: c_uint) -> u32 ; } unsafe extern "C" { # [doc = " @brief\n Provide the module version hexadecimal value\n with format 0xMMIIPPPP where M is major,\n I is minor and P is patch\n\n @return\n Hexadecimal integer containing packed version"] pub fn metacall_version_hex () -> u32 ; } unsafe extern "C" { # [doc = " @brief\n Provide the module version string\n\n @return\n Static string containing module version"] pub fn metacall_version_str () -> * const :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Provide the module version revision string\n\n @return\n Static string containing module version revision"] pub fn metacall_version_revision () -> * const :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Provide the module version name\n\n @return\n Static string containing module version name"] pub fn metacall_version_name () -> * const :: std :: os :: raw :: c_char ; } unsafe extern "C" { # [doc = " @brief\n Provide the module information\n\n @return\n Static string containing module information"] pub fn metacall_print_info () -> * const :: std :: os :: raw :: c_char ; } \ No newline at end of file +pub type __pid_t = ::std::os::raw::c_int; +pub type pid_t = __pid_t; +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum metacall_allocator_id { + METACALL_ALLOCATOR_STD = 0, + METACALL_ALLOCATOR_NGINX = 1, +} +unsafe extern "C" { + #[doc = " @brief\n Create an allocator instance\n\n @param[in] allocator_id\n Type of allocator to be created\n\n @param[in] ctx\n Context of the allocator\n\n @return\n Pointer to allocator if success, null otherwise"] + pub fn metacall_allocator_create( + allocator_id: metacall_allocator_id, + ctx: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Reserve memory from an allocator instance\n\n @param[in] allocator\n Pointer to allocator instance\n\n @param[in] size\n Size in bytes to be allocated\n\n @return\n Pointer to allocated data on success, null otherwise"] + pub fn metacall_allocator_alloc( + allocator: *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Reallocate memory from an allocator instance\n\n @param[in] allocator\n Pointer to allocator instance\n\n @param[in] data\n Original pointer to data\n\n @param[in] size\n Original size in bytes\n\n @param[in] new_size\n New size in bytes to be reallocated\n\n @return\n Pointer to new reallocated data on success, null otherwise"] + pub fn metacall_allocator_realloc( + allocator: *mut ::std::os::raw::c_void, + data: *mut ::std::os::raw::c_void, + size: usize, + new_size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Free memory from an allocator instance\n\n @param[in] allocator\n Pointer to allocator instance\n\n @param[in] data\n Pointer to data to be freed"] + pub fn metacall_allocator_free( + allocator: *mut ::std::os::raw::c_void, + data: *mut ::std::os::raw::c_void, + ); +} +unsafe extern "C" { + #[doc = " @brief\n Destroy an allocator instance\n\n @param[in] allocator\n Pointer to allocator instance"] + pub fn metacall_allocator_destroy(allocator: *mut ::std::os::raw::c_void); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct metacall_exception_type { + pub message: *const ::std::os::raw::c_char, + pub label: *const ::std::os::raw::c_char, + pub code: i64, + pub stacktrace: *const ::std::os::raw::c_char, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of metacall_exception_type"][::std::mem::size_of::() - 32usize]; + ["Alignment of metacall_exception_type"] + [::std::mem::align_of::() - 8usize]; + ["Offset of field: metacall_exception_type::message"] + [::std::mem::offset_of!(metacall_exception_type, message) - 0usize]; + ["Offset of field: metacall_exception_type::label"] + [::std::mem::offset_of!(metacall_exception_type, label) - 8usize]; + ["Offset of field: metacall_exception_type::code"] + [::std::mem::offset_of!(metacall_exception_type, code) - 16usize]; + ["Offset of field: metacall_exception_type::stacktrace"] + [::std::mem::offset_of!(metacall_exception_type, stacktrace) - 24usize]; +}; +pub type metacall_exception = *mut metacall_exception_type; +unsafe extern "C" { + #[doc = " @brief\n Create an throwable value from an exception with a simple API in a single instruction\n\n @param[in] label\n Label of the exception\n\n @param[in] code\n Error code of the exception\n\n @param[in] stacktrace\n Stack trace of the exception\n\n @param[in] message\n Message of the exception to be formatted with the variable arguments\n\n @param[in] va_args\n Arguments for formatting the message\n\n @return\n The value of type throwable containing the exception created"] + pub fn metacall_error_throw( + label: *const ::std::os::raw::c_char, + code: i64, + stacktrace: *const ::std::os::raw::c_char, + message: *const ::std::os::raw::c_char, + ... + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Retrieve the exception from a value, it can be either a throwable value with an exception inside or an exception itself\n\n @param[in] v\n Value that represents the exception to be retrieved\n\n @param[out] ex\n Exception that will be used as out parameter, the lifetime of the struct fields is attached to @v\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_error_from_value( + v: *mut ::std::os::raw::c_void, + ex: metacall_exception, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Retrieve last error that has happened after a call to any API from MetaCall\n\n @param[out] ex\n Exception that will be used as out parameter, the lifetime of the struct fields is attached to the internal MetaCall exception\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_error_last(ex: metacall_exception) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Clear last error that has happened after a call to any API from MetaCall"] + pub fn metacall_error_clear(); +} +unsafe extern "C" { + #[doc = " @brief\n Initialize link detours and allocate shared memory\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_link_initialize() -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Register a function pointer in order to allow function\n interposition when loading a library, if you register a\n function @symbol called 'foo', when you try to dlsym (or the equivalent\n on every platform), you will get the pointer to @fn, even if\n the symbol does not exist in the library, it will work.\n Function interposition is required in order to hook into runtimes\n and dynamically interpose our functions.\n\n @param[in] tag\n Name of the loader which the @library belongs to\n\n @param[in] library\n Name of the library that is going to be hooked\n\n @param[in] symbol\n Name of the function to be interposed\n\n @param[in] fn\n Function pointer that will be returned by dlsym (or equivalent) when accessing to @symbol\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_link_register( + tag: *const ::std::os::raw::c_char, + library: *const ::std::os::raw::c_char, + symbol: *const ::std::os::raw::c_char, + fn_: ::std::option::Option, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Register a function pointer in order to allow function\n interposition when loading a library, if you register a\n function @symbol called 'foo', when you try to dlsym (or the equivalent\n on every platform), you will get the pointer to @fn, even if\n the symbol does not exist in the library, it will work.\n Function interposition is required in order to hook into runtimes\n and dynamically interpose our functions.\n\n @param[in] loader\n Pointer to the loader which the @library belongs to\n\n @param[in] library\n Name of the library that is going to be hooked\n\n @param[in] symbol\n Name of the function to be interposed\n\n @param[in] fn\n Function pointer that will be returned by dlsym (or equivalent) when accessing to @symbol\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_link_register_loader( + loader: *mut ::std::os::raw::c_void, + library: *const ::std::os::raw::c_char, + symbol: *const ::std::os::raw::c_char, + fn_: ::std::option::Option, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Remove the hook previously registered\n\n @param[in] tag\n Name of the loader which the @library belongs to\n\n @param[in] library\n Name of the library that is going to be hooked\n\n @param[in] symbol\n Name of the function to be interposed\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_link_unregister( + tag: *const ::std::os::raw::c_char, + library: *const ::std::os::raw::c_char, + symbol: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Unregister link detours and destroy shared memory"] + pub fn metacall_link_destroy(); +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum metacall_log_id { + METACALL_LOG_STDIO = 0, + METACALL_LOG_FILE = 1, + METACALL_LOG_SOCKET = 2, + METACALL_LOG_SYSLOG = 3, + METACALL_LOG_NGINX = 4, + METACALL_LOG_CUSTOM = 5, +} +unsafe extern "C" { + #[doc = " @brief\n Create a log instance\n\n @param[in] log_id\n Type of log to be created\n\n @param[in] ctx\n Context of the log (a pointer to metacall_log_{stdio, file, socket, syslog, nginx, custom}_type)\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_log( + log_id: metacall_log_id, + ctx: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum metacall_value_id { + METACALL_BOOL = 0, + METACALL_CHAR = 1, + METACALL_SHORT = 2, + METACALL_INT = 3, + METACALL_LONG = 4, + METACALL_FLOAT = 5, + METACALL_DOUBLE = 6, + METACALL_STRING = 7, + METACALL_BUFFER = 8, + METACALL_ARRAY = 9, + METACALL_MAP = 10, + METACALL_PTR = 11, + METACALL_FUTURE = 12, + METACALL_FUNCTION = 13, + METACALL_NULL = 14, + METACALL_CLASS = 15, + METACALL_OBJECT = 16, + METACALL_EXCEPTION = 17, + METACALL_THROWABLE = 18, + METACALL_SIZE = 19, + METACALL_INVALID = 20, +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from boolean @b\n\n @param[in] b\n Boolean will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_bool(b: ::std::os::raw::c_uchar) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from char @c\n\n @param[in] c\n Character will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_char(c: ::std::os::raw::c_char) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from short @s\n\n @param[in] s\n Short will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_short(s: ::std::os::raw::c_short) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from integer @i\n\n @param[in] i\n Integer will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_int(i: ::std::os::raw::c_int) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from long @l\n\n @param[in] l\n Long integer will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_long(l: ::std::os::raw::c_long) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from single precision floating point number @f\n\n @param[in] f\n Float will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_float(f: f32) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from double precision floating point number @d\n\n @param[in] d\n Double will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_double(d: f64) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from a C string @str\n\n @param[in] str\n Constant string will be copied into value (needs to be null terminated)\n\n @param[in] length\n Length of the constant string\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_string( + str_: *const ::std::os::raw::c_char, + length: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value buffer from array @buffer\n\n @param[in] buffer\n Constant memory block will be copied into value array\n\n @param[in] size\n Size in bytes of data contained in the array\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_buffer( + buffer: *const ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value array from array of values @values\n\n @param[in] values\n Constant array of values will be copied into value list\n\n @param[in] size\n Number of elements contained in the array\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_array( + values: *mut *const ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value map from array of tuples @map\n\n @param[in] tuples\n Constant array of tuples will be copied into value map\n\n @param[in] size\n Number of elements contained in the map\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_map( + tuples: *mut *const ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from pointer @ptr\n\n @param[in] ptr\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_ptr( + ptr: *const ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from future @f\n\n @param[in] f\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_future( + f: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from function @f\n\n @param[in] f\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_function( + f: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from function @f binding a closure @c to it\n\n @param[in] f\n Pointer to constant data will be copied into value\n\n @param[in] c\n Pointer to closure that will be binded into function @f\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_function_closure( + f: *mut ::std::os::raw::c_void, + c: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value of type null\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_null() -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from class @c\n\n @param[in] c\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_class( + c: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from object @o\n\n @param[in] o\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_object( + o: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from exception @ex\n\n @param[in] ex\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_exception( + ex: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a value from throwable @th\n\n @param[in] th\n Pointer to constant data will be copied into value\n\n @return\n Pointer to value if success, null otherwhise"] + pub fn metacall_value_create_throwable( + th: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Returns the size of the value\n\n @param[in] v\n Reference to the value\n\n @return\n Size in bytes of the value"] + pub fn metacall_value_size(v: *mut ::std::os::raw::c_void) -> usize; +} +unsafe extern "C" { + #[doc = " @brief\n Returns the amount of values this value contains\n\n @param[in] v\n Reference to the value\n\n @return\n Number of values @v represents"] + pub fn metacall_value_count(v: *mut ::std::os::raw::c_void) -> usize; +} +unsafe extern "C" { + #[doc = " @brief\n Provide type id of value\n\n @param[in] v\n Reference to the value\n\n @return\n Return type id assigned to value"] + pub fn metacall_value_id(v: *mut ::std::os::raw::c_void) -> metacall_value_id; +} +unsafe extern "C" { + #[doc = " @brief\n Provide type id in a readable form (as string) of a type id\n\n @param[in] id\n Value type identifier\n\n @return\n Return string related to the type id"] + pub fn metacall_value_id_name(id: metacall_value_id) -> *const ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Provide type id in a readable form (as string) of value\n\n @param[in] v\n Reference to the value\n\n @return\n Return string related to the type id assigned to value"] + pub fn metacall_value_type_name( + v: *mut ::std::os::raw::c_void, + ) -> *const ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Deep copies the value @v, the result copy resets\n the reference counter and ownership, including the finalizer\n\n @param[in] v\n Reference to the value to be copied\n\n @return\n Copy of the value @v on success, null otherwhise"] + pub fn metacall_value_copy(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Creates a new pointer value, with a reference to the\n data contained inside the value @v. For example:\n\n void *v = metacall_value_create_int(20);\n void *ptr = metacall_value_reference(v);\n\n In this case, void *ptr is a value equivalent to int*,\n and it points directly to the integer contained in void *v.\n Note that if we destroy the value @v, the reference will\n point to already freed memory, causing use-after-free when used.\n\n @param[in] v\n Reference to the value to be referenced\n\n @return\n A new value of type pointer, pointing to the @v data"] + pub fn metacall_value_reference(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n If you pass a reference previously created (i.e a value of\n type pointer, pointing to another value), it returns the\n original value. It does not modify the memory of the values\n neither allocates anything. If the value @v is pointing to\n has been deleted, it will cause an use-after-free. For example:\n\n void *v = metacall_value_create_int(20);\n void *ptr = metacall_value_reference(v);\n void *w = metacall_value_dereference(ptr);\n assert(v == w); // Both are the same value\n\n @param[in] v\n Reference to the value to be dereferenced\n\n @return\n The value containing the data which ptr is pointing to"] + pub fn metacall_value_dereference( + v: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Copies the ownership from @src to @dst, including the finalizer,\n and resets the owner and finalizer of @src\n\n @param[in] src\n Source value which will lose the ownership\n\n @param[in] dst\n Destination value which will recieve the ownership"] + pub fn metacall_value_move(src: *mut ::std::os::raw::c_void, dest: *mut ::std::os::raw::c_void); +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to boolean\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to boolean"] + pub fn metacall_value_to_bool(v: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_uchar; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to char\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to char"] + pub fn metacall_value_to_char(v: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to short\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to short"] + pub fn metacall_value_to_short(v: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_short; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to integer\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to integer"] + pub fn metacall_value_to_int(v: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to long integer\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to long integer"] + pub fn metacall_value_to_long(v: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_long; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to single precision floating point\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to float"] + pub fn metacall_value_to_float(v: *mut ::std::os::raw::c_void) -> f32; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to double precision floating point\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to dobule"] + pub fn metacall_value_to_double(v: *mut ::std::os::raw::c_void) -> f64; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to string\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to C string (null terminated)"] + pub fn metacall_value_to_string(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to buffer\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to memory block"] + pub fn metacall_value_to_buffer(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to array of values\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to array of values"] + pub fn metacall_value_to_array( + v: *mut ::std::os::raw::c_void, + ) -> *mut *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to map\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to map (array of tuples (array of values))"] + pub fn metacall_value_to_map( + v: *mut ::std::os::raw::c_void, + ) -> *mut *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to pointer\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to pointer"] + pub fn metacall_value_to_ptr(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to future\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to future"] + pub fn metacall_value_to_future(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to function\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to function"] + pub fn metacall_value_to_function( + v: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to null\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to null"] + pub fn metacall_value_to_null(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to class\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to class"] + pub fn metacall_value_to_class(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to object\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to object"] + pub fn metacall_value_to_object(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to exception\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to exception"] + pub fn metacall_value_to_exception( + v: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v to throwable\n\n @param[in] v\n Reference to the value\n\n @return\n Value converted to throwable"] + pub fn metacall_value_to_throwable( + v: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign boolean @b to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] b\n Boolean to be assigned to value @v\n\n @return\n Value with boolean @b assigned to it"] + pub fn metacall_value_from_bool( + v: *mut ::std::os::raw::c_void, + b: ::std::os::raw::c_uchar, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign character @c to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] c\n Character to be assigned to value @v\n\n @return\n Value with char @c assigned to it"] + pub fn metacall_value_from_char( + v: *mut ::std::os::raw::c_void, + c: ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign short @s to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] s\n Short to be assigned to value @v\n\n @return\n Value with short @s assigned to it"] + pub fn metacall_value_from_short( + v: *mut ::std::os::raw::c_void, + s: ::std::os::raw::c_short, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign integer @i to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] i\n Integer to be assigned to value @v\n\n @return\n Value with integer @i assigned to it"] + pub fn metacall_value_from_int( + v: *mut ::std::os::raw::c_void, + i: ::std::os::raw::c_int, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign long integer @l to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] l\n Long integer to be assigned to value @v\n\n @return\n Value with long @l assigned to it"] + pub fn metacall_value_from_long( + v: *mut ::std::os::raw::c_void, + l: ::std::os::raw::c_long, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign single precision floating point @f to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] f\n Float to be assigned to value @v\n\n @return\n Value with float @f assigned to it"] + pub fn metacall_value_from_float( + v: *mut ::std::os::raw::c_void, + f: f32, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign double precision floating point @d to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] d\n Double to be assigned to value @v\n\n @return\n Value with double @d assigned to it"] + pub fn metacall_value_from_double( + v: *mut ::std::os::raw::c_void, + d: f64, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign string @str to value @v, truncates to @v size if it is smaller\n than @length + 1. It does not add null terminator if truncated.\n\n @param[in] v\n Reference to the value\n\n @param[in] str\n Constant string to be assigned to value @v (it needs to be null terminated)\n\n @param[in] length\n Length of the constant string @str\n\n @return\n Value with string @str assigned to it"] + pub fn metacall_value_from_string( + v: *mut ::std::os::raw::c_void, + str_: *const ::std::os::raw::c_char, + length: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign array @buffer to value buffer @v\n\n @param[in] v\n Reference to the value\n\n @param[in] buffer\n Constant array to be assigned to value @v\n\n @param[in] size\n Number of elements contained in @buffer\n\n @return\n Value with array @buffer assigned to it"] + pub fn metacall_value_from_buffer( + v: *mut ::std::os::raw::c_void, + buffer: *const ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign array of values @values to value array @v\n\n @param[in] v\n Reference to the value\n\n @param[in] values\n Constant array of values to be assigned to value array @v\n\n @param[in] size\n Number of values contained in constant array @values\n\n @return\n Value with array of values @values assigned to it"] + pub fn metacall_value_from_array( + v: *mut ::std::os::raw::c_void, + values: *mut *const ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign array of values @values to value map @v\n\n @param[in] v\n Reference to the value\n\n @param[in] tuples\n Constant array of tuples to be assigned to value map @v\n\n @param[in] size\n Number of values contained in constant array @tuples\n\n @return\n Value with array of tuples @tuples assigned to it"] + pub fn metacall_value_from_map( + v: *mut ::std::os::raw::c_void, + tuples: *mut *const ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign pointer reference @ptr to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] ptr\n Pointer to be assigned to value @v\n\n @return\n Value with pointer @ptr assigned to it"] + pub fn metacall_value_from_ptr( + v: *mut ::std::os::raw::c_void, + ptr: *const ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign future @f to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] f\n Future to be assigned to value @v\n\n @return\n Value with future @f assigned to it"] + pub fn metacall_value_from_future( + v: *mut ::std::os::raw::c_void, + f: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign function @f to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] f\n Function to be assigned to value @v\n\n @return\n Value with function @f assigned to it"] + pub fn metacall_value_from_function( + v: *mut ::std::os::raw::c_void, + f: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign null to value @v\n\n @param[in] v\n Reference to the value\n\n @return\n Value with null assigned to it"] + pub fn metacall_value_from_null(v: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign class @c to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] c\n Class to be assigned to value @v\n\n @return\n Value with class @c assigned to it"] + pub fn metacall_value_from_class( + v: *mut ::std::os::raw::c_void, + c: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign object @o to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] o\n Object to be assigned to value @v\n\n @return\n Value with object @o assigned to it"] + pub fn metacall_value_from_object( + v: *mut ::std::os::raw::c_void, + o: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign exception @ex to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] ex\n Exception to be assigned to value @v\n\n @return\n Value with exception @ex assigned to it"] + pub fn metacall_value_from_exception( + v: *mut ::std::os::raw::c_void, + ex: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Assign throwable @th to value @v\n\n @param[in] v\n Reference to the value\n\n @param[in] th\n Throwable to be assigned to value @v\n\n @return\n Value with throwable @th assigned to it"] + pub fn metacall_value_from_throwable( + v: *mut ::std::os::raw::c_void, + th: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Casts a value to a new type @id\n\n @param[in] v\n Reference to the value\n\n @param[in] id\n New type id of value to be casted\n\n @return\n Casted value or reference to @v if casting is between equivalent types"] + pub fn metacall_value_cast( + v: *mut ::std::os::raw::c_void, + id: metacall_value_id, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to boolean\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to boolean"] + pub fn metacall_value_cast_bool(v: *mut *mut ::std::os::raw::c_void) + -> ::std::os::raw::c_uchar; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to char\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to char"] + pub fn metacall_value_cast_char(v: *mut *mut ::std::os::raw::c_void) -> ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to short\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to short"] + pub fn metacall_value_cast_short( + v: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_short; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to int\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to int"] + pub fn metacall_value_cast_int(v: *mut *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to long\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to long"] + pub fn metacall_value_cast_long(v: *mut *mut ::std::os::raw::c_void) -> ::std::os::raw::c_long; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to float\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to float"] + pub fn metacall_value_cast_float(v: *mut *mut ::std::os::raw::c_void) -> f32; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to double\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to double"] + pub fn metacall_value_cast_double(v: *mut *mut ::std::os::raw::c_void) -> f64; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to string\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to a C string (null terminated)"] + pub fn metacall_value_cast_string( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to buffer\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to buffer"] + pub fn metacall_value_cast_buffer( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to array\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to array of values"] + pub fn metacall_value_cast_array( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to map\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to map"] + pub fn metacall_value_cast_map( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to ptr\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to ptr"] + pub fn metacall_value_cast_ptr( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to future\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to future"] + pub fn metacall_value_cast_future( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to function\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to function"] + pub fn metacall_value_cast_function( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to null\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to null"] + pub fn metacall_value_cast_null( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to class\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to class"] + pub fn metacall_value_cast_class( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to object\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to object"] + pub fn metacall_value_cast_object( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to exception\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to exception"] + pub fn metacall_value_cast_exception( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert value @v implicitly to throwable\n\n @param[in] v\n Reference to the reference of the value\n\n @return\n Value converted to throwable"] + pub fn metacall_value_cast_throwable( + v: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Destroy a value from scope stack\n\n @param[in] v\n Reference to the value"] + pub fn metacall_value_destroy(v: *mut ::std::os::raw::c_void); +} +pub type metacall_pid = pid_t; +pub type metacall_pre_fork_callback_ptr = ::std::option::Option< + unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, +>; +pub type metacall_post_fork_callback_ptr = ::std::option::Option< + unsafe extern "C" fn( + arg1: metacall_pid, + arg2: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, +>; +unsafe extern "C" { + #[doc = " @brief\n Initialize fork detours and allocate shared memory\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_fork_initialize() -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Set fork hook callback\n\n @param[in] pre_callback\n Callback to be called before fork detour is executed\n\n @param[in] post_callback\n Callback to be called after fork detour is executed"] + pub fn metacall_fork( + pre_callback: metacall_pre_fork_callback_ptr, + post_callback: metacall_post_fork_callback_ptr, + ); +} +unsafe extern "C" { + #[doc = " @brief\n Unregister fork detours and destroy shared memory"] + pub fn metacall_fork_destroy(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct metacall_initialize_configuration_type { + pub tag: *const ::std::os::raw::c_char, + pub options: *mut ::std::os::raw::c_void, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of metacall_initialize_configuration_type"] + [::std::mem::size_of::() - 16usize]; + ["Alignment of metacall_initialize_configuration_type"] + [::std::mem::align_of::() - 8usize]; + ["Offset of field: metacall_initialize_configuration_type::tag"] + [::std::mem::offset_of!(metacall_initialize_configuration_type, tag) - 0usize]; + ["Offset of field: metacall_initialize_configuration_type::options"] + [::std::mem::offset_of!(metacall_initialize_configuration_type, options) - 8usize]; +}; +pub type metacall_await_callback = ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, +>; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct metacall_await_callbacks_type { + pub resolve: metacall_await_callback, + pub reject: metacall_await_callback, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of metacall_await_callbacks_type"] + [::std::mem::size_of::() - 16usize]; + ["Alignment of metacall_await_callbacks_type"] + [::std::mem::align_of::() - 8usize]; + ["Offset of field: metacall_await_callbacks_type::resolve"] + [::std::mem::offset_of!(metacall_await_callbacks_type, resolve) - 0usize]; + ["Offset of field: metacall_await_callbacks_type::reject"] + [::std::mem::offset_of!(metacall_await_callbacks_type, reject) - 8usize]; +}; +pub type metacall_await_callbacks = metacall_await_callbacks_type; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct metacall_version_type { + pub major: ::std::os::raw::c_uint, + pub minor: ::std::os::raw::c_uint, + pub patch: ::std::os::raw::c_uint, + pub revision: *const ::std::os::raw::c_char, + pub str_: *const ::std::os::raw::c_char, + pub name: *const ::std::os::raw::c_char, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of metacall_version_type"][::std::mem::size_of::() - 40usize]; + ["Alignment of metacall_version_type"] + [::std::mem::align_of::() - 8usize]; + ["Offset of field: metacall_version_type::major"] + [::std::mem::offset_of!(metacall_version_type, major) - 0usize]; + ["Offset of field: metacall_version_type::minor"] + [::std::mem::offset_of!(metacall_version_type, minor) - 4usize]; + ["Offset of field: metacall_version_type::patch"] + [::std::mem::offset_of!(metacall_version_type, patch) - 8usize]; + ["Offset of field: metacall_version_type::revision"] + [::std::mem::offset_of!(metacall_version_type, revision) - 16usize]; + ["Offset of field: metacall_version_type::str_"] + [::std::mem::offset_of!(metacall_version_type, str_) - 24usize]; + ["Offset of field: metacall_version_type::name"] + [::std::mem::offset_of!(metacall_version_type, name) - 32usize]; +}; +unsafe extern "C" { + #[doc = " @brief\n Returns default serializer used by MetaCall\n\n @return\n Name of the serializer to be used with serialization methods"] + pub fn metacall_serial() -> *const ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Returns default detour used by MetaCall\n\n @return\n Name of the detour to be used with detouring methods"] + pub fn metacall_detour() -> *const ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Disables MetaCall logs, must be called before @metacall_initialize.\n\n When initializing MetaCall, it initializes a default logs to stdout\n if none was defined. If you want to benchmark or simply disable this\n default logs, you can call to this function before @metacall_initialize."] + pub fn metacall_log_null(); +} +unsafe extern "C" { + #[doc = " @brief\n Flags to be set in MetaCall library\n\n @param[in] flags\n Combination of flags referring to definitions METACALL_FLAGS_*"] + pub fn metacall_flags(flags: ::std::os::raw::c_int); +} +unsafe extern "C" { + #[doc = " @brief\n Initialize MetaCall library\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_initialize() -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Initialize MetaCall library with configuration arguments\n\n @param[in] initialize_config\n Extension of the script to be loaded in memory with data to be injected\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_initialize_ex( + initialize_config: *mut metacall_initialize_configuration_type, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Initialize MetaCall application arguments\n\n @param[in] argc\n Number of additional parameters to be passed to the runtime when initializing\n\n @param[in] argv\n Additional parameters to be passed to the runtime when initializing (when using MetaCall as an application)"] + pub fn metacall_initialize_args( + argc: ::std::os::raw::c_int, + argv: *mut *mut ::std::os::raw::c_char, + ); +} +unsafe extern "C" { + #[doc = " @brief\n Get the number of arguments in which MetaCall was initialized\n\n @return\n An integer equal or greater than zero"] + pub fn metacall_argc() -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Get the arguments in which MetaCall was initialized\n\n @return\n A pointer to an array of strings with the additional arguments"] + pub fn metacall_argv() -> *mut *mut ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Check if script context is loaded by @tag\n\n @param[in] tag\n Extension of the script (if tag is NULL, it returns the status of the whole MetaCall instance)\n\n @return\n Zero if context is initialized, different from zero otherwise"] + pub fn metacall_is_initialized(tag: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Amount of function call arguments supported by MetaCall\n\n @return\n Number of arguments suported"] + pub fn metacall_args_size() -> usize; +} +unsafe extern "C" { + #[doc = " @brief\n Set a execution path defined by @path to the extension script @tag\n\n @param[in] tag\n Extension of the script\n\n @param[in] path\n Path to be loaded\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_execution_path( + tag: *const ::std::os::raw::c_char, + path: *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Set a execution path defined by @path to the extension script @tag with length\n\n @param[in] tag\n Extension of the script\n\n @param[in] tag_length\n Length of the extension of the tag\n\n @param[in] path\n Path to be loaded\n\n @param[in] path_length\n Length of the path\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_execution_path_s( + tag: *const ::std::os::raw::c_char, + tag_length: usize, + path: *const ::std::os::raw::c_char, + path_length: usize, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Loads a script from file specified by @path\n\n @param[in] tag\n Extension of the script\n\n @param[in] paths\n Path array of files\n\n @param[in] size\n Size of the array @paths\n\n @param[inout] handle\n Optional pointer to reference of loaded handle. If the parameter is NULL, the symbols loaded are\n propagated to the loader scope (i.e they will share the scope between all previously loaded files and they can collide).\n Otherwise, if we pass a void* pointer set to NULL, it will behave as output parameter, obtaining the reference to the\n created handle, which can be later on used for calling to functions of that handle. The symbols will not be propagated\n to the loader scope and they will be private (this prevents collisions). The last case is if we pass an already allocated\n handle (i.e a void* pointer pointing to an previously loaded handle), then in this case, the symbols loaded will be propagated\n to the previously allocated handle, and it will behave as a in parameter.\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_load_from_file( + tag: *const ::std::os::raw::c_char, + paths: *mut *const ::std::os::raw::c_char, + size: usize, + handle: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Loads a script from memory\n\n @param[in] tag\n Extension of the script\n\n @param[in] buffer\n Memory block representing the string of the script\n\n @param[in] size\n Memory block representing the string of the script\n\n @param[inout] handle\n Optional pointer to reference of loaded handle. If the parameter is NULL, the symbols loaded are\n propagated to the loader scope (i.e they will share the scope between all previously loaded files and they can collide).\n Otherwise, if we pass a void* pointer set to NULL, it will behave as output parameter, obtaining the reference to the\n created handle, which can be later on used for calling to functions of that handle. The symbols will not be propagated\n to the loader scope and they will be private (this prevents collisions). The last case is if we pass an already allocated\n handle (i.e a void* pointer pointing to an previously loaded handle), then in this case, the symbols loaded will be propagated\n to the previously allocated handle, and it will behave as a in parameter.\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_load_from_memory( + tag: *const ::std::os::raw::c_char, + buffer: *const ::std::os::raw::c_char, + size: usize, + handle: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Loads a package of scrips from file specified by @path into loader defined by @extension\n\n @param[in] tag\n Extension of the script\n\n @param[in] path\n Path of the package\n\n @param[inout] handle\n Optional pointer to reference of loaded handle. If the parameter is NULL, the symbols loaded are\n propagated to the loader scope (i.e they will share the scope between all previously loaded files and they can collide).\n Otherwise, if we pass a void* pointer set to NULL, it will behave as output parameter, obtaining the reference to the\n created handle, which can be later on used for calling to functions of that handle. The symbols will not be propagated\n to the loader scope and they will be private (this prevents collisions). The last case is if we pass an already allocated\n handle (i.e a void* pointer pointing to an previously loaded handle), then in this case, the symbols loaded will be propagated\n to the previously allocated handle, and it will behave as a in parameter.\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_load_from_package( + tag: *const ::std::os::raw::c_char, + path: *const ::std::os::raw::c_char, + handle: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Loads a a list of scrips from configuration specified by @path into loader\n with the following format:\n {\n \"language_id\": \"\",\n \"path\": \"\",\n \"scripts\": [ \"\", \"\", ..., \"\" ]\n }\n\n @param[in] path\n Path of the configuration\n\n @param[inout] handle\n Optional pointer to reference of loaded handle. If the parameter is NULL, the symbols loaded are\n propagated to the loader scope (i.e they will share the scope between all previously loaded files and they can collide).\n Otherwise, if we pass a void* pointer set to NULL, it will behave as output parameter, obtaining the reference to the\n created handle, which can be later on used for calling to functions of that handle. The symbols will not be propagated\n to the loader scope and they will be private (this prevents collisions). The last case is if we pass an already allocated\n handle (i.e a void* pointer pointing to an previously loaded handle), then in this case, the symbols loaded will be propagated\n to the previously allocated handle, and it will behave as a in parameter.\n\n @param[in] allocator\n Pointer to allocator will allocate the configuration\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_load_from_configuration( + path: *const ::std::os::raw::c_char, + handle: *mut *mut ::std::os::raw::c_void, + allocator: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by value array @args\n\n @param[in] name\n Name of the function\n\n @param[in] args\n Array of pointers to data\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallv( + name: *const ::std::os::raw::c_char, + args: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by value array @args\n\n @param[in] name\n Name of the function\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of the call\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallv_s( + name: *const ::std::os::raw::c_char, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by handle @handle value array @args\n This function allows to avoid name collisions when calling functions by name\n\n @param[in] handle\n Handle where the function belongs\n\n @param[in] name\n Name of the function\n\n @param[in] args\n Array of pointers to data\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallhv( + handle: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + args: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by handle @handle value array @args\n This function allows to avoid name collisions when calling functions by name\n Includes @size in order to allow variadic arguments or safe calls\n\n @param[in] handle\n Handle where the function belongs\n\n @param[in] name\n Name of the function\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of the call\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallhv_s( + handle: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by variable arguments @va_args\n\n @param[in] name\n Name of the function\n\n @param[in] va_args\n Varidic function parameters\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacall(name: *const ::std::os::raw::c_char, ...) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by type array @ids and variable arguments @va_args\n\n @param[in] name\n Name of the function\n\n @param[in] ids\n Array of types refered to @va_args\n\n @param[in] va_args\n Varidic function parameters\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallt( + name: *const ::std::os::raw::c_char, + ids: *const metacall_value_id, + ... + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by type array @ids and variable arguments @va_args\n\n @param[in] name\n Name of the function\n\n @param[in] ids\n Array of types refered to @va_args\n\n @param[in] size\n Number of elements of the call\n\n @param[in] va_args\n Varidic function parameters\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallt_s( + name: *const ::std::os::raw::c_char, + ids: *const metacall_value_id, + size: usize, + ... + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by type array @ids and variable arguments @va_args\n\n @param[in] handle\n Pointer to the handle returned by metacall_load_from_{file, memory, package}\n\n @param[in] name\n Name of the function\n\n @param[in] ids\n Array of types refered to @va_args\n\n @param[in] size\n Number of elements of the call\n\n @param[in] va_args\n Varidic function parameters\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallht_s( + handle: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + ids: *const metacall_value_id, + size: usize, + ... + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Get the function by @name\n\n @param[in] name\n Name of the function\n\n @return\n Function reference, null if the function does not exist"] + pub fn metacall_function(name: *const ::std::os::raw::c_char) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create an empty handler into a loader with name @name\n\n @param[in] loader\n Pointer to the loader which the handle belongs to\n\n @param[in] name\n Name of the handle\n\n @param[out] handle_ptr\n On success, returns the pointer to the handle created, otherwise NULL\n\n @return\n Return zero on success, different from zero on error"] + pub fn metacall_handle_initialize( + loader: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + handle_ptr: *mut *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Populate the objects of @handle_src into @handle_dest\n\n @param[inout] handle_dest\n Handle where the objects from @handle_src will be stored\n\n @param[in] handle_src\n Handle from where the objects will be copied\n\n @return\n Return zero on success, different from zero on error"] + pub fn metacall_handle_populate( + handle_dest: *mut ::std::os::raw::c_void, + handle_src: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Get the function by @name from @handle\n\n @param[in] handle\n Pointer to the handle returned by metacall_load_from_{file, memory, package}\n\n @param[in] name\n Name of the function\n\n @return\n Function reference, null if the function does not exist"] + pub fn metacall_handle_function( + handle: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Get the function parameter type id\n\n @param[in] func\n The pointer to the function obtained from metacall_function\n\n @param[in] parameter\n The index of the parameter to be retrieved\n\n @param[out] id\n The parameter type id that will be returned\n\n @return\n Return 0 if the @parameter index exists and @func is valid, 1 otherwhise"] + pub fn metacall_function_parameter_type( + func: *mut ::std::os::raw::c_void, + parameter: usize, + id: *mut metacall_value_id, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Get the function return type id\n\n @param[in] func\n The pointer to the function obtained from metacall_function\n\n\n @param[out] id\n The value id of the return type of the function @func\n\n @return\n Return 0 if the @func is valid, 1 otherwhise"] + pub fn metacall_function_return_type( + func: *mut ::std::os::raw::c_void, + id: *mut metacall_value_id, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Get minimun mumber of arguments accepted by function @func\n\n @param[in] func\n Function reference\n\n @return\n Return mumber of arguments"] + pub fn metacall_function_size(func: *mut ::std::os::raw::c_void) -> usize; +} +unsafe extern "C" { + #[doc = " @brief\n Check if the function @func is asynchronous or synchronous\n\n @param[in] func\n Function reference\n\n @return\n Return 0 if it is syncrhonous, 1 if it is asynchronous and -1 if the function is NULL"] + pub fn metacall_function_async(func: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Get the handle by @name\n\n @param[in] tag\n Extension of the script\n\n @param[in] name\n Name of the handle\n\n @return\n Handle reference, null if the function does not exist"] + pub fn metacall_handle( + tag: *const ::std::os::raw::c_char, + name: *const ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Get name of a @handle\n\n @param[in] handle\n Pointer to the handle to be retrieved\n\n @return\n String that references the handle"] + pub fn metacall_handle_id(handle: *mut ::std::os::raw::c_void) + -> *const ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Return a value representing the handle as a map of functions (or values)\n\n @param[in] handle\n Reference to the handle to be described\n\n @return\n A value of type map on success, null otherwise"] + pub fn metacall_handle_export( + handle: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by value array @args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to data\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallfv( + func: *mut ::std::os::raw::c_void, + args: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by value array @args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of function arguments\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallfv_s( + func: *mut ::std::os::raw::c_void, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by variable arguments @va_args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallf(func: *mut ::std::os::raw::c_void, ...) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by function @func and serial @buffer of size @size\n\n @param[in] func\n Reference to function to be called\n\n @param[in] buffer\n String representing an array to be deserialized into arguments of the function\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallfs( + func: *mut ::std::os::raw::c_void, + buffer: *const ::std::os::raw::c_char, + size: usize, + allocator: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by value map (@keys -> @values) and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] keys\n Array of values representing argument keys\n\n @param[in] values\n Array of values representing argument values data\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallfmv( + func: *mut ::std::os::raw::c_void, + keys: *mut *mut ::std::os::raw::c_void, + values: *mut *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a function anonymously by function @func and serial @buffer of size @size\n\n @param[in] func\n Reference to function to be called\n\n @param[in] buffer\n String representing a map to be deserialized into arguments of the function\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallfms( + func: *mut ::std::os::raw::c_void, + buffer: *const ::std::os::raw::c_char, + size: usize, + allocator: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Register a function by name @name and arguments @va_args\n\n @param[in] name\n Name of the function (if it is NULL, function is not registered into host scope)\n\n @param[in] invoke\n Pointer to function invoke interface (argc, argv, data)\n\n @param[out] func\n Will set the pointer to the function if the parameter is not null\n\n @param[in] return_type\n Type of return value\n\n @param[in] size\n Number of function arguments\n\n @param[in] va_args\n Varidic function parameter types\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacall_register( + name: *const ::std::os::raw::c_char, + invoke: ::std::option::Option< + unsafe extern "C" fn( + arg1: usize, + arg2: *mut *mut ::std::os::raw::c_void, + arg3: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + func: *mut *mut ::std::os::raw::c_void, + return_type: metacall_value_id, + size: usize, + ... + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Register a function by name @name and arguments @types\n\n @param[in] name\n Name of the function (if it is NULL, function is not registered into host scope)\n\n @param[in] invoke\n Pointer to function invoke interface (argc, argv, data)\n\n @param[out] func\n Will set the pointer to the function if the parameter is not null\n\n @param[in] return_type\n Type of return value\n\n @param[in] size\n Number of function arguments\n\n @param[in] types\n List of parameter types\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacall_registerv( + name: *const ::std::os::raw::c_char, + invoke: ::std::option::Option< + unsafe extern "C" fn( + arg1: usize, + arg2: *mut *mut ::std::os::raw::c_void, + arg3: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + func: *mut *mut ::std::os::raw::c_void, + return_type: metacall_value_id, + size: usize, + types: *mut metacall_value_id, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Obtain the loader instance by @tag\n\n @param[in] tag\n Tag in which the loader is identified, normally it is the extension of the script\n\n @return\n Pointer the loader by @tag"] + pub fn metacall_loader(tag: *const ::std::os::raw::c_char) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Register a function by name @name and arguments @types\n\n @param[in] loader\n Opaque pointer to the loader in which you want to register the function (this allows to register the function into a different loader than the host)\n\n @param[in] handle\n Opaque pointer to the handle in which you want to register the function (if it is NULL, it will be defined on the global scope of the loader)\n\n @param[in] name\n Name of the function (if it is NULL, function is not registered into host scope)\n\n @param[in] invoke\n Pointer to function invoke interface (argc, argv, data)\n\n @param[in] return_type\n Type of return value\n\n @param[in] size\n Number of function arguments\n\n @param[in] types\n List of parameter types\n\n @return\n Zero if the function was registered properly, distinct from zero otherwise"] + pub fn metacall_register_loaderv( + loader: *mut ::std::os::raw::c_void, + handle: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + invoke: ::std::option::Option< + unsafe extern "C" fn( + arg1: usize, + arg2: *mut *mut ::std::os::raw::c_void, + arg3: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + return_type: metacall_value_id, + size: usize, + types: *mut metacall_value_id, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Executes an asynchronous call to the function and registers a callback to be executed when a future is resolved (it does block)\n\n @param[in] name\n The name of the function to be called asynchronously\n\n @param[in] args\n Array of pointers to the values to be passed to the function\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacall_await( + name: *const ::std::os::raw::c_char, + args: *mut *mut ::std::os::raw::c_void, + resolve_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + reject_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Awaits for a promise and registers a callback to be executed when a future is resolved\n\n @param[in] f\n The pointer to the future\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacall_await_future( + f: *mut ::std::os::raw::c_void, + resolve_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + reject_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Executes an asynchronous call to the function and registers a callback to be executed when a future is resolved (it does block)\n\n @param[in] name\n The name of the function to be called asynchronously\n\n @param[in] args\n Array of pointers to the values to be passed to the function\n\n @param[in] size\n Number of elements of the array @args\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacall_await_s( + name: *const ::std::os::raw::c_char, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + resolve_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + reject_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call an asynchronous function anonymously by value array @args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to values\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacallfv_await( + func: *mut ::std::os::raw::c_void, + args: *mut *mut ::std::os::raw::c_void, + resolve_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + reject_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call an asynchronous function anonymously by value array @args and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to values\n\n @param[in] size\n Number of elements of the array @args\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacallfv_await_s( + func: *mut ::std::os::raw::c_void, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + resolve_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + reject_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call an asynchronous function anonymously by value array @args and function @func (offered without function pointers for languages without support to function pointers)\n\n @param[in] func\n Reference to function to be called\n\n @param[in] args\n Array of pointers to values\n\n @param[in] size\n Number of elements of the array @args\n\n @param[in] cb\n Pointer to struct containing the function pointers to reject and resolve that will be executed when task completion or error\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacallfv_await_struct_s( + func: *mut ::std::os::raw::c_void, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + cb: metacall_await_callbacks, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call an asynchronous function anonymously by value map (@keys -> @values) and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] keys\n Array of values representing argument keys\n\n @param[in] values\n Array of values representing argument values data\n\n @param[in] size\n Number of elements of the arrays @keys and @values\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacallfmv_await( + func: *mut ::std::os::raw::c_void, + keys: *mut *mut ::std::os::raw::c_void, + values: *mut *mut ::std::os::raw::c_void, + resolve_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + reject_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call an asynchronous function anonymously by value map (@keys -> @values) and function @func\n\n @param[in] func\n Reference to function to be called\n\n @param[in] keys\n Array of values representing argument keys\n\n @param[in] values\n Array of values representing argument values data\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacallfmv_await_s( + func: *mut ::std::os::raw::c_void, + keys: *mut *mut ::std::os::raw::c_void, + values: *mut *mut ::std::os::raw::c_void, + size: usize, + resolve_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + reject_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call an asynchronous function anonymously by function @func and serial @buffer of size @size\n\n @param[in] func\n Reference to function to be called\n\n @param[in] buffer\n String representing an array to be deserialized into arguments of the function\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacallfs_await( + func: *mut ::std::os::raw::c_void, + buffer: *const ::std::os::raw::c_char, + size: usize, + allocator: *mut ::std::os::raw::c_void, + resolve_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + reject_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call an asynchronous function anonymously by function @func and serial @buffer of size @size\n\n @param[in] func\n Reference to function to be called\n\n @param[in] buffer\n String representing a map to be deserialized into arguments of the function\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @param[in] resolve_callback\n Pointer to function that will be executed when task completion\n @param[in] void *\n Value representing the result of the future resolution\n @param[in] void *\n A reference to @data that will be used as a closure for the chain\n @return\n Value containing the result of the operation,\n it will be wrapped into a future later on to be returned by the function\n\n @param[in] reject_callback\n Pointer to function that will be executed when task error (signature is identical as resolve_callback)\n\n @param[in] data\n Pointer to a context that will act as a closure for the chain\n\n @return\n Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future"] + pub fn metacallfms_await( + func: *mut ::std::os::raw::c_void, + buffer: *const ::std::os::raw::c_char, + size: usize, + allocator: *mut ::std::os::raw::c_void, + resolve_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + reject_callback: ::std::option::Option< + unsafe extern "C" fn( + arg1: *mut ::std::os::raw::c_void, + arg2: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void, + >, + data: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Get the class by @name\n\n @param[in] name\n Name of the class\n\n @return\n Class reference, null if the class does not exist"] + pub fn metacall_class(name: *const ::std::os::raw::c_char) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a class method anonymously by value array @args (this procedure assumes there's no overloaded methods and does type conversion on values)\n\n @param[in] cls\n Pointer to the class\n\n @param[in] name\n Name of the method\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of args array\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallv_class( + cls: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a class method anonymously by value array @args and return value type @ret (helps to resolve overloading methods)\n\n @param[in] cls\n Pointer to the class\n\n @param[in] name\n Name of the method\n\n @param[in] ret\n Type of the return value of the method\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of args array\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallt_class( + cls: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + ret: metacall_value_id, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Create a new object instance from @cls by value array @args\n\n @param[in] cls\n Pointer to the class\n\n @param[in] name\n Name of the new object\n\n @param[in] args\n Array of pointers constructor parameters\n\n @param[in] size\n Number of elements of constructor parameters\n\n @return\n Pointer to the new object value instance"] + pub fn metacall_class_new( + cls: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Get an attribute from @cls by @key name\n\n @param[in] cls\n Pointer to the class\n\n @param[in] key\n Name of the attribute to get\n\n @return\n Pointer to the class attribute value or NULL if an error occurred"] + pub fn metacall_class_static_get( + cls: *mut ::std::os::raw::c_void, + key: *const ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Set an attribute to @cls by @key name\n\n @param[in] cls\n Pointer to the class\n\n @param[in] key\n Name of the attribute to set\n\n @param[in] value\n Value to set\n\n @return\n Non-zero integer if an error ocurred"] + pub fn metacall_class_static_set( + cls: *mut ::std::os::raw::c_void, + key: *const ::std::os::raw::c_char, + v: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Call an object method anonymously by value array @args\n\n @param[in] obj\n Pointer to the object\n\n @param[in] name\n Name of the method\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of args array\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallv_object( + obj: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Call a object method anonymously by value array @args and return value type @ret (helps to resolve overloading methods)\n\n @param[in] obj\n Pointer to the object\n\n @param[in] name\n Name of the method\n\n @param[in] ret\n Type of the return value of the method\n\n @param[in] args\n Array of pointers to data\n\n @param[in] size\n Number of elements of args array\n\n @return\n Pointer to value containing the result of the call"] + pub fn metacallt_object( + obj: *mut ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + ret: metacall_value_id, + args: *mut *mut ::std::os::raw::c_void, + size: usize, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Get an attribute from @obj by @key name\n\n @param[in] obj\n Pointer to the object\n\n @param[in] key\n Name of the attribute to get\n\n @return\n Pointer to the object attribute value or NULL if an error occurred"] + pub fn metacall_object_get( + obj: *mut ::std::os::raw::c_void, + key: *const ::std::os::raw::c_char, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Set an attribute to @obj by @key name\n\n @param[in] obj\n Pointer to the object\n\n @param[in] key\n Name of the attribute to set\n\n @param[in] value\n Value to set\n\n @return\n Non-zero integer if an error ocurred"] + pub fn metacall_object_set( + obj: *mut ::std::os::raw::c_void, + key: *const ::std::os::raw::c_char, + v: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Get the value contained by throwable object @th\n\n @param[in] th\n Pointer to the throwable object\n\n @return\n Pointer to the value inside of the throwable or NULL in case of error"] + pub fn metacall_throwable_value(th: *mut ::std::os::raw::c_void) + -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Provide information about all loaded objects\n\n @param[out] size\n Size in bytes of return buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the string\n\n @return\n String containing introspection information"] + pub fn metacall_inspect( + size: *mut usize, + allocator: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Provide information about all loaded objects as a value\n\n @return\n Value containing introspection information"] + pub fn metacall_inspect_value() -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Convert the value @v to serialized string\n\n @param[in] name\n Name of the serial to be used\n\n @param[in] v\n Reference to the value\n\n @param[out] size\n Size of new allocated string\n\n @param[in] allocator\n Pointer to allocator will allocate the string\n\n @return\n New allocated string containing stringified value"] + pub fn metacall_serialize( + name: *const ::std::os::raw::c_char, + v: *mut ::std::os::raw::c_void, + size: *mut usize, + allocator: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Convert the string @buffer to value\n\n @param[in] name\n Name of the serial to be used\n\n @param[in] buffer\n String to be deserialized\n\n @param[in] size\n Size of string @buffer\n\n @param[in] allocator\n Pointer to allocator will allocate the value\n\n @return\n New allocated value representing the string (must be freed)"] + pub fn metacall_deserialize( + name: *const ::std::os::raw::c_char, + buffer: *const ::std::os::raw::c_char, + size: usize, + allocator: *mut ::std::os::raw::c_void, + ) -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Clear handle from memory and unload related resources\n\n @param[in] handle\n Reference to the handle to be unloaded\n\n @return\n Zero if success, different from zero otherwise"] + pub fn metacall_clear(handle: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int; +} +unsafe extern "C" { + #[doc = " @brief\n Get the plugin extension handle to be used for loading plugins\n\n @return\n Pointer to the extension handle, or null if it failed to load"] + pub fn metacall_plugin_extension() -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Get the handle containing all the functionality of the plugins from core\n\n @return\n Pointer to the core plugin handle, or null if it failed to load"] + pub fn metacall_plugin_core() -> *mut ::std::os::raw::c_void; +} +unsafe extern "C" { + #[doc = " @brief\n Get the plugin extension path to be used for accessing the plugins folder\n\n @return\n String containing the core plugin path, or null if it failed to load the plugin extension"] + pub fn metacall_plugin_path() -> *const ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Destroy MetaCall library"] + pub fn metacall_destroy(); +} +unsafe extern "C" { + #[doc = " @brief\n Provide the module version struct\n\n @return\n Static struct containing unpacked version"] + pub fn metacall_version() -> *const metacall_version_type; +} +unsafe extern "C" { + #[doc = " @brief\n Provide the module version hexadecimal value\n with format 0xMMIIPPPP where M is @major,\n I is @minor and P is @patch\n\n @param[in] major\n Unsigned integer representing major version\n\n @param[in] minor\n Unsigned integer representing minor version\n\n @param[in] patch\n Unsigned integer representing patch version\n\n @return\n Hexadecimal integer containing packed version"] + pub fn metacall_version_hex_make( + major: ::std::os::raw::c_uint, + minor: ::std::os::raw::c_uint, + patch: ::std::os::raw::c_uint, + ) -> u32; +} +unsafe extern "C" { + #[doc = " @brief\n Provide the module version hexadecimal value\n with format 0xMMIIPPPP where M is major,\n I is minor and P is patch\n\n @return\n Hexadecimal integer containing packed version"] + pub fn metacall_version_hex() -> u32; +} +unsafe extern "C" { + #[doc = " @brief\n Provide the module version string\n\n @return\n Static string containing module version"] + pub fn metacall_version_str() -> *const ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Provide the module version revision string\n\n @return\n Static string containing module version revision"] + pub fn metacall_version_revision() -> *const ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Provide the module version name\n\n @return\n Static string containing module version name"] + pub fn metacall_version_name() -> *const ::std::os::raw::c_char; +} +unsafe extern "C" { + #[doc = " @brief\n Provide the module information\n\n @return\n Static string containing module information"] + pub fn metacall_print_info() -> *const ::std::os::raw::c_char; +} diff --git a/source/ports/rs_port/src/lib.rs b/source/ports/rs_port/src/lib.rs index 328236d57..678ba3fbf 100644 --- a/source/ports/rs_port/src/lib.rs +++ b/source/ports/rs_port/src/lib.rs @@ -41,15 +41,15 @@ //! Now let's jump into Rust: //! //! ``` -//! use metacall::{switch, metacall, loaders}; +//! use metacall::{initialize, metacall, load}; //! //! fn main() { //! // Initialize MetaCall at the top -//! let _metacall = switch::initialize().unwrap(); +//! let _metacall = initialize().unwrap(); //! //! // Load the file (Checkout the loaders module for loading multiple files //! // or loading from string) -//! load::from_single_file("ts", "sum.ts").unwrap(); +//! load::from_single_file(load::Tag::TypeScript, "sum.ts").unwrap(); //! //! // Call the sum function (Also checkout other metacall functions) //! let sum = metacall::("sum", [1.0, 2.0]).unwrap(); @@ -66,14 +66,14 @@ pub(crate) use macros::private_macros::*; /// Contains MetaCall loaders from file and memory. Usage example: ... /// ``` /// // Loading a single file with Nodejs. -/// metacall::load::from_single_file("node", "index.js").unwrap(); +/// metacall::load::from_single_file(metacall::load::Tag::NodeJS, "index.js").unwrap(); /// /// // Loading multiple files with Nodejs. -/// metacall::load::from_file("node", ["index.js", "main.js"]).unwrap(); +/// metacall::load::from_file(metacall::load::Tag::NodeJS, ["index.js", "main.js"]).unwrap(); /// /// // Loading a string with Nodejs. /// let script = "function greet() { return 'hi there!' }; module.exports = { greet };"; -/// metacall::load::from_memory("node", script).unwrap(); +/// metacall::load::from_memory(metacall::load::Tag::NodeJS, script, None).unwrap(); /// ``` pub mod load; diff --git a/source/ports/rs_port/src/load.rs b/source/ports/rs_port/src/load.rs index 4c9f8cc55..290c7071d 100644 --- a/source/ports/rs_port/src/load.rs +++ b/source/ports/rs_port/src/load.rs @@ -1,62 +1,157 @@ use crate::{ - bindings::{metacall_load_from_file, metacall_load_from_memory}, + bindings::{metacall_clear, metacall_load_from_file, metacall_load_from_memory}, cstring_enum, types::MetaCallLoaderError, }; use std::{ ffi::CString, + fmt, + os::raw::c_void, path::{Path, PathBuf}, - ptr, + ptr::null_mut, }; -/// Loads a script from a single file. Usage example: ... +pub enum Tag { + C, + Cobol, + Crystal, + CSharp, + Dart, + Deno, + Extension, + File, + Java, + Julia, + JavaScript, + JSM, + Kind, + LLVM, + Lua, + Mock, + NodeJS, + Python, + Ruby, + RPC, + Rust, + TypeScript, + Wasm, +} + +impl fmt::Display for Tag { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Tag::C => write!(f, "c"), + Tag::Cobol => write!(f, "cob"), + Tag::Crystal => write!(f, "cr"), + Tag::CSharp => write!(f, "cs"), + Tag::Dart => write!(f, "dart"), + Tag::Deno => write!(f, "deno"), + Tag::Extension => write!(f, "ext"), + Tag::File => write!(f, "file"), + Tag::Java => write!(f, "java"), + Tag::Julia => write!(f, "jl"), + Tag::JavaScript => write!(f, "js"), + Tag::JSM => write!(f, "jsm"), + Tag::Kind => write!(f, "kind"), + Tag::LLVM => write!(f, "llvm"), + Tag::Lua => write!(f, "lua"), + Tag::Mock => write!(f, "mock"), + Tag::NodeJS => write!(f, "node"), + Tag::Python => write!(f, "py"), + Tag::Ruby => write!(f, "rb"), + Tag::RPC => write!(f, "rpc"), + Tag::Rust => write!(f, "rs"), + Tag::TypeScript => write!(f, "ts"), + Tag::Wasm => write!(f, "wasm"), + } + } +} + +pub struct Handle(*mut c_void); + +impl Handle { + pub fn new() -> Self { + Self(null_mut()) + } + + pub fn as_mut_raw_ptr(&mut self) -> *mut c_void { + self.0 + } +} + +impl Default for Handle { + fn default() -> Self { + Self::new() + } +} + +impl Drop for Handle { + fn drop(&mut self) { + let result = unsafe { metacall_clear(self.0) }; + + if result != 0 { + // Log or handle the error as needed + eprintln!("Error during cleanup, metacall_clear returned: {}", result); + } + } +} + +/// Loads a file from a single file. Usage example: ... /// ``` -/// // A Nodejs script +/// // A Nodejs path /// metacall::load::from_single_file("node", "index.js").unwrap(); /// ``` pub fn from_single_file( - tag: impl ToString, - script: impl AsRef, + tag: Tag, + path: impl AsRef, + handle: Option<&mut Handle>, ) -> Result<(), MetaCallLoaderError> { - from_file(tag, [script]) + from_file(tag, [path], handle) } -/// Loads a script from file. Usage example: ... + +/// Loads a path from file. Usage example: ... /// ``` /// // A Nodejs script -/// metacall::load::from_file("node", ["index.js", "main.js"]).unwrap(); +/// metacall::load::from_file(Tag::NodeJS, ["index.js", "main.js"]).unwrap(); /// ``` pub fn from_file( - tag: impl ToString, - scripts: impl IntoIterator>, + tag: Tag, + paths: impl IntoIterator>, + handle: Option<&mut Handle>, ) -> Result<(), MetaCallLoaderError> { let c_tag = cstring_enum!(tag, MetaCallLoaderError)?; - let mut c_script: CString; + let mut c_path: CString; - let mut new_scripts: Vec<*const i8> = Vec::new(); - for script in scripts.into_iter() { - let script_as_pathbuf = PathBuf::from(script.as_ref()); - let script_as_str = script_as_pathbuf.to_str().unwrap(); + let mut new_paths: Vec<*const i8> = Vec::new(); + for path in paths.into_iter() { + let path_as_pathbuf = PathBuf::from(path.as_ref()); + let path_as_str = path_as_pathbuf.to_str().unwrap(); - if !script_as_pathbuf.exists() { - return Err(MetaCallLoaderError::FileNotFound(script_as_pathbuf)); + if !path_as_pathbuf.exists() { + return Err(MetaCallLoaderError::FileNotFound(path_as_pathbuf)); } - if !script_as_pathbuf.is_file() { + if !path_as_pathbuf.is_file() { return Err(MetaCallLoaderError::NotAFileOrPermissionDenied( - script_as_pathbuf, + path_as_pathbuf, )); } - c_script = cstring_enum!(script_as_str, MetaCallLoaderError)?; + c_path = cstring_enum!(path_as_str, MetaCallLoaderError)?; - new_scripts.push(c_script.as_ptr()); + new_paths.push(c_path.as_ptr()); } + let handle_ref = match handle { + Some(handle_ptr) => &mut handle_ptr.0, + None => null_mut(), + }; + if unsafe { metacall_load_from_file( c_tag.as_ptr(), - new_scripts.as_mut_ptr(), - new_scripts.len(), - ptr::null_mut(), + new_paths.as_mut_ptr(), + new_paths.len(), + handle_ref, ) } != 0 { @@ -71,19 +166,28 @@ pub fn from_file( /// let script = "function greet() { return 'hi there!' }; module.exports = { greet };"; /// /// // A Nodejs script -/// metacall::load::from_memory("node", script).unwrap(); +/// metacall::load::from_memory(Tag::NodeJS, script).unwrap(); /// ``` -pub fn from_memory(tag: impl ToString, script: impl ToString) -> Result<(), MetaCallLoaderError> { +pub fn from_memory( + tag: Tag, + script: impl ToString, + handle: Option<&mut Handle>, +) -> Result<(), MetaCallLoaderError> { let script = script.to_string(); let c_tag = cstring_enum!(tag, MetaCallLoaderError)?; let c_script = cstring_enum!(script, MetaCallLoaderError)?; + let handle_ref = match handle { + Some(handle_ptr) => &mut handle_ptr.0, + None => null_mut(), + }; + if unsafe { metacall_load_from_memory( c_tag.as_ptr(), c_script.as_ptr(), script.len() + 1, - ptr::null_mut(), + handle_ref, ) } != 0 { diff --git a/source/ports/rs_port/src/metacall.rs b/source/ports/rs_port/src/metacall.rs index f6e75c307..7fe38a8bc 100644 --- a/source/ports/rs_port/src/metacall.rs +++ b/source/ports/rs_port/src/metacall.rs @@ -1,6 +1,7 @@ use crate::{ - bindings::{metacall_function, metacall_value_destroy, metacallfv_s}, + bindings::{metacall_function, metacall_value_destroy, metacallfv_s, metacallhv_s}, cast, cstring_enum, + load::Handle, types::{MetaCallError, MetaCallNull, MetaCallValue}, }; use std::ffi::c_void; @@ -31,6 +32,33 @@ fn metacall_inner( Ok(ret) } + +fn metacall_inner_handle( + handle: &mut Handle, + func: impl ToString, + args: impl IntoIterator, +) -> Result<*mut c_void, MetaCallError> { + let c_function = cstring_enum!(func, MetaCallError)?; + + let mut c_args = cast::metacallobj_to_raw_args(args); + let args_length = c_args.len(); + + let ret = unsafe { + metacallhv_s( + handle.as_mut_raw_ptr(), + c_function.as_ptr(), + c_args.as_mut_ptr(), + args_length, + ) + }; + + for c_arg in c_args { + unsafe { metacall_value_destroy(c_arg) }; + } + + Ok(ret) +} + /// Calls a function same as [metacall](metacall) but returns a trait object /// of [MetaCallValue](MetaCallValue). This is useful when you don't know the return /// type of that function or the function may return multiple types. Checkout @@ -70,6 +98,24 @@ pub fn metacall( Err(original) => Err(MetaCallError::FailedCasting(original)), } } + +/// Calls a function with arguments. The generic parameter is the return type of the function +/// you're calling. Checkout [MetaCallValue](MetaCallValue) for possible types. +/// For example: ... +/// ``` +/// let sum = metacall::metacall_handle::(handle, "sum", [1, 2]).unwrap(); +/// ``` +pub fn metacall_handle( + handle: &mut Handle, + func: impl ToString, + args: impl IntoIterator, +) -> Result { + match cast::raw_to_metacallobj::(metacall_inner_handle(handle, func, args)?) { + Ok(ret) => Ok(ret), + Err(original) => Err(MetaCallError::FailedCasting(original)), + } +} + /// Calls a function same as [metacall](metacall) without passing any arguments. For example: ... /// ``` /// let greet = metacall::metacall_no_arg::("greet").unwrap(); @@ -77,3 +123,14 @@ pub fn metacall( pub fn metacall_no_arg(func: impl ToString) -> Result { metacall::(func, [] as [MetaCallNull; 0]) } + +/// Calls a function same as [metacall](metacall) without passing any arguments. For example: ... +/// ``` +/// let greet = metacall::metacall_no_arg::("greet").unwrap(); +/// ``` +pub fn metacall_handle_no_arg( + handle: &mut Handle, + func: impl ToString, +) -> Result { + metacall_handle::(handle, func, [] as [MetaCallNull; 0]) +} diff --git a/source/ports/rs_port/src/types/metacall_future.rs b/source/ports/rs_port/src/types/metacall_future.rs index de051d0d5..6caa25d53 100644 --- a/source/ports/rs_port/src/types/metacall_future.rs +++ b/source/ports/rs_port/src/types/metacall_future.rs @@ -19,7 +19,8 @@ use std::{ /// and the second argument is the data that you may want to access when the function gets called. /// Checkout [MetaCallFuture resolve](MetaCallFuture#method.then) or /// [MetaCallFuture reject](MetaCallFuture#method.catch) for usage. -pub type MetaCallFutureHandler = fn(Box, Box) -> Box; +pub type MetaCallFutureHandler = + fn(Box, Option>) -> Box; /// Represents MetaCallFuture. Keep in mind that it's not supported to pass a future as an argument. /// @@ -118,7 +119,12 @@ type MetaCallFutureFFIData = ( unsafe extern "C" fn resolver(resolve_data: *mut c_void, upper_data: *mut c_void) -> *mut c_void { let (resolve, _, data) = *Box::from_raw(upper_data as *mut MetaCallFutureFFIData); - let user_data = Box::from_raw(data); + + let user_data = if !data.is_null() { + Some(Box::from_raw(data)) + } else { + None + }; let result = (resolve.unwrap())( cast::raw_to_metacallobj_untyped_leak(resolve_data), @@ -133,7 +139,12 @@ unsafe extern "C" fn resolver(resolve_data: *mut c_void, upper_data: *mut c_void } unsafe extern "C" fn rejecter(reject_data: *mut c_void, upper_data: *mut c_void) -> *mut c_void { let (_, reject, data) = *Box::from_raw(upper_data as *mut MetaCallFutureFFIData); - let user_data = Box::from_raw(data); + + let user_data = if !data.is_null() { + Some(Box::from_raw(data)) + } else { + None + }; let result = (reject.unwrap())( cast::raw_to_metacallobj_untyped_leak(reject_data), @@ -273,28 +284,6 @@ impl MetaCallFuture { None }, if reject_is_some { Some(rejecter) } else { None }, - // TODO: Solve the memory leak that happens here - // For reproducing the error, use the following commands: - // cargo test --no-run - // valgrind --trace-children=yes --leak-check=full --tool=memcheck --suppressions=../../../source/tests/memcheck/valgrind-node.supp ./target/debug/deps/metacall_test-248af33824f71bd1 &> output - // ==20664== 60 (32 direct, 28 indirect) bytes in 1 blocks are definitely lost in loss record 11 of 35 - // ==20664== at 0x4842839: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) - // ==20664== by 0x17B549: alloc (alloc.rs:93) - // ==20664== by 0x17B549: alloc::alloc::Global::alloc_impl (alloc.rs:175) - // ==20664== by 0x17B342: allocate (alloc.rs:235) - // ==20664== by 0x17B342: alloc::alloc::exchange_malloc (alloc.rs:324) - // ==20664== by 0x1873D0: new<(core::option::Option, alloc::boxed::Box)>, core::option::Option, alloc::boxed::Box)>, *mut dyn metacall::types::metacall_value::MetaCallValue)> (boxed.rs:217) - // ==20664== by 0x1873D0: metacall::types::metacall_future::MetaCallFuture::await_fut (metacall_future.rs:182) - // ==20664== by 0x1296E6: metacall_test::test_future::{{closure}} (metacall_test.rs:202) - // ==20664== by 0x1286A2: metacall_test::generate_test_custom_validation (metacall_test.rs:42) - // ==20664== by 0x12625A: metacall_test::test_future (metacall_test.rs:193) - // ==20664== by 0x126954: metacall_test::metacall (metacall_test.rs:368) - // ==20664== by 0x129736: metacall_test::metacall::{{closure}} (metacall_test.rs:337) - // ==20664== by 0x1256B4: core::ops::function::FnOnce::call_once (function.rs:250) - // ==20664== by 0x166EBE: call_once core::result::Result<(), alloc::string::String>, ()> (function.rs:250) - // ==20664== by 0x166EBE: test::__rust_begin_short_backtrace (lib.rs:655) - // ==20664== by 0x13456B: {closure#1} (lib.rs:646) - // ==20664== by 0x13456B: core::ops::function::FnOnce::call_once{{vtable-shim}} (function.rs:250) Box::into_raw(Box::new((self.resolve, self.reject, self.data))) as *mut c_void, )) }; diff --git a/source/ports/rs_port/sys/Cargo.toml b/source/ports/rs_port/sys/Cargo.toml new file mode 100644 index 000000000..398dcaf52 --- /dev/null +++ b/source/ports/rs_port/sys/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "metacall-sys" +version = "0.1.2" +repository = "https://github.com/metacall/core/tree/develop/source/ports/rs_port/sys" +keywords = ["ffi", "bindings", "metacall"] +edition = "2021" +license = "Apache-2.0" +description = "Crate for finding metacall library in the system." + +[lib] +crate-type = ["lib"] +doctest = false +edition = "2021" +name = "metacall_sys" +path = "src/lib.rs" diff --git a/source/ports/rs_port/sys/src/lib.rs b/source/ports/rs_port/sys/src/lib.rs new file mode 100644 index 000000000..f33176aaf --- /dev/null +++ b/source/ports/rs_port/sys/src/lib.rs @@ -0,0 +1,297 @@ +use std::{ + env, fs, + path::{Path, PathBuf}, + vec, +}; + +// Search for MetaCall libraries in platform-specific locations +// Handle custom installation paths via environment variables +// Find configuration files recursively +// Provide helpful error messages when things aren't found + +/// Represents the install paths for a platform +struct InstallPath { + paths: Vec, + names: Vec<&'static str>, +} + +/// Represents the match of a library when it's found +struct LibraryPath { + path: PathBuf, + library: String, +} + +/// Find files recursively in a directory matching a pattern +fn find_files_recursively>( + root_dir: P, + filename: &str, + max_depth: Option, +) -> Result, Box> { + let mut matches = Vec::new(); + let mut stack = vec![(root_dir.as_ref().to_path_buf(), 0)]; + + while let Some((current_dir, depth)) = stack.pop() { + if let Some(max) = max_depth { + if depth > max { + continue; + } + } + + if let Ok(entries) = fs::read_dir(¤t_dir) { + for entry in entries.flatten() { + let path = entry.path(); + + if path.is_file() { + // Simple filename comparison instead of regex + if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) { + if file_name == filename { + matches.push(path); + } + } + } else if path.is_dir() { + stack.push((path, depth + 1)); + } + } + } + } + + Ok(matches) +} + +fn platform_install_paths() -> Result> { + if cfg!(target_os = "windows") { + // Defaults to path: C:\Users\Default\AppData\Local + let local_app_data = env::var("LOCALAPPDATA") + .unwrap_or_else(|_| String::from("C:\\Users\\Default\\AppData\\Local")); + + Ok(InstallPath { + paths: vec![PathBuf::from(local_app_data) + .join("MetaCall") + .join("metacall")], + names: vec!["metacall.lib"], + }) + } else if cfg!(target_os = "macos") { + Ok(InstallPath { + paths: vec![ + PathBuf::from("/opt/homebrew/lib/"), + PathBuf::from("/usr/local/lib/"), + ], + names: vec!["libmetacall.dylib"], + }) + } else if cfg!(target_os = "linux") { + Ok(InstallPath { + paths: vec![PathBuf::from("/usr/local/lib/"), PathBuf::from("/gnu/lib/")], + names: vec!["libmetacall.so"], + }) + } else { + Err(format!("Platform {} not supported", env::consts::OS).into()) + } +} + +/// Get search paths, checking for custom installation path first +fn get_search_config() -> Result> { + // First, check if user specified a custom path + if let Ok(custom_path) = env::var("METACALL_INSTALL_PATH") { + // For custom paths, we need to search for any metacall library variant + return Ok(InstallPath { + paths: vec![PathBuf::from(custom_path)], + names: vec![ + "libmetacall.so", + "libmetacalld.so", + "libmetacall.dylib", + "libmetacalld.dylib", + "metacall.lib", + "metacalld.lib", + ], + }); + } + + // Fall back to platform-specific paths + platform_install_paths() +} + +/// Get the parent path and library name +fn get_parent_and_library(path: &Path) -> Option<(PathBuf, String)> { + let parent = path.parent()?.to_path_buf(); + + // Get the file stem (filename without extension) + let stem = path.file_stem()?.to_str()?; + + // Remove "lib" prefix if present + let cleaned_stem = stem.strip_prefix("lib").unwrap_or(stem).to_string(); + + Some((parent, cleaned_stem)) +} + +/// Find the MetaCall library +/// This orchestrates the search process +fn find_metacall_library() -> Result> { + let search_config = get_search_config()?; + + // Search in each configured path + for search_path in &search_config.paths { + for name in &search_config.names { + // Search with no limit in depth + match find_files_recursively(search_path, name, None) { + Ok(files) if !files.is_empty() => { + let found_lib = fs::canonicalize(&files[0])?; + + match get_parent_and_library(&found_lib) { + Some((parent, name)) => { + return Ok(LibraryPath { + path: parent, + library: name, + }) + } + None => continue, + }; + } + Ok(_) => { + // No files found in this path, continue searching + continue; + } + Err(e) => { + eprintln!("Error searching in {}: {}", search_path.display(), e); + continue; + } + } + } + } + + // If we get here, library wasn't found + let search_paths: Vec = search_config + .paths + .iter() + .map(|p| p.display().to_string()) + .collect(); + + Err(format!( + "MetaCall library not found. Searched in: {}. \ + If you have it installed elsewhere, set METACALL_INSTALL_PATH environment variable.", + search_paths.join(", ") + ) + .into()) +} + +fn define_library_search_path(env_var: &str, separator: &str, path: &Path) -> String { + // Get the current value of the env var, if any + let existing = env::var(env_var).unwrap_or_default(); + let path_str: String = String::from(path.to_str().unwrap()); + + // Append to it + let combined = if existing.is_empty() { + path_str + } else { + format!("{}{}{}", existing, separator, path_str) + }; + + format!("{}={}", env_var, combined) +} + +/// Set RPATH for runtime library discovery +/// This binaries work outside cargo +fn set_rpath(lib_path: &Path) { + let path_str = lib_path.to_str().unwrap(); + + #[cfg(target_os = "linux")] + { + // On Linux, use RPATH with $ORIGIN for relocatable binaries + println!("cargo:rustc-link-arg=-Wl,-rpath,{}", path_str); + // Also set a backup rpath relative to the executable location + println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN"); + println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/../lib"); + } + + #[cfg(target_os = "macos")] + { + // On macOS, use @rpath and @loader_path + println!("cargo:rustc-link-arg=-Wl,-rpath,{}", path_str); + // Also set loader-relative paths for relocatable binaries + println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path"); + println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path/../lib"); + } + + #[cfg(target_os = "aix")] + { + // Add default system library paths to avoid breaking standard lookup + println!("cargo:rustc-link-arg=-Wl,-blibpath:{}:/usr/lib:/lib", path_str); + } + + #[cfg(target_os = "windows")] + { + // Windows doesn't use RPATH, but we can inform the user + println!( + "cargo:warning=On Windows, make sure {} is in your PATH or next to your executable", + path_str + ); + } +} + +pub fn build() { + // When running tests from CMake + if let Ok(val) = env::var("PROJECT_OUTPUT_DIR") { + // Link search path to build folder + println!("cargo:rustc-link-search=native={val}"); + + // Link against correct version of metacall + match env::var("CMAKE_BUILD_TYPE") { + Ok(val) => { + if val == "Debug" { + // Try to link the debug version when running tests + println!("cargo:rustc-link-lib=dylib=metacalld"); + } else { + println!("cargo:rustc-link-lib=dylib=metacall"); + } + } + Err(_) => { + println!("cargo:rustc-link-lib=dylib=metacall"); + } + } + } else { + // When building from Cargo, try to find MetaCall + match find_metacall_library() { + Ok(lib_path) => { + // Define linker flags + println!("cargo:rustc-link-search=native={}", lib_path.path.display()); + println!("cargo:rustc-link-lib=dylib={}", lib_path.library); + + // Set RPATH so the binary can find libraries at runtime + set_rpath(&lib_path.path); + + // Set the runtime environment variable for finding the library during tests + #[cfg(target_os = "linux")] + const ENV_VAR: &str = "LD_LIBRARY_PATH"; + + #[cfg(target_os = "macos")] + const ENV_VAR: &str = "DYLD_LIBRARY_PATH"; + + #[cfg(target_os = "windows")] + const ENV_VAR: &str = "PATH"; + + #[cfg(target_os = "aix")] + const ENV_VAR: &str = "LIBPATH"; + + #[cfg(any(target_os = "linux", target_os = "macos", target_os = "aix"))] + const SEPARATOR: &str = ":"; + + #[cfg(target_os = "windows")] + const SEPARATOR: &str = ";"; + + println!( + "cargo:rustc-env={}", + define_library_search_path(ENV_VAR, SEPARATOR, &lib_path.path) + ); + } + Err(e) => { + // Print the error + eprintln!( + "Failed to find MetaCall library with: {e} \ + Still trying to link in case the library is in system paths" + ); + + // Still try to link in case the library is in system paths + println!("cargo:rustc-link-lib=dylib=metacall") + } + } + } +} diff --git a/source/ports/rs_port/tests/inlines_test.rs b/source/ports/rs_port/tests/inlines_test.rs index ff5f48308..27861f2fb 100644 --- a/source/ports/rs_port/tests/inlines_test.rs +++ b/source/ports/rs_port/tests/inlines_test.rs @@ -1,7 +1,8 @@ use metacall::{ initialize, inline::{node, py, ts}, - is_initialized, load, + is_initialized, + load::{self, Tag}, }; #[test] @@ -10,30 +11,30 @@ fn inlines() { assert!(is_initialized()); - if load::from_memory("py", "").is_ok() { + if load::from_memory(Tag::Python, "", None).is_ok() { py! { print("hello world") } } - if load::from_memory("py", "").is_ok() { + if load::from_memory(Tag::Python, "", None).is_ok() { py! {print("hello world")} } - if load::from_memory("node", "").is_ok() { + if load::from_memory(Tag::NodeJS, "", None).is_ok() { node! { console.log("hello world"); } } - if load::from_memory("node", "").is_ok() { + if load::from_memory(Tag::NodeJS, "", None).is_ok() { node! {console.log("hello world")} } - if load::from_memory("ts", "").is_ok() { + if load::from_memory(Tag::TypeScript, "", None).is_ok() { ts! { console.log("hello world"); } } - if load::from_memory("ts", "").is_ok() { + if load::from_memory(Tag::TypeScript, "", None).is_ok() { ts! {console.log("hello world")} } } diff --git a/source/ports/rs_port/tests/invalid_loaders_test.rs b/source/ports/rs_port/tests/invalid_loaders_test.rs index ec58d0bcb..bd59e89a9 100644 --- a/source/ports/rs_port/tests/invalid_loaders_test.rs +++ b/source/ports/rs_port/tests/invalid_loaders_test.rs @@ -1,4 +1,8 @@ -use metacall::{initialize, is_initialized, load, MetaCallLoaderError}; +use metacall::{ + initialize, is_initialized, + load::{self, Tag}, + MetaCallLoaderError, +}; use std::env; #[test] @@ -12,14 +16,16 @@ fn invalid_loaders() { let valid_file = scripts_dir.join("script.js"); if let Err(MetaCallLoaderError::FileNotFound(_)) = - load::from_single_file("random", inavlid_file) + load::from_single_file(load::Tag::NodeJS, inavlid_file, None) { // Everything Ok } else { panic!("Expected the loader fail with `FileNotFound` error variant!"); } - if let Err(MetaCallLoaderError::FromFileFailure) = load::from_single_file("random", valid_file) + // We use JSM here because it is not implemented, it should fail + if let Err(MetaCallLoaderError::FromFileFailure) = + load::from_single_file(Tag::JSM, valid_file, None) { // Everything Ok } else { @@ -27,7 +33,7 @@ fn invalid_loaders() { } if let Err(MetaCallLoaderError::FromMemoryFailure) = - load::from_memory("random", "Invalid code!") + load::from_memory(load::Tag::NodeJS, "Invalid code!", None) { // Everything Ok } else { diff --git a/source/ports/rs_port/tests/loaders_test.rs b/source/ports/rs_port/tests/loaders_test.rs index c45c4c17b..abb274521 100644 --- a/source/ports/rs_port/tests/loaders_test.rs +++ b/source/ports/rs_port/tests/loaders_test.rs @@ -1,4 +1,8 @@ -use metacall::{initialize, is_initialized, load, metacall_no_arg}; +use metacall::{ + initialize, is_initialized, + load::{self, Tag}, + metacall_no_arg, +}; use std::{ env, fs::{self, File}, @@ -11,16 +15,18 @@ use std::{ const SCRIPT1: &str = "function greet1() { return 'hi there!' } \nmodule.exports = { greet1 }"; const SCRIPT2: &str = "function greet2() { return 'hi there!' } \nmodule.exports = { greet2 };"; const SCRIPT3: &str = "console.log('Hello world')"; + fn call_greet(test: &str, num: u32) { let out = metacall_no_arg::(format!("greet{}", num)).unwrap(); assert_eq!(out.as_str(), "hi there!", "Testing {}", test); } fn load_from_memory_test() { - load::from_memory("node", SCRIPT1).unwrap(); + load::from_memory(Tag::NodeJS, SCRIPT1, None).unwrap(); + call_greet("load_from_memory", 1); - load::from_memory("node", SCRIPT3).unwrap(); + load::from_memory(Tag::NodeJS, SCRIPT3, None).unwrap(); } fn load_from_file_test() { @@ -34,7 +40,7 @@ fn load_from_file_test() { temp_js.write_all(SCRIPT2.as_bytes()).unwrap(); temp_js.flush().unwrap(); - load::from_single_file("node", temp_js_path).unwrap(); + load::from_single_file(Tag::NodeJS, temp_js_path, None).unwrap(); call_greet("load_from_file", 2); diff --git a/source/ports/rs_port/tests/metacall_exception_test.rs b/source/ports/rs_port/tests/metacall_exception_test.rs index 780aba056..fe16caad7 100644 --- a/source/ports/rs_port/tests/metacall_exception_test.rs +++ b/source/ports/rs_port/tests/metacall_exception_test.rs @@ -1,8 +1,11 @@ -use metacall::{initialize, is_initialized, load}; +use metacall::{ + initialize, is_initialized, + load::{self, Tag}, +}; use std::env; #[test] -fn inlines() { +fn metacall_exception() { let _d = initialize().unwrap(); assert!(is_initialized()); @@ -10,7 +13,7 @@ fn inlines() { let tests_dir = env::current_dir().unwrap().join("tests/scripts"); let js_test_file = tests_dir.join("script.js"); - if load::from_single_file("node", js_test_file).is_ok() { + if load::from_single_file(Tag::NodeJS, js_test_file, None).is_ok() { // This should not generate a segmentation fault let val = metacall::metacall_no_arg::("test_exception").unwrap(); diff --git a/source/ports/rs_port/tests/metacall_handle_test.rs b/source/ports/rs_port/tests/metacall_handle_test.rs new file mode 100644 index 000000000..516d5b52f --- /dev/null +++ b/source/ports/rs_port/tests/metacall_handle_test.rs @@ -0,0 +1,52 @@ +use metacall::{ + initialize, is_initialized, + load::{self, Handle, Tag}, + metacall_handle_no_arg, +}; + +#[test] +fn metacall_handle() { + let _d = initialize().unwrap(); + + assert!(is_initialized()); + + const SCRIPT1: &str = "function greet() { return 1 } \nmodule.exports = { greet }"; + const SCRIPT2: &str = "function greet() { return 2 } \nmodule.exports = { greet }"; + + let mut handle1 = Handle::new(); + let mut handle2 = Handle::new(); + + let result1 = load::from_memory(Tag::NodeJS, SCRIPT1, Some(&mut handle1)); + let result2 = load::from_memory(Tag::NodeJS, SCRIPT2, Some(&mut handle2)); + + assert!(result1.is_ok()); + assert!(result2.is_ok()); + + // Load first handle + if result1.is_ok() { + let out = metacall_handle_no_arg::(&mut handle1, "greet").unwrap(); + assert_eq!(out, 1.0, "Testing greet 1"); + } + + // Load second handle + if result2.is_ok() { + let out = metacall_handle_no_arg::(&mut handle2, "greet").unwrap(); + assert_eq!(out, 2.0, "Testing greet 2"); + } + + // Now, testing loading again into an existing handle number 2 + // This should make the handle have greet (2) and yeet functions together + const SCRIPT3: &str = "function yeet() { return 3 } \nmodule.exports = { yeet }"; + + let result3 = load::from_memory(Tag::NodeJS, SCRIPT3, Some(&mut handle2)); + + assert!(result3.is_ok()); + + if result3.is_ok() { + let out = metacall_handle_no_arg::(&mut handle2, "greet").unwrap(); + assert_eq!(out, 2.0, "Testing greet 2"); + + let out = metacall_handle_no_arg::(&mut handle2, "yeet").unwrap(); + assert_eq!(out, 3.0, "Testing yeet 2"); + } +} diff --git a/source/ports/rs_port/tests/metacall_test.rs b/source/ports/rs_port/tests/metacall_test.rs index d23e2e2ae..81d73511a 100644 --- a/source/ports/rs_port/tests/metacall_test.rs +++ b/source/ports/rs_port/tests/metacall_test.rs @@ -1,7 +1,8 @@ use metacall::{ - initialize, is_initialized, load, MetaCallClass, MetaCallException, MetaCallFunction, - MetaCallFuture, MetaCallNull, MetaCallObject, MetaCallPointer, MetaCallThrowable, - MetaCallValue, + initialize, is_initialized, + load::{self, Tag}, + MetaCallClass, MetaCallException, MetaCallFunction, MetaCallFuture, MetaCallNull, + MetaCallObject, MetaCallPointer, MetaCallThrowable, MetaCallValue, }; use std::{any::Any, collections::HashMap, env, fmt::Debug}; @@ -171,16 +172,19 @@ fn test_pointer() { ); } fn test_future() { - fn validate(upper_result: Box, upper_data: Box) { - match upper_data.downcast::() { - Ok(ret) => { - if ret.as_str() != "data" { - invalid_return_value("data", ret) + fn validate(upper_result: Box, upper_data: Option>) { + match upper_data { + Some(data) => match data.downcast::() { + Ok(ret) => { + if ret.as_str() != "data" { + invalid_return_value("data", ret) + } } - } - Err(original) => { - invalid_return_type("'string' for the data", original); - } + Err(original) => { + invalid_return_type("'string' for the data", original); + } + }, + None => println!("user_data is None."), } match upper_result.downcast::() { @@ -202,7 +206,7 @@ fn test_future() { move |future| { fn resolve( result: Box, - data: Box, + data: Option>, ) -> Box { validate(result.clone(), data); result.clone() @@ -218,7 +222,7 @@ fn test_future() { move |future| { fn reject( result: Box, - data: Box, + data: Option>, ) -> Box { validate(result.clone(), data); result.clone() @@ -368,7 +372,7 @@ fn metacall() { let js_test_file = tests_dir.join("script.js"); let c_test_file = tests_dir.join("script.c"); let py_test_file = tests_dir.join("script.py"); - let py_loaded = load::from_single_file("py", py_test_file).is_ok(); + let py_loaded = load::from_single_file(Tag::Python, py_test_file, None).is_ok(); if py_loaded { test_buffer(); @@ -381,7 +385,7 @@ fn metacall() { test_string(); test_null(); } - if load::from_single_file("c", c_test_file).is_ok() { + if load::from_single_file(load::Tag::C, c_test_file, None).is_ok() { test_char(); test_double(); test_float(); @@ -390,7 +394,7 @@ fn metacall() { test_short(); test_mixed_numbers(); } - if load::from_single_file("node", js_test_file).is_ok() { + if load::from_single_file(load::Tag::NodeJS, js_test_file, None).is_ok() { test_exception(); test_throwable(); test_future(); diff --git a/source/ports/rs_port/upload.sh b/source/ports/rs_port/upload.sh index c85fac147..a072d2c65 100644 --- a/source/ports/rs_port/upload.sh +++ b/source/ports/rs_port/upload.sh @@ -21,7 +21,7 @@ function publish() { local crate_version=`cargo search --quiet $1 | grep "$1" | head -n 1 | awk '{ print $3 }'` - local project_version=`cargo metadata --format-version=1 --no-deps | jq '.packages[0].version'` + local project_version=`cargo metadata --format-version=1 --no-deps | jq ".packages[] | select(.name == \"$1\") | .version"` # Check if versions do not match, and if so, publish them if [ ! "${crate_version}" = "${project_version}" ]; then @@ -30,8 +30,15 @@ function publish() { fi } -# Publish -cd inline +# Publish sys crate +pushd sys +publish metacall-sys +popd + +# Publish inline crate +pushd inline publish metacall-inline -cd .. +popd + +# Publish metacall crate publish metacall diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 6e6ad2ffc..2f2e6bb89 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -246,3 +246,4 @@ add_subdirectory(metacall_cli_core_plugin_test) add_subdirectory(metacall_cli_core_plugin_await_test) add_subdirectory(metacall_backtrace_plugin_test) add_subdirectory(metacall_sandbox_plugin_test) +add_subdirectory(metacall_cxx_port_test) diff --git a/source/tests/adt_trie_test/source/adt_trie_test.cpp b/source/tests/adt_trie_test/source/adt_trie_test.cpp index cb1edbf28..1d9541dc0 100644 --- a/source/tests/adt_trie_test/source/adt_trie_test.cpp +++ b/source/tests/adt_trie_test/source/adt_trie_test.cpp @@ -123,7 +123,7 @@ TEST_F(adt_trie_test, DefaultConstructor) log_write("metacall", LOG_LEVEL_DEBUG, "%" PRIuS " -> %s", iterator, value_str); - EXPECT_EQ((int)0, (int)strcmp(values_str[keys_size - iterator - 1], value_str)); + EXPECT_STREQ(values_str[keys_size - iterator - 1], value_str); vector_pop_back(keys_copy); } @@ -144,7 +144,7 @@ TEST_F(adt_trie_test, DefaultConstructor) log_write("metacall", LOG_LEVEL_DEBUG, "%s/", key_str); - EXPECT_EQ((int)0, (int)strcmp(keys_str[iterator], key_str)); + EXPECT_STREQ(keys_str[iterator], key_str); } vector_pop_back(keys); diff --git a/source/tests/detour_test/source/detour_test.cpp b/source/tests/detour_test/source/detour_test.cpp index 15b56ec58..4882867e8 100644 --- a/source/tests/detour_test/source/detour_test.cpp +++ b/source/tests/detour_test/source/detour_test.cpp @@ -111,7 +111,7 @@ TEST_F(detour_test, DefaultConstructor) ASSERT_NE((detour)NULL, (detour)d); - EXPECT_EQ((int)0, (int)strcmp(name, detour_name(d))); + EXPECT_STREQ(name, detour_name(d)); /* Load detour of detour library */ handle = detour_load_file(d, NULL); diff --git a/source/tests/dynlink_test/source/dynlink_test.cpp b/source/tests/dynlink_test/source/dynlink_test.cpp index 8bebf4526..0119510ca 100644 --- a/source/tests/dynlink_test/source/dynlink_test.cpp +++ b/source/tests/dynlink_test/source/dynlink_test.cpp @@ -101,7 +101,7 @@ TEST_F(dynlink_test, DefaultConstructor) log_write("metacall", LOG_LEVEL_DEBUG, "Dynamic linked shared object file: %s", dynlink_get_path(handle)); - EXPECT_EQ((int)0, (int)strcmp(library_name, dynlink_get_name(handle))); + EXPECT_STREQ(library_name, dynlink_get_name(handle)); if (handle != NULL) { @@ -146,8 +146,8 @@ TEST_F(dynlink_test, DefaultConstructor) log_write("metacall", LOG_LEVEL_DEBUG, "Dynamic linked shared object file name: %s", dynlink_get_path(handle)); log_write("metacall", LOG_LEVEL_DEBUG, "Dynamic linked shared object file: %s", dynlink_get_name(handle)); - EXPECT_EQ((int)0, (int)strcmp(absolute_path, dynlink_get_path(handle))); - EXPECT_EQ((int)0, (int)strcmp(library_name, dynlink_get_name(handle))); + EXPECT_STREQ(absolute_path, dynlink_get_path(handle)); + EXPECT_STREQ(library_name, dynlink_get_name(handle)); if (handle != NULL) { diff --git a/source/tests/environment_test/source/environment_test.cpp b/source/tests/environment_test/source/environment_test.cpp index dee634141..576dfb28a 100644 --- a/source/tests/environment_test/source/environment_test.cpp +++ b/source/tests/environment_test/source/environment_test.cpp @@ -39,7 +39,7 @@ TEST_F(environment_test, variable_text) ASSERT_NE((const char *)NULL, (const char *)variable_text); - EXPECT_EQ((int)0, (int)strcmp(variable_text, "abcd")); + EXPECT_STREQ(variable_text, "abcd"); environment_variable_destroy(variable_text); } @@ -52,7 +52,7 @@ TEST_F(environment_test, variable_text_default) ASSERT_NE((const char *)NULL, (const char *)variable_text); - EXPECT_EQ((int)0, (int)strcmp(variable_text, "default")); + EXPECT_STREQ(variable_text, "default"); environment_variable_destroy(variable_text); } @@ -63,7 +63,7 @@ TEST_F(environment_test, variable_static) const char *variable_text_static = environment_variable_get(variable_text_name, "default"); - EXPECT_EQ((int)0, (int)strcmp(variable_text_static, "abcd")); + EXPECT_STREQ(variable_text_static, "abcd"); } TEST_F(environment_test, variable_path) @@ -74,7 +74,7 @@ TEST_F(environment_test, variable_path) ASSERT_NE((const char *)NULL, (const char *)variable_path); - EXPECT_EQ((int)0, (int)strcmp(variable_path, "abcd" ENVIRONMENT_VARIABLE_PATH_SEPARATOR_STR)); + EXPECT_STREQ(variable_path, "abcd" ENVIRONMENT_VARIABLE_PATH_SEPARATOR_STR); environment_variable_path_destroy(variable_path); } @@ -87,7 +87,7 @@ TEST_F(environment_test, variable_path_default) ASSERT_NE((const char *)NULL, (const char *)variable_path); - EXPECT_EQ((int)0, (int)strcmp(variable_path, "default_path" ENVIRONMENT_VARIABLE_PATH_SEPARATOR_STR)); + EXPECT_STREQ(variable_path, "default_path" ENVIRONMENT_VARIABLE_PATH_SEPARATOR_STR); environment_variable_path_destroy(variable_path); } @@ -100,7 +100,7 @@ TEST_F(environment_test, variable_path_sanitized) ASSERT_NE((const char *)NULL, (const char *)variable_path); - EXPECT_EQ((int)0, (int)strcmp(variable_path, "abcd" ENVIRONMENT_VARIABLE_PATH_SEPARATOR_STR)); + EXPECT_STREQ(variable_path, "abcd" ENVIRONMENT_VARIABLE_PATH_SEPARATOR_STR); environment_variable_path_destroy(variable_path); } diff --git a/source/tests/log_test/source/log_test.cpp b/source/tests/log_test/source/log_test.cpp index 2a1505e71..3e1121bc7 100644 --- a/source/tests/log_test/source/log_test.cpp +++ b/source/tests/log_test/source/log_test.cpp @@ -85,7 +85,7 @@ TEST_F(log_test, DefaultConstructor) unsigned int value = *((unsigned int *)value_ptr); - EXPECT_EQ((int)0, (int)strcmp(log_name_list[value].name, key)); + EXPECT_STREQ(log_name_list[value].name, key); } EXPECT_EQ((int)log_map_destroy(map), (int)0); diff --git a/source/tests/metacall_c_metacall_test/CMakeLists.txt b/source/tests/metacall_c_metacall_test/CMakeLists.txt new file mode 100644 index 000000000..00d36ad94 --- /dev/null +++ b/source/tests/metacall_c_metacall_test/CMakeLists.txt @@ -0,0 +1,160 @@ +# Check if this loader is enabled +if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_C OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_C) + return() +endif() + +# +# Executable name and options +# + +# Target name +set(target metacall-c-metacall-test) +message(STATUS "Test ${target}") + +# +# Compiler warnings +# + +include(Warnings) + +# +# Compiler security +# + +include(SecurityFlags) + +# +# Sources +# + +set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}") +set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source") + +set(sources + ${source_path}/main.cpp + ${source_path}/metacall_c_metacall_test.cpp +) + +# Group source files +set(header_group "Header Files (API)") +set(source_group "Source Files") +source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$" + ${header_group} ${headers}) +source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$" + ${source_group} ${sources}) + +# +# Create executable +# + +# Build executable +add_executable(${target} + ${sources} +) + +# Create namespaced alias +add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) + +# +# Project options +# + +set_target_properties(${target} + PROPERTIES + ${DEFAULT_PROJECT_OPTIONS} + FOLDER "${IDE_FOLDER}" +) + +# +# Include directories +# + +target_include_directories(${target} + PRIVATE + ${DEFAULT_INCLUDE_DIRECTORIES} + ${PROJECT_BINARY_DIR}/source/include +) + +# +# Libraries +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LIBRARIES} + + GTest + + ${META_PROJECT_NAME}::metacall +) + +# +# Compile definitions +# + +target_compile_definitions(${target} + PRIVATE + ${DEFAULT_COMPILE_DEFINITIONS} + + METACALL_INCLUDE_DIR="${CMAKE_SOURCE_DIR}/source/metacall/include" + METACALL_API_INCLUDE_DIR="${CMAKE_BINARY_DIR}/source/metacall/include" + METACALL_LIBRARY="${PROJECT_OUTPUT_DIR}" +) + +# +# Compile options +# + +target_compile_options(${target} + PRIVATE + ${DEFAULT_COMPILE_OPTIONS} +) + +# +# Compile features +# + +target_compile_features(${target} + PRIVATE + cxx_std_17 +) + +# +# Linker options +# + +target_link_options(${target} + PRIVATE + ${DEFAULT_LINKER_OPTIONS} +) + +# +# Define test +# + +add_test(NAME ${target} + COMMAND $ +) + +# +# Define dependencies +# + +add_dependencies(${target} + c_loader +) + +# +# Define test properties +# + +set_property(TEST ${target} + PROPERTY LABELS ${target} +) + +include(TestEnvironmentVariables) + +test_environment_variables(${target} + "" + ${TESTS_ENVIRONMENT_VARIABLES} +) diff --git a/source/tests/metacall_c_metacall_test/source/main.cpp b/source/tests/metacall_c_metacall_test/source/main.cpp new file mode 100644 index 000000000..37d4adc23 --- /dev/null +++ b/source/tests/metacall_c_metacall_test/source/main.cpp @@ -0,0 +1,28 @@ +/* + * Loader Library by Parra Studios + * A plugin for loading ruby code at run-time into a process. + * + * Copyright (C) 2016 - 2025 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/source/tests/metacall_c_metacall_test/source/metacall_c_metacall_test.cpp b/source/tests/metacall_c_metacall_test/source/metacall_c_metacall_test.cpp new file mode 100644 index 000000000..f26e1471b --- /dev/null +++ b/source/tests/metacall_c_metacall_test/source/metacall_c_metacall_test.cpp @@ -0,0 +1,70 @@ +/* + * Loader Library by Parra Studios + * A plugin for loading ruby code at run-time into a process. + * + * Copyright (C) 2016 - 2025 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include + +class metacall_c_metacall_test : public testing::Test +{ +protected: +}; + +TEST_F(metacall_c_metacall_test, DefaultConstructor) +{ + ASSERT_EQ((int)0, (int)metacall_initialize()); + + ASSERT_EQ((int)0, metacall_execution_path("c", METACALL_INCLUDE_DIR)); + ASSERT_EQ((int)0, metacall_execution_path("c", METACALL_API_INCLUDE_DIR)); + ASSERT_EQ((int)0, metacall_execution_path("c", METACALL_LIBRARY)); + + ASSERT_EQ((int)0, (int)metacall_load_from_package("c", "metacall", NULL)); + + void *ret = metacall("metacall_print_info"); + + ASSERT_EQ((void *)NULL, (void *)ret); + + EXPECT_EQ((enum metacall_value_id)metacall_value_id(ret), (enum metacall_value_id)METACALL_STRING); + + EXPECT_EQ((int)0, strncmp(metacall_value_to_string(ret), "MetaCall", 8)); + + /* Print inspect information */ + { + size_t size = 0; + + struct metacall_allocator_std_type std_ctx = { &std::malloc, &std::realloc, &std::free }; + + void *allocator = metacall_allocator_create(METACALL_ALLOCATOR_STD, (void *)&std_ctx); + + char *inspect_str = metacall_inspect(&size, allocator); + + EXPECT_NE((char *)NULL, (char *)inspect_str); + + EXPECT_GT((size_t)size, (size_t)0); + + std::cout << inspect_str << std::endl; + + metacall_allocator_free(allocator, inspect_str); + + metacall_allocator_destroy(allocator); + } + + metacall_destroy(); +} diff --git a/source/tests/metacall_clear_test/CMakeLists.txt b/source/tests/metacall_clear_test/CMakeLists.txt index 859807d95..6698be908 100644 --- a/source/tests/metacall_clear_test/CMakeLists.txt +++ b/source/tests/metacall_clear_test/CMakeLists.txt @@ -1,5 +1,5 @@ # Check if this loader is enabled -if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_PY OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_PY) +if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_PY OR NOT OPTION_BUILD_LOADERS_NODE OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_PY OR NOT OPTION_BUILD_SCRIPTS_NODE) return() endif() @@ -146,6 +146,7 @@ add_test(NAME ${target} add_dependencies(${target} py_loader + node_loader ) # diff --git a/source/tests/metacall_clear_test/source/metacall_clear_test.cpp b/source/tests/metacall_clear_test/source/metacall_clear_test.cpp index f6dbc7fcb..3eab66835 100644 --- a/source/tests/metacall_clear_test/source/metacall_clear_test.cpp +++ b/source/tests/metacall_clear_test/source/metacall_clear_test.cpp @@ -76,5 +76,51 @@ TEST_F(metacall_clear_test, DefaultConstructor) } #endif /* OPTION_BUILD_LOADERS_PY */ +/* NodeJS */ +#if defined(OPTION_BUILD_LOADERS_NODE) + { + static const char script1[] = "function greet() { return 1 }\nmodule.exports = { greet }"; + static const char script2[] = "function greet() { return 2 }\nmodule.exports = { greet }"; + static const char script3[] = "function yeet() { return 3 }\nmodule.exports = { yeet }"; + + void *handle1 = NULL; + void *handle2 = NULL; + + void *ret; + + ASSERT_EQ((int)0, (int)metacall_load_from_memory("node", script1, sizeof(script1), &handle1)); + + ret = metacallhv(handle1, "greet", metacall_null_args); + + EXPECT_NE((void *)NULL, (void *)ret); + + EXPECT_EQ((double)1.0, (double)metacall_value_to_double(ret)); + + ASSERT_EQ((int)0, (int)metacall_load_from_memory("node", script2, sizeof(script2), &handle2)); + + ret = metacallhv(handle2, "greet", metacall_null_args); + + EXPECT_NE((void *)NULL, (void *)ret); + + EXPECT_EQ((double)2.0, (double)metacall_value_to_double(ret)); + + metacall_value_destroy(ret); + + // Now load script number 3 into handle number 2 + ASSERT_EQ((int)0, (int)metacall_load_from_memory("node", script3, sizeof(script3), &handle2)); + + ret = metacallhv(handle2, "yeet", metacall_null_args); + + EXPECT_NE((void *)NULL, (void *)ret); + + EXPECT_EQ((double)3.0, (double)metacall_value_to_double(ret)); + + metacall_value_destroy(ret); + + EXPECT_EQ((int)0, (int)metacall_clear(handle1)); + EXPECT_EQ((int)0, (int)metacall_clear(handle2)); + } +#endif /* OPTION_BUILD_LOADERS_NODE */ + metacall_destroy(); } diff --git a/source/tests/metacall_configuration_exec_path_test/source/metacall_configuration_exec_path_test.cpp b/source/tests/metacall_configuration_exec_path_test/source/metacall_configuration_exec_path_test.cpp index 7458311c0..0219e58aa 100644 --- a/source/tests/metacall_configuration_exec_path_test/source/metacall_configuration_exec_path_test.cpp +++ b/source/tests/metacall_configuration_exec_path_test/source/metacall_configuration_exec_path_test.cpp @@ -49,7 +49,7 @@ TEST_F(metacall_configuration_exec_path_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Python hello_world: test")); + EXPECT_STREQ(metacall_value_to_string(ret), "Python hello_world: test"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_configuration_exec_relative_path_test/source/metacall_configuration_exec_relative_path_test.cpp b/source/tests/metacall_configuration_exec_relative_path_test/source/metacall_configuration_exec_relative_path_test.cpp index 9257ec918..cd56aa446 100644 --- a/source/tests/metacall_configuration_exec_relative_path_test/source/metacall_configuration_exec_relative_path_test.cpp +++ b/source/tests/metacall_configuration_exec_relative_path_test/source/metacall_configuration_exec_relative_path_test.cpp @@ -49,7 +49,7 @@ TEST_F(metacall_configuration_exec_relative_path_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Python hello_world: test")); + EXPECT_STREQ(metacall_value_to_string(ret), "Python hello_world: test"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_cs_test/source/metacall_cs_test.cpp b/source/tests/metacall_cs_test/source/metacall_cs_test.cpp index 769382b15..799b24ec0 100644 --- a/source/tests/metacall_cs_test/source/metacall_cs_test.cpp +++ b/source/tests/metacall_cs_test/source/metacall_cs_test.cpp @@ -81,7 +81,7 @@ TEST_F(metacall_cs_test, Concat) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp((const char *)metacall_value_to_string(ret), "Hello World")); + EXPECT_STREQ((const char *)metacall_value_to_string(ret), "Hello World"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_cxx_port_test/CMakeLists.txt b/source/tests/metacall_cxx_port_test/CMakeLists.txt new file mode 100644 index 000000000..1a4b07292 --- /dev/null +++ b/source/tests/metacall_cxx_port_test/CMakeLists.txt @@ -0,0 +1,151 @@ +# Check if this loader is enabled +if(NOT OPTION_BUILD_PORTS OR NOT OPTION_BUILD_PORTS_CXX) + return() +endif() + +# +# Executable name and options +# + +# Target name +set(target metacall-cxx-port-test) +message(STATUS "Test ${target}") + +# +# Compiler warnings +# + +include(Warnings) + +# +# Compiler security +# + +include(SecurityFlags) + +# +# Sources +# + +set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}") +set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source") + +set(sources + ${source_path}/main.cpp + ${source_path}/metacall_cxx_port_test.cpp +) + +# Group source files +set(header_group "Header Files (API)") +set(source_group "Source Files") +source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$" + ${header_group} ${headers}) +source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$" + ${source_group} ${sources}) + +# +# Create executable +# + +# Build executable +add_executable(${target} + ${sources} +) + +# Create namespaced alias +add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) + +# +# Project options +# + +set_target_properties(${target} + PROPERTIES + ${DEFAULT_PROJECT_OPTIONS} + FOLDER "${IDE_FOLDER}" +) + +# +# Include directories +# + +target_include_directories(${target} + PRIVATE + ${DEFAULT_INCLUDE_DIRECTORIES} + ${PROJECT_BINARY_DIR}/source/include +) + +# +# Libraries +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LIBRARIES} + + GTest + + ${META_PROJECT_NAME}::cxx_port +) + +# +# Compile definitions +# + +target_compile_definitions(${target} + PRIVATE + ${DEFAULT_COMPILE_DEFINITIONS} + + LIBFFI_INCLUDE_DIR="${LIBFFI_INCLUDE_DIR}" + LIBFFI_LIBRARY="${LIBFFI_LIBRARY}" +) + +# +# Compile options +# + +target_compile_options(${target} + PRIVATE + ${DEFAULT_COMPILE_OPTIONS} +) + +# +# Compile features +# + +target_compile_features(${target} + PRIVATE + cxx_std_17 +) + +# +# Linker options +# + +target_link_options(${target} + PRIVATE + ${DEFAULT_LINKER_OPTIONS} +) + +# +# Define test +# + +add_test(NAME ${target} + COMMAND $ +) + +# +# Define test properties +# + +set_property(TEST ${target} + PROPERTY LABELS ${target} +) + +include(TestEnvironmentVariables) + +test_environment_variables(${target} + "" + ${TESTS_ENVIRONMENT_VARIABLES} +) diff --git a/source/tests/metacall_cxx_port_test/source/main.cpp b/source/tests/metacall_cxx_port_test/source/main.cpp new file mode 100644 index 000000000..37d4adc23 --- /dev/null +++ b/source/tests/metacall_cxx_port_test/source/main.cpp @@ -0,0 +1,28 @@ +/* + * Loader Library by Parra Studios + * A plugin for loading ruby code at run-time into a process. + * + * Copyright (C) 2016 - 2025 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/source/tests/metacall_cxx_port_test/source/metacall_cxx_port_test.cpp b/source/tests/metacall_cxx_port_test/source/metacall_cxx_port_test.cpp new file mode 100644 index 000000000..90e987e0a --- /dev/null +++ b/source/tests/metacall_cxx_port_test/source/metacall_cxx_port_test.cpp @@ -0,0 +1,196 @@ +/* + * Loader Library by Parra Studios + * A plugin for loading ruby code at run-time into a process. + * + * Copyright (C) 2016 - 2025 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include + +class metacall_cxx_port_test : public testing::Test +{ +protected: +}; + +void *cxx_map_test(size_t argc, void *args[], void *data) +{ + metacall::map m(args[0]); + + (void)argc; + (void)data; + + EXPECT_EQ((float)m["hello"], (float)3.0f); + EXPECT_EQ((float)m["world"], (float)4.0f); + + printf("hello => %f\n", m["hello"]); + printf("world => %f\n", m["world"]); + fflush(stdout); + + return metacall::metacall_value_create_null(); +} + +void *cxx_array_test(size_t argc, void *args[], void *data) +{ + metacall::array a(args[0]); + + (void)argc; + (void)data; + + EXPECT_EQ((float)a[0].as(), (int)3); + EXPECT_EQ((float)a[1].as(), (float)4.0f); + + EXPECT_EQ((float)a.get(0), (int)3); + EXPECT_EQ((float)a.get(1), (float)4.0f); + + printf("a[0] => %d\n", a[0].as()); + printf("a[1] => %f\n", a[1].as()); + fflush(stdout); + + return metacall::metacall_value_create_null(); +} + +void *cxx_map_array_test(size_t argc, void *args[], void *data) +{ + metacall::map m(args[0]); + + (void)argc; + (void)data; + + EXPECT_STREQ(m["includes"][0].as().c_str(), "/a/path"); + EXPECT_STREQ(m["includes"][1].as().c_str(), "/another/path"); + + EXPECT_STREQ(m["libraries"][0].as().c_str(), "/a/path"); + EXPECT_STREQ(m["libraries"][1].as().c_str(), "/another/path"); + + printf("m['includes'][0] => %s\n", m["includes"][0].as().c_str()); + printf("m['includes'][1] => %s\n", m["includes"][1].as().c_str()); + + printf("m['libraries'][0] => %s\n", m["libraries"][0].as().c_str()); + printf("m['libraries'][1] => %s\n", m["libraries"][1].as().c_str()); + + return metacall::metacall_value_create_null(); +} + +// TODO: +/* +void *cxx_recursive_map_test(size_t argc, void *args[], void *data) +{ + metacall::map> m(args[0]); + + (void)argc; + (void)data; + + EXPECT_EQ((float)m["hello"]["world"], (float)4.0f); + + printf("hello => %f\n", m["hello"]["world"]); + fflush(stdout); + + return metacall_value_create_null(); +} +*/ + +void *cxx_float_int_int_test(size_t argc, void *args[], void *data) +{ + metacall::value a0(args[0]); + metacall::value a1(args[1]); + + (void)argc; + (void)data; + + EXPECT_EQ(a0.to_value(), 7); + EXPECT_EQ(a1.to_value(), 8); + + return metacall::metacall_value_create_float(3.0f); +} + +TEST_F(metacall_cxx_port_test, DefaultConstructor) +{ + ASSERT_EQ((int)0, (int)metacall::metacall_initialize()); + + { + metacall::map m = { + { "hello", 3.0f }, + { "world", 4.0f } + }; + + metacall::metacall_register("cxx_map_test", cxx_map_test, NULL, metacall::METACALL_NULL, 1, metacall::METACALL_MAP); + + EXPECT_EQ(nullptr, metacall::metacall("cxx_map_test", m)); + } + + { + metacall::array a(3, 4.0f); + + metacall::metacall_register("cxx_array_test", cxx_array_test, NULL, metacall::METACALL_NULL, 1, metacall::METACALL_ARRAY); + + EXPECT_EQ(nullptr, metacall::metacall("cxx_array_test", a)); + } + + { + metacall::map m = { + { "includes", metacall::array("/a/path", "/another/path") }, + { "libraries", metacall::array("/a/path", "/another/path") } + }; + + metacall::metacall_register("cxx_map_array_test", cxx_map_array_test, NULL, metacall::METACALL_NULL, 1, metacall::METACALL_MAP); + + EXPECT_EQ(nullptr, metacall::metacall("cxx_map_array_test", m)); + } + + // TODO: + /* + { + metacall::map> m = { + { "hello", { "world", 4.0f } } + }; + + metacall::metacall_register("cxx_recursive_map_test", cxx_recursive_map_test, NULL, metacall::METACALL_NULL, 1, metacall::METACALL_MAP); + + EXPECT_EQ(nullptr, metacall::metacall("cxx_recursive_map_test", m)); + } + */ + + { + metacall::metacall_register("cxx_float_int_int_test", cxx_float_int_int_test, NULL, metacall::METACALL_FLOAT, 2, metacall::METACALL_INT, metacall::METACALL_INT); + + EXPECT_EQ(3.0f, metacall::metacall("cxx_float_int_int_test", 7, 8)); + } + + /* Print inspect information */ + { + size_t size = 0; + + metacall::metacall_allocator_std_type std_ctx = { &std::malloc, &std::realloc, &std::free }; + + void *allocator = metacall_allocator_create(metacall::METACALL_ALLOCATOR_STD, (void *)&std_ctx); + + char *inspect_str = metacall::metacall_inspect(&size, allocator); + + EXPECT_NE((char *)NULL, (char *)inspect_str); + + EXPECT_GT((size_t)size, (size_t)0); + + std::cout << inspect_str << std::endl; + + metacall::metacall_allocator_free(allocator, inspect_str); + + metacall::metacall_allocator_destroy(allocator); + } + + metacall::metacall_destroy(); +} diff --git a/source/tests/metacall_distributable_test/source/metacall_distributable_test.cpp b/source/tests/metacall_distributable_test/source/metacall_distributable_test.cpp index 59138c84e..30b2033cb 100644 --- a/source/tests/metacall_distributable_test/source/metacall_distributable_test.cpp +++ b/source/tests/metacall_distributable_test/source/metacall_distributable_test.cpp @@ -106,7 +106,7 @@ TEST_F(metacall_distributable_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello Universe")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello Universe"); metacall_value_destroy(ret); } @@ -143,7 +143,7 @@ TEST_F(metacall_distributable_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello meta-programmer!")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello meta-programmer!"); metacall_value_destroy(ret); @@ -193,7 +193,7 @@ TEST_F(metacall_distributable_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "abcdef")); + EXPECT_STREQ(metacall_value_to_string(ret), "abcdef"); metacall_value_destroy(ret); @@ -201,7 +201,7 @@ TEST_F(metacall_distributable_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "efg")); + EXPECT_STREQ(metacall_value_to_string(ret), "efg"); metacall_value_destroy(ret); } @@ -246,7 +246,7 @@ TEST_F(metacall_distributable_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello World")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello World"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_ducktype_test/source/metacall_ducktype_test.cpp b/source/tests/metacall_ducktype_test/source/metacall_ducktype_test.cpp index b9555204a..0b8e2e2e8 100644 --- a/source/tests/metacall_ducktype_test/source/metacall_ducktype_test.cpp +++ b/source/tests/metacall_ducktype_test/source/metacall_ducktype_test.cpp @@ -123,7 +123,7 @@ TEST_F(metacall_ducktype_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_cast_string(&ret), "Hello Universe")); + EXPECT_STREQ(metacall_value_cast_string(&ret), "Hello Universe"); metacall_value_destroy(ret); @@ -209,7 +209,7 @@ TEST_F(metacall_ducktype_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_cast_string(&ret), "PepicoWalas")); + EXPECT_STREQ(metacall_value_cast_string(&ret), "PepicoWalas"); metacall_value_destroy(ret); metacall_value_destroy(args[0]); @@ -260,7 +260,7 @@ TEST_F(metacall_ducktype_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_cast_string(&ret), "Hello meta-programmer!")); + EXPECT_STREQ(metacall_value_cast_string(&ret), "Hello meta-programmer!"); metacall_value_destroy(ret); @@ -344,7 +344,7 @@ TEST_F(metacall_ducktype_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_cast_string(&ret), "abcdef")); + EXPECT_STREQ(metacall_value_cast_string(&ret), "abcdef"); metacall_value_destroy(ret); diff --git a/source/tests/metacall_function_test/source/metacall_function_test.cpp b/source/tests/metacall_function_test/source/metacall_function_test.cpp index 950bf6b1a..8b837151a 100644 --- a/source/tests/metacall_function_test/source/metacall_function_test.cpp +++ b/source/tests/metacall_function_test/source/metacall_function_test.cpp @@ -221,7 +221,7 @@ TEST_F(metacall_function_test, DefaultConstructor) EXPECT_EQ((enum metacall_value_id)METACALL_STRING, (enum metacall_value_id)metacall_value_id(ret)); - EXPECT_EQ((int)0, (int)strcmp("hello world", metacall_value_to_string(ret))); + EXPECT_STREQ("hello world", metacall_value_to_string(ret)); metacall_value_destroy(ret); diff --git a/source/tests/metacall_handle_get_test/source/metacall_handle_get_test.cpp b/source/tests/metacall_handle_get_test/source/metacall_handle_get_test.cpp index fff68579b..2e8013038 100644 --- a/source/tests/metacall_handle_get_test/source/metacall_handle_get_test.cpp +++ b/source/tests/metacall_handle_get_test/source/metacall_handle_get_test.cpp @@ -113,7 +113,7 @@ TEST_F(metacall_handle_get_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello from s1")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello from s1"); metacall_value_destroy(ret); @@ -135,7 +135,7 @@ TEST_F(metacall_handle_get_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello from s2")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello from s2"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_java_test/source/metacall_java_test.cpp b/source/tests/metacall_java_test/source/metacall_java_test.cpp index 996ff70ca..5eb6141cc 100644 --- a/source/tests/metacall_java_test/source/metacall_java_test.cpp +++ b/source/tests/metacall_java_test/source/metacall_java_test.cpp @@ -102,8 +102,8 @@ TEST_F(metacall_java_test, DefaultConstructor) { //GET ARRAYS void *str_test = metacall_class_static_get(myclass, "STRING_TEST_Arr"); void **str_test_arr = metacall_value_to_array(str_test); - ASSERT_EQ((int)0, (int)strcmp(metacall_value_to_string(str_test_arr[0]), "Hello")); - ASSERT_EQ((int)0, (int)strcmp(metacall_value_to_string(str_test_arr[1]), "world")); + ASSERT_STREQ(metacall_value_to_string(str_test_arr[0]), "Hello"); + ASSERT_STREQ(metacall_value_to_string(str_test_arr[1]), "world"); metacall_value_destroy(str_test); void *class_test = metacall_class_static_get(myclass, "CLASS_TEST_Arr"); diff --git a/source/tests/metacall_load_configuration_test/source/metacall_load_configuration_test.cpp b/source/tests/metacall_load_configuration_test/source/metacall_load_configuration_test.cpp index 5562783fa..21657b9c8 100644 --- a/source/tests/metacall_load_configuration_test/source/metacall_load_configuration_test.cpp +++ b/source/tests/metacall_load_configuration_test/source/metacall_load_configuration_test.cpp @@ -108,7 +108,7 @@ TEST_F(metacall_load_configuration_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello Universe")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello Universe"); metacall_value_destroy(ret); @@ -192,7 +192,7 @@ TEST_F(metacall_load_configuration_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello Universe")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello Universe"); metacall_value_destroy(ret); } @@ -225,7 +225,7 @@ TEST_F(metacall_load_configuration_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello meta-programmer!")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello meta-programmer!"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_map_await_test/source/metacall_map_await_test.cpp b/source/tests/metacall_map_await_test/source/metacall_map_await_test.cpp index 7c68df229..d3f1d4eb7 100644 --- a/source/tests/metacall_map_await_test/source/metacall_map_await_test.cpp +++ b/source/tests/metacall_map_await_test/source/metacall_map_await_test.cpp @@ -96,7 +96,7 @@ static void *hello_world_await_ok(void *result, void *data) fflush(stdout); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(result), "Hello World")); + EXPECT_STREQ(metacall_value_to_string(result), "Hello World"); ++success_callbacks; diff --git a/source/tests/metacall_map_test/source/metacall_map_test.cpp b/source/tests/metacall_map_test/source/metacall_map_test.cpp index 5f98a5a5f..84d641f4d 100644 --- a/source/tests/metacall_map_test/source/metacall_map_test.cpp +++ b/source/tests/metacall_map_test/source/metacall_map_test.cpp @@ -201,7 +201,7 @@ TEST_F(metacall_map_test, DefaultConstructor) ASSERT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "ACK: OK!")); + EXPECT_STREQ(metacall_value_to_string(ret), "ACK: OK!"); metacall_value_destroy(ret); */ diff --git a/source/tests/metacall_node_exception_test/source/metacall_node_exception_test.cpp b/source/tests/metacall_node_exception_test/source/metacall_node_exception_test.cpp index 9de810277..fd1c3b2e2 100644 --- a/source/tests/metacall_node_exception_test/source/metacall_node_exception_test.cpp +++ b/source/tests/metacall_node_exception_test/source/metacall_node_exception_test.cpp @@ -53,7 +53,7 @@ TEST_F(metacall_node_exception_test, DefaultConstructor) EXPECT_EQ((int)0, (int)metacall_error_from_value(ret, &ex)); - EXPECT_EQ((int)0, (int)strcmp("Yeet", ex.message)); + EXPECT_STREQ("Yeet", ex.message); metacall_value_destroy(ret); @@ -61,7 +61,7 @@ TEST_F(metacall_node_exception_test, DefaultConstructor) EXPECT_EQ((int)0, (int)metacall_error_from_value(ret, &ex)); - EXPECT_EQ((int)0, (int)strcmp("YeetThrown", ex.message)); + EXPECT_STREQ("YeetThrown", ex.message); metacall_value_destroy(ret); diff --git a/source/tests/metacall_node_extension_test/source/metacall_node_extension_test.cpp b/source/tests/metacall_node_extension_test/source/metacall_node_extension_test.cpp index 4e0986485..ef5fd6caf 100644 --- a/source/tests/metacall_node_extension_test/source/metacall_node_extension_test.cpp +++ b/source/tests/metacall_node_extension_test/source/metacall_node_extension_test.cpp @@ -52,7 +52,7 @@ TEST_F(metacall_node_extension_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp("world", metacall_value_to_string(ret))); + EXPECT_STREQ("world", metacall_value_to_string(ret)); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_node_port_test/source/metacall_node_port_test.cpp b/source/tests/metacall_node_port_test/source/metacall_node_port_test.cpp index 081bf8337..ab1d6df11 100644 --- a/source/tests/metacall_node_port_test/source/metacall_node_port_test.cpp +++ b/source/tests/metacall_node_port_test/source/metacall_node_port_test.cpp @@ -59,7 +59,7 @@ TEST_F(metacall_node_port_test, DefaultConstructor) struct await_data_type *await_data = static_cast(data); std::unique_lock lock(await_data->m); const char *str = metacall_value_to_string(v); - EXPECT_EQ((int)0, (int)strcmp(str, "Tests passed without errors")); + EXPECT_STREQ(str, "Tests passed without errors"); await_data->c.notify_one(); return NULL; }; diff --git a/source/tests/metacall_python_dict_test/source/metacall_python_dict_test.cpp b/source/tests/metacall_python_dict_test/source/metacall_python_dict_test.cpp index cab84c549..f5db7671c 100644 --- a/source/tests/metacall_python_dict_test/source/metacall_python_dict_test.cpp +++ b/source/tests/metacall_python_dict_test/source/metacall_python_dict_test.cpp @@ -61,7 +61,7 @@ TEST_F(metacall_python_dict_test, DefaultConstructor) } else if (strcmp(key, "hello") == 0) { - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(array[1]), "world")); + EXPECT_STREQ(metacall_value_to_string(array[1]), "world"); } else if (strcmp(key, "efg") == 0) { @@ -134,14 +134,14 @@ TEST_F(metacall_python_dict_test, DefaultConstructor) char *ret_key0 = metacall_value_to_string(ret_pair0[0]); long ret_value0 = metacall_value_to_long(ret_pair0[1]); - EXPECT_EQ((int)0, (int)strcmp(ret_key0, "new")); + EXPECT_STREQ(ret_key0, "new"); EXPECT_EQ((long)5, (long)ret_value0); void **ret_pair1 = metacall_value_to_array(ret_map[1]); char *ret_key1 = metacall_value_to_string(ret_pair1[0]); long ret_value1 = metacall_value_to_long(ret_pair1[1]); - EXPECT_EQ((int)0, (int)strcmp(ret_key1, "whatever")); + EXPECT_STREQ(ret_key1, "whatever"); EXPECT_EQ((long)7, (long)ret_value1); metacall_value_destroy(ret); diff --git a/source/tests/metacall_python_exception_test/source/metacall_python_exception_test.cpp b/source/tests/metacall_python_exception_test/source/metacall_python_exception_test.cpp index 8d902ced5..14ec35d75 100644 --- a/source/tests/metacall_python_exception_test/source/metacall_python_exception_test.cpp +++ b/source/tests/metacall_python_exception_test/source/metacall_python_exception_test.cpp @@ -54,9 +54,9 @@ TEST_F(metacall_python_exception_test, DefaultConstructor) EXPECT_EQ((int)0, (int)metacall_error_from_value(ret, &ex)); - EXPECT_EQ((int)0, (int)strcmp("yeet", ex.message)); + EXPECT_STREQ("yeet", ex.message); - EXPECT_EQ((int)0, (int)strcmp("TypeError", ex.label)); + EXPECT_STREQ("TypeError", ex.label); metacall_value_destroy(ret); @@ -64,9 +64,9 @@ TEST_F(metacall_python_exception_test, DefaultConstructor) EXPECT_EQ((int)0, (int)metacall_error_from_value(ret, &ex)); - EXPECT_EQ((int)0, (int)strcmp("asdf", ex.message)); + EXPECT_STREQ("asdf", ex.message); - EXPECT_EQ((int)0, (int)strcmp("BaseException", ex.label)); + EXPECT_STREQ("BaseException", ex.label); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_python_loader_port_test/source/metacall_python_loader_port_test.cpp b/source/tests/metacall_python_loader_port_test/source/metacall_python_loader_port_test.cpp index 106797f36..ffa904326 100644 --- a/source/tests/metacall_python_loader_port_test/source/metacall_python_loader_port_test.cpp +++ b/source/tests/metacall_python_loader_port_test/source/metacall_python_loader_port_test.cpp @@ -37,7 +37,7 @@ void *callback_host(size_t argc, void *args[], void *data) printf("Host callback: %s\n", str); - EXPECT_EQ((int)0, (int)strcmp(str, "some text")); + EXPECT_STREQ(str, "some text"); return metacall_value_create_int(25); } @@ -86,7 +86,7 @@ TEST_F(metacall_python_loader_port_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_cast_string(&ret), "Hello meta-programmer!")); + EXPECT_STREQ(metacall_value_cast_string(&ret), "Hello meta-programmer!"); metacall_value_destroy(ret); diff --git a/source/tests/metacall_python_open_test/source/metacall_python_open_test.cpp b/source/tests/metacall_python_open_test/source/metacall_python_open_test.cpp index 3eda60fe5..0174eb61f 100644 --- a/source/tests/metacall_python_open_test/source/metacall_python_open_test.cpp +++ b/source/tests/metacall_python_open_test/source/metacall_python_open_test.cpp @@ -49,7 +49,7 @@ TEST_F(metacall_python_open_test, DefaultConstructor) const char *result = metacall_value_to_string(ret); - EXPECT_NE((int)0, (int)strcmp(result, "Error")); + EXPECT_STRNE(result, "Error"); metacall_value_destroy(ret); @@ -65,7 +65,7 @@ TEST_F(metacall_python_open_test, DefaultConstructor) const char *token = metacall_value_to_string(ret); - EXPECT_EQ((int)0, (int)strcmp(token, "eyJhbGciOiJIUzI1NiJ9.SGVsbG8gV29ybGQ.Iyc6PWVbK538giVdaInTeIO3jvvC1Vuy_czZUzoRRec")); + EXPECT_STREQ(token, "eyJhbGciOiJIUzI1NiJ9.SGVsbG8gV29ybGQ.Iyc6PWVbK538giVdaInTeIO3jvvC1Vuy_czZUzoRRec"); metacall_value_destroy(args[0]); diff --git a/source/tests/metacall_python_port_test/source/metacall_python_port_test.cpp b/source/tests/metacall_python_port_test/source/metacall_python_port_test.cpp index a86f7f111..7ebb7c236 100644 --- a/source/tests/metacall_python_port_test/source/metacall_python_port_test.cpp +++ b/source/tests/metacall_python_port_test/source/metacall_python_port_test.cpp @@ -46,7 +46,7 @@ TEST_F(metacall_python_port_test, DefaultConstructor) void *ret = metacallv("main", metacall_null_args); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Tests passed without errors")); + EXPECT_STREQ(metacall_value_to_string(ret), "Tests passed without errors"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_return_monad_test/source/metacall_return_monad_test.cpp b/source/tests/metacall_return_monad_test/source/metacall_return_monad_test.cpp index dfcf6e70c..5194d3ab8 100644 --- a/source/tests/metacall_return_monad_test/source/metacall_return_monad_test.cpp +++ b/source/tests/metacall_return_monad_test/source/metacall_return_monad_test.cpp @@ -78,7 +78,7 @@ TEST_F(metacall_return_monad_test, DefaultConstructor) EXPECT_EQ((enum metacall_value_id)METACALL_STRING, (enum metacall_value_id)metacall_value_id(ret)); - EXPECT_EQ((int)0, (int)strcmp("asd", metacall_value_to_string(ret))); + EXPECT_STREQ("asd", metacall_value_to_string(ret)); value_str = metacall_serialize(metacall_serial(), ret, &size, allocator); diff --git a/source/tests/metacall_ruby_parser_integration_test/source/metacall_ruby_parser_integration_test.cpp b/source/tests/metacall_ruby_parser_integration_test/source/metacall_ruby_parser_integration_test.cpp index b269fd9c2..0e38e65ac 100644 --- a/source/tests/metacall_ruby_parser_integration_test/source/metacall_ruby_parser_integration_test.cpp +++ b/source/tests/metacall_ruby_parser_integration_test/source/metacall_ruby_parser_integration_test.cpp @@ -74,7 +74,7 @@ TEST_F(metacall_ruby_parser_integration_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "call")); + EXPECT_STREQ(metacall_value_to_string(ret), "call"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_rust_load_from_package_dep_test/source/metacall_rust_load_from_package_dep_test.cpp b/source/tests/metacall_rust_load_from_package_dep_test/source/metacall_rust_load_from_package_dep_test.cpp index bc2d7930c..565883bc2 100644 --- a/source/tests/metacall_rust_load_from_package_dep_test/source/metacall_rust_load_from_package_dep_test.cpp +++ b/source/tests/metacall_rust_load_from_package_dep_test/source/metacall_rust_load_from_package_dep_test.cpp @@ -40,7 +40,7 @@ TEST_F(metacall_rust_load_from_package_dep_test, DefaultConstructor) const char *text = "{\"name\": \"John Doe\"}"; void *ret = metacall("compile", text); ASSERT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "\"John Doe\"")); + EXPECT_STREQ(metacall_value_to_string(ret), "\"John Doe\""); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_rust_load_from_package_test/source/metacall_rust_load_from_package_test.cpp b/source/tests/metacall_rust_load_from_package_test/source/metacall_rust_load_from_package_test.cpp index 37f6394bb..cfb3b4995 100644 --- a/source/tests/metacall_rust_load_from_package_test/source/metacall_rust_load_from_package_test.cpp +++ b/source/tests/metacall_rust_load_from_package_test/source/metacall_rust_load_from_package_test.cpp @@ -93,7 +93,7 @@ TEST_F(metacall_rust_load_from_mem_test, DefaultConstructor) // void *ret = metacall("string_len", "Test String"); // EXPECT_EQ((long)11, (long)metacall_value_to_long(ret)); // ret = metacall("new_string", 123); - // EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "get number 123")); + // EXPECT_STREQ(metacall_value_to_string(ret), "get number 123"); // metacall_value_destroy(ret); // } diff --git a/source/tests/metacall_rust_test/source/metacall_rust_test.cpp b/source/tests/metacall_rust_test/source/metacall_rust_test.cpp index 85b9253da..55736c73e 100644 --- a/source/tests/metacall_rust_test/source/metacall_rust_test.cpp +++ b/source/tests/metacall_rust_test/source/metacall_rust_test.cpp @@ -94,13 +94,13 @@ TEST_F(metacall_rust_test, DefaultConstructor) // void *ret = metacall("string_len", "Test String"); // EXPECT_EQ((long)11, (long)metacall_value_to_long(ret)); // ret = metacall("new_string", 123); - // EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "get number 123")); + // EXPECT_STREQ(metacall_value_to_string(ret), "get number 123"); // metacall_value_destroy(ret); // } { void *ret = metacall("str_slice", "hellow"); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "hel")); + EXPECT_STREQ(metacall_value_to_string(ret), "hel"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_test/source/metacall_test.cpp b/source/tests/metacall_test/source/metacall_test.cpp index 3f250b3cd..ddbf10c03 100644 --- a/source/tests/metacall_test/source/metacall_test.cpp +++ b/source/tests/metacall_test/source/metacall_test.cpp @@ -216,7 +216,7 @@ TEST_F(metacall_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello Universe")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello Universe"); metacall_value_destroy(ret); @@ -276,7 +276,7 @@ TEST_F(metacall_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), web_content)); + EXPECT_STREQ(metacall_value_to_string(ret), web_content); metacall_value_destroy(ret); @@ -353,7 +353,7 @@ TEST_F(metacall_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello meta-programmer!")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello meta-programmer!"); metacall_value_destroy(ret); @@ -420,7 +420,7 @@ TEST_F(metacall_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "abcdef")); + EXPECT_STREQ(metacall_value_to_string(ret), "abcdef"); metacall_value_destroy(ret); @@ -428,7 +428,7 @@ TEST_F(metacall_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "efg")); + EXPECT_STREQ(metacall_value_to_string(ret), "efg"); metacall_value_destroy(ret); } @@ -473,7 +473,7 @@ TEST_F(metacall_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "Hello World")); + EXPECT_STREQ(metacall_value_to_string(ret), "Hello World"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_test/source/metacall_test_split.cpp b/source/tests/metacall_test/source/metacall_test_split.cpp index 49d0fc8f1..0a19bce6a 100644 --- a/source/tests/metacall_test/source/metacall_test_split.cpp +++ b/source/tests/metacall_test/source/metacall_test_split.cpp @@ -131,7 +131,7 @@ TEST_F(metacall_loader_test, Python) EXPECT_NE((value)NULL, (value)ret); - EXPECT_EQ((int)0, (int)strcmp(value_to_string(ret), "Hello Universe")); + EXPECT_STREQ(value_to_string(ret), "Hello Universe"); value_destroy(ret); } @@ -167,7 +167,7 @@ TEST_F(metacall_loader_test, Ruby) EXPECT_NE((value)NULL, (value)ret); - EXPECT_EQ((int)0, (int)strcmp(value_to_string(ret), "Hello meta-programmer!")); + EXPECT_STREQ(value_to_string(ret), "Hello meta-programmer!"); value_destroy(ret); } @@ -207,7 +207,7 @@ TEST_F(metacall_loader_test, JavascriptV8) EXPECT_NE((value)NULL, (value)ret); - EXPECT_EQ((int)0, (int)strcmp(value_to_string(ret), "abcdef")); + EXPECT_STREQ(value_to_string(ret), "abcdef"); value_destroy(ret); } @@ -251,7 +251,7 @@ TEST_F(metacall_loader_test, Mock) EXPECT_NE((value)NULL, (value)ret); - EXPECT_EQ((int)0, (int)strcmp(value_to_string(ret), "Hello World")); + EXPECT_STREQ(value_to_string(ret), "Hello World"); value_destroy(ret); @@ -259,7 +259,7 @@ TEST_F(metacall_loader_test, Mock) EXPECT_NE((value)NULL, (value)ret); - EXPECT_EQ((int)0, (int)strcmp(value_to_string(ret), "Hello World")); + EXPECT_STREQ(value_to_string(ret), "Hello World"); value_destroy(ret); } diff --git a/source/tests/metacall_typescript_tsx_test/source/metacall_typescript_tsx_test.cpp b/source/tests/metacall_typescript_tsx_test/source/metacall_typescript_tsx_test.cpp index 16404c17d..52a406737 100644 --- a/source/tests/metacall_typescript_tsx_test/source/metacall_typescript_tsx_test.cpp +++ b/source/tests/metacall_typescript_tsx_test/source/metacall_typescript_tsx_test.cpp @@ -52,7 +52,7 @@ TEST_F(metacall_tsx_test, DefaultConstructor) EXPECT_NE((void *)NULL, (void *)ret); - EXPECT_EQ((int)0, (int)strcmp(metacall_value_to_string(ret), "

Hello metaprogrammer

")); + EXPECT_STREQ(metacall_value_to_string(ret), "

Hello metaprogrammer

"); metacall_value_destroy(ret); } diff --git a/source/tests/metacall_version_test/source/metacall_version_test.cpp b/source/tests/metacall_version_test/source/metacall_version_test.cpp index b7023840b..ef703c79a 100644 --- a/source/tests/metacall_version_test/source/metacall_version_test.cpp +++ b/source/tests/metacall_version_test/source/metacall_version_test.cpp @@ -31,7 +31,7 @@ TEST_F(metacall_version_test, DefaultConstructor) { metacall_print_info(); - ASSERT_EQ((int)0, (int)strcmp(METACALL_VERSION, metacall_version_str())); + ASSERT_STREQ(METACALL_VERSION, metacall_version_str()); /* TODO: Test other version functions */ } diff --git a/source/tests/portability_path_test/source/portability_path_test.cpp b/source/tests/portability_path_test/source/portability_path_test.cpp index 15534b235..f4c638c2f 100644 --- a/source/tests/portability_path_test/source/portability_path_test.cpp +++ b/source/tests/portability_path_test/source/portability_path_test.cpp @@ -68,6 +68,33 @@ TEST_F(portability_path_test, portability_path_test_path_get_module_name_with_ra EXPECT_EQ((char)'\0', (char)result[size - 1]); } +TEST_F(portability_path_test, portability_path_test_path_get_name_null) +{ + static const char result[] = ""; + + string_name name; + + size_t size = portability_path_get_name(NULL, 0, name, NAME_SIZE); + + EXPECT_STREQ(name, result); + EXPECT_EQ((size_t)size, (size_t)sizeof(result)); + EXPECT_EQ((char)'\0', (char)result[size - 1]); +} + +TEST_F(portability_path_test, portability_path_test_path_get_name_empty) +{ + static const char base[] = ""; + static const char result[] = ""; + + string_name name; + + size_t size = portability_path_get_name(base, sizeof(base), name, NAME_SIZE); + + EXPECT_STREQ(name, result); + EXPECT_EQ((size_t)size, (size_t)sizeof(result)); + EXPECT_EQ((char)'\0', (char)result[size - 1]); +} + TEST_F(portability_path_test, portability_path_test_path_get_name) { static const char base[] = "/a/b/c/asd.txt"; @@ -110,6 +137,34 @@ TEST_F(portability_path_test, portability_path_test_path_get_name_without_dot) EXPECT_EQ((char)'\0', (char)result[size - 1]); } +TEST_F(portability_path_test, portability_path_test_path_get_name_dot_in_path) +{ + static const char base[] = "/a/b.c/d/asd"; + static const char result[] = "asd"; + + string_name name; + + size_t size = portability_path_get_name(base, sizeof(base), name, NAME_SIZE); + + EXPECT_STREQ(name, result); + EXPECT_EQ((size_t)size, (size_t)sizeof(result)); + EXPECT_EQ((char)'\0', (char)result[size - 1]); +} + +TEST_F(portability_path_test, portability_path_test_path_get_name_dot_in_path_and_name) +{ + static const char base[] = "/a/b.c/d/asd.txt"; + static const char result[] = "asd"; + + string_name name; + + size_t size = portability_path_get_name(base, sizeof(base), name, NAME_SIZE); + + EXPECT_STREQ(name, result); + EXPECT_EQ((size_t)size, (size_t)sizeof(result)); + EXPECT_EQ((char)'\0', (char)result[size - 1]); +} + TEST_F(portability_path_test, portability_path_test_path_get_name_only_separator_dot) { static const char base[] = "/."; diff --git a/source/tests/reflect_object_class_test/source/reflect_object_class_test.cpp b/source/tests/reflect_object_class_test/source/reflect_object_class_test.cpp index a0d7e0cc2..1abd68347 100644 --- a/source/tests/reflect_object_class_test/source/reflect_object_class_test.cpp +++ b/source/tests/reflect_object_class_test/source/reflect_object_class_test.cpp @@ -500,7 +500,7 @@ TEST_F(reflect_object_class_test, DefaultConstructor) ASSERT_NE((value)NULL, (value)ret); - ASSERT_EQ((int)0, (int)strcmp(value_to_string(ret), "Hello World")); + ASSERT_STREQ(value_to_string(ret), "Hello World"); value_type_destroy(ret); @@ -557,7 +557,7 @@ TEST_F(reflect_object_class_test, DefaultConstructor) ASSERT_NE((value)NULL, (value)ret); - ASSERT_EQ((int)0, (int)strcmp(value_to_string(ret), "Hello World")); + ASSERT_STREQ(value_to_string(ret), "Hello World"); value_type_destroy(ret); diff --git a/source/tests/serial_test/source/serial_test.cpp b/source/tests/serial_test/source/serial_test.cpp index 921a417bb..bf2d158ac 100644 --- a/source/tests/serial_test/source/serial_test.cpp +++ b/source/tests/serial_test/source/serial_test.cpp @@ -35,9 +35,9 @@ class serial_test : public testing::Test ASSERT_NE((serial)NULL, (serial)s); - EXPECT_EQ((int)0, (int)strcmp(name, serial_name(s))); + EXPECT_STREQ(name, serial_name(s)); - EXPECT_EQ((int)0, (int)strcmp(extension, serial_extension(s))); + EXPECT_STREQ(extension, serial_extension(s)); } const char *rapid_json_name() @@ -140,7 +140,7 @@ TEST_F(serial_test, DefaultConstructor) EXPECT_EQ((size_t)sizeof(value_list_str), (size_t)serialize_size); EXPECT_NE((char *)NULL, (char *)buffer); - EXPECT_EQ((int)0, (int)strcmp(buffer, value_list_str)); + EXPECT_STREQ(buffer, value_list_str); value_destroy(v); @@ -161,7 +161,7 @@ TEST_F(serial_test, DefaultConstructor) EXPECT_EQ((size_t)sizeof(value_map_str), (size_t)serialize_size); EXPECT_NE((value)NULL, (value)v); - EXPECT_EQ((int)0, (int)strcmp(buffer, value_map_str)); + EXPECT_STREQ(buffer, value_map_str); value *v_map = value_to_map(v); @@ -189,7 +189,7 @@ TEST_F(serial_test, DefaultConstructor) EXPECT_EQ((size_t)sizeof(json_empty_array), (size_t)serialize_size); EXPECT_NE((value)NULL, (value)v); - EXPECT_EQ((int)0, (int)strcmp(buffer, json_empty_array)); + EXPECT_STREQ(buffer, json_empty_array); value_destroy(v); @@ -206,7 +206,7 @@ TEST_F(serial_test, DefaultConstructor) EXPECT_NE((value *)NULL, (value *)v_array); EXPECT_EQ((type_id)TYPE_STRING, (type_id)value_type_id(v_array[0])); - EXPECT_EQ((int)0, (int)strcmp(value_to_string(v_array[0]), "asdf")); + EXPECT_STREQ(value_to_string(v_array[0]), "asdf"); EXPECT_EQ((type_id)TYPE_INT, (type_id)value_type_id(v_array[1])); EXPECT_EQ((int)443, (int)value_to_int(v_array[1])); @@ -237,7 +237,7 @@ TEST_F(serial_test, DefaultConstructor) value *tupla = value_to_array(v_map[0]); EXPECT_EQ((type_id)TYPE_STRING, (type_id)value_type_id(tupla[0])); - EXPECT_EQ((int)0, (int)strcmp(value_to_string(tupla[0]), "abc")); + EXPECT_STREQ(value_to_string(tupla[0]), "abc"); EXPECT_EQ((type_id)TYPE_FLOAT, (type_id)value_type_id(tupla[1])); EXPECT_EQ((float)9.9f, (float)value_to_float(tupla[1])); @@ -250,7 +250,7 @@ TEST_F(serial_test, DefaultConstructor) tupla = value_to_array(v_map[1]); EXPECT_EQ((type_id)TYPE_STRING, (type_id)value_type_id(tupla[0])); - EXPECT_EQ((int)0, (int)strcmp(value_to_string(tupla[0]), "cde")); + EXPECT_STREQ(value_to_string(tupla[0]), "cde"); EXPECT_EQ((type_id)TYPE_FLOAT, (type_id)value_type_id(tupla[1])); EXPECT_EQ((float)1.5f, (float)value_to_float(tupla[1]));