def test_new_array_args(self):
ffi = FFI(backend=self.Backend())
# this tries to be closer to C: where we say "int x[5] = {10, 20, ..}"
# then here we must enclose the items in a list
p = ffi.new("int[5]", [10, 20, 30, 40, 50])
assert p[0] == 10
assert p[1] == 20
assert p[2] == 30
assert p[3] == 40
assert p[4] == 50
p = ffi.new("int[4]", [25])
assert p[0] == 25
assert p[1] == 0 # follow C convention rather than LuaJIT's
assert p[2] == 0
assert p[3] == 0
p = ffi.new("int[4]", [ffi.cast("int", -5)])
assert p[0] == -5
assert repr(p) == "<cdata 'int[4]' owning %d bytes>" % (4*SIZE_OF_INT)
评论列表
文章目录