From 75e73abc9c784f5f1aa8c4ca7c282804800360a6 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 26 Jan 2022 19:19:05 +0100 Subject: Updated Lua project headings and minor details --- how_to_organize_your_lua_project.html | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'how_to_organize_your_lua_project.html') diff --git a/how_to_organize_your_lua_project.html b/how_to_organize_your_lua_project.html index 63d952d..4a25626 100644 --- a/how_to_organize_your_lua_project.html +++ b/how_to_organize_your_lua_project.html @@ -3,7 +3,7 @@ - + @@ -13,7 +13,7 @@

How to Organize Your Lua Project

-

Published on 2021-01-07 15:45:00+01:00, last modified on 2021-08-07 14:07:00+02:00 +

Published on 2021-01-07 15:45:00+01:00, last modified on 2022-01-26 19:20:00+01:00

From time to time I hear complaints about how Lua handles modules. Here and there I see and even answer myself questions regarding require and adjusting the paths in package to allow some desired behaviour, with the most prominent issue of relative imports that always work. @@ -25,7 +25,7 @@ mechanism in Lua: -

How require handles paths

+

How Does require Handle Paths

Both package and require are surprisingly interesting tools. At first glance they are simple. When you look into them, they are still understandable while gaining some complexity that doesn't reach unnecessary extremes. They are elegant. @@ -59,7 +59,7 @@ However, in our case this knowledge will suffice.

If you are curious how exactly path is loaded be sure to check out setpath. -

Endgame

+

Production Environment

To prepare for development, we need to know where we are heading. First step is to consider the execution environment. Of course, this and packaging are journeys on their own, so let's just look at two common examples: an application that uses some framework that uses Lua (e.g. a game made in LÖVE) and a @@ -81,7 +81,7 @@ use the environmental variables to prepare for development. If you run your appl then Lua will have access to your modules no matter where it is run. Additionally, it will be consistent with the target environment and won't need any additional hacks. -

Development environment

+

Development Environment

All this talk comes down to: set LUA_PATH in your development environment so that it includes your project files even if they are not installed in system. A simple approach is to source following in each session:

@@ -117,7 +117,7 @@ results.

a random whale -

Organizing your files

+

How to Structure Your Lua Project Files

Finally, this is what we're waiting for. Assume you have a directory that is a parent of all of your project files. We'll call it a project root. Usually, this is also root directory for your version control system, be it git or anything else, and for other tools such as building systems or even entire IDEs. @@ -189,13 +189,15 @@ $ find . ./Makefile ./README $ cat Makefile -PREFIX?=/usr/local/lib/lua/5.4 +PREFIX?=/usr/local +LIBDIR?=$(PREFIX)/lib +LUADIR?=$(LIBDIR)/lua/5.4 all: @echo Nothing to be done install: - cp -r hello $(PREFIX) + cp -r hello $(DESTDIR)$(LUADIR) uninstall: - rm -fd $(PREFIX)/hello/* $(PREFIX)/hello + rm -fd $(DESTDIR)$(LUADIR)/hello/* $(DESTDIR)$(LUADIR)/hello

As you can see Makefile in this example has targets for installation and removal of the package. The structure again is simple. Root works as part of the resolution path and so our module is placed in it's own directory named after -- cgit v1.1