lua-users home
lua-l archive

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


On Tue, Apr 20, 2010 at 2:41 PM, Stuart P. Bentley
<stuart@testtrack4.com> wrote:
> One case where I've actually encountered unavoidable issues with a Lua
> design due to type coercion was something like this, if I recall correctly:
>
> num_table{[2]="This gets printed instead"}
>
> index_searched_for="2"
>
> print(num_table[index_searched_for] or "Even though this is what should be
> printed!")
>
> If I've got that right and am not mis-remembering the problem, then Lua 5.2
> should make the change that type coercion never comes into play when
> indexing tables.

It looks like you are misremembering (or maybe an older version than 5.1?):

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> num_table = {[2]="This gets printed instead"}
> index_searched_for="2"
> print(num_table[index_searched_for] or "Even though this is what should be printed!")
Even though this is what should be printed!
>

-Duncan