Esempio n. 1
0
LUALIB_API void luaL_addwstring (luaL_Buffer *B, const lua_WChar *s) {
  luaL_addlwstring(B, s, lua_WChar_len(s));
}
Esempio n. 2
0
LUALIB_API int lua_dowstring (lua_State *L, const lua_WChar *str, const char *name) {
  return lua_dowbuffer(L, str, lua_WChar_len(str), name);
}
Esempio n. 3
0
int wstr_format_helper (luaL_Buffer* b, lua_State *L, int arg) {
  size_t sfl;
  const lua_WChar *strfrmt = luaL_checklwstring(L, arg, &sfl);
  const lua_WChar *strfrmt_end = strfrmt+sfl;
  luaL_wbuffinit(L, b);
  while (strfrmt < strfrmt_end) {
    if (*strfrmt != L_ESC)
      luaL_addwchar(b, *strfrmt++);
    else if (*++strfrmt == L_ESC)
      luaL_addwchar(b, *strfrmt++);  /* %% */
    else { /* format item */
      lua_WChar form[MAX_FORMAT];  /* to store the format (`%...') */
      lua_WChar buff[MAX_ITEM];  /* to store the formatted item */
      char _form[MAX_FORMAT];
      char _buff[MAX_ITEM];
      if (iswdigit(*strfrmt) && *(strfrmt+1) == '$')
        return luaL_error(L, "obsolete `format' option (d$)");
      arg++;
      strfrmt = scanformat(L, strfrmt, form);
      switch (*strfrmt++) {
        case 'c': {
          translate_wide_to_single(form, _form);
          sprintf(_buff, _form, luaL_checkint(L, arg));
          translate_single_to_wide(_buff, buff);
          break;
        }
        case 'd':  case 'i': {
          addintlen(form);
          translate_wide_to_single(form, _form);
          sprintf(_buff, _form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
          translate_single_to_wide(_buff, buff);
          break;
        }
        case 'o':  case 'u':  case 'x':  case 'X': {
          //?? How should this be for integers?
          translate_wide_to_single(form, _form);
          sprintf(_buff, _form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
          translate_single_to_wide(_buff, buff);
          break;
        }
        case 'e':  case 'E': case 'f':
        case 'g': case 'G': {
          translate_wide_to_single(form, _form);
          sprintf(_buff, _form, luaL_checknumber(L, arg));
          translate_single_to_wide(_buff, buff);
          break;
        }
        case 'q': {
          luaI_addquoted(L, b, arg);
          continue;  /* skip the 'addsize' at the end */
        }
        case 's': {
          size_t l;
          const lua_WChar *s = luaL_checklwstring(L, arg, &l);  (void)s;
          if (!lua_WChar_chr(form, '.') && l >= 100) {
            /* no precision and string is too long to be formatted;
               keep original string */
            lua_pushvalue(L, arg);
            luaL_addvalue(b);
            continue;  /* skip the `addsize' at the end */
          }
          else {
            assert(0);
//			swprintf((wchar_t*)buff, (wchar_t*)form, s);
            break;
          }
        }
        case 'b':
		{
		  buff[1] = buff[2] = buff[3] = buff[4] = buff[5] = buff[6] = buff[7] = buff[8] = 0;
		  switch (*strfrmt++)
		  {
		  case 'b': {
            unsigned int num = (unsigned int)luaL_checkint(L, arg);
		    buff[0] = (unsigned char)num;
            luaL_addlwstring(b, buff, 1);
			break;
          }
		  case 'd': {
            unsigned int num = (unsigned int)luaL_checkint(L, arg);
		    *(unsigned int*)(&buff) = num;
            luaL_addlwstring(b, buff, 4);
			break;
          }
		  case 'w': {
            unsigned int num = (unsigned int)luaL_checkint(L, arg);
			*(unsigned short*)(&buff) = (unsigned short)num;
            luaL_addlwstring(b, buff, 2);
			break;
          }
		  case 'f': {
            float numF = (float)luaL_checknumber(L, arg);
			*(float*)(&buff) = numF;
            luaL_addlwstring(b, buff, 4);
			break;
          }
		  case 'F': {
            double numD = (double)luaL_checknumber(L, arg);
			*(double*)(&buff) = numD;
            luaL_addlwstring(b, buff, 8);
			break;
          }

		  default:
			  break;
		  }
		  buff[0] = 0;

		  break;
		}
      }
      luaL_addlwstring(b, buff, lua_WChar_len(buff));
    }
  }
  return 1;
}
Esempio n. 4
0
LUALIB_API int (luaL_loadwstring) (lua_State *L, const lua_WChar *s) {
  return luaL_loadwbuffer(L, s, lua_WChar_len(s), "buffer");
}
Esempio n. 5
0
int LuaState::LoadWString(const lua_WChar* str)
{
	return luaL_loadwbuffer(m_state, str, lua_WChar_len(str), "name");
}