A better way to integrate LuaRocks with Haxe Lua target

Hi,

I’m using Haxe with Lua target, both for embedded Lua and for standalone Lua scripts. For the embedded use case, I have full control over initialization, which is done outside of the scripts, so it works well. However, for the standalone case, I’d like to avoid having to prepare a runner scripts that would dofile on the Haxe output. What I need, basically, is inserting the require("luarocks.loader") at the top of the generated file (because things like lua-utf8 are required way before the static __init__ section, not to mention main method execution).

The only way to get this that I found was to modify genlua.ml, adding

print ctx "pcall(function () require\"luarocks.loader\" end)\n";

here: haxe/genlua.ml at development · HaxeFoundation/haxe · GitHub

It works without problems, but I’m a little reluctant to handle it this way. Is there a better way?

EDIT: after browsing the forum a bit it looks like --macro includeFile could be a way to go, will check it out.

I don’t use the Lua target, but it looks like includeFile is the way to go. There is also @:luaRequire which may also help you out.

I’m basing this purely off of the initial post of the Lua target: Hello Lua! - Haxe - The Cross-platform Toolkit

Is utf8 required? If not, you can always target Lua vanilla and get rid of all deps at the price of loosing some high level thing like utf8 support

For the record: yes, includeFile worked without problems. Thanks!

I need utf8, very much so! I’m using LuaJIT with Awesome window manager. My native language has all those pesky ąść characters, so for example, when I trim the length of a window title without utf8 support, it often looks bad (ie. sometimes characters encoded as more than 1 byte are sliced in half, resulting in junk being displayed).

I’m generally happy with my setup, Haxe and LuaJIT combo seems to work quite well, but I’m still trying to get a feel of how to best code in that environment. Unfortunately, it doesn’t seem popular as a Haxe target, and there are many rough edges (like in this thread: Macro to generate nested Lua tables from typedef), so for the moment, I’m trying first to make the development convenient, and plan to worry about performance later. The biggest problem I currently have is the “declarative layout” system that exploits the dual nature of Lua tables to describe widget hierarchies: Topic 03-declarative-layout.md - awesome API documentation No matter what I do, it doesn’t look nearly as nice in Haxe (yet) :slight_smile: