lua-users home
lua-l archive

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

Am 13.06.2014 09:07 schröbte Ross Bencina:
On 13/06/2014 4:13 PM, Thomas Jericke wrote:
I'll leave it to others to determine whether using string literals in
an interface is ever good style.


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

local myLib = require "MyLib" -- Oops a string literal
-- 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.

You're intentionally twisting my words.

It's one thing to be able to use a string literal, quite enough to
require its use in an interface.

We're not talking about module or function names here, we're talking
about constants that are usually integers.

In Lua:
    collectgarbage( "collect" )
    collectgarbage( "stop" )
    collectgarbage( "restart" )
    collectgarbage( "count" )
    f:seek( "cur", 0 )
    f:seek( "set", 0 )
    f:seek( "end", 0 )
    os.setlocale( "en_US.UTF8", "all" )
    os.setlocale( "en_US.UTF8", "numeric" )
    os.setlocale( "en_US.UTF8", "monetary" )

In C:
    lua_gc( L, LUA_GCCOLLECT, 0 );
    lua_gc( L, LUA_GCSTOP, 0 );
    lua_gc( L, LUA_GCRESTART, 0 );
    lua_gc( L, LUA_GCCOUNT, 0 );
    fseek( f, 0, SEEK_CUR );
    fseek( f, 0, SEEK_SET );
    fseek( f, 0, SEEK_END );
    setlocale( LC_ALL, "en_US.UTF8" );
    setlocale( LC_NUMERIC, "en_US.UTF8" );
    setlocale( LC_MONETARY, "en_US.UTF8" );

There is even a Lua API function[1] that makes this kind of thing easier ...