- changed milestone to 3.0.7
Table.Insert errors when trying to append value to table
Issue #46
new
Take the following code example:
tbl = {}
Table.Insert(tbl, 'value')
This code is supposed to append the value 'value'
to the table tbl
so that afterwards tbl
is equivalent to this:
{ 1='value' }
However, when trying to execute the above script, the following error is thrown:
Exception: bad argument #2 (number expected, got string)
Stack traceback:
[Java]: in function 'Insert'
stdin:1: in function 'main'
Looking at the Java source code of Table.Insert
, we can find the following:
@MtsNativeFunction
public static void insert( MtsValue argTable, MtsValue arg2, MtsValue arg3 )
{
MtsTableList list = checkTable( argTable, 0 ).list();
if ( arg3.isNil() )
list.add( arg2 );
checkNumber( arg2, 1 );
list.add( arg2.asNumber(), arg3 );
}
The error is caused in line 9 above because the if-statement which checks if arg3
is nil
does not return
after adding the value to the table.
Comments (1)
-
reporter - Log in to comment