└── addons └── cffi ├── build └── .gdignore ├── cffi.gdextension.uid ├── cffi_library.gd.uid ├── plugin ├── plugin.gd.uid ├── shlibs_export_plugin.gd.uid ├── plugin.gd └── shlibs_export_plugin.gd ├── cffi_library_resource_format_loader.gd.uid ├── plugin.cfg ├── cffi_library_resource_format_loader.gd ├── UNLICENSE ├── cffi_library.gd └── cffi.gdextension /addons/cffi/build/.gdignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /addons/cffi/cffi.gdextension.uid: -------------------------------------------------------------------------------- 1 | uid://ci5eejaumgrag 2 | -------------------------------------------------------------------------------- /addons/cffi/cffi_library.gd.uid: -------------------------------------------------------------------------------- 1 | uid://dektpoitfd7j8 2 | -------------------------------------------------------------------------------- /addons/cffi/plugin/plugin.gd.uid: -------------------------------------------------------------------------------- 1 | uid://dcaxyo4xyba41 2 | -------------------------------------------------------------------------------- /addons/cffi/plugin/shlibs_export_plugin.gd.uid: -------------------------------------------------------------------------------- 1 | uid://dlqmhmhkmkb8x 2 | -------------------------------------------------------------------------------- /addons/cffi/cffi_library_resource_format_loader.gd.uid: -------------------------------------------------------------------------------- 1 | uid://b52kc1yxr0ld 2 | -------------------------------------------------------------------------------- /addons/cffi/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name="cffi" 4 | description="Custom FFI library resource loader and export plugin" 5 | author="gilzoide" 6 | version="0.2.0" 7 | script="plugin/plugin.gd" 8 | -------------------------------------------------------------------------------- /addons/cffi/plugin/plugin.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends EditorPlugin 3 | 4 | var export_plugin 5 | 6 | 7 | func _enter_tree(): 8 | export_plugin = preload("shlibs_export_plugin.gd").new() 9 | add_export_plugin(export_plugin) 10 | 11 | 12 | func _exit_tree(): 13 | remove_export_plugin(export_plugin) 14 | -------------------------------------------------------------------------------- /addons/cffi/plugin/shlibs_export_plugin.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends EditorExportPlugin 3 | 4 | 5 | func _export_file(path, type, features): 6 | if path.begins_with("res://addons/cffi/plugin"): 7 | skip() 8 | elif path.ends_with(".ffilibrary"): 9 | var libpath = load(path).find_library_path(features) 10 | if libpath: 11 | add_shared_object(libpath, features, "") 12 | 13 | 14 | func _get_name(): 15 | return "CFFILibrary" 16 | -------------------------------------------------------------------------------- /addons/cffi/cffi_library_resource_format_loader.gd: -------------------------------------------------------------------------------- 1 | @tool 2 | extends ResourceFormatLoader 3 | class_name FFILibraryResourceFormatLoader 4 | 5 | const LIBRARIES_SECTION = "libraries" 6 | 7 | 8 | func _get_recognized_extensions(): 9 | return ["ffilibrary"] 10 | 11 | 12 | func _handles_type(type): 13 | return type == "CFFILibrary" 14 | 15 | 16 | func _load(path, original_path, use_sub_threads, cache_mode): 17 | var config = ConfigFile.new() 18 | var res = config.load(original_path) 19 | if res != OK: 20 | return res 21 | if not config.has_section(LIBRARIES_SECTION): 22 | return ERR_INVALID_DATA 23 | var libraries = {} 24 | for key in config.get_section_keys(LIBRARIES_SECTION): 25 | libraries[key] = config.get_value(LIBRARIES_SECTION, key) 26 | var resource = CFFILibrary.new() 27 | resource.libraries = libraries 28 | return resource 29 | -------------------------------------------------------------------------------- /addons/cffi/UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /addons/cffi/cffi_library.gd: -------------------------------------------------------------------------------- 1 | extends Resource 2 | class_name CFFILibrary 3 | 4 | @export var libraries: Dictionary 5 | 6 | 7 | func find_library_path(tags := PackedStringArray()) -> String: 8 | if tags.is_empty(): 9 | return _find_library_path(func(tag): return OS.has_feature(tag)) 10 | else: 11 | return _find_library_path(func(tag): return tags.has(tag)) 12 | 13 | 14 | func open(tags := PackedStringArray()) -> CFFILibraryHandle: 15 | var library_path = find_library_path(tags) 16 | if not OS.has_feature("editor"): 17 | library_path = library_path.get_file() 18 | return CFFI.open(library_path) 19 | 20 | 21 | func _find_library_path(has_tag: Callable) -> String: 22 | var best_matching_tags := PackedStringArray() 23 | var best_library_path := "" 24 | for key in libraries: 25 | var lib_tags: PackedStringArray = (key as String).split(".") 26 | var all_tags_met = true 27 | for tag in lib_tags: 28 | if not has_tag.call(tag.strip_edges()): 29 | all_tags_met = false 30 | break 31 | if all_tags_met and lib_tags.size() > best_matching_tags.size(): 32 | best_library_path = libraries[key] 33 | best_matching_tags = lib_tags 34 | if not best_library_path.is_empty() and best_library_path.is_relative_path(): 35 | best_library_path = resource_path.get_base_dir().path_join(best_library_path) 36 | return best_library_path 37 | -------------------------------------------------------------------------------- /addons/cffi/cffi.gdextension: -------------------------------------------------------------------------------- 1 | [configuration] 2 | 3 | entry_symbol = "cffi_entrypoint" 4 | compatibility_minimum = "4.1" 5 | reloadable = true 6 | 7 | [libraries] 8 | 9 | macos.debug = "build/libcffi.macos.template_debug.universal.dylib" 10 | macos.release = "build/libcffi.macos.template_release.universal.dylib" 11 | ios.debug = "build/libcffi.ios.template_debug.universal.dylib" 12 | ios.release = "build/libcffi.ios.template_release.universal.dylib" 13 | windows.debug.x86_32 = "build/libcffi.windows.template_debug.x86_32.dll" 14 | windows.release.x86_32 = "build/libcffi.windows.template_release.x86_32.dll" 15 | windows.debug.x86_64 = "build/libcffi.windows.template_debug.x86_64.dll" 16 | windows.release.x86_64 = "build/libcffi.windows.template_release.x86_64.dll" 17 | linux.debug.x86_32 = "build/libcffi.linux.template_debug.x86_32.so" 18 | linux.release.x86_32 = "build/libcffi.linux.template_release.x86_32.so" 19 | linux.debug.x86_64 = "build/libcffi.linux.template_debug.x86_64.so" 20 | linux.release.x86_64 = "build/libcffi.linux.template_release.x86_64.so" 21 | android.debug.x86_32 = "build/libcffi.android.template_debug.x86_32.so" 22 | android.release.x86_32 = "build/libcffi.android.template_release.x86_32.so" 23 | android.debug.x86_64 = "build/libcffi.android.template_debug.x86_64.so" 24 | android.release.x86_64 = "build/libcffi.android.template_release.x86_64.so" 25 | android.debug.arm32 = "build/libcffi.android.template_debug.arm32.so" 26 | android.release.arm32 = "build/libcffi.android.template_release.arm32.so" 27 | android.debug.arm64 = "build/libcffi.android.template_debug.arm64.so" 28 | android.release.arm64 = "build/libcffi.android.template_release.arm64.so" 29 | --------------------------------------------------------------------------------