lua5.4
lctype.h
浏览该文件的文档.
1 /*
2 ** $Id: lctype.h $
3 ** 'ctype' functions for Lua
4 ** See Copyright Notice in lua.h
5 */
6 
7 #ifndef lctype_h
8 #define lctype_h
9 
10 #include "lua.h"
11 
12 
13 /*
14 ** WARNING: the functions defined here do not necessarily correspond
15 ** to the similar functions in the standard C ctype.h. They are
16 ** optimized for the specific needs of Lua.
17 */
18 
19 #if !defined(LUA_USE_CTYPE)
20 
21 #if 'A' == 65 && '0' == 48
22 /* ASCII case: can use its own tables; faster and fixed */
23 #define LUA_USE_CTYPE 0
24 #else
25 /* must use standard C ctype */
26 #define LUA_USE_CTYPE 1
27 #endif
28 
29 #endif
30 
31 
32 #if !LUA_USE_CTYPE /* { */
33 
34 #include <limits.h>
35 
36 #include "llimits.h"
37 
38 
39 #define ALPHABIT 0
40 #define DIGITBIT 1
41 #define PRINTBIT 2
42 #define SPACEBIT 3
43 #define XDIGITBIT 4
44 
45 
46 #define MASK(B) (1 << (B))
47 
48 
49 /*
50 ** add 1 to char to allow index -1 (EOZ)
51 */
52 #define testprop(c,p) (luai_ctype_[(c)+1] & (p))
53 
54 /*
55 ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
56 */
57 #define lislalpha(c) testprop(c, MASK(ALPHABIT))
58 #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
59 #define lisdigit(c) testprop(c, MASK(DIGITBIT))
60 #define lisspace(c) testprop(c, MASK(SPACEBIT))
61 #define lisprint(c) testprop(c, MASK(PRINTBIT))
62 #define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
63 
64 
65 /*
66 ** In ASCII, this 'ltolower' is correct for alphabetic characters and
67 ** for '.'. That is enough for Lua needs. ('check_exp' ensures that
68 ** the character either is an upper-case letter or is unchanged by
69 ** the transformation, which holds for lower-case letters and '.'.)
70 */
71 #define ltolower(c) \
72  check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \
73  (c) | ('A' ^ 'a'))
74 
75 
76 /* one entry for each character and for -1 (EOZ) */
77 LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];)
78 
79 
80 #else /* }{ */
81 
82 /*
83 ** use standard C ctypes
84 */
85 
86 #include <ctype.h>
87 
88 
89 #define lislalpha(c) (isalpha(c) || (c) == '_')
90 #define lislalnum(c) (isalnum(c) || (c) == '_')
91 #define lisdigit(c) (isdigit(c))
92 #define lisspace(c) (isspace(c))
93 #define lisprint(c) (isprint(c))
94 #define lisxdigit(c) (isxdigit(c))
95 
96 #define ltolower(c) (tolower(c))
97 
98 #endif /* } */
99 
100 #endif
101 
luai_ctype_
LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX+2]
Definition: lctype.c:28
LUA_TFUNCTION
#define LUA_TFUNCTION
Definition: lua.h:71
lua_pushliteral
#define lua_pushliteral(L, s)
Definition: lua.h:381
lua_isyieldable
LUA_API int lua_isyieldable(lua_State *L)
Definition: ldo.c:736
lua_resume
LUA_API int lua_resume(lua_State *L, lua_State *from, int nargs, int *nresults)
Definition: ldo.c:701
luaB_cocreate
static int luaB_cocreate(lua_State *L)
Definition: lcorolib.c:92
luaB_cowrap
static int luaB_cowrap(lua_State *L)
Definition: lcorolib.c:102
LUA_OK
#define LUA_OK
Definition: lua.h:49
lua_pushstring
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
Definition: lapi.c:514
luaB_close
static int luaB_close(lua_State *L)
Definition: lcorolib.c:167
lua_checkstack
LUA_API int lua_checkstack(lua_State *L, int n)
Definition: lapi.c:98
LUA_TSTRING
#define LUA_TSTRING
Definition: lua.h:69
lua_pushthread
LUA_API int lua_pushthread(lua_State *L)
Definition: lapi.c:600
luaB_auxwrap
static int luaB_auxwrap(lua_State *L)
Definition: lcorolib.c:73
luaB_corunning
static int luaB_corunning(lua_State *L)
Definition: lcorolib.c:160
lua_pop
#define lua_pop(L, n)
Definition: lua.h:364
lua_concat
LUA_API void lua_concat(lua_State *L, int n)
Definition: lapi.c:1260
COS_YIELD
#define COS_YIELD
Definition: lcorolib.c:116
llimits.h
lua_type
LUA_API int lua_type(lua_State *L, int idx)
Definition: lapi.c:260
lislalpha
#define lislalpha(c)
Definition: lctype.h:57
auxstatus
static int auxstatus(lua_State *L, lua_State *co)
Definition: lcorolib.c:124
lua_tothread
LUA_API lua_State * lua_tothread(lua_State *L, int idx)
Definition: lapi.c:438
luaB_coresume
static int luaB_coresume(lua_State *L)
Definition: lcorolib.c:56
lua_Debug
Definition: lua.h:469
luaL_argexpected
#define luaL_argexpected(L, cond, arg, tname)
Definition: lauxlib.h:135
LUAI_DDEF
#define LUAI_DDEF
Definition: luaconf.h:311
lua.h
lua_yield
#define lua_yield(L, n)
Definition: lua.h:305
luaB_yield
static int luaB_yield(lua_State *L)
Definition: lcorolib.c:109
lua_insert
#define lua_insert(L, idx)
Definition: lua.h:389
lua_pushcclosure
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
Definition: lapi.c:555
luaL_Reg
Definition: lauxlib.h:37
COS_RUN
#define COS_RUN
Definition: lcorolib.c:114
lprefix.h
COS_NORM
#define COS_NORM
Definition: lcorolib.c:117
lu_byte
unsigned char lu_byte
Definition: llimits.h:36
statname
static const char *const statname[]
Definition: lcorolib.c:120
lua_getstack
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)
Definition: ldebug.c:164
getco
static lua_State * getco(lua_State *L)
Definition: lcorolib.c:21
lua_gettop
LUA_API int lua_gettop(lua_State *L)
Definition: lapi.c:168
lua_State
Definition: lstate.h:273
lauxlib.h
lualib.h
lua_pushboolean
LUA_API void lua_pushboolean(lua_State *L, int b)
Definition: lapi.c:581
lua_pushvalue
LUA_API void lua_pushvalue(lua_State *L, int idx)
Definition: lapi.c:246
luaB_costatus
static int luaB_costatus(lua_State *L)
Definition: lcorolib.c:146
luaL_checktype
LUALIB_API void luaL_checktype(lua_State *L, int arg, int t)
Definition: lauxlib.c:390
COS_DEAD
#define COS_DEAD
Definition: lcorolib.c:115
lua_status
LUA_API int lua_status(lua_State *L)
Definition: lapi.c:1100
LUA_YIELD
#define LUA_YIELD
Definition: lua.h:50
luaopen_coroutine
LUAMOD_API int luaopen_coroutine(lua_State *L)
Definition: lcorolib.c:203
auxresume
static int auxresume(lua_State *L, lua_State *co, int narg)
Definition: lcorolib.c:32
LUAMOD_API
#define LUAMOD_API
Definition: luaconf.h:286
lua_xmove
LUA_API void lua_xmove(lua_State *from, lua_State *to, int n)
Definition: lapi.c:120
LUAI_DDEC
#define LUAI_DDEC(dec)
Definition: luaconf.h:310
luaL_newlib
#define luaL_newlib(L, l)
Definition: lauxlib.h:129
luaL_error
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
Definition: lauxlib.c:234
luaL_where
LUALIB_API void luaL_where(lua_State *L, int level)
Definition: lauxlib.c:216
lua_isnone
#define lua_isnone(L, n)
Definition: lua.h:378
lua_resetthread
int lua_resetthread(lua_State *L)
Definition: lstate.c:324
luaB_yieldable
static int luaB_yieldable(lua_State *L)
Definition: lcorolib.c:153
co_funcs
static const luaL_Reg co_funcs[]
Definition: lcorolib.c:189
lua_upvalueindex
#define lua_upvalueindex(i)
Definition: lua.h:45
NONA
#define NONA
Definition: lctype.c:24
lctype.h
LUA_ERRMEM
#define LUA_ERRMEM
Definition: lua.h:53
lua_newthread
LUA_API lua_State * lua_newthread(lua_State *L)
Definition: lstate.c:282
lua_error
LUA_API int lua_error(lua_State *L)
Definition: lapi.c:1212