aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/lapi.c b/lapi.c
index b8c11eef..7b4e7024 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.178 2013/04/29 17:12:50 roberto Exp roberto $ 2** $Id: lapi.c,v 2.179 2013/05/02 12:37:24 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -331,6 +331,28 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
331} 331}
332 332
333 333
334LUA_API int lua_cvtonum (lua_State *L, int idx) {
335 TValue *o = index2addr(L, idx);
336 if (ttisnumber(o)) return 1; /* already a number? */
337 else if (!ttisstring(o)) return 0; /* only strings can be converted */
338 else {
339 lua_Integer i; lua_Number n;
340 const char *s = svalue(o);
341 size_t len = tsvalue(o)->len;
342 if (luaO_str2int(s, len, &i)) {
343 setivalue(o, i);
344 return 1;
345 }
346 else if (luaO_str2d(s, len, &n)) {
347 setivalue(o, i);
348 setnvalue(o, n);
349 return 1;
350 }
351 else return 0;
352 }
353}
354
355
334LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { 356LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) {
335 lua_Number n; 357 lua_Number n;
336 const TValue *o = index2addr(L, idx); 358 const TValue *o = index2addr(L, idx);