Skip to content
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

Support lua scripting #69

Closed
penguinol opened this issue Sep 19, 2023 · 6 comments
Closed

Support lua scripting #69

penguinol opened this issue Sep 19, 2023 · 6 comments

Comments

@penguinol
Copy link

Lots of MQTT broker support lua scripting, such as vernemq and emqtt.
Lua can make it easier to develop plugins.

@bigsmoke
Copy link
Contributor

As far as I know Wiebe's intentions, a big part of FlashMQ's design philosophy is to have a minimal set of dependencies; another is to do one thing and to do it well. In my opinion, built-in Lua support would add needless complexity and an extra dependency. Though the latter could be configurable at compile-time, that in itself creates more packaging choices and difficulties.

The best approach for those wishing to work with Lua (or any other scripting language for that matter) would be to write a plugin (in C++) that adds support for that language. FlashMQ's plugin ABI is stable, and, since there's not much you can't do with a plugin within FlashMQ's plugin architecture, implementing scripting support shouldn't be hugely difficult.

However … another cornerstone of FlashMQ is performance, and I would venture that in most cases it would be unwise to surrender some of that performance to the drag imposed by an interpreted language.

Then there is the matter of type safety. FlashMQ is written in strongly-typed C++ to make it as fault-free as possible. A quick Google reveals that there are a number of competing approaches to make Lua more strongly type than the baseline language.

All in all, I can't speak for Wiebe, but I think that adding Lua suport to FlashMQ itself would be a mistake. As for a plugin that adds Lua support: I think it can work fine, but would strongly advice to invest that energy in becoming a bit more comfortable in C++. Who doesn't want a non-scripting language on their CV after all?

@bigsmoke
Copy link
Contributor

May I ask, @penguinol, if you have some specific plugin functionality in mind to make you wish you could implent it in Lua?

I'm asking because there are plans for a bunch of example C++ plugins, so that it will be less daunting for novice C++ programmers to build on these examples for most trivial needs, and it will be good to have some concrete needs and wishes in the back of our heads when creating these examples.

@penguinol
Copy link
Author

penguinol commented Sep 22, 2023

I'm a C++ programmer, but i don't think everything must be implemented in C++.
A external lua scripting plugin is fine. With lua, we can implement auth with http\reids\sql in less than 100 lines of lua code and no need to worry about dependencies, make file, compiler and so on.
This can make flashmq out of box and easier to use. Not only for C++ programmers, but also for ops and other programmers.
I don't really worry about the performance of lua, something like openresty also works fine. The cost of redis/http/sql query is much higher than lua. If users do care about the performance, they should write c++ plugins, otherwise, lua is enough.
A lua plugin with sql\redis\http\json support can fit most of needs.

@halfgaar
Copy link
Owner

halfgaar commented Sep 26, 2023

@bigsmoke said it. A plugin for Lua may be good idea just to have, however:

With lua, we can implement auth with http\reids\sql in less than 100 lines of lua code and no need to worry about dependencies, make file, compiler and so on.
This can make flashmq out of box and easier to use. Not only for C++ programmers, but also for ops and other programmers.

I don't really worry about the performance of lua, something like openresty also works fine. The cost of redis/http/sql query is much higher than lua.

I suspect the way this will be implemented would be a blocking/synchronous call. An SQL query can take a few milliseconds easily, which is an eternity in FlashMQ time. You may as well then use other brokers that do support Lua.

For HTTP calls, there is an example plugin for async libcurl to avoid blocking calls, and I suspect that will be impossible to implement with Lua. Or, at least write as technical debt from the start (quick to set up, inflexible/limited later).

@bigsmoke
Copy link
Contributor

@halfgaar , I think you can close this issue?

@halfgaar
Copy link
Owner

@halfgaar , I think you can close this issue?

After some consideration, I agree. I'm all for people developing a lua plugin, but as a core feature, I have to conclude that it's not the most logical feature. FlashMQ's fast, fully async model is too easily undermined with lua.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants