External Lua modules with Defold?

Let’s say I have this module https://luarocks.org/modules/siffiejoe/compat53/0.7-1 and I want to use it with Defold.

What’s the procedure?

I’d understand putting some Lua files into the project and “requiring” them once. But this module consists of this stuff:

build = {
   type = "builtin",
   modules = {
      ["compat53.init"] = "compat53/init.lua",
      ["compat53.module"] = "compat53/module.lua",
      ["compat53.utf8"] = "lutf8lib.c",
      ["compat53.table"] = "ltablib.c",
      ["compat53.string"] = "lstrlib.c",
   }
}

Some of it is C.

Am I supposed to build it using luarocks make? Because I’ve failed to do it, I get weird errors

But I’m not even sure what the correct procedure here is.

1 Like

No, that will not work. You need to build the C code to all target platforms and you need to integrate the C code into the engine and bind the public C API to Lua functions.

Fortunately Defold has a system called native extension that can be used for including native code and exposing it to Lua. You can read about it here and in the other native extension manuals.

2 Likes