lua-users home
lua-l archive

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


So far I have this:
local function int2bytes( int, size )
    local i = 1
    local t = {}
    while i < size do
        t[i] = int & 0xFF
        int = int >> 8
        i = i + 1
    end
    return t
end
...
                tmp = nk.edit_string(ctx,nk.EDIT_SIMPLE,text,100)
                if gui.handle and gui.handle:valid() == true then
                    if tmp ~= text then
                        if v.signed then
                            tmp = int2bytes(0+tmp,v.signed)
...
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 = luaL_checkinteger(L,3), i;
    uchar * array = NULL;

    if ( !(*handle) || !lua_istable(L,4) || size < 1 ) {
        lua_pushinteger(L,0);
        return 1;
    }

    if ( !(array = calloc( size, 1 )) ) {
        lua_pushinteger(L,0);
        return 1;
    }

    fprintf( stderr, "For address %p:\n", (void*)addr );
    for ( i = 0; i < size; ++i ) {
        lua_geti(L,4,i+1);
        array[i] = lua_tointeger(L,-1);
        fprintf( stderr, "array[%d] = %u\n", (int)i, array[i] );
        lua_pop(L,1);
    }
    fprintf( stderr, "Writing %d byte/s...\n", (int)i );
    size = i ? proc_change_data( NULL, *handle, addr, array, i ) : 0;
    free(array);
    if ( size < 1 ) {
        lua_pushinteger(L,0);
        return 1;
    }
    lua_pushinteger(L,size);
    return 1;
}

However when I type a 9 in the control for some reason the final array
receives 0 all the way through, any ideas where I might be going
wrong?
Btw the control returns a string, the 0+tmp is my attempt to override
that to a integer