Git Product home page Git Product logo

Comments (2)

rubyFeedback avatar rubyFeedback commented on September 21, 2024

So this is also a bit a request for documentation. A separate file
would be nice, linked in from the main README. It's also ok
if this is outdated. Better to have outdated documentation than
no documentation.

from azul.

fschutt avatar fschutt commented on September 21, 2024

How difficult would this be to add for ruby, and what would be necessary?

You need to build a "C extension" for Ruby (or any other language). Azuls entire API is defined in a JSON file: https://github.com/fschutt/azul/blob/master/api.json

The JSON file describes the entire public API, data types and functions, including documentation. The Python binding code (and the C and C++ headers) are then auto-generated from the build.py file:

azul/build.py

Lines 1200 to 1201 in e0bcb55

# Generates the azul-dll/python.rs file (pyo3 bindings)
def generate_python_api(api_data, structs_map, functions_map):

The build.py file itself generates a 20000-line python.rs file: https://github.com/fschutt/azul/blob/master/azul-dll/src/python.rs. I am using PyO3 to generate the bindings for Python, you'd have to use something like Helix or raw Ruby-FFI. There are also guides for binding Ruby to Rust: https://www.cloudbees.com/blog/improving-ruby-performance-with-rust, but you just need to Google that. I recommend building a small hello-world extension first and testing that helix works.

The python extension bindings generate a lot of extra code, which is why they are behind a --feature=python-extension feature-flag. Overall it should be relatively easy to generate the necessary Rust code, if you know how to parse a JSON file and output text to a file (with 20 years of experience, I think you should be able to handle that).

The only special thing with managed languages is how to pass function callbacks into Rust. For that, there are special "patches" to create a PyFunction object here: https://github.com/fschutt/azul/tree/master/api/_patches/python, especially how to invoke python function objects from Rust, see the layout_callback.rs file. I just adapted the PyO3 examples: https://pyo3.rs/v0.14.5/python_from_rust.html. Same thing would have to be done for Ruby.

The CSS string is a feature of PyO3 (converting a Python String into a Rust String). Python creates the string object, passes it into a Rust function where it gets converted into a Rust String, then the CSS parser parses the string.

from azul.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.