Permalink
Browse files

Fix recently introduced bug in LuaObject.toString and add variable le…

…ngth return unittest
  • Loading branch information...
1 parent 73ebca2 commit d05151d3528f2a42d7a26395040d5c80031ac261 @JakobOvrum committed May 13, 2012
Showing with 31 additions and 2 deletions.
  1. +1 −1 luad/base.d
  2. +29 −1 luad/conversions/functions.d
  3. +1 −0 luad/stack.d
View
@@ -158,7 +158,7 @@ struct LuaObject
const(char)* cstr = luaL_tolstring(state, -1, &len);
auto str = cstr[0 .. len].idup;
- lua_pop(state, 1);
+ lua_pop(state, 2);
return str;
}
@@ -357,6 +357,8 @@ unittest
unittest_lua(L, `assert(returnArg("foo") == "foo")`);
}
+version(unittest) import luad.base;
+
// multiple return values
unittest
{
@@ -372,7 +374,7 @@ unittest
result.age = ageInfo[idx];
return result;
}
-
+
pushValue(L, &getInfo);
lua_setglobal(L, "getInfo");
@@ -399,6 +401,32 @@ unittest
assert(first == "Foo")
assert(last == "Bar")
`);
+
+ // variable length returns
+ LuaObject[] makeList(uint n)
+ {
+ LuaObject[] list;
+
+ foreach(i; 1 .. n + 1)
+ {
+ pushValue(L, i);
+ auto obj = popValue!LuaObject(L);
+ list ~= obj;
+ }
+
+ return list;
+ }
+
+ pushValue(L, &makeList);
+ lua_setglobal(L, "makeList");
+
+ unittest_lua(L, `
+ local one, two, three, four = makeList(4)
+ assert(one == 1)
+ assert(two == 2)
+ assert(three == 3)
+ assert(four == 4)
+ `);
}
// D-style typesafe varargs
View
@@ -446,6 +446,7 @@ int pushReturnValues(T)(lua_State* L, T value)
assert(obj.state == L);
obj.push();
}
+
return value.length;
}
else static if(isTuple!T)

0 comments on commit d05151d

Please sign in to comment.