-
Notifications
You must be signed in to change notification settings - Fork 17
Use lib from other #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bbb00f1
db56049
5562c40
570637a
0691180
18e4672
c498302
9908163
28fb328
95a0951
7c300bc
fc335ea
a717791
1da4ae0
29c3551
78cd2f6
a784e7d
8c3721d
aa24dd9
fcb9e18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| dart-sdk/* | ||
| .build/* | ||
| build/* | ||
| artifacts/* | ||
| artifacts/* | ||
| depot_tools/* | ||
| out/* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,34 @@ | ||
| cmake_minimum_required(VERSION 3.21) | ||
| cmake_minimum_required(VERSION 3.20) | ||
|
|
||
| project(DartSharedLibrary VERSION 0.1) | ||
|
|
||
| option(BUILD_SMAPLES "Build the Sampels" ON) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 11) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
| set(DART_DLL_DIR "${PROJECT_SOURCE_DIR}/src") | ||
| if(NOT DART_DIR) | ||
| set(DART_DIR "${PROJECT_SOURCE_DIR}/dart-sdk/sdk") | ||
| endif() | ||
|
|
||
| set( OUTPUT_PATH_EXT "x86" ) | ||
| if (CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
| set( IS_64_BIT 1 ) | ||
| set( OUTPUT_PATH_EXT "x64" ) | ||
| endif () | ||
|
|
||
| set(OUTPUT_DEBUG "${OUTPUT_PATH_EXT}/Debug") | ||
| set(OUTPUT_RELEASE "${OUTPUT_PATH_EXT}/Release") | ||
| set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out/$<$<CONFIG:DEBUG>:${OUTPUT_DEBUG}>$<$<CONFIG:RELEASE>:${OUTPUT_RELEASE}>") | ||
| set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/out/${OUTPUT_PATH_EXT}/${CMAKE_BUILD_TYPE}") | ||
| set(LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out/${OUTPUT_PATH_EXT}/${CMAKE_BUILD_TYPE}") | ||
|
|
||
|
|
||
| add_subdirectory(src) | ||
| add_subdirectory(examples) | ||
| if(BUILD_SMAPLES) | ||
| add_subdirectory(examples) | ||
| endif(BUILD_SMAPLES) | ||
|
|
||
| MESSAGE(STATUS "CMake output directory is ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") | ||
| MESSAGE(STATUS "Building executables to ${EXECUTABLE_OUTPUT_PATH}") | ||
| MESSAGE(STATUS "Building libraries to ${LIBRARY_OUTPUT_DIRECTORY}") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ import 'dart:ffi'; | |
| import 'drawable.dart'; | ||
|
|
||
| class WorkFfiCalls { | ||
| // On Linux this search fo Function in libdart_dll why on Windows it Works? | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've fixed FFI resolution for the realtime_example on Linux. The issue is that symbols in executables are not exported by default, so Dart can't find them. You need to add |
||
| final DynamicLibrary processLib = DynamicLibrary.process(); | ||
| //final DynamicLibrary processLib = DynamicLibrary.executable(); | ||
|
|
||
| late final createEntity = processLib | ||
| .lookup<NativeFunction<Uint32 Function(Int32, Int32, Int32, Int32)>>( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #include <dart_api.h> | ||
| #include <cute.h> | ||
| using namespace Cute; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include "exportfunc.h" | ||
|
|
||
| std::unordered_map<unsigned int, Drawable*> entity_drawable_map; | ||
| unsigned int next_entity_id = 1; | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| WORM_EXPORT unsigned int create_entity(int x, int y, int width, int height) { | ||
| Drawable* d = new Drawable{x, y, width, height, color_blue()}; | ||
| unsigned int entity_id = next_entity_id; | ||
| entity_drawable_map[entity_id] = d; | ||
|
|
||
| next_entity_id++; | ||
|
|
||
| return entity_id; | ||
| } | ||
|
|
||
| WORM_EXPORT void destroy_entity(unsigned int entity_id) { | ||
| const auto& itr = entity_drawable_map.find(entity_id); | ||
| if (itr != entity_drawable_map.end()) { | ||
| delete itr->second; | ||
| entity_drawable_map.erase(itr); | ||
| } | ||
| } | ||
|
|
||
| WORM_EXPORT Drawable* get_drawable(unsigned int entity_id) { | ||
| const auto& itr = entity_drawable_map.find(entity_id); | ||
| if (itr != entity_drawable_map.end()) { | ||
| return itr->second; | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
||
| WORM_EXPORT bool get_key_just_pressed(int key_code) { | ||
| return cf_key_just_pressed((CF_KeyButton)key_code); | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
| #include <unordered_map> | ||
| #include "drawable.h" | ||
|
|
||
| // | ||
| // Dart accessible funcitons | ||
| // These need to be exposed as "C" functions and be exported | ||
| // | ||
| #if defined(_WIN32) | ||
| #define WORM_EXPORT __declspec(dllexport) | ||
| #elif defined(__GNUC__) | ||
| #define WORM_EXPORT __attribute__((visibility("default"))) | ||
| #else | ||
| #define WORM_EXPORT | ||
| #endif | ||
|
|
||
|
|
||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| WORM_EXPORT unsigned int create_entity(int x, int y, int width, int height); | ||
| WORM_EXPORT void destroy_entity(unsigned int entity_id); | ||
| WORM_EXPORT Drawable* get_drawable(unsigned int entity_id); | ||
| WORM_EXPORT bool get_key_just_pressed(int key_code); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's more of a personal setting than a project setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"dart.analysisExcludedFolders": [
"dart-sdk"
]
This was hard too find without this you see millions from Warnings in VS Code. And not the Warnings of Code in this Lib. I don't how handle it.