aboutsummaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c60
1 files changed, 1 insertions, 59 deletions
diff --git a/lstrlib.c b/lstrlib.c
index da9ef911..54692a6e 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.260 2017/11/23 19:29:04 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.261 2018/02/21 13:48:44 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -220,25 +220,6 @@ static int tonum (lua_State *L, int arg) {
220} 220}
221 221
222 222
223static int toint (lua_State *L, int arg) {
224 if (!tonum(L, arg))
225 return 0; /* not coercible to a number */
226 else if (lua_isinteger(L, arg))
227 return 1; /* already an integer */
228 else { /* a float */
229 int ok;
230 lua_Integer n = lua_tointegerx(L, arg, &ok);
231 if (!ok)
232 return 0;
233 else {
234 lua_pop(L, 1); /* remove the float */
235 lua_pushinteger(L, n); /* push an integer */
236 return 1;
237 }
238 }
239}
240
241
242static void trymt (lua_State *L, const char *mtname) { 223static void trymt (lua_State *L, const char *mtname) {
243 lua_settop(L, 2); /* back to the original arguments */ 224 lua_settop(L, 2); /* back to the original arguments */
244 if (lua_type(L, 2) == LUA_TSTRING || !luaL_getmetafield(L, 2, mtname)) 225 if (lua_type(L, 2) == LUA_TSTRING || !luaL_getmetafield(L, 2, mtname))
@@ -258,15 +239,6 @@ static int arith (lua_State *L, int op, const char *mtname) {
258} 239}
259 240
260 241
261static int bitwise (lua_State *L, int op, const char *mtname) {
262 if (toint(L, 1) && toint(L, 2))
263 lua_arith(L, op); /* result will be on the top */
264 else
265 trymt(L, mtname);
266 return 1;
267}
268
269
270static int arith_add (lua_State *L) { 242static int arith_add (lua_State *L) {
271 return arith(L, LUA_OPADD, "__add"); 243 return arith(L, LUA_OPADD, "__add");
272} 244}
@@ -299,30 +271,6 @@ static int arith_unm (lua_State *L) {
299 return arith(L, LUA_OPUNM, "__unm"); 271 return arith(L, LUA_OPUNM, "__unm");
300} 272}
301 273
302static int bitwise_band (lua_State *L) {
303 return bitwise(L, LUA_OPBAND, "__band");
304}
305
306static int bitwise_bor (lua_State *L) {
307 return bitwise(L, LUA_OPBOR, "__bor");
308}
309
310static int bitwise_bxor (lua_State *L) {
311 return bitwise(L, LUA_OPBXOR, "__bxor");
312}
313
314static int bitwise_shl (lua_State *L) {
315 return bitwise(L, LUA_OPSHL, "__shl");
316}
317
318static int bitwise_shr (lua_State *L) {
319 return bitwise(L, LUA_OPSHR, "__shr");
320}
321
322static int bitwise_bnot (lua_State *L) {
323 return bitwise(L, LUA_OPBNOT, "__bnot");
324}
325
326 274
327static const luaL_Reg stringmetamethods[] = { 275static const luaL_Reg stringmetamethods[] = {
328 {"__add", arith_add}, 276 {"__add", arith_add},
@@ -333,12 +281,6 @@ static const luaL_Reg stringmetamethods[] = {
333 {"__div", arith_div}, 281 {"__div", arith_div},
334 {"__idiv", arith_idiv}, 282 {"__idiv", arith_idiv},
335 {"__unm", arith_unm}, 283 {"__unm", arith_unm},
336 {"__band", bitwise_band},
337 {"__bor", bitwise_bor},
338 {"__bxor", bitwise_bxor},
339 {"__shl", bitwise_shl},
340 {"__shr", bitwise_shr},
341 {"__bnot", bitwise_bnot},
342 {"__index", NULL}, /* placeholder */ 284 {"__index", NULL}, /* placeholder */
343 {NULL, NULL} 285 {NULL, NULL}
344}; 286};