[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua for unicode
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 03 Dec 2002 09:20:58 +0000
> What issues would be involved getting lua to natively use the MS Windows
> 16-bit unicode effort?
Mainly you have to change all calls (from str* to wstr*, but also from
fopen to _wfopen etc etc), redefine `char' to wchar_t, add "L" to all
literal strings in the code, add "L" to all literal characters in the
code, and then redefine some other stuff (such as EOF). We tried to
automate that in Lua, using lots of macros (I think some of 4.1 work
versions have it). It did work (I sussessfully compiled and ran Lua in
Windows using that stuff), but it was lots of pain to keep (mainly the
macros to put the "L"s), so we removed those macros.
Currently we try to facilitate the task, without explicit support. Among
other things, we avoid using "..." or '.' inside comments, we try to use
"char" only for characters (otherwise we use lu_byte), and we try to
keep the code independent of the fact that sizeof(char)==1. (I think
Luiz has some code to add "L" to your literals.)
Attached follows a list of what is (or was, for Lua 4.1w) involved in
the translation.
-- Roberto
#ifndef wwwc_h
#define wwc_h
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>
#define L_CHAR wchar_t
#define l_charint wint_t
#define uchar(c) (c)
#define l_c(x) L##x
#define l_saux(x) L##x
#define l_s(x) l_saux(x)
#undef EOF
#define EOF WEOF
#define strcspn wcscspn
#define fgetc fgetwc
#define fgets fgetws
#define fprintf fwprintf
#define fputs fputws
#define fscanf fwscanf
#define printf wprintf
#define sprintf swprintf
#define strchr wcschr
#define strcmp wcscmp
#define strcoll wcscoll
#define strcpy wcscpy
#define strftime wcsftime
#define strlen wcslen
#define strncpy wcsncpy
#define strpbrk wcspbrk
#define strtod wcstod
#define strtol wcstol
#define strtoul wcstoul
#define vsprintf vswprintf
#define fopen _wfopen
#define strerror(x) L"system error"
#define system _wsystem
#define remove _wremove
#define rename _wrename
#define tmpnam _wtmpnam
#define getenv _wgetenv
#define setlocale _wsetlocale
#define perror _wperror
#undef isalnum
#define isalnum iswalnum
#undef isalpha
#define isalpha iswalpha
#undef iscntrl
#define iscntrl iswcntrl
#undef isdigit
#define isdigit iswdigit
#undef islower
#define islower iswlower
#undef ispunct
#define ispunct iswpunct
#undef isspace
#define isspace iswspace
#undef isupper
#define isupper iswupper
#undef isxdigit
#define isxdigit iswxdigit
#define main wmain
#endif