LuaSTG-x Core API
package Class Reference

Public Member Functions

static function loadlib (local libname, local funcname)
 
static function seeall (local module)
 

Public Attributes

string cpath
 
table loaded
 
table loaders
 
string path
 
table preload
 

Member Function Documentation

◆ seeall()

static function seeall ( local  module)

这个路径被 require 在 Lua 加载器中做搜索时用到。

在启动时,Lua 用环境变量 LUA_PATH 来初始化这个变量。

或采用 luaconf.h 中的默认路径。

环境变量中出现的所有 ";;" 都会被替换成默认路径。 保存有一些特殊模块的加载器(参见 require)。

这个变量仅仅是对真正那张表的引用;

改变这个值并不会改变 require 使用的表。 A table used by require to control how to load modules.

Each entry in this table is a searcher function. When looking for a

module, require calls each of these searchers in ascending order, with the

module name (the argument given to require) as its sole parameter. The

function can return another function (the module loader) plus an extra

value that will be passed to that loader, or a string explaining why it did

not find that module (or nil if it has nothing to say).

Lua initializes this table with four searcher functions.

The first searcher simply looks for a loader in the package.preload table.

The second searcher looks for a loader as a Lua library, using the path

stored at package.path. The search is done as described in function

package.searchpath.

The third searcher looks for a loader as a C library, using the path given

by the variable package.cpath`. Again, the search is done as described in

function package.searchpath. For instance, if the C path is the string

"`./?.so;./?.dll;/usr/local/?/init.so`"

the searcher for module foo will try to open the files ``./foo.so, ./foo

.dll, and/usr/local/foo/init.so, in that order. Once it finds a C

library, this searcher first uses a dynamic link facility to link the

application with the library. Then it tries to find a C function inside the

library to be used as the loader. 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

suffix after (and including) the first hyphen is removed. For instance, if

the module name is a.b.c-v2.1, the function name will be luaopen_a_b_c.

The fourth searcher tries an all-in-one loader. It searches the C path for

a library for the root name of the given module. For instance, when

requiring a.b.c, it will search for a C library for a. If found, it

looks into it for an open function for the submodule; in our example, that

would be luaopen_a_b_c. With this facility, a package can pack several C

submodules into one single library, with each submodule keeping its original

open function.

All searchers except the first one (preload) return as the extra value the

file name where the module was found, as returned by package.searchpath.

The first searcher returns no extra value. Sets a metatable for module with its __index field referring to the global

environment, so that this module inherits values from the global environment.

To be used as an option to function module.

Member Data Documentation

◆ cpath

string cpath

这个路径被 require 在 C 加载器中做搜索时用到。

Lua 用和初始化 Lua 路径 package.path 相同的方式初始化 C 路径 package.cpath 。 它会使用环境变量 LUA_CPATH 初始化。 要么就采用 luaconf.h 中定义的默认路径。

◆ loaded

table loaded

用于 require 控制哪些模块已经被加载的表。 当你请求一个 modname 模块,且 package.loaded[modname] 不为假时, require 简单返回储存在内的值。

这个变量仅仅是对真正那张表的引用; 改变这个值并不会改变 require 使用的表。

◆ loaders

table loaders

A table used by require to control how to load modules.

Each entry in this table is a searcher function. When looking for a module, require calls each of these searchers in ascending order, with the module name (the argument given to require) as its sole parameter. The function can return another function (the module loader) plus an extra value that will be passed to that loader, or a string explaining why it did not find that module (or nil if it has nothing to say).

Lua initializes this table with four searcher functions.

The first searcher simply looks for a loader in the package.preload table.

The second searcher looks for a loader as a Lua library, using the path stored at package.path. The search is done as described in function package.searchpath.

The third searcher looks for a loader as a C library, using the path given by the variable package.cpath<tt>. Again, the search is done as described in functionpackage.searchpath`. For instance, if the C path is the string

"`./?.so;./?.dll;/usr/local/?/init.so`"

the searcher for module foo will try to open the files ./foo.so, ./foo .dll`, and/usr/local/foo/init.so`, in that order. Once it finds a C library, this searcher first uses a dynamic link facility to link the application with the library. Then it tries to find a C function inside the library to be used as the loader. 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 suffix after (and including) the first hyphen is removed. For instance, if the module name is a.b.c-v2.1, the function name will be luaopen_a_b_c.

The fourth searcher tries an all-in-one loader. It searches the C path for a library for the root name of the given module. For instance, when requiring a.b.c, it will search for a C library for a. If found, it looks into it for an open function for the submodule; in our example, that would be luaopen_a_b_c. With this facility, a package can pack several C submodules into one single library, with each submodule keeping its original open function.

All searchers except the first one (preload) return as the extra value the file name where the module was found, as returned by package.searchpath. The first searcher returns no extra value.

◆ path

string path

这个路径被 require 在 Lua 加载器中做搜索时用到。

在启动时,Lua 用环境变量 LUA_PATH 来初始化这个变量。 或采用 luaconf.h 中的默认路径。 环境变量中出现的所有 ";;" 都会被替换成默认路径。

◆ preload

table preload

保存有一些特殊模块的加载器(参见 require)。

这个变量仅仅是对真正那张表的引用; 改变这个值并不会改变 require 使用的表。


The documentation for this class was generated from the following files: