mirror of https://github.com/rusefi/lua.git
addition of '.0' to float representation done by the kernel
This commit is contained in:
parent
27d9219cf3
commit
45c430eac0
11
lauxlib.c
11
lauxlib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lauxlib.c,v 1.261 2014/04/01 18:55:06 roberto Exp roberto $
|
** $Id: lauxlib.c,v 1.262 2014/04/15 18:25:49 roberto Exp roberto $
|
||||||
** Auxiliary functions for building Lua libraries
|
** Auxiliary functions for building Lua libraries
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -757,13 +757,8 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
|
||||||
case LUA_TNUMBER: {
|
case LUA_TNUMBER: {
|
||||||
if (lua_isinteger(L, idx))
|
if (lua_isinteger(L, idx))
|
||||||
lua_pushfstring(L, "%I", lua_tointeger(L, idx));
|
lua_pushfstring(L, "%I", lua_tointeger(L, idx));
|
||||||
else {
|
else
|
||||||
const char *s = lua_pushfstring(L, "%f", lua_tonumber(L, idx));
|
lua_pushfstring(L, "%f", lua_tonumber(L, idx));
|
||||||
if (s[strspn(s, "-0123456789")] == '\0') { /* looks like an int? */
|
|
||||||
lua_pushliteral(L, ".0"); /* add a '.0' to result */
|
|
||||||
lua_concat(L, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LUA_TSTRING:
|
case LUA_TSTRING:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lobject.c,v 2.84 2014/05/01 18:18:06 roberto Exp roberto $
|
** $Id: lobject.c,v 2.85 2014/05/12 21:22:05 roberto Exp roberto $
|
||||||
** Some generic functions over Lua objects
|
** Some generic functions over Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -356,14 +356,17 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
|
||||||
}
|
}
|
||||||
case 'd': {
|
case 'd': {
|
||||||
setivalue(L->top++, cast_int(va_arg(argp, int)));
|
setivalue(L->top++, cast_int(va_arg(argp, int)));
|
||||||
|
luaV_tostring(L, L->top - 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'I': {
|
case 'I': {
|
||||||
setivalue(L->top++, cast(lua_Integer, va_arg(argp, l_uacInt)));
|
setivalue(L->top++, cast(lua_Integer, va_arg(argp, l_uacInt)));
|
||||||
|
luaV_tostring(L, L->top - 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'f': {
|
case 'f': {
|
||||||
setfltvalue(L->top++, cast_num(va_arg(argp, l_uacNumber)));
|
setfltvalue(L->top++, cast_num(va_arg(argp, l_uacNumber)));
|
||||||
|
luaV_tostring(L, L->top - 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'p': {
|
case 'p': {
|
||||||
|
|
15
lvm.c
15
lvm.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 2.207 2014/05/12 19:13:32 roberto Exp roberto $
|
** $Id: lvm.c,v 2.208 2014/05/12 21:22:05 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -135,9 +135,16 @@ int luaV_tostring (lua_State *L, StkId obj) {
|
||||||
return 0;
|
return 0;
|
||||||
else {
|
else {
|
||||||
char buff[MAXNUMBER2STR];
|
char buff[MAXNUMBER2STR];
|
||||||
size_t len = (ttisinteger(obj))
|
size_t len;
|
||||||
? lua_integer2str(buff, ivalue(obj))
|
if (ttisinteger(obj))
|
||||||
: lua_number2str(buff, fltvalue(obj));
|
len = lua_integer2str(buff, ivalue(obj));
|
||||||
|
else {
|
||||||
|
len = lua_number2str(buff, fltvalue(obj));
|
||||||
|
if (buff[strspn(buff, "-0123456789")] == '\0') { /* looks like an int? */
|
||||||
|
buff[len++] = '.';
|
||||||
|
buff[len++] = '0'; /* adds '.0' to result */
|
||||||
|
}
|
||||||
|
}
|
||||||
setsvalue2s(L, obj, luaS_newlstr(L, buff, len));
|
setsvalue2s(L, obj, luaS_newlstr(L, buff, len));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue