Прочие компоненты пакета
All the Tarantool modules are, at some level, inside a package which,
appropriately, is named package
. There are also miscellaneous functions
and variables which are outside all modules.
Имя | Назначение |
---|---|
tonumber64() | Конвертация строки или Lua-числа в 64-битное целое число |
dostring() | Анализ и выполнение произвольного Lua-кода |
package.path | Where Tarantool looks for Lua additions |
package.cpath | Where Tarantool looks for C additions |
package.loaded | What Tarantool has already looked for and found |
package.setsearchroot | Set the root path for a directory search |
package.searchroot | Get the root path for a directory search |
-
tonumber64
(value)¶ Конвертация строки или Lua-числа в 64-битное целое число. Входное значение может быть выражено десятичным, двоичным (например, 0b1010) или шестнадцатеричным (например, -0xffff) числом. Результат может использоваться в арифметике, причем скорее в 64-битной целочисленной арифметике, а не в арифметике в системе с плавающей запятой. (Операции с неконвертированными Lua-числами выполняются в арифметике в системе с плавающей запятой.) Функция
tonumber64()
в Tarantool является глобальной.Пример:
tarantool> type(123456789012345), type(tonumber64(123456789012345)) --- - number - number ... tarantool> i = tonumber64('1000000000') --- ... tarantool> type(i), i / 2, i - 2, i * 2, i + 2, i % 2, i ^ 2 --- - number - 500000000 - 999999998 - 2000000000 - 1000000002 - 0 - 1000000000000000000 ...
Warning: There is an underlying LuaJIT library that operates with C rules. Therefore you should expect odd results if you compare unsigned and signed (for example 0ULL > -1LL is false), or if you use numbers outside the 64-bit integer range (for example 9223372036854775808LL is negative). Also you should be aware that
type(number-literal-ending-in-ULL)
is cdata, not a Lua arithmetic type, which prevents direct use with some functions in Lua libraries such as math. See the LuaJIT reference and look for the phrase «64 bit integer arithmetic». and the phrase «64 bit integer comparison». Or see the comments on Issue#4089.
-
dostring
(lua-chunk-string[, lua-chunk-string-argument ...])¶ Анализ и выполнение произвольного Lua-кода. Данная функция используется преимущественно для определения и выполнения Lua-кода без необходимости внесения изменений в глобальное Lua-окружение.
Параметры: - lua-chunk-string (
string
) – Lua-код - lua-chunk-string-argument (
lua-value
) – ноль или другие скалярные значения, которые заменяются или к которым прибавляются значения.
возвращает: то, что возвращает Lua-код.
Возможные ошибки: Ошибка компиляции появляется как Lua-ошибка.
Пример:
tarantool> dostring('abc') --- error: '[string "abc"]:1: ''='' expected near ''<eof>''' ... tarantool> dostring('return 1') --- - 1 ... tarantool> dostring('return ...', 'hello', 'world') --- - hello - world ... tarantool> dostring([[ > local f = function(key) > local t = box.space.tester:select{key} > if t ~= nil then > return t[1] > else > return nil > end > end > return f(...)]], 1) --- - null ...
- lua-chunk-string (
-
package.
path
¶ This is a string that Tarantool uses to search for Lua modules, especially important for
require()
. See Modules, rocks and applications.
-
package.
cpath
¶ This is a string that Tarantool uses to search for C modules, especially important for
require()
. See Modules, rocks and applications.
-
package.
loaded
¶ This is a string that shows what Lua or C modules Tarantool has loaded, so that their functions and members are available. Initially it has all the pre-loaded modules, which don’t need
require()
.
-
package.
setsearchroot
([search-root])¶ Set the search root. The search root is the root directory from which dependencies are loaded.
Параметры: - search-root (
string
) – the path. Default = current directory.
The search-root string must contain a relative or absolute path. If it is a relative path, then it will be expanded to an absolute path. If search-root is omitted, or is box.NULL, then the search root is reset to the current directory, which is found with debug.sourcedir().
Пример:
Suppose that a Lua file
myapp/init.lua
is the project root.
Suppose the current path is/home/tara
.
Add this as the first line ofmyapp/init.lua
:
package.setsearchroot()
Start the project with
$ tarantool myapp/init.lua
The search root will be the default, made absolute:/home/tara/myapp
. Within the Lua application all dependencies will be searched relative to/home/tara/myapp
.- search-root (
-
package.
searchroot
()¶ Return a string with the current search root. After
package.setsearchroot('/home')
the returned string will be/home'
.