lua-users home
lua-l archive

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


On 06/13/2014 04:58 AM, Ross Bencina wrote:
On 13/06/2014 12:15 PM, Coda Highland wrote:
On Thu, Jun 12, 2014 at 7:12 PM, Rena<hyperhacker@gmail.com>  wrote:
>On Wed, Jun 11, 2014 at 10:13 PM, Ross Bencina<rossb-lists@audiomulch.com>
>wrote:
>>
>>The problem is in Lua (unless I'm missing something), you don't have
>>symbolic constants

[snip]

>Well, Lua *does* have constants:

String literals are *not* symbolic constants.


>switch event.type
>   case 'move' print("I was moved to", event.x, event.y) break
>   case 'resize' print("I was resized to", event.w, event.h) break
>   case else print("I don't know how to deal with", event.type)
>end
>
And thanks to string interning, these are as fast as integer comparisons.

That doesn't help you when you already have an integer.

I'll leave it to others to determine whether using string literals in an interface is ever good style.

Ross.


Show me a Lua API that doesn't use string literals.

local myLib = require "MyLib" -- Oops a string literal
myLib.myFunction()
-- which is syntactic sugar for:
myLib["myFunction"]() -- Oops, another one.

So without sting literals, you cannot use globals, require, access table elements of type string.

--
Thomas