mirror of
https://github.com/ccxvii/mujs.git
synced 2026-09-22 15:13:35 +08:00
Rename jsR_numbertostring to jsR_stringfromnumber.
Add js_tointeger, js_toint32, js_touint32.
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ static int Np_toString(js_State *J, int n)
|
||||
{
|
||||
js_Object *self = js_toobject(J, 0);
|
||||
if (self->type != JS_CNUMBER) jsR_error(J, "TypeError");
|
||||
js_pushliteral(J, jsR_numbertostring(J, self->u.number));
|
||||
js_pushliteral(J, jsR_stringfromnumber(J, self->u.number));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ static int jsB_parseInt(js_State *J, int argc)
|
||||
static int jsB_parseFloat(js_State *J, int argc)
|
||||
{
|
||||
const char *s = js_tostring(J, 1);
|
||||
js_pushnumber(J, jsR_stringtonumber(J, s));
|
||||
js_pushnumber(J, jsR_numberfromstring(J, s));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -155,6 +155,21 @@ double js_tonumber(js_State *J, int idx)
|
||||
return jsR_tonumber(J, stackidx(J, idx));
|
||||
}
|
||||
|
||||
double js_tointeger(js_State *J, int idx)
|
||||
{
|
||||
return tointeger(jsR_tonumber(J, stackidx(J, idx)));
|
||||
}
|
||||
|
||||
int js_toint32(js_State *J, int idx)
|
||||
{
|
||||
return toint32(jsR_tonumber(J, stackidx(J, idx)));
|
||||
}
|
||||
|
||||
unsigned int js_touint32(js_State *J, int idx)
|
||||
{
|
||||
return touint32(jsR_tonumber(J, stackidx(J, idx)));
|
||||
}
|
||||
|
||||
const char *js_tostring(js_State *J, int idx)
|
||||
{
|
||||
return jsR_tostring(J, stackidx(J, idx));
|
||||
|
||||
@@ -28,8 +28,8 @@ int jsR_compare(js_State *J);
|
||||
int jsR_equal(js_State *J);
|
||||
int jsR_strictequal(js_State *J);
|
||||
|
||||
const char *jsR_numbertostring(js_State *J, double number);
|
||||
double jsR_stringtonumber(js_State *J, const char *string);
|
||||
const char *jsR_stringfromnumber(js_State *J, double number);
|
||||
double jsR_numberfromstring(js_State *J, const char *string);
|
||||
|
||||
/* public */
|
||||
|
||||
@@ -69,9 +69,12 @@ int js_iscallable(js_State *J, int idx);
|
||||
|
||||
int js_toboolean(js_State *J, int idx);
|
||||
double js_tonumber(js_State *J, int idx);
|
||||
double js_tointeger(js_State *J, int idx);
|
||||
const char *js_tostring(js_State *J, int idx);
|
||||
|
||||
double js_tointeger(js_State *J, int idx);
|
||||
int js_toint32(js_State *J, int idx);
|
||||
unsigned int js_touint32(js_State *J, int idx);
|
||||
|
||||
void js_pop(js_State *J, int n);
|
||||
void js_dup(js_State *J);
|
||||
void js_copy(js_State *J, int idx);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "jsobject.h"
|
||||
#include "jsrun.h"
|
||||
|
||||
const char *jsR_numbertostring(js_State *J, double n)
|
||||
const char *jsR_stringfromnumber(js_State *J, double n)
|
||||
{
|
||||
char buf[32];
|
||||
if (isnan(n)) return "NaN";
|
||||
@@ -12,7 +12,7 @@ const char *jsR_numbertostring(js_State *J, double n)
|
||||
return js_intern(J, buf);
|
||||
}
|
||||
|
||||
double jsR_stringtonumber(js_State *J, const char *s)
|
||||
double jsR_numberfromstring(js_State *J, const char *s)
|
||||
{
|
||||
/* TODO: use lexer to parse string grammar */
|
||||
return strtod(s, NULL);
|
||||
@@ -99,7 +99,7 @@ double jsR_tonumber(js_State *J, const js_Value *v)
|
||||
case JS_TNULL: return 0;
|
||||
case JS_TBOOLEAN: return v->u.boolean;
|
||||
case JS_TNUMBER: return v->u.number;
|
||||
case JS_TSTRING: return jsR_stringtonumber(J, v->u.string);
|
||||
case JS_TSTRING: return jsR_numberfromstring(J, v->u.string);
|
||||
case JS_TOBJECT:
|
||||
{
|
||||
js_Value vv = jsR_toprimitive(J, v, JS_HNUMBER);
|
||||
@@ -115,7 +115,7 @@ const char *jsR_tostring(js_State *J, const js_Value *v)
|
||||
case JS_TUNDEFINED: return "undefined";
|
||||
case JS_TNULL: return "null";
|
||||
case JS_TBOOLEAN: return v->u.boolean ? "true" : "false";
|
||||
case JS_TNUMBER: return jsR_numbertostring(J, v->u.number);
|
||||
case JS_TNUMBER: return jsR_stringfromnumber(J, v->u.number);
|
||||
case JS_TSTRING: return v->u.string;
|
||||
case JS_TOBJECT:
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user