misc Lua Version difference fixes
This commit is contained in:
4
Makefile
4
Makefile
@@ -48,9 +48,9 @@ ckiwi.o: ckiwi.h
|
|||||||
luakiwi.o: ckiwi.h luakiwi-int.h luacompat.h
|
luakiwi.o: ckiwi.h luakiwi-int.h luacompat.h
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CFLAGS) $(CFLAGS_EXTRA) -I$(LUA_INCDIR) -c -o $@ $<
|
$(CC) -I$(LUA_INCDIR) $(CFLAGS) $(CFLAGS_EXTRA) -c -o $@ $<
|
||||||
|
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) $(CFLAGS) $(CXXFLAGS_EXTRA) -c -o $@ $<
|
$(CXX) -I$(LUA_INCDIR) $(CXXFLAGS) $(CFLAGS) $(CXXFLAGS_EXTRA) -c -o $@ $<
|
||||||
|
|
||||||
.PHONY: all install clean
|
.PHONY: all install clean
|
||||||
|
|||||||
@@ -35,23 +35,6 @@ static lua_Number lua_tonumberx(lua_State* L, int i, int* isnum) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int luaL_typeerror(lua_State* L, int arg, const char* tname) {
|
|
||||||
const char* msg;
|
|
||||||
const char* typearg; /* name for the type of the actual argument */
|
|
||||||
if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING)
|
|
||||||
typearg = lua_tostring(L, -1); /* use the given type name */
|
|
||||||
else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)
|
|
||||||
typearg = "light userdata"; /* special name for messages */
|
|
||||||
else
|
|
||||||
typearg = luaL_typename(L, arg); /* standard name */
|
|
||||||
msg = lua_pushfstring(L, "%s expected, got %s", tname, typearg);
|
|
||||||
return luaL_argerror(L, arg, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* LUA_VERSION_NUM == 501 */
|
|
||||||
|
|
||||||
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502
|
|
||||||
|
|
||||||
static lua_Integer lua_tointegerx(lua_State* L, int i, int* isnum) {
|
static lua_Integer lua_tointegerx(lua_State* L, int i, int* isnum) {
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
lua_Number n = lua_tonumberx(L, i, &ok);
|
lua_Number n = lua_tonumberx(L, i, &ok);
|
||||||
@@ -67,37 +50,6 @@ static lua_Integer lua_tointegerx(lua_State* L, int i, int* isnum) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compat_reverse(lua_State* L, int a, int b) {
|
|
||||||
for (; a < b; ++a, --b) {
|
|
||||||
lua_pushvalue(L, a);
|
|
||||||
lua_pushvalue(L, b);
|
|
||||||
lua_replace(L, a);
|
|
||||||
lua_replace(L, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void lua_rotate(lua_State* L, int idx, int n) {
|
|
||||||
int n_elems = 0;
|
|
||||||
idx = lua_absindex(L, idx);
|
|
||||||
n_elems = lua_gettop(L) - idx + 1;
|
|
||||||
if (n < 0)
|
|
||||||
n += n_elems;
|
|
||||||
if (n > 0 && n < n_elems) {
|
|
||||||
luaL_checkstack(L, 2, "not enough stack slots available");
|
|
||||||
n = n_elems - n;
|
|
||||||
compat_reverse(L, idx, idx + n - 1);
|
|
||||||
compat_reverse(L, idx + n, idx + n_elems - 1);
|
|
||||||
compat_reverse(L, idx, idx + n_elems - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lua_geti(lua_State* L, int index, lua_Integer i) {
|
|
||||||
index = lua_absindex(L, index);
|
|
||||||
lua_pushinteger(L, i);
|
|
||||||
lua_gettable(L, index);
|
|
||||||
return lua_type(L, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* luaL_tolstring(lua_State* L, int idx, size_t* len) {
|
static const char* luaL_tolstring(lua_State* L, int idx, size_t* len) {
|
||||||
if (!luaL_callmeta(L, idx, "__tostring")) {
|
if (!luaL_callmeta(L, idx, "__tostring")) {
|
||||||
int t = lua_type(L, idx), tt = 0;
|
int t = lua_type(L, idx), tt = 0;
|
||||||
@@ -131,7 +83,58 @@ static const char* luaL_tolstring(lua_State* L, int idx, size_t* len) {
|
|||||||
return lua_tolstring(L, -1, len);
|
return lua_tolstring(L, -1, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /* LUA_VERSION_NUM == 501 */
|
||||||
|
|
||||||
|
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502
|
||||||
|
|
||||||
|
static void compat_reverse(lua_State* L, int a, int b) {
|
||||||
|
for (; a < b; ++a, --b) {
|
||||||
|
lua_pushvalue(L, a);
|
||||||
|
lua_pushvalue(L, b);
|
||||||
|
lua_replace(L, a);
|
||||||
|
lua_replace(L, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void lua_rotate(lua_State* L, int idx, int n) {
|
||||||
|
int n_elems = 0;
|
||||||
|
idx = lua_absindex(L, idx);
|
||||||
|
n_elems = lua_gettop(L) - idx + 1;
|
||||||
|
if (n < 0)
|
||||||
|
n += n_elems;
|
||||||
|
if (n > 0 && n < n_elems) {
|
||||||
|
luaL_checkstack(L, 2, "not enough stack slots available");
|
||||||
|
n = n_elems - n;
|
||||||
|
compat_reverse(L, idx, idx + n - 1);
|
||||||
|
compat_reverse(L, idx + n, idx + n_elems - 1);
|
||||||
|
compat_reverse(L, idx, idx + n_elems - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lua_geti(lua_State* L, int index, lua_Integer i) {
|
||||||
|
index = lua_absindex(L, index);
|
||||||
|
lua_pushinteger(L, i);
|
||||||
|
lua_gettable(L, index);
|
||||||
|
return lua_type(L, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* LUA_VERSION_NUM <= 502 */
|
||||||
|
|
||||||
|
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 503
|
||||||
|
static int luaL_typeerror(lua_State* L, int arg, const char* tname) {
|
||||||
|
const char* msg;
|
||||||
|
const char* typearg; /* name for the type of the actual argument */
|
||||||
|
if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING)
|
||||||
|
typearg = lua_tostring(L, -1); /* use the given type name */
|
||||||
|
else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA)
|
||||||
|
typearg = "light userdata"; /* special name for messages */
|
||||||
|
else
|
||||||
|
typearg = luaL_typename(L, arg); /* standard name */
|
||||||
|
msg = lua_pushfstring(L, "%s expected, got %s", tname, typearg);
|
||||||
|
return luaL_argerror(L, arg, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* LUA_VERSION_NUM <= 503 */
|
||||||
|
|
||||||
#if !defined(luaL_newlibtable)
|
#if !defined(luaL_newlibtable)
|
||||||
#define luaL_newlibtable(L, l) lua_createtable(L, 0, sizeof(l) / sizeof((l)[0]) - 1)
|
#define luaL_newlibtable(L, l) lua_createtable(L, 0, sizeof(l) / sizeof((l)[0]) - 1)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ end)
|
|||||||
|
|
||||||
describe("Constraint", function()
|
describe("Constraint", function()
|
||||||
local kiwi = require("kiwi")
|
local kiwi = require("kiwi")
|
||||||
|
local LUA_VERSION = tonumber(_VERSION:match("%d+%.%d+"))
|
||||||
|
|
||||||
describe("construction", function()
|
describe("construction", function()
|
||||||
local v, lhs
|
local v, lhs
|
||||||
@@ -32,18 +33,31 @@ describe("Constraint", function()
|
|||||||
assert.equal(kiwi.strength.STRONG, c:strength())
|
assert.equal(kiwi.strength.STRONG, c:strength())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- TODO: standardize formatting
|
||||||
it("formats well", function()
|
it("formats well", function()
|
||||||
local c = kiwi.Constraint(lhs)
|
local c = kiwi.Constraint(lhs)
|
||||||
assert.equal("1 foo + 1 == 0 | required", tostring(c))
|
if LUA_VERSION <= 5.2 then
|
||||||
|
assert.equal("1 foo + 1 == 0 | required", tostring(c))
|
||||||
|
else
|
||||||
|
assert.equal("1.0 foo + 1.0 == 0 | required", tostring(c))
|
||||||
|
end
|
||||||
|
|
||||||
c = kiwi.Constraint(lhs * 2, nil, "GE", kiwi.strength.STRONG)
|
c = kiwi.Constraint(lhs * 2, nil, "GE", kiwi.strength.STRONG)
|
||||||
assert.equal("2 foo + 2 >= 0 | strong", tostring(c))
|
if LUA_VERSION <= 5.2 then
|
||||||
|
assert.equal("2 foo + 2 >= 0 | strong", tostring(c))
|
||||||
|
else
|
||||||
|
assert.equal("2.0 foo + 2.0 >= 0 | strong", tostring(c))
|
||||||
|
end
|
||||||
|
|
||||||
c = kiwi.Constraint(lhs / 2, nil, "LE", kiwi.strength.MEDIUM)
|
c = kiwi.Constraint(lhs / 2, nil, "LE", kiwi.strength.MEDIUM)
|
||||||
assert.equal("0.5 foo + 0.5 <= 0 | medium", tostring(c))
|
assert.equal("0.5 foo + 0.5 <= 0 | medium", tostring(c))
|
||||||
|
|
||||||
c = kiwi.Constraint(lhs, kiwi.Expression(3), "GE", kiwi.strength.WEAK)
|
c = kiwi.Constraint(lhs, kiwi.Expression(3), "GE", kiwi.strength.WEAK)
|
||||||
assert.equal("1 foo + -2 >= 0 | weak", tostring(c))
|
if LUA_VERSION <= 5.2 then
|
||||||
|
assert.equal("1 foo + -2 >= 0 | weak", tostring(c))
|
||||||
|
else
|
||||||
|
assert.equal("1.0 foo + -2.0 >= 0 | weak", tostring(c))
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("rejects invalid args", function()
|
it("rejects invalid args", function()
|
||||||
|
|||||||
Reference in New Issue
Block a user