lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>> I have volunteered in the past in this very forum to work with the
>> implementors on making Lua Win32-friendly, but have received no reply.

> Sorry about that. I think we did not understand your offer. 

No problems.  I actually thought it was an e-mail problem.

> As we said before, we would like to make Lua as WinCE-friendly as
> possible, but not more than that :-) (that means, as long as it does not
> conflict with other Lua goals, mainly simplicity and portability to other
> platforms). 

That's a good goal, and it shouldn't be any more difficult than making any 
two versions of UNIX run off the same source.  :-)

> As you said, we are already changing Lua to make the FILE uses more easy
> to modify/avoid. 

Yep.  I appreciate that too.

> About the Unicode stuff, we do not know what is involved. We would
> apreciate to know what kind of changes we would have to do in Lua to
> support wide characters, or at least to work in an environment that uses
> that kind of string.

In my own code I now use a self-defined type (call it "MyChar" for this 
example) which is #ifdef-controlled.  One way it is typedefed as "char"; 
another way as "wchar_t".  Anywhere where Lua currently uses "char" it 
should be replaced with "MyChar" (only use a good name instead).  (Wchar_t 
is ANSI standard these days, so you shouldn't have a problem, right?)

	#ifdef WIDE_CHARACTERS_IN_USE
	typedef char MyChar;
	#else
	typedef wchar_t MyChar;
	#endif

That's step 1.

Step 2 involves replacing calls to anything that works with strings and 
such to equivalent wide-character calls when the appropriate #ifdef is in 
place.  Examples would be wtoi, wtol, wprintf, fwprintf, etc.  In most 
cases simple boilerplate would suffice:

	#ifdef WIDE_CHARACTERS_IN_USE
	fwprintf(stderr, L"OOPS!  Bad thing just happened!");
	#else
	fprintf(stderr, "OOPS!  Bad thing just happened!");
	#endif

The 'L' in the first part is *not* a typo!  In fact, it is probably best to 
put a macro around string constants to enforce the use of 'L'.  The macro 
would look like this:

	#ifdef WIDE_CHARACTERS_IN_USE
	#define _T(x) L##x
	#else
	#define _T(x) x
	#endif

This would turn the original block of code into this:

	#ifdef WIDE_CHARACTERS_IN_USE
	fwprintf(stderr, _T("OOPS!  Bad thing just happened!"));
	#else
	fprintf(stderr, _T("OOPS!  Bad thing just happened!"));
	#endif

With that in place, you've got guaranteed type security and you've got an 
easy migration path for those of us who have to work with UNICODE (an 
ever-increasing set).

-- 
Michael T. Richter    <mtr@ottawa.com>    http://www.igs.net/~mtr/
          PGP Key: http://www.igs.net/~mtr/pgp-key.html
PGP Fingerprint: 40D1 33E0 F70B 6BB5 8353 4669 B4CC DD09 04ED 4FE8