aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorE. Westbrook <github@westbrook.io>2019-02-27 20:55:43 -0700
committerE. Westbrook <github@westbrook.io>2019-03-10 00:03:04 -0700
commit98800e9129a63e8d0f751108d79efdffe58e98f7 (patch)
treecf004e0431b27ef07d2e7a2537e38121011c239b /src
parent2af4872a401cbd0c1255e19ee26620f0431dd9f5 (diff)
downloadluasocket-98800e9129a63e8d0f751108d79efdffe58e98f7.tar.gz
luasocket-98800e9129a63e8d0f751108d79efdffe58e98f7.tar.bz2
luasocket-98800e9129a63e8d0f751108d79efdffe58e98f7.zip
auxiliar: pragma visibility
Diffstat (limited to 'src')
-rw-r--r--src/auxiliar.c26
-rw-r--r--src/auxiliar.h16
2 files changed, 20 insertions, 22 deletions
diff --git a/src/auxiliar.c b/src/auxiliar.c
index 0bd7927..93a66a0 100644
--- a/src/auxiliar.c
+++ b/src/auxiliar.c
@@ -7,13 +7,10 @@
7#include <string.h> 7#include <string.h>
8#include <stdio.h> 8#include <stdio.h>
9 9
10/*=========================================================================*\
11* Exported functions
12\*=========================================================================*/
13/*-------------------------------------------------------------------------*\ 10/*-------------------------------------------------------------------------*\
14* Initializes the module 11* Initializes the module
15\*-------------------------------------------------------------------------*/ 12\*-------------------------------------------------------------------------*/
16LUASOCKET_PRIVATE int auxiliar_open(lua_State *L) { 13int auxiliar_open(lua_State *L) {
17 (void) L; 14 (void) L;
18 return 0; 15 return 0;
19} 16}
@@ -22,7 +19,7 @@ LUASOCKET_PRIVATE int auxiliar_open(lua_State *L) {
22* Creates a new class with given methods 19* Creates a new class with given methods
23* Methods whose names start with __ are passed directly to the metatable. 20* Methods whose names start with __ are passed directly to the metatable.
24\*-------------------------------------------------------------------------*/ 21\*-------------------------------------------------------------------------*/
25LUASOCKET_PRIVATE void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) { 22void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func) {
26 luaL_newmetatable(L, classname); /* mt */ 23 luaL_newmetatable(L, classname); /* mt */
27 /* create __index table to place methods */ 24 /* create __index table to place methods */
28 lua_pushstring(L, "__index"); /* mt,"__index" */ 25 lua_pushstring(L, "__index"); /* mt,"__index" */
@@ -45,7 +42,7 @@ LUASOCKET_PRIVATE void auxiliar_newclass(lua_State *L, const char *classname, lu
45/*-------------------------------------------------------------------------*\ 42/*-------------------------------------------------------------------------*\
46* Prints the value of a class in a nice way 43* Prints the value of a class in a nice way
47\*-------------------------------------------------------------------------*/ 44\*-------------------------------------------------------------------------*/
48LUASOCKET_PRIVATE int auxiliar_tostring(lua_State *L) { 45int auxiliar_tostring(lua_State *L) {
49 char buf[32]; 46 char buf[32];
50 if (!lua_getmetatable(L, 1)) goto error; 47 if (!lua_getmetatable(L, 1)) goto error;
51 lua_pushstring(L, "__index"); 48 lua_pushstring(L, "__index");
@@ -66,7 +63,7 @@ error:
66/*-------------------------------------------------------------------------*\ 63/*-------------------------------------------------------------------------*\
67* Insert class into group 64* Insert class into group
68\*-------------------------------------------------------------------------*/ 65\*-------------------------------------------------------------------------*/
69LUASOCKET_PRIVATE void auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) { 66void auxiliar_add2group(lua_State *L, const char *classname, const char *groupname) {
70 luaL_getmetatable(L, classname); 67 luaL_getmetatable(L, classname);
71 lua_pushstring(L, groupname); 68 lua_pushstring(L, groupname);
72 lua_pushboolean(L, 1); 69 lua_pushboolean(L, 1);
@@ -77,7 +74,7 @@ LUASOCKET_PRIVATE void auxiliar_add2group(lua_State *L, const char *classname, c
77/*-------------------------------------------------------------------------*\ 74/*-------------------------------------------------------------------------*\
78* Make sure argument is a boolean 75* Make sure argument is a boolean
79\*-------------------------------------------------------------------------*/ 76\*-------------------------------------------------------------------------*/
80LUASOCKET_PRIVATE int auxiliar_checkboolean(lua_State *L, int objidx) { 77int auxiliar_checkboolean(lua_State *L, int objidx) {
81 if (!lua_isboolean(L, objidx)) 78 if (!lua_isboolean(L, objidx))
82 auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN)); 79 auxiliar_typeerror(L, objidx, lua_typename(L, LUA_TBOOLEAN));
83 return lua_toboolean(L, objidx); 80 return lua_toboolean(L, objidx);
@@ -87,7 +84,7 @@ LUASOCKET_PRIVATE int auxiliar_checkboolean(lua_State *L, int objidx) {
87* Return userdata pointer if object belongs to a given class, abort with 84* Return userdata pointer if object belongs to a given class, abort with
88* error otherwise 85* error otherwise
89\*-------------------------------------------------------------------------*/ 86\*-------------------------------------------------------------------------*/
90LUASOCKET_PRIVATE void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) { 87void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) {
91 void *data = auxiliar_getclassudata(L, classname, objidx); 88 void *data = auxiliar_getclassudata(L, classname, objidx);
92 if (!data) { 89 if (!data) {
93 char msg[45]; 90 char msg[45];
@@ -101,7 +98,7 @@ LUASOCKET_PRIVATE void *auxiliar_checkclass(lua_State *L, const char *classname,
101* Return userdata pointer if object belongs to a given group, abort with 98* Return userdata pointer if object belongs to a given group, abort with
102* error otherwise 99* error otherwise
103\*-------------------------------------------------------------------------*/ 100\*-------------------------------------------------------------------------*/
104LUASOCKET_PRIVATE void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) { 101void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) {
105 void *data = auxiliar_getgroupudata(L, groupname, objidx); 102 void *data = auxiliar_getgroupudata(L, groupname, objidx);
106 if (!data) { 103 if (!data) {
107 char msg[45]; 104 char msg[45];
@@ -114,7 +111,7 @@ LUASOCKET_PRIVATE void *auxiliar_checkgroup(lua_State *L, const char *groupname,
114/*-------------------------------------------------------------------------*\ 111/*-------------------------------------------------------------------------*\
115* Set object class 112* Set object class
116\*-------------------------------------------------------------------------*/ 113\*-------------------------------------------------------------------------*/
117LUASOCKET_PRIVATE void auxiliar_setclass(lua_State *L, const char *classname, int objidx) { 114void auxiliar_setclass(lua_State *L, const char *classname, int objidx) {
118 luaL_getmetatable(L, classname); 115 luaL_getmetatable(L, classname);
119 if (objidx < 0) objidx--; 116 if (objidx < 0) objidx--;
120 lua_setmetatable(L, objidx); 117 lua_setmetatable(L, objidx);
@@ -124,7 +121,7 @@ LUASOCKET_PRIVATE void auxiliar_setclass(lua_State *L, const char *classname, in
124* Get a userdata pointer if object belongs to a given group. Return NULL 121* Get a userdata pointer if object belongs to a given group. Return NULL
125* otherwise 122* otherwise
126\*-------------------------------------------------------------------------*/ 123\*-------------------------------------------------------------------------*/
127LUASOCKET_PRIVATE void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) { 124void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) {
128 if (!lua_getmetatable(L, objidx)) 125 if (!lua_getmetatable(L, objidx))
129 return NULL; 126 return NULL;
130 lua_pushstring(L, groupname); 127 lua_pushstring(L, groupname);
@@ -142,7 +139,7 @@ LUASOCKET_PRIVATE void *auxiliar_getgroupudata(lua_State *L, const char *groupna
142* Get a userdata pointer if object belongs to a given class. Return NULL 139* Get a userdata pointer if object belongs to a given class. Return NULL
143* otherwise 140* otherwise
144\*-------------------------------------------------------------------------*/ 141\*-------------------------------------------------------------------------*/
145LUASOCKET_PRIVATE void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { 142void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) {
146 return luaL_testudata(L, objidx, classname); 143 return luaL_testudata(L, objidx, classname);
147} 144}
148 145
@@ -150,9 +147,8 @@ LUASOCKET_PRIVATE void *auxiliar_getclassudata(lua_State *L, const char *classna
150* Throws error when argument does not have correct type. 147* Throws error when argument does not have correct type.
151* Used to be part of lauxlib in Lua 5.1, was dropped from 5.2. 148* Used to be part of lauxlib in Lua 5.1, was dropped from 5.2.
152\*-------------------------------------------------------------------------*/ 149\*-------------------------------------------------------------------------*/
153LUASOCKET_PRIVATE int auxiliar_typeerror (lua_State *L, int narg, const char *tname) { 150int auxiliar_typeerror (lua_State *L, int narg, const char *tname) {
154 const char *msg = lua_pushfstring(L, "%s expected, got %s", tname, 151 const char *msg = lua_pushfstring(L, "%s expected, got %s", tname,
155 luaL_typename(L, narg)); 152 luaL_typename(L, narg));
156 return luaL_argerror(L, narg, msg); 153 return luaL_argerror(L, narg, msg);
157} 154}
158
diff --git a/src/auxiliar.h b/src/auxiliar.h
index 65511d4..234b00a 100644
--- a/src/auxiliar.h
+++ b/src/auxiliar.h
@@ -29,20 +29,22 @@
29* reverse mapping are done using lauxlib. 29* reverse mapping are done using lauxlib.
30\*=========================================================================*/ 30\*=========================================================================*/
31 31
32#include "lua.h" 32#include "luasocket.h"
33#include "lauxlib.h" 33
34#include "compat.h" 34#pragma GCC visibility push(hidden)
35 35
36int auxiliar_open(lua_State *L); 36int auxiliar_open(lua_State *L);
37void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func); 37void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func);
38int auxiliar_tostring(lua_State *L);
38void auxiliar_add2group(lua_State *L, const char *classname, const char *group); 39void auxiliar_add2group(lua_State *L, const char *classname, const char *group);
39void auxiliar_setclass(lua_State *L, const char *classname, int objidx); 40int auxiliar_checkboolean(lua_State *L, int objidx);
40void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx); 41void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx);
41void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx); 42void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx);
42void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); 43void auxiliar_setclass(lua_State *L, const char *classname, int objidx);
43void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); 44void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx);
44int auxiliar_checkboolean(lua_State *L, int objidx); 45void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx);
45int auxiliar_tostring(lua_State *L);
46int auxiliar_typeerror(lua_State *L, int narg, const char *tname); 46int auxiliar_typeerror(lua_State *L, int narg, const char *tname);
47 47
48#pragma GCC visibility pop
49
48#endif /* AUXILIAR_H */ 50#endif /* AUXILIAR_H */