Inverted syntax: Difference between revisions

→‎{{header|Lua}}: added Lua solution
(→‎{{header|Lua}}: added Lua solution)
Line 622:
let 6 = 'b.
println: b. ;; 6</lang>
 
=={{header|Lua}}==
In general, Lua does not support any ''truly'' inverted syntax, though there are some metamethod techniques and taking advantage of syntactic sugar that perhaps at least give the ''illusion'' that syntax has been inverted. Here, calling a library method passing a table, versus the table itself calling as if its own method, equivalently:
<lang lua>a = {1,3,5,4,2} -- a "plain" table
table.sort(a) -- library method passing a as param
print(table.concat(a)) -- and again --> "12345"
 
b = {1,3,5,4,2} -- a "plain" table, so far..
setmetatable(b, {__index=table}) -- ..but now "meta-decorated"
b:sort() -- syntax sugar passes b as "self"
print(b:concat()) -- and again --> "12345"</lang>
 
=={{header|M2000 Interpreter}}==
Anonymous user