lua-users home
lua-l archive

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


I'll start with an example of how the function is called:
handle:write(0xBADF00D,{0xC0,0xFF,0xEE})
Would this be the right way to extra each value in the second argument's table?
int lua_proc_change_data( lua_State *L ) {
proc_handle_t **handle = (proc_handle_t**)
luaL_checkudata(L,1,PROC_HANDLE_CLASS);
intptr_t addr = luaL_checkinteger(L,2);
intptr_t size, i;
uchar * array;
if ( !lua_istable(L,3) ) {
lua_pushinteger(L,0);
return 1;
}
size = lua_len(L,3);
if ( size < 1 ) {
lua_pushinteger(L,0);
return 1;
}
array = calloc( size, 1 );
for ( i = 0; i < size; ++i ) {
lua_pushinteger(L,i+1);
lua_gettable(L,3);
array[i] = lua_checkinteger(L,-1);
}
size = proc_change_data( NULL, *handle, addr, array, size );
free(array);
if ( size < 1 ) {
lua_pushinteger(L,0);
return 1;
}
lua_pushinteger(L,0);
return 1;
}