Skip to content

Commit b27e35d

Browse files
committed
Fix declarations
1 parent d453607 commit b27e35d

2 files changed

Lines changed: 137 additions & 143 deletions

File tree

Distribution/LuaBridge/LuaBridge.h

Lines changed: 68 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,74 @@ constexpr void unused(Args&&...)
123123
{
124124
}
125125

126+
#if LUA_VERSION_NUM < 502
127+
using lua_Unsigned = std::make_unsigned_t<lua_Integer>;
128+
129+
#if ! LUABRIDGE_ON_LUAU
130+
inline int lua_absindex(lua_State* L, int idx)
131+
{
132+
if (idx > LUA_REGISTRYINDEX && idx < 0)
133+
return lua_gettop(L) + idx + 1;
134+
else
135+
return idx;
136+
}
137+
#endif
138+
139+
#define LUA_OPEQ 1
140+
#define LUA_OPLT 2
141+
#define LUA_OPLE 3
142+
143+
inline int lua_compare(lua_State* L, int idx1, int idx2, int op)
144+
{
145+
switch (op)
146+
{
147+
case LUA_OPEQ:
148+
return lua_equal(L, idx1, idx2);
149+
150+
case LUA_OPLT:
151+
return lua_lessthan(L, idx1, idx2);
152+
153+
case LUA_OPLE:
154+
return lua_equal(L, idx1, idx2) || lua_lessthan(L, idx1, idx2);
155+
156+
default:
157+
return 0;
158+
}
159+
}
160+
161+
#if ! LUABRIDGE_ON_LUAJIT
162+
inline void* luaL_testudata(lua_State* L, int ud, const char* tname)
163+
{
164+
void* p = lua_touserdata(L, ud);
165+
if (p == nullptr)
166+
return nullptr;
167+
168+
if (! lua_getmetatable(L, ud))
169+
return nullptr;
170+
171+
luaL_getmetatable(L, tname);
172+
if (! lua_rawequal(L, -1, -2))
173+
p = nullptr;
174+
175+
lua_pop(L, 2);
176+
return p;
177+
}
178+
#endif
179+
180+
inline int get_length(lua_State* L, int idx)
181+
{
182+
return static_cast<int>(lua_objlen(L, idx));
183+
}
184+
#else
185+
inline int get_length(lua_State* L, int idx)
186+
{
187+
lua_len(L, idx);
188+
const int len = static_cast<int>(luaL_checknumber(L, -1));
189+
lua_pop(L, 1);
190+
return len;
191+
}
192+
#endif
193+
126194
#if LUABRIDGE_ON_LUAU
127195
inline int luaL_ref(lua_State* L, int idx)
128196
{
@@ -311,77 +379,6 @@ inline lua_Integer to_integerx(lua_State* L, int idx, int* isnum)
311379

312380
return 0;
313381
}
314-
315-
#endif
316-
317-
#if LUA_VERSION_NUM < 502
318-
using lua_Unsigned = std::make_unsigned_t<lua_Integer>;
319-
320-
#if ! LUABRIDGE_ON_LUAU
321-
inline int lua_absindex(lua_State* L, int idx)
322-
{
323-
if (idx > LUA_REGISTRYINDEX && idx < 0)
324-
return lua_gettop(L) + idx + 1;
325-
else
326-
return idx;
327-
}
328-
#endif
329-
330-
#define LUA_OPEQ 1
331-
#define LUA_OPLT 2
332-
#define LUA_OPLE 3
333-
334-
inline int lua_compare(lua_State* L, int idx1, int idx2, int op)
335-
{
336-
switch (op)
337-
{
338-
case LUA_OPEQ:
339-
return lua_equal(L, idx1, idx2);
340-
341-
case LUA_OPLT:
342-
return lua_lessthan(L, idx1, idx2);
343-
344-
case LUA_OPLE:
345-
return lua_equal(L, idx1, idx2) || lua_lessthan(L, idx1, idx2);
346-
347-
default:
348-
return 0;
349-
}
350-
}
351-
352-
#if ! LUABRIDGE_ON_LUAJIT
353-
inline void* luaL_testudata(lua_State* L, int ud, const char* tname)
354-
{
355-
void* p = lua_touserdata(L, ud);
356-
if (p == nullptr)
357-
return nullptr;
358-
359-
if (! lua_getmetatable(L, ud))
360-
return nullptr;
361-
362-
luaL_getmetatable(L, tname);
363-
if (! lua_rawequal(L, -1, -2))
364-
p = nullptr;
365-
366-
lua_pop(L, 2);
367-
return p;
368-
}
369-
#endif
370-
371-
inline int get_length(lua_State* L, int idx)
372-
{
373-
return static_cast<int>(lua_objlen(L, idx));
374-
}
375-
376-
#else
377-
inline int get_length(lua_State* L, int idx)
378-
{
379-
lua_len(L, idx);
380-
const int len = static_cast<int>(luaL_checknumber(L, -1));
381-
lua_pop(L, 1);
382-
return len;
383-
}
384-
385382
#endif
386383

387384
#ifndef LUA_OK

Source/LuaBridge/detail/LuaHelpers.h

Lines changed: 69 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,75 @@ constexpr void unused(Args&&...)
2525
{
2626
}
2727

