RFC: support for Lua, Python, and Rust in Fluid

31 views
Skip to first unread message

melcher....@googlemail.com

unread,
Nov 4, 2022, 6:32:31 PM11/4/22
to fltk.coredev

First off, this is *not* about adding language wrappers to FLTK. This is about giving Fluid the ability to write source code for different language wrappers.

I am excited that we found a very nice new group of users through pyFLTK,  moonfltk Lua, and recently through fltk-rs Rust. We know that the Rust community has a .fl-to-Rust converter, so Fluid is actually in use to generate UIs for other languages. I am very excited about that. I did implement a crude Lua writer a few weeks ago to understand what's involved in supporting multiple languages.

I understand that Albrecht is concerned that we take on a new feature that may not be supported in the long run. I like to think that instead we add devs from the Rust and pyFLTK community who may see a benefit in maintaining the feature, and who are knowledgable in the respective language.

may642.2000 suggested to use a better format for .fd files like json to make interpreting the .fd file easier for external authors, which would solve issues with interpreting .fd files, but still leaves the complexity of writing the actual code.

To me, the code for a good wrapper has pretty much the same basic structure in all languages. It's mostly the syntax that changes. In Lua, most of the C++ code generator can be reused by adjusting the syntax. Python is probably quite similar. I have no clue about Rust.

Here is a little example that explains how I would implement multiple writers. We would need to treat about 300 lines to modify output syntax. 

pre is the line prefix string
const char *s = comment();
if (strchr(s, '\n')==0L) {
  // single line comment
  if (pre) write_c("%s", pre);
  write_c("// %s\n", s);
  if (!pre) write_c("%s", indent_plus(1));
} else {
  write_c("%s/*\n", pre?pre:"");

And in the two-language version:

const char *s = comment();
if (strchr(s, '\n')==0L) {
  // single line comment
  if (pre) write_all("%s", pre);
  write_c("// %s\n", s);
  write_py("# %s\n", s);
  if (!pre) write_all("%s", indent_plus(1));
} else {
  write_c("%s/*\n", pre?pre:"");
  write_py("%s```\n", pre?pre:"");
...

where write_c does nothing if we are writing a Python file, and write_py does nothing for C++. 

melcher....@googlemail.com

unread,
Nov 8, 2022, 1:24:29 PM11/8/22
to fltk.coredev
Just to complete this conversation: there were at least two devs against this and nobody for it, so I'll close this RFC.

Instead I added full documentation for the Fluid .fl file format, making it possible to write an interpreter that converts .fl designs into source code for any other language.

Albrecht Schlosser

unread,
Nov 8, 2022, 1:35:13 PM11/8/22
to fltkc...@googlegroups.com
I believe this is a good move. Thank you.

Mohammed

unread,
Nov 9, 2022, 1:08:54 PM11/9/22
to fltkc...@googlegroups.com
This is great. The readme clarifies a lot of things. I’ve started working on a tool which would parse fluid files and output json files. It uses C++11 and std types (vector, string etc) since the json library I’m using (nlohmann/json, single-header) supports serializing std types to json, and this would simplify a lot of code.

Sent from my iPhone

On 8 Nov 2022, at 21:24, 'melcher....@googlemail.com' via fltk.coredev <fltkc...@googlegroups.com> wrote:

Just to complete this conversation: there were at least two devs against this and nobody for it, so I'll close this RFC.

Instead I added full documentation for the Fluid .fl file format, making it possible to write an interpreter that converts .fl designs into source code for any other language.

--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkcoredev/065bd559-ec65-4e34-a1f3-ad77193f32b8n%40googlegroups.com.

melcher....@googlemail.com

unread,
Nov 9, 2022, 4:44:33 PM11/9/22
to fltk.coredev
Great. Please keep us posted. Maybe we can some day move to JSON, although with large verbatim code chunks, I was more thinking XML, but it's not really my expertise anyway ;-).

Mo_Al_

unread,
Nov 12, 2022, 7:52:03 AM11/12/22
to fltk.coredev
I have a proof of concept here, which I still intend to work on. I've also ported the work to Rust for use in fl2rust.


The json generated by nlohmann json isn't the prettiest, it's not ordered for example since spec conformance doesn't require it. But it's the only json lib in C++ (AFAIK) which supports generating json from a predefined struct.

Reply all
Reply to author
Forward
0 new messages