Permalink
Browse files

Fix two argument form of ffi.fill

Fixes #44
  • Loading branch information...
1 parent 5f82a7a commit 26fbafc6cd0187ac46971a3a4387a8f1dc2c4e8e @jmckaskill jmckaskill committed Jun 5, 2012
Showing with 11 additions and 2 deletions.
  1. +6 −2 ffi.c
  2. +5 −0 test.lua
View
8 ffi.c
@@ -2445,10 +2445,14 @@ static int ffi_copy(lua_State* L)
static int ffi_fill(lua_State* L)
{
struct ctype ct;
- void* to = check_pointer(L, 1, &ct);
- size_t sz = (size_t) luaL_checknumber(L, 2);
+ void* to;
+ size_t sz;
int val = 0;
+ setmintop(L, 3);
+ to = check_pointer(L, 1, &ct);
+ sz = (size_t) luaL_checknumber(L, 2);
+
if (!lua_isnoneornil(L, 3)) {
val = (int) luaL_checkinteger(L, 3);
}
View
@@ -813,5 +813,10 @@ int strncmp(const signed char *s1, const unsigned char *s2, size_t n);
]]
assert(ffi.C.strncmp("two", "three", 3) ~= 0)
+ffi.fill(d, 3, 1)
+assert(d[2] == 1)
+ffi.fill(d, 3)
+assert(d[2] == 0)
+
print('Test PASSED')

0 comments on commit 26fbafc

Please sign in to comment.