[Home] [Downloads] [Search] [Help/forum]

Register forum user name Search FAQ


Assignment lets you "assign" (set) a variable to a value.


a = 42
b = "hello"

You can do multiple assignments, eg.

a, b = 42, "hello"

That does the same thing as the first example.

Multiple assignments are not generally used on their own (they can be confusing to read), except in collecting the results from a function. Functions can return multiple results, so multiple assignment is a useful way of getting those results. eg.

a, b, c = string.find ("the quick brown fox", "(a+)")

In this example, a will get the start character position of the match, b will get the end position, and c will get the capture.

With multiple assignment, if you (or the function) provides too few values, the extra ones are set to nil, eg.

a, b, c, d = 0, 1

This sets a to 0, b to 1, and c and d are both set to nil.

If you provide too many values, the extra ones are silently discarded, eg.

a = 1, 2, 3, 4, 5, 6

The values 2, 3, 4, 5, 6 are just discarded.

See Also ...

Lua keywords/topics

data types
for (generic)
for (numeric)
if / then / else
logical operators
relational operators
string literals


Lua base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua LPEG library
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua SQLite (database) interface
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting callbacks - plugins

(Help topic: lua=assignment)

Documentation contents page

Search ...

Enter a search string to find matching documentation.

Search for:   

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]