Esempio n. 1
0
File: lvm.c Progetto: zapline/zlib
NAMESPACE_LUA_BEGIN

/* limit for table tag-method chains (to avoid loops) */
#define MAXTAGLOOP	100


#if LUA_REFCOUNT
const TValue *luaV_tonumber (lua_State *L, const TValue *obj, TValue *n) {
#else
const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
#endif /* LUA_REFCOUNT */
  lua_Number num;
  if (ttisnumber(obj)) return obj;
  if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {
    setnvalue(n, num);
    return n;
  }
#if LUA_WIDESTRING
  else if (ttiswstring(obj) && luaO_wstr2d(wsvalue(obj), &num)) {
    setnvalue(n, num);
    return n;
  }
#endif /* LUA_WIDESTRING */
  else
    return NULL;
}
Esempio n. 2
0
const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
  lua_Number num;
  if (ttisnumber(obj)) return obj;
  if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {
    setnvalue(n, num);
    return n;
  }
  else if (ttiswstring(obj) && luaO_wstr2d(wsvalue(obj), &num)) {
    setnvalue(n, num);
    return n;
  }
  else
    return NULL;
}
Esempio n. 3
0
File: lgc.c Progetto: gitrider/wxsj2
static void traverseproto (GCState *st, Proto *f) {
  int i;
  stringmark(f->source);
  for (i=0; i<f->sizek; i++) {  /* mark literal strings */
    if (ttisstring(f->k+i) || ttiswstring(f->k+i))
      stringmark(tsvalue(f->k+i));
  }
  for (i=0; i<f->sizeupvalues; i++)  /* mark upvalue names */
    stringmark(f->upvalues[i]);
  for (i=0; i<f->sizep; i++)  /* mark nested protos */
    markvalue(st, f->p[i]);
  for (i=0; i<f->sizelocvars; i++)  /* mark local-variable names */
    stringmark(f->locvars[i].varname);
  lua_assert(luaG_checkcode(f));
}
Esempio n. 4
0
File: lvm.c Progetto: zapline/zlib
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
  int res;
  if (ttype(l) != ttype(r))
    return luaG_ordererror(L, l, r);
  else if (ttisnumber(l))
    return luai_numlt(nvalue(l), nvalue(r));
  else if (ttisstring(l))
    return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
#if LUA_WIDESTRING
  else if (ttiswstring(l))
    return l_wstrcmp(rawtwsvalue(l), rawtwsvalue(r)) < 0;
#endif /* LUA_WIDESTRING */
  else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
    return res;
  return luaG_ordererror(L, l, r);
}
Esempio n. 5
0
LUA_API const lua_WChar *lua_tolwstring (lua_State *L, int idx, size_t *len) {
  StkId o = index2adr(L, idx);
  if (!ttiswstring(o)) {
    lua_lock(L);  /* `luaV_tostring' may create a new string */
    if (!luaV_towstring(L, o)) {  /* conversion failed? */
      if (len != NULL) *len = 0;
      lua_unlock(L);
      return NULL;
    }
    luaC_checkGC(L);
    o = index2adr(L, idx);  /* previous call may reallocate the stack */
    lua_unlock(L);
  }
  if (len != NULL) *len = twsvalue(o)->len;
  return wsvalue(o);
}
Esempio n. 6
0
File: lvm.c Progetto: zapline/zlib
static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
  int res;
  if (ttype(l) != ttype(r))
    return luaG_ordererror(L, l, r);
  else if (ttisnumber(l))
    return luai_numle(nvalue(l), nvalue(r));
  else if (ttisstring(l))
    return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
#if LUA_WIDESTRING
  else if (ttiswstring(l))
    return l_wstrcmp(rawtwsvalue(l), rawtwsvalue(r)) <= 0;
#endif /* LUA_WIDESTRING */
  else if ((res = call_orderTM(L, l, r, TM_LE)) != -1)  /* first try `le' */
    return res;
  else if ((res = call_orderTM(L, r, l, TM_LT)) != -1)  /* else try `lt' */
    return !res;
  return luaG_ordererror(L, l, r);
}
Esempio n. 7
0
File: lvm.c Progetto: chaosren/HHHH
NAMESPACE_LUA_BEGIN

/* limit for table tag-method chains (to avoid loops) */
#define MAXTAGLOOP	100

const TValue *luaV_tonumber(const TValue *obj, TValue *n)
{
	lua_Number num = 0.0f;
	if (ttisnumber(obj))
		return obj;
	if (ttisstring(obj) && luaO_str2d(svalue(obj), &num))
	{
		setnvalue(n, num);
		return n;
	}
	else if (ttiswstring(obj) && luaO_wstr2d(wsvalue(obj), &num))
	{
		setnvalue(n, num);
		return n;
	}
	else
		return NULL;
}
Esempio n. 8
0
File: lgc.c Progetto: gitrider/wxsj2
static int valismarked (const TObject *o) {
  if (ttisstring(o) || ttiswstring(o))
    stringmark(tsvalue(o));  /* strings are `values', so are never weak */
  return !iscollectable(o) || testbit(o->value.gc->gch.marked, 0);
}