Ejemplo n.º 1
0
LUA_API const lua_WChar *lua_towstring (lua_State *L, int index) {
  StkId o = luaA_indexAcceptable(L, index);
  if (o == NULL)
    return NULL;
  else if (ttype(o) == LUA_TWSTRING)
    return wsvalue(o);
  else {
    const lua_WChar *s;
    lua_lock(L);  /* `luaV_tostring' may create a new string */
    s = (luaV_towstring(L, o) == 0) ? wsvalue(o) : NULL;
    lua_unlock(L);
    return s;
  }
}
Ejemplo n.º 2
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);
}