# A better way to integrate LuaRocks with Haxe Lua target

**URL:** <https://community.haxe.org/t/a-better-way-to-integrate-luarocks-with-haxe-lua-target/3802>\
**Category:** Haxe\
**Created:** [December 17, 2022, 12:00pm UTC](https://community.haxe.org/t/a-better-way-to-integrate-luarocks-with-haxe-lua-target/3802 "2022-12-17T12:00:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![piotrklibert](https://community.haxe.org/user_avatar/community.haxe.org/piotrklibert/32/1593_2.png) [@piotrklibert](https://community.haxe.org/u/piotrklibert)\
**Post date:** [December 17, 2022, 12:00pm UTC](https://community.haxe.org/t/a-better-way-to-integrate-luarocks-with-haxe-lua-target/3802/1 "2022-12-17T12:00:00Z")

</div>

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

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

```

here: [haxe/genlua.ml at development · HaxeFoundation/haxe · GitHub](https://github.com/HaxeFoundation/haxe/blob/development/src/generators/genlua.ml#L1952)

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.

---

<div class="post-metadata">

**Author:** ![davidbruce](https://community.haxe.org/user_avatar/community.haxe.org/davidbruce/32/555_2.png) [@davidbruce](https://community.haxe.org/u/davidbruce)\
**Post date:** [December 17, 2022, 4:21pm UTC](https://community.haxe.org/t/a-better-way-to-integrate-luarocks-with-haxe-lua-target/3802/2 "2022-12-17T16:21:29Z")

</div>

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](https://haxe.org/blog/hello-lua/)

---

<div class="post-metadata">

**Author:** ![danielo515](https://community.haxe.org/user_avatar/community.haxe.org/danielo515/32/2052_2.png) [@danielo515](https://community.haxe.org/u/danielo515)\
**Post date:** [December 17, 2022, 5:54pm UTC](https://community.haxe.org/t/a-better-way-to-integrate-luarocks-with-haxe-lua-target/3802/3 "2022-12-17T17:54:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![piotrklibert](https://community.haxe.org/user_avatar/community.haxe.org/piotrklibert/32/1593_2.png) [@piotrklibert](https://community.haxe.org/u/piotrklibert)\
**Post date:** [December 17, 2022, 6:14pm UTC](https://community.haxe.org/t/a-better-way-to-integrate-luarocks-with-haxe-lua-target/3802/4 "2022-12-17T18:14:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![piotrklibert](https://community.haxe.org/user_avatar/community.haxe.org/piotrklibert/32/1593_2.png) [@piotrklibert](https://community.haxe.org/u/piotrklibert)\
**Post date:** [December 17, 2022, 6:35pm UTC](https://community.haxe.org/t/a-better-way-to-integrate-luarocks-with-haxe-lua-target/3802/5 "2022-12-17T18:35:58Z")

</div>

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](https://community.haxe.org/t/macro-to-generate-nested-lua-tables-from-typedef/3795)), 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](https://awesomewm.org/apidoc/documentation/03-declarative-layout.md.html) No matter what I do, it doesn’t look nearly as nice in Haxe (yet) 🙂
