File: 017-bitaccess.lua

package info (click to toggle)
lua-gtk 0.9%2B20100528-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,176 kB
  • ctags: 1,934
  • sloc: ansic: 9,571; sh: 373; makefile: 241
file content (41 lines) | stat: -rwxr-xr-x 886 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/env lua
-- vim:sw=4:sts=4
-- Test access to non-byte structure members, i.e. bit fields etc.

require "gtk"

c = gtk.hbox_new(false, 0)

-- relevant part of GtkContainer:
-- { 18069, 528, 1, 13, 0 }, /* need_resize */
-- { 18081, 529, 2, 13, 0 }, /* resize_mode */
-- { 18093, 531, 1, 13, 0 }, /* reallocate_redraws */

-- try a 16 bit field
c.border_width = 65535
assert(c.border_width == 65535)

-- initialized to zero.
assert(c.need_resize == 0)
assert(c.resize_mode == 0)
assert(c.reallocate_redraws == 0)

-- set the bit
c.need_resize = 1
assert(c.need_resize == 1)

-- this results in zero, because it's just one bit wide (overflow).
c.need_resize = 2
assert(c.need_resize == 0)

-- two bit wide
c.resize_mode = 3
assert(c.resize_mode == 3)

c.resize_mode = 4
assert(c.resize_mode == 0)

-- mustn't change
assert(c.need_resize == 0)
assert(c.reallocate_redraws == 0)