Skip to content

Commit 352107d

Browse files
committed
Applied formatting
1 parent 15814ef commit 352107d

13 files changed

+1607
-1556
lines changed

lcm-lua/debug_support.h

+80-78
Original file line numberDiff line numberDiff line change
@@ -4,104 +4,106 @@
44
#ifdef __cplusplus
55
extern "C" {
66
#endif
7-
#include "lua.h"
87
#include "lauxlib.h"
8+
#include "lua.h"
99
#ifdef __cplusplus
1010
}
1111
#endif
1212

1313
#include "stdio.h"
1414

15-
inline void stackDump(lua_State *L) {
16-
int i;
17-
int top = lua_gettop(L);
18-
for (i = 1; i <= top; i++) { /* repeat for each level */
19-
int t = lua_type(L, i);
20-
switch (t) {
21-
case LUA_TSTRING: /* strings */
22-
printf("`%s'", lua_tostring(L, i));
23-
break;
24-
25-
case LUA_TBOOLEAN: /* booleans */
26-
printf(lua_toboolean(L, i) ? "true" : "false");
27-
break;
28-
29-
case LUA_TNUMBER: /* numbers */
30-
printf("%g", lua_tonumber(L, i));
31-
break;
32-
33-
default: /* other values */
34-
printf("%s", lua_typename(L, t));
35-
break;
36-
}
37-
printf(" "); /* put a separator */
38-
}
39-
printf("\n"); /* end the listing */
40-
}
41-
42-
inline void tableDump(lua_State *L, int index) {
43-
int top = lua_gettop(L);
44-
lua_pushvalue(L, index);
45-
int t = top + 1;
46-
47-
if (lua_type(L, t) != LUA_TTABLE) {
48-
printf("not a table\n");
49-
return;
50-
}
51-
52-
lua_pushnil(L);
53-
while (lua_next(L, t) != 0) {
54-
/* key */
55-
{
56-
int type = lua_type(L, -2);
57-
switch (type) {
15+
inline void stackDump(lua_State *L)
16+
{
17+
int i;
18+
int top = lua_gettop(L);
19+
for (i = 1; i <= top; i++) { /* repeat for each level */
20+
int t = lua_type(L, i);
21+
switch (t) {
5822
case LUA_TSTRING: /* strings */
59-
printf("`%s'", lua_tostring(L, -2));
60-
break;
23+
printf("`%s'", lua_tostring(L, i));
24+
break;
6125

6226
case LUA_TBOOLEAN: /* booleans */
63-
printf(lua_toboolean(L, -2) ? "true" : "false");
64-
break;
27+
printf(lua_toboolean(L, i) ? "true" : "false");
28+
break;
6529

6630
case LUA_TNUMBER: /* numbers */
67-
printf("%g", lua_tonumber(L, -2));
68-
break;
31+
printf("%g", lua_tonumber(L, i));
32+
break;
6933

7034
default: /* other values */
71-
printf("%s", lua_typename(L, type));
72-
break;
73-
}
74-
printf(": "); /* put a separator */
35+
printf("%s", lua_typename(L, t));
36+
break;
37+
}
38+
printf(" "); /* put a separator */
7539
}
40+
printf("\n"); /* end the listing */
41+
}
7642

77-
/* value */
78-
{
79-
int type = lua_type(L, -1);
80-
switch (type) {
81-
case LUA_TSTRING: /* strings */
82-
printf("`%s'", lua_tostring(L, -1));
83-
break;
84-
85-
case LUA_TBOOLEAN: /* booleans */
86-
printf(lua_toboolean(L, -1) ? "true" : "false");
87-
break;
88-
89-
case LUA_TNUMBER: /* numbers */
90-
printf("%g", lua_tonumber(L, -1));
91-
break;
43+
inline void tableDump(lua_State *L, int index)
44+
{
45+
int top = lua_gettop(L);
46+
lua_pushvalue(L, index);
47+
int t = top + 1;
9248

93-
default: /* other values */
94-
printf("%s", lua_typename(L, type));
95-
break;
96-
}
97-
printf(", "); /* put a separator */
49+
if (lua_type(L, t) != LUA_TTABLE) {
50+
printf("not a table\n");
51+
return;
9852
}
9953

100-
lua_pop(L, 1); /* pop value, keep key */
101-
}
102-
printf("\n");
54+
lua_pushnil(L);
55+
while (lua_next(L, t) != 0) {
56+
/* key */
57+
{
58+
int type = lua_type(L, -2);
59+
switch (type) {
60+
case LUA_TSTRING: /* strings */
61+
printf("`%s'", lua_tostring(L, -2));
62+
break;
63+
64+
case LUA_TBOOLEAN: /* booleans */
65+
printf(lua_toboolean(L, -2) ? "true" : "false");
66+
break;
67+
68+
case LUA_TNUMBER: /* numbers */
69+
printf("%g", lua_tonumber(L, -2));
70+
break;
71+
72+
default: /* other values */
73+
printf("%s", lua_typename(L, type));
74+
break;
75+
}
76+
printf(": "); /* put a separator */
77+
}
78+
79+
/* value */
80+
{
81+
int type = lua_type(L, -1);
82+
switch (type) {
83+
case LUA_TSTRING: /* strings */
84+
printf("`%s'", lua_tostring(L, -1));
85+
break;
86+
87+
case LUA_TBOOLEAN: /* booleans */
88+
printf(lua_toboolean(L, -1) ? "true" : "false");
89+
break;
90+
91+
case LUA_TNUMBER: /* numbers */
92+
printf("%g", lua_tonumber(L, -1));
93+
break;
94+
95+
default: /* other values */
96+
printf("%s", lua_typename(L, type));
97+
break;
98+
}
99+
printf(", "); /* put a separator */
100+
}
101+
102+
lua_pop(L, 1); /* pop value, keep key */
103+
}
104+
printf("\n");
103105

104-
lua_settop(L, top);
106+
lua_settop(L, top);
105107
}
106108

107109
#endif /* DEBUG_SUPPORT_H_ */

lcm-lua/init.c

+28-24
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,53 @@ extern "C" {
66
}
77
#endif
88

9-
#include "lualcm_lcm.h"
109
#include "lualcm_hash.h"
10+
#include "lualcm_lcm.h"
1111
#include "lualcm_pack.h"
1212

13-
int luaopen_lcm_lcm(lua_State* L) {
14-
ll_lcm_makemetatable(L);
15-
ll_lcm_register_new(L);
13+
int luaopen_lcm_lcm(lua_State *L)
14+
{
15+
ll_lcm_makemetatable(L);
16+
ll_lcm_register_new(L);
1617

17-
return 1;
18+
return 1;
1819
}
1920

20-
int luaopen_lcm__hash(lua_State* L) {
21-
ll_hash_makemetatable(L);
22-
ll_hash_register_new(L);
21+
int luaopen_lcm__hash(lua_State *L)
22+
{
23+
ll_hash_makemetatable(L);
24+
ll_hash_register_new(L);
2325

24-
return 1;
26+
return 1;
2527
}
2628

27-
int luaopen_lcm__pack(lua_State* L) {
28-
ll_pack_register(L);
29+
int luaopen_lcm__pack(lua_State *L)
30+
{
31+
ll_pack_register(L);
2932

30-
return 1;
33+
return 1;
3134
}
3235

3336
#if defined(_WIN32)
3437
__declspec(dllexport)
3538
#elif __GNUC__ >= 4 || defined(__clang__)
3639
__attribute__((visibility ("default")))
3740
#endif
38-
int luaopen_lcm(lua_State* L) {
39-
lua_newtable(L);
41+
int luaopen_lcm(lua_State *L)
42+
{
43+
lua_newtable(L);
4044

41-
lua_pushstring(L, "lcm");
42-
luaopen_lcm_lcm(L);
43-
lua_rawset(L, -3);
45+
lua_pushstring(L, "lcm");
46+
luaopen_lcm_lcm(L);
47+
lua_rawset(L, -3);
4448

45-
lua_pushstring(L, "_hash");
46-
luaopen_lcm__hash(L);
47-
lua_rawset(L, -3);
49+
lua_pushstring(L, "_hash");
50+
luaopen_lcm__hash(L);
51+
lua_rawset(L, -3);
4852

49-
lua_pushstring(L, "_pack");
50-
luaopen_lcm__pack(L);
51-
lua_rawset(L, -3);
53+
lua_pushstring(L, "_pack");
54+
luaopen_lcm__pack(L);
55+
lua_rawset(L, -3);
5256

53-
return 1;
57+
return 1;
5458
}

lcm-lua/lua_ref_helper.c

+38-35
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,46 @@
99
/* convert a stack index to positive */
1010
/* stolen from lauxlib.c, converted to a function */
1111

12-
static int abs_index(lua_State *L, int i) {
13-
return i > 0 || i <= LUA_REGISTRYINDEX ? i : lua_gettop(L) + i + 1;
12+
static int abs_index(lua_State *L, int i)
13+
{
14+
return i > 0 || i <= LUA_REGISTRYINDEX ? i : lua_gettop(L) + i + 1;
1415
}
1516

16-
LUALIB_API int luaX_ref(lua_State *L, int t, int l) {
17-
int ref;
18-
t = abs_index(L, t);
19-
l = abs_index(L, l);
20-
if (lua_isnil(L, -1)) {
21-
lua_pop(L, 1); /* remove from stack */
22-
return LUA_REFNIL; /* 'nil' has a unique fixed reference */
23-
}
24-
lua_rawgeti(L, l, FREELIST_REF); /* get first free element */
25-
ref = (int)lua_tointeger(L, -1); /* ref = l[FREELIST_REF] */
26-
lua_pop(L, 1); /* remove it from stack */
27-
if (ref != 0) { /* any free element? */
28-
lua_rawgeti(L, l, ref); /* remove it from list */
29-
lua_rawseti(L, l, FREELIST_REF); /* (l[FREELIST_REF] = l[ref]) */
30-
} else { /* no free elements */
31-
ref = (int)lua_objlen(L, l);
32-
ref++; /* create new reference */
33-
}
34-
lua_pushboolean(L, 1);
35-
lua_rawseti(L, l, ref); /* l[ref] = true */
36-
lua_rawseti(L, t, ref); /* t[ref] = value */
37-
return ref;
38-
}
39-
40-
LUALIB_API void luaX_unref(lua_State *L, int t, int l, int ref) {
41-
if (ref >= 0) {
17+
LUALIB_API int luaX_ref(lua_State *L, int t, int l)
18+
{
19+
int ref;
4220
t = abs_index(L, t);
4321
l = abs_index(L, l);
44-
lua_rawgeti(L, l, FREELIST_REF);
45-
lua_rawseti(L, l, ref); /* l[ref] = l[FREELIST_REF] */
46-
lua_pushinteger(L, ref);
47-
lua_rawseti(L, l, FREELIST_REF); /* l[FREELIST_REF] = ref */
48-
lua_pushnil(L);
49-
lua_rawseti(L, t, ref); /* t[ref] = nil */
50-
}
22+
if (lua_isnil(L, -1)) {
23+
lua_pop(L, 1); /* remove from stack */
24+
return LUA_REFNIL; /* 'nil' has a unique fixed reference */
25+
}
26+
lua_rawgeti(L, l, FREELIST_REF); /* get first free element */
27+
ref = (int) lua_tointeger(L, -1); /* ref = l[FREELIST_REF] */
28+
lua_pop(L, 1); /* remove it from stack */
29+
if (ref != 0) { /* any free element? */
30+
lua_rawgeti(L, l, ref); /* remove it from list */
31+
lua_rawseti(L, l, FREELIST_REF); /* (l[FREELIST_REF] = l[ref]) */
32+
} else { /* no free elements */
33+
ref = (int) lua_objlen(L, l);
34+
ref++; /* create new reference */
35+
}
36+
lua_pushboolean(L, 1);
37+
lua_rawseti(L, l, ref); /* l[ref] = true */
38+
lua_rawseti(L, t, ref); /* t[ref] = value */
39+
return ref;
40+
}
41+
42+
LUALIB_API void luaX_unref(lua_State *L, int t, int l, int ref)
43+
{
44+
if (ref >= 0) {
45+
t = abs_index(L, t);
46+
l = abs_index(L, l);
47+
lua_rawgeti(L, l, FREELIST_REF);
48+
lua_rawseti(L, l, ref); /* l[ref] = l[FREELIST_REF] */
49+
lua_pushinteger(L, ref);
50+
lua_rawseti(L, l, FREELIST_REF); /* l[FREELIST_REF] = ref */
51+
lua_pushnil(L);
52+
lua_rawseti(L, t, ref); /* t[ref] = nil */
53+
}
5154
}

lcm-lua/lua_ref_helper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#ifdef __cplusplus
55
extern "C" {
66
#endif
7-
#include "lua.h"
87
#include "lauxlib.h"
8+
#include "lua.h"
99
#ifdef __cplusplus
1010
}
1111
#endif

lcm-lua/lua_ver_helper.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#elif LUA_VERSION_NUM >= 502
1616

1717
#define luaX_registerglobal(L, NAME, FUNCS) \
18-
do { \
19-
lua_newtable(L); \
20-
luaL_setfuncs(L, FUNCS, 0); \
21-
} while (0)
18+
do { \
19+
lua_newtable(L); \
20+
luaL_setfuncs(L, FUNCS, 0); \
21+
} while (0)
2222
#define luaX_registertable(L, FUNCS) luaL_setfuncs(L, FUNCS, 0)
2323
#define luaX_setfenv(L, INDEX) lua_setuservalue(L, INDEX)
2424
#define luaX_getfenv(L, INDEX) lua_getuservalue(L, INDEX)

0 commit comments

Comments
 (0)