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

久未见 提交于 2021-02-07 13:46:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/31904392/what-do-the-last-lines-in-luas-package-config-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!