diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
| commit | c787dccd9b5c3e55547a2c4bb598c0276de65034 (patch) | |
| tree | c4cdf2f7319fee48e048472a2044119f541e8da2 /lauxlib.c | |
| parent | b44e35b773bcaa9891d80a117392911ab5f656e5 (diff) | |
| download | lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.gz lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.bz2 lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.zip | |
"const" !!!
Diffstat (limited to 'lauxlib.c')
| -rw-r--r-- | lauxlib.c | 41 |
1 files changed, 16 insertions, 25 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.16 1999/03/10 14:19:41 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.17 1999/03/11 18:59:19 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -20,7 +20,7 @@ | |||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | int luaL_findstring (char *name, char *list[]) { | 23 | int luaL_findstring (const char *name, const char *const list[]) { |
| 24 | int i; | 24 | int i; |
| 25 | for (i=0; list[i]; i++) | 25 | for (i=0; list[i]; i++) |
| 26 | if (strcmp(list[i], name) == 0) | 26 | if (strcmp(list[i], name) == 0) |
| @@ -28,9 +28,9 @@ int luaL_findstring (char *name, char *list[]) { | |||
| 28 | return -1; /* name not found */ | 28 | return -1; /* name not found */ |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | void luaL_argerror (int numarg, char *extramsg) { | 31 | void luaL_argerror (int numarg, const char *extramsg) { |
| 32 | lua_Function f = lua_stackedfunction(0); | 32 | lua_Function f = lua_stackedfunction(0); |
| 33 | char *funcname; | 33 | const char *funcname; |
| 34 | lua_getobjname(f, &funcname); | 34 | lua_getobjname(f, &funcname); |
| 35 | numarg -= lua_nups(f); | 35 | numarg -= lua_nups(f); |
| 36 | if (funcname == NULL) | 36 | if (funcname == NULL) |
| @@ -42,58 +42,50 @@ void luaL_argerror (int numarg, char *extramsg) { | |||
| 42 | numarg, funcname, extramsg); | 42 | numarg, funcname, extramsg); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | char *luaL_check_lstr (int numArg, long *len) | 45 | const char *luaL_check_lstr (int numArg, long *len) { |
| 46 | { | ||
| 47 | lua_Object o = lua_getparam(numArg); | 46 | lua_Object o = lua_getparam(numArg); |
| 48 | luaL_arg_check(lua_isstring(o), numArg, "string expected"); | 47 | luaL_arg_check(lua_isstring(o), numArg, "string expected"); |
| 49 | if (len) *len = lua_strlen(o); | 48 | if (len) *len = lua_strlen(o); |
| 50 | return lua_getstring(o); | 49 | return lua_getstring(o); |
| 51 | } | 50 | } |
| 52 | 51 | ||
| 53 | char *luaL_opt_lstr (int numArg, char *def, long *len) | 52 | const char *luaL_opt_lstr (int numArg, const char *def, long *len) { |
| 54 | { | ||
| 55 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : | 53 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : |
| 56 | luaL_check_lstr(numArg, len); | 54 | luaL_check_lstr(numArg, len); |
| 57 | } | 55 | } |
| 58 | 56 | ||
| 59 | double luaL_check_number (int numArg) | 57 | double luaL_check_number (int numArg) { |
| 60 | { | ||
| 61 | lua_Object o = lua_getparam(numArg); | 58 | lua_Object o = lua_getparam(numArg); |
| 62 | luaL_arg_check(lua_isnumber(o), numArg, "number expected"); | 59 | luaL_arg_check(lua_isnumber(o), numArg, "number expected"); |
| 63 | return lua_getnumber(o); | 60 | return lua_getnumber(o); |
| 64 | } | 61 | } |
| 65 | 62 | ||
| 66 | 63 | ||
| 67 | double luaL_opt_number (int numArg, double def) | 64 | double luaL_opt_number (int numArg, double def) { |
| 68 | { | ||
| 69 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : | 65 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : |
| 70 | luaL_check_number(numArg); | 66 | luaL_check_number(numArg); |
| 71 | } | 67 | } |
| 72 | 68 | ||
| 73 | 69 | ||
| 74 | lua_Object luaL_tablearg (int arg) | 70 | lua_Object luaL_tablearg (int arg) { |
| 75 | { | ||
| 76 | lua_Object o = lua_getparam(arg); | 71 | lua_Object o = lua_getparam(arg); |
| 77 | luaL_arg_check(lua_istable(o), arg, "table expected"); | 72 | luaL_arg_check(lua_istable(o), arg, "table expected"); |
| 78 | return o; | 73 | return o; |
| 79 | } | 74 | } |
| 80 | 75 | ||
| 81 | lua_Object luaL_functionarg (int arg) | 76 | lua_Object luaL_functionarg (int arg) { |
| 82 | { | ||
| 83 | lua_Object o = lua_getparam(arg); | 77 | lua_Object o = lua_getparam(arg); |
| 84 | luaL_arg_check(lua_isfunction(o), arg, "function expected"); | 78 | luaL_arg_check(lua_isfunction(o), arg, "function expected"); |
| 85 | return o; | 79 | return o; |
| 86 | } | 80 | } |
| 87 | 81 | ||
| 88 | lua_Object luaL_nonnullarg (int numArg) | 82 | lua_Object luaL_nonnullarg (int numArg) { |
| 89 | { | ||
| 90 | lua_Object o = lua_getparam(numArg); | 83 | lua_Object o = lua_getparam(numArg); |
| 91 | luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected"); | 84 | luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected"); |
| 92 | return o; | 85 | return o; |
| 93 | } | 86 | } |
| 94 | 87 | ||
| 95 | void luaL_openlib (struct luaL_reg *l, int n) | 88 | void luaL_openlib (const struct luaL_reg *l, int n) { |
| 96 | { | ||
| 97 | int i; | 89 | int i; |
| 98 | lua_open(); /* make sure lua is already open */ | 90 | lua_open(); /* make sure lua is already open */ |
| 99 | for (i=0; i<n; i++) | 91 | for (i=0; i<n; i++) |
| @@ -101,8 +93,7 @@ void luaL_openlib (struct luaL_reg *l, int n) | |||
| 101 | } | 93 | } |
| 102 | 94 | ||
| 103 | 95 | ||
| 104 | void luaL_verror (char *fmt, ...) | 96 | void luaL_verror (const char *fmt, ...) { |
| 105 | { | ||
| 106 | char buff[500]; | 97 | char buff[500]; |
| 107 | va_list argp; | 98 | va_list argp; |
| 108 | va_start(argp, fmt); | 99 | va_start(argp, fmt); |
| @@ -112,14 +103,14 @@ void luaL_verror (char *fmt, ...) | |||
| 112 | } | 103 | } |
| 113 | 104 | ||
| 114 | 105 | ||
| 115 | void luaL_chunkid (char *out, char *source, int len) { | 106 | void luaL_chunkid (char *out, const char *source, int len) { |
| 116 | len -= 13; /* 13 = strlen("string ''...\0") */ | 107 | len -= 13; /* 13 = strlen("string ''...\0") */ |
| 117 | if (*source == '@') | 108 | if (*source == '@') |
| 118 | sprintf(out, "file `%.*s'", len, source+1); | 109 | sprintf(out, "file `%.*s'", len, source+1); |
| 119 | else if (*source == '(') | 110 | else if (*source == '(') |
| 120 | strcpy(out, "(C code)"); | 111 | strcpy(out, "(C code)"); |
| 121 | else { | 112 | else { |
| 122 | char *b = strchr(source , '\n'); /* stop string at first new line */ | 113 | const char *b = strchr(source , '\n'); /* stop string at first new line */ |
| 123 | int lim = (b && (b-source)<len) ? b-source : len; | 114 | int lim = (b && (b-source)<len) ? b-source : len; |
| 124 | sprintf(out, "string `%.*s'", lim, source); | 115 | sprintf(out, "string `%.*s'", lim, source); |
| 125 | strcpy(out+lim+(13-5), "...'"); /* 5 = strlen("...'\0") */ | 116 | strcpy(out+lim+(13-5), "...'"); /* 5 = strlen("...'\0") */ |
| @@ -127,7 +118,7 @@ void luaL_chunkid (char *out, char *source, int len) { | |||
| 127 | } | 118 | } |
| 128 | 119 | ||
| 129 | 120 | ||
| 130 | void luaL_filesource (char *out, char *filename, int len) { | 121 | void luaL_filesource (char *out, const char *filename, int len) { |
| 131 | if (filename == NULL) filename = "(stdin)"; | 122 | if (filename == NULL) filename = "(stdin)"; |
| 132 | sprintf(out, "@%.*s", len-2, filename); /* -2 for '@' and '\0' */ | 123 | sprintf(out, "@%.*s", len-2, filename); /* -2 for '@' and '\0' */ |
| 133 | } | 124 | } |
