lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 17/12/14 03:26 AM, Dirk Laurie wrote:
2014-12-17 4:54 GMT+02:00 Soni L. <fakedme@gmail.com>:

First of all I want to be able to _G:table.insert("something").
Secondly, I want to be able to _G:["print"]().
What exactly are these supposed to be syntax sugar for?

It's opcode sugar, actually.

_G:["print"](...) is already supported by the opcode, just use a non-constant index. It basically translates to _G["print"](_G, ...) (but _G only gets evaluated once).

_G:table.insert("something") is a bit trickier to implement. (it uses more opcodes) But think about it like this: in the same way that _G:print() translates to _G.print(_G), _G:table.insert("something") translates to _G.table.insert(_G, "something"). (add `do local _ = _G ... end` boilerplate as needed)

And ofc, _G:["table"]["insert"]("something"), I guess you can guess what this does.

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.