lua-users home
lua-l archive

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

>>>>> "Lee" == Lee Shallis <> writes:

 Lee> I'll start with an example of how the function is called:
 Lee> handle:write(0xBADF00D,{0xC0,0xFF,0xEE})
 Lee> Would this be the right way to extra each value in the second
 Lee> argument's table?

 >> if ( !lua_istable(L,3) ) {

In cases like this you have to ask: does the object actually _have_ to
be a table, or could it be anything that's indexable with integers?

If the latter, then lua_istable is too strict a check.

 >> array = calloc( size, 1 );

This will leak the allocated array permanently if any of the
checkinteger calls throws an error. You can use a temporary userdata
which will be GC'd, or some other variation.

 >> for ( i = 0; i < size; ++i ) {
 >> lua_pushinteger(L,i+1);
 >> lua_gettable(L,3);

See lua_geti() to combine these two calls

 >> array[i] = lua_checkinteger(L,-1);

You need to pop the value off the stack after using it.

And I second the other comments about providing code as plain text with
proper indentation, not mangled into html.