FREENOTE
Sign up
Login
New paste
Home
Trending
Archive
English
English
Sign up
Login
New Paste
Browse
The stand-alone interpreter (also called lua.c due to its source file, or simply lua due to its executable) is a small program that allows the direct use of Lua. This section presents its main options. When the interpreter loads a file, it ignores its first line if that line starts with a number sign (`#´). That feature allows the use of Lua as a script interpreter in Unix systems. If you start your program with something like #!/usr/local/bin/lua (assuming that the stand-alone interpreter is located at /usr/local/bin), or #!/usr/bin/env lua then you can call the program directly, without explicitly calling the Lua interpreter. The usage of lua is lua [options] [script [args]] Everything is optional. As we have seen already, when we call lua without arguments the interpreter enters in interactive mode. The -e option allows us to enter code directly into the command line. For instance, prompt> lua -e "print(math.sin(12))" --> -0.53657291800043 (Unix needs the double quotes to stop the shell from interpreting the parentheses.) As we previously saw, -l loads a file and -i enters interactive mode after running the other arguments. So, for instance, the call prompt> lua -i -l a.lua -e "x = 10" will load the file a.lua, then execute the assignment x = 10, and finally present a prompt for interaction. Whenever the global variable _PROMPT is defined, lua uses its value as the prompt when interacting. So, you can change the prompt with a call like this: prompt> lua -i -e "_PROMPT=' lua> '" lua> We are assuming that "prompt" is the system's prompt. In the example, the outer quotes stop the shell from interpreting the inner quotes, which are interpreted by Lua. More exactly, Lua receives the following command to run: _PROMPT=' lua> ' which assigns the string " lua> " to the global variable _PROMPT. Before it starts running arguments, lua looks for an environment variable called LUA_INIT. If there is such a variable and its content is @filename, then lua loads the given file. If LUA_INIT is defined but does not start with `@´, then lua assumes that it contains Lua code and runs it. This variable gives you great power when configuring the stand-alone interpreter, because you have the full power of Lua in the configuration. You can pre-load packages, change the prompt and the path, define your own functions, rename or delete functions, and so on. A main script can retrieve its arguments in the global variable arg. In a call like prompt> lua script a b c lua creates the table arg with all the command-line arguments, before running the script. The script name goes into index 0; its first argument (a in the example), goes to index 1, and so on. Eventual options go to negative indices, as they appear before the script. For instance, in the call prompt> lua -e "sin=math.sin" script a b lua collects the arguments as follows: arg[-3] = "lua" arg[-2] = "-e" arg[-1] = "sin=math.sin" arg[0] = "script" arg[1] = "a" arg[2] = "b" More often than not, the script only uses the positive indices (arg[1] and arg[2], in the example).
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Do you like cookies?
🍪 We use cookies to ensure you get the best experience on our website.
Learn more
I agree