Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

rawget and rawset

Even if a table has an __index or __newindex meta method, values in that table can still be set directly. These meta methods can be bypassed with the rawset and rawget functions, which set and get the values of a table directly.

rawget takes two arguments, the table being accessed and the key being retrieved. It has the following signature:

rawget(table, key)

rawset takes three arguments, the table being accessed, the key being set, and the value being set. It has the following signature:

rawset(table, key, value)

To demonstrate how this works, let's use the previous sample code to set the foo member of table x directly:

x = { }y = { }z = {  __index = function(table, key)    return z[key]  end, __newindex = function(table, key, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content