lua-users home
lua-l archive

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


{ "foo" = "bar" } isn't a valid statement; keyed fields in a table
constructor have to have either no quotes (in which case the lhs is
interpreted as a string key) or have to be enclosed in square brackets
(in which case the expression within the brackets is evaluated and
used as the key). See section 2.5.6 of the manual.

Ben


On Thu, 10 Mar 2005 18:35:42 +0100, PA <petite.abeille@gmail.com> wrote:
> Hello,
> 
> I'm trying to load a table from a string, using loadstring(). This
> works alright, but I'm somewhat unsure about the proper syntax for the
> table...
> 
> To load the table, I do the following:
> 
> local aContent = aFile:read( "*all" )
> local aChunk, aStatus = loadstring( "return " .. aContent )
> local aTable = aChunk()
> 
> But if I use the following construct:
> 
> {
>        "669" = "audio/x-mod"
> }
> 
> ... loadstring() fails with the following exception:
> 
> [string \"return {...\"]:2: `}' expected (to close `{' at line 1) near
> `='
> 
> If I use the more formal bracket notation:
> 
> {
>        [ "669" ] = "audio/x-mod"
> }
> 
> ... everything works fine.
> 
> What gives?
> 
> For the record I'm using lua-5.1-work5.
> 
> Thanks!
> 
> Cheers
> 
> --
> PA, Onnay Equitursay
> http://alt.textdrive.com/
> 
>