Stephan Hennig contributed the Lua keywords.
2175h∗lang2i
We begin with the keywords for Lua 5.0:
2176%%
2177%% Lua definitions (c) 2013 Stephan Hennig
2178%%
2179\lst@definelanguage[5.0]{Lua}{%
To enable highlighting of library keywords, the dot needs to be a letter.
2180 alsoletter={.},%
The language definition knows
• language keywords
2181 morekeywords=[1]{%
2182 and, break, do, else, elseif, end, false, for, function, if, in,%
2183 local, nil, not, or, repeat, return, then, true, until, while,%
2184 },%
• the standard library identifiers
2185 morekeywords=[2]{%
– coming from the base library
2186 _G, _LOADED, _REQUIREDNAME, _VERSION, LUA_PATH,%
2187 assert, collectgarbage, dofile, error, gcinfo, getfenv,%
2188 getmetatable, ipairs, loadfile, loadlib, loadstring, newproxy,%
2189 next, pairs, pcall, print, rawequal, rawget, rawset, require,%
2190 setfenv, setmetatable, tonumber, tostring, type, unpack, xpcall,%
– coming from the coroutine library
2191 coroutine, coroutine.create, coroutine.resume,%
2192 coroutine.status, coroutine.wrap, coroutine.yield,%
– the debug library
2193 _TRACEBACK, debug, debug.debug, debug.gethook, debug.getinfo,%
2194 debug.getlocal, debug.getupvalue, debug.sethook, debug.setlocal,%
2195 debug.setupvalue,debug.traceback,%
– the io library
2196 io, io.close, io.flush, io.input, io.lines, io.open, io.output,%
2197 io.popen, io.read, io.stderr, io.stdin, io.stdout, io.tmpfile,%
2198 io.type, io.write,%
– the mathematical library
2199 __pow, math, math.abs, math.acos, math.asin, math.atan, math.atan2,%
2200 math.ceil, math.cos, math.deg, math.exp, math.floor, math.frexp,%
2201 math.ldexp, math.log, math.log10, math.max, math.min, math.mod,%
2202 math.pi, math.pow, math.rad, math.random, math.randomseed, math.sin,%
2203 math.sqrt, math.tan,%
– the os library
2204 os, os.clock, os.date, os.difftime, os.execute, os.exit, os.getenv,%
2205 os.remove, os.rename, os.setlocale, os.time, os.tmpname,%
– the string library
2206 string, string.byte, string.char, string.dump, string.find,%
2207 string.format, string.gfind, string.gsub, string.len, string.lower,%
2208 string.rep, string.sub, string.upper,%
– the table library
2209 table, table.concat, table.foreach, table.foreachi, table.getn,%
2210 table.insert, table.remove, table.setn, table.sort,%
2211 },%
and some additional identifiers
2212 morekeywords=[2]{%
2213 _PROMPT, _PROMPT2, arg,%
2214 },%
These are the common language settings
2215 sensitive=true,%
2216 % single line comments
2217 morecomment=[l]{--},%
2218 % multi line comments
2219 morecomment=[s]{--[[}{]]},%
2220 % backslash escaped strings
2221 morestring=[b]",%
2222 morestring=[b]’,%
2223 % multi line strings
2224 morestring=[s]{[[}{]]},%
2225}[keywords,comments,strings]%
And here are the new definitions for Lua 5.1:
2226\lst@definelanguage[5.1]{Lua}[5.0]{Lua}{%
There are some deletions
2227 deletekeywords=[2]{%
concerning
• the base library
2228 _LOADED, _REQUIREDNAME, LUA_PATH, gcinfo, loadlib,%
• the debug library
2229 _TRACEBACK,%
• the mathematical library
2230 __pow, math.mod,%
• the string library
2231 string.gfind,%
• the table library
2232 table.foreach, table.foreachi, table.getn, table.setn,%
2233 },%
and some new identifiers in standard libraries like
2234 morekeywords=[2]{%
• the base library
2235 load, select,%
• coroutine library
2236 coroutine.running,%
• debug library
2237 debug.getfenv, debug.getmetatable, debug.getregistry, debug.setfenv,%
2238 debug.setmetatable,%
• the mathematical library
2239 math.cosh, math.fmod, math.huge, math.modf, math.sinh, math.tanh,%
• the package library which itself is new in Lua 5.1
2240 module, package, package.config, package.cpath, package.loaded,%
2241 package.loaders, package.loadlib, package.path, package.preload,%
2242 package.seeall,%
• the string library and
2243 string.gmatch, string.match, string.reverse,%
• the table library
2244 table.maxn,%
2245 },%
In Lua 5.1 long bracket comments were introduced also
2246 morecomment=[s]{--[=[}{]=]},%
2247 morecomment=[s]{--[==[}{]==]},%
2248 morecomment=[s]{--[===[}{]===]},%
2249 morecomment=[s]{--[====[}{]====]},%
2250 morecomment=[s]{--[=====[}{]=====]},%
2251 morecomment=[s]{--[======[}{]======]},%
2252 morecomment=[s]{--[=======[}{]=======]},%
2253 morecomment=[s]{--[========[}{]========]},%
2254 morecomment=[s]{--[=========[}{]=========]},%
2255 morecomment=[s]{--[==========[}{]==========]},%
as well as long bracket strings
2256 morestring=[s]{[=[}{]=]},%
2257 morestring=[s]{[==[}{]==]},%
2258 morestring=[s]{[===[}{]===]},%
2259 morestring=[s]{[====[}{]====]},%
2260 morestring=[s]{[=====[}{]=====]},%
2261 morestring=[s]{[======[}{]======]},%
2262 morestring=[s]{[=======[}{]=======]},%
2263 morestring=[s]{[========[}{]========]},%
2264 morestring=[s]{[=========[}{]=========]},%
2265 morestring=[s]{[==========[}{]==========]},%
2266}[keywords,comments,strings]%
Lua 5.2 again has some changed features. These are
2267\lst@definelanguage[5.2]{Lua}[5.1]{Lua}{%
• new language keywords
2268 morekeywords=[1]{%
2269 goto,%
2270 },%
• deleted identifiers from the standard libraries like
2271 deletekeywords=[2]{%
– the base library
2272 getfenv, loadstring, module, newproxy, setfenv, unpack,%
– the debug library
2273 debug.getfenv, debug.setfenv,%
– the mathematical library
2274 math.log10,%
– the package library and
2275 package.loaders, package.seeall,%
– the table library
2276 table.maxn,%
2277 },%
Again there are some new identifiers in the standard libraries
2278 morekeywords=[2]{%
like
• the base library
2279 rawlen,%
• the bit library
2280 bit32, bit32.arshift, bit32.band, bit32.bnot, bit32.bor,%
2281 bit32.btest, bit32.bxor, bit32.extract, bit32.lrotate,%
2282 bit32.lshift, bit32.replace, bit32.rrotate, bit32.rshift,%
• the debug library
2283 debug.getuservalue, debug.setuservalue, debug.upvalueid,%
2284 debug.upvaluejoin,%
• the package library
2285 package.searchers, package.searchpath,%
• the table library
2286 table.pack, table.unpack,%
2287 },%
There is a new additional identifier
2288 morekeywords=[2]{%
2289 _ENV,%
2290 },%
and labels are also new in Lua 5.2
2291 moredelim=[s][keywordstyle3]{::}{::},%
2292}[keywords,comments,strings]%
In January 2015 Lua 5.3 was released, Stephan Hennig again contributed the Lua keywords.
2293\lst@definelanguage[5.3]{Lua}[5.2]{Lua}{%
• some libraries are deprecated, so the following identifiers are deleted
2294 deletekeywords=[2]{%
– thebit32library
2295 bit32, bit32.arshift, bit32.band, bit32.bnot, bit32.bor,%
2296 bit32.btest, bit32.bxor, bit32.extract, bit32.lrotate,%
2297 bit32.lshift, bit32.replace, bit32.rrotate, bit32.rshift,%
– the mathematical library
2298 math.atan2, math.cosh, math.frexp, math.ldexp, math.pow,%
2299 math.sinh, math.tanh,%
2300 },%
Again there are some new identifiers in the standard libraries
2301 morekeywords=[2]{%
like
• the coroutine library
2302 coroutine.isyieldable,%
• the mathematical library
2303 math.maxinteger, math.mininteger, math.tointeger, math.type,%
2304 math.ult,%
• the string library
2305 string.pack, string.packsize, string.unpack,%
• the table library
2306 table.move,%
• the utf-8 library
2307 utf8, utf8.char, utf8.charpattern, utf8.codepoint, utf8.codes,%
2308 utf8.len, utf8.offset,%
2309 },%
2310 }[keywords,comments,strings]%
2311 h/lang2i
Stephan Hennig also supplied a definition of a style for printing Lua code:
2312h∗lua-prfi
2313\usepackage[rgb, x11names]{xcolor}
2314\lstdefinestyle{Lua}{%
2315 language=[5.2]Lua,
2316 basicstyle=\ttfamily,
2317 columns=spaceflexible,
2318 keywordstyle=\bfseries\color{Blue4},% language keywords
2319 keywordstyle=[2]\bfseries\color{RoyalBlue3},% std. library identifiers
2320 keywordstyle=[3]\bfseries\color{Purple3},% labels
2321 stringstyle=\bfseries\color{Coral4},% strings
2322 commentstyle=\itshape\color{Green4},% comments
2323}
This code is provided in the filelistings-lua.prf, see section 2.4.1 (Preferences) of thelistingsdocumentation.
2324h/lua-prfi