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?)

	typedef char MyChar;
	typedef wchar_t MyChar;

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:

	fwprintf(stderr, L"OOPS!  Bad thing just happened!");
	fprintf(stderr, "OOPS!  Bad thing just happened!");

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:

	#define _T(x) L##x
	#define _T(x) x

This would turn the original block of code into this:

	fwprintf(stderr, _T("OOPS!  Bad thing just happened!"));
	fprintf(stderr, _T("OOPS!  Bad thing just happened!"));

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    <>
          PGP Key:
PGP Fingerprint: 40D1 33E0 F70B 6BB5 8353 4669 B4CC DD09 04ED 4FE8