Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kojix2 committed Sep 1, 2024
1 parent 8283f5a commit fa80bc8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,34 @@ See [examples](examples).
- Notes:
- On Windows, libui-ng's msg_box implementation uses TaskDialog. ComCtl32.dll version6 is required to call TaskDialog. The standard ComCtl32 is version 5, so a manifest file is required.

### Closures are not always possible

- A function pointer in C is a Proc in Crystal.
- If data can be passed as an argument, it can be a closure, but not always; if data cannot be passed, it works only if the Proc is not a closure.

## Development

- https://forum.crystal-lang.org/t/6361
1. Low-level bindings are located in `src/uing/lib_ui/lib_ui.cr`.

- `UIng::LibUI.new_window`, `UIng::LibUI::AreaHandler.new`, etc.

2. Middle-level bindings are located in `src/uing.cr`. `UIng.new_window` etc.

- `UIng::Window.new`, `UIng::AreaHandler.new`, `UIng::AreaDrawParams.new(ref_ptr)`, etc.

3. High-level object-oriented bindings are not yet implemented, and parhaps never will be, but they should be found in `src/uing/*.cr`.

- `Window = UIng::Window.new`, `window.on_closing { |w| ... }`, etc.

- Enums are defined under `UIng` module. Both low-level and high-level bindings use them.
- The Crystal object corresponding to a C structure may have a reference pointer, or it may have the structure. Crystal objects have structure if it is necessary to allocate memory for the structure on the Crystal side. Otherwise, it should hold the reference.

- History: https://forum.crystal-lang.org/t/6361
- Rules:
- `UIng::LibUI` is a module for binding.
- Use [crystal_lib](https://github.com/crystal-lang/crystal_lib) to create bindings.
- Method names should be snake_case.
- Use [crystal_lib](https://github.com/crystal-lang/crystal_lib) to create low-level bindings. You will need to modify the generated code.
- [Passing a Proc to a C function](https://crystal-lang.org/api/1.12.1/Proc.html#passing-a-proc-to-a-c-function)

- A function pointer in C is a Proc in Crystal.
- If data can be passed as an argument, it can be a closure, but not always; if data cannot be passed, it works only if the Proc is not a closure.

## Contributing

- Fork this repository
Expand Down

0 comments on commit fa80bc8

Please sign in to comment.