28+
// These are for Lua versions prior to 5.2.0.
29+
#if LUA_VERSION_NUM < 502
30+
using lua_Unsigned = std::make_unsigned_t<lua_Integer>;
31+
32+
#if ! LUABRIDGE_ON_LUAU
33+
inline int lua_absindex(lua_State* L, int idx)
34+
{
35+
if (idx > LUA_REGISTRYINDEX && idx < 0)
36+
return lua_gettop(L) + idx + 1;
37+
else
38+
return idx;
39+
}
40+
#endif
41+
42+
#define LUA_OPEQ 1
43+
#define LUA_OPLT 2
44+
#define LUA_OPLE 3
45+
46+
inline int lua_compare(lua_State* L, int idx1, int idx2, int op)
47+
{
48+
switch (op)
49+
{
50+
case LUA_OPEQ:
51+
return lua_equal(L, idx1, idx2);
52+
53+
case LUA_OPLT:
54+
return lua_lessthan(L, idx1, idx2);
55+
56+
case LUA_OPLE:
57+
return lua_equal(L, idx1, idx2) || lua_lessthan(L, idx1, idx2);
58+
59+
default:
60+
return 0;
61+
}
62+
}
63+
64+
#if ! LUABRIDGE_ON_LUAJIT
65+
inline void* luaL_testudata(lua_State* L, int ud, const char* tname)
66+
{
67+
void* p = lua_touserdata(L, ud);
68+
if (p == nullptr)
69+
return nullptr;
70+
71+
if (! lua_getmetatable(L, ud))
72+
return nullptr;
73+
74+
luaL_getmetatable(L, tname);
75+
if (! lua_rawequal(L, -1, -2))
76+
p = nullptr;
77+
78+
lua_pop(L, 2);
79+
return p;
80+
}
81+
#endif
82+
83+
inline int get_length(lua_State* L, int idx)
84+
{
85+
return static_cast<int>(lua_objlen(L, idx));
86+
}
87+
#else // LUA_VERSION_NUM >= 502
88+
inline int get_length(lua_State* L, int idx)
89+
{
90+
lua_len(L, idx);
91+
const int len = static_cast<int>(luaL_checknumber(L, -1));
92+
lua_pop(L, 1);
93+
return len;
94+
}
95+
#endif // LUA_VERSION_NUM < 502
96+
2897
// These functions and defines are for Luau.
2998
#if LUABRIDGE_ON_LUAU
3099
inline int luaL_ref(lua_State* L, int idx)
@@ -216,80 +285,8 @@ inline lua_Integer to_integerx(lua_State* L, int idx, int* isnum)
216285

217286
return 0;
218287
}
219-
220288
#endif // LUA_VERSION_NUM < 503
221289

222-
// These are for Lua versions prior to 5.2.0.
223-
#if LUA_VERSION_NUM < 502
224-
using lua_Unsigned = std::make_unsigned_t<lua_Integer>;
225-
226-
#if ! LUABRIDGE_ON_LUAU
227-
inline int lua_absindex(lua_State* L, int idx)
228-
{
229-
if (idx > LUA_REGISTRYINDEX && idx < 0)
230-
return lua_gettop(L) + idx + 1;
231-
else
232-
return idx;
233-
}
234-
#endif
235-
236-
#define LUA_OPEQ 1
237-
#define LUA_OPLT 2
238-
#define LUA_OPLE 3
239-
240-
inline int lua_compare(lua_State* L, int idx1, int idx2, int op)
241-
{
242-
switch (op)
243-
{
244-
case LUA_OPEQ:
245-
return lua_equal(L, idx1, idx2);
246-
247-
case LUA_OPLT:
248-
return lua_lessthan(L, idx1, idx2);
249-
250-
case LUA_OPLE:
251-
return lua_equal(L, idx1, idx2) || lua_lessthan(L, idx1, idx2);
252-
253-
default:
254-
return 0;
255-
}
256-
}
257-
258-
#if ! LUABRIDGE_ON_LUAJIT
259-
inline void* luaL_testudata(lua_State* L, int ud, const char* tname)
260-
{
261-
void* p = lua_touserdata(L, ud);
262-
if (p == nullptr)
263-
return nullptr;
264-
265-
if (! lua_getmetatable(L, ud))
266-
return nullptr;
267-
268-
luaL_getmetatable(L, tname);
269-
if (! lua_rawequal(L, -1, -2))
270-
p = nullptr;
271-
272-
lua_pop(L, 2);
273-
return p;
274-
}
275-
#endif
276-
277-
inline int get_length(lua_State* L, int idx)
278-
{
279-
return static_cast<int>(lua_objlen(L, idx));
280-
}
281-
282-
#else // LUA_VERSION_NUM >= 502
283-
inline int get_length(lua_State* L, int idx)
284-
{
285-
lua_len(L, idx);
286-
const int len = static_cast<int>(luaL_checknumber(L, -1));
287-
lua_pop(L, 1);
288-
return len;
289-
}
290-
291-
#endif // LUA_VERSION_NUM < 502
292-
293290
#ifndef LUA_OK
294291
#define LUABRIDGE_LUA_OK 0
295292
#else

0 commit comments

Comments
 (0)