Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the last lines in Lua's `package.config` mean?

Tags:

require

lua

The Lua specs say about package.config (numbering added by me):

  1. The first line is the directory separator string. Default is '\' for Windows and '/' for all other systems.
  2. The second line is the character that separates templates in a path. Default is ';'.
  3. The third line is the string that marks the substitution points in a template. Default is '?'.
  4. The fourth line is a string that, in a path in Windows, is replaced by the executable's directory. Default is '!'.
  5. The fifth line is a mark to ignore all text before it when building the luaopen_ function name. Default is '-'.

My paraphrasing:

  1. Absolutely clear (example for Windows/other systems makes it fool proof)
  2. There can be multiple paths in a path string. They are separated by this symbol (; by default).
  3. Wherever Lua finds this character in the path string (? by default), it will replace it with the module name supplied to the require or package.searchpath functions and check whether that file exists.

So far, so good, but the last two lines aren't entirely clear to me.

  1. Why does it say "in a path in Windows"? Does that mean on other platforms, this doesn't have any significance? If so, why?
  2. It took me a while to make sense of this, but eventually another part of the specs gave me a hint:

    The name of this C function is the string "luaopen_" concatenated with a copy of the module name where each dot is replaced by an underscore. Moreover, if the module name has a hyphen, its prefix up to (and including) the first hyphen is removed. For instance, if the module name is a.v1-b.c, the function name will be luaopen_b_c.

    So is this symbol (- by default) intended to make different versions of a library available at the same time – potentially with an unprefixed symlink to the newest version so that the same library would be accessible on two paths (i.e. under two module names), but with only one C symbol name?

like image 669
Thomas W Avatar asked Aug 09 '15 12:08

Thomas W


1 Answers

4: Applications for Linux have libraries installed system-wide; however, for Windows, libraries can be installed in the current directory.

5: Versioning and project forking, I believe, would be the reason behind this.

like image 89
RyanSquared Avatar answered Sep 19 '22 14:09

RyanSquared