WinCE?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

WinCE?

pachydr
don't know if this has been asked before -- and i may even have done so
;) -- but has anyone ported Lua to WinCE devices?

thanx,

jdm



Reply | Threaded
Open this post in threaded view
|

Re: WinCE?

Michael T. Richter
> don't know if this has been asked before -- and i may even have done so
> ;) -- but has anyone ported Lua to WinCE devices?

I've tried and got bogged down.  Porting to a DLL-based Win32 library was 
relatively simple -- a matter of exporting the right functions and 
variables.  Moving it to Windows CE is non-trivial, however, for the 
following reasons:

1) File operations all use UNIX-style high-level file I/O (fopen, etc.).  
These functions aren't supported in the CRT supplied by Microsoft for CE.  
Just cutting out these functions isn't a useful way to handle things 
because error reporting is done using fprintf -- another unsupported 
function in Windows CE.

2) The native string type of Lua seems to be "array of bytes".  The native 
string type in Windows CE is Unicode.  This could present some problems 
down the line.

I got about half-way through resolving problem 1 before I had to return to 
stuff that pays my paycheque.  I'll get back to working on it probably 
sometime in January.

For the 3.2 release of Lua, I'd make these recommendations to the 
implementors:

1) Move as much of the I/O into contextual wrapper functions ("report 
error" or "write to file") as possible (and maybe even more than what is 
possible:-).  I believe this is already being worked on.

2) Provide compiler switches to allow for wide-character compilation.  It's 
necessary if Lua is to be internationalized anyway.

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.

-- 
Michael T. Richter    <[hidden email]>    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

Reply | Threaded
Open this post in threaded view
|

Re: WinCE?

Roberto Ierusalimschy
> 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. 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).
As you said, we are already changing Lua to make the FILE uses more
easy to modify/avoid. 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.

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: WinCE?

Michael T. Richter
>> 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    <[hidden email]>    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

Reply | Threaded
Open this post in threaded view
|

#ifdef considered harmful (was Re: WinCE?)

Norman Ramsey-3
 > 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

Please, please, never use #ifdef in code, only in header files.
It's much better to try, e.g,

#ifdef WIDE_CHARACTERS_IN_USE

typedef wchar_t lua_char;
#define lua_fprintf fwprintf
#define lua_atoi    wtoi

...

#else

typedef char lua_char;
#define lua_fprintf fprintf
#define lua_atoi    atoi

...

#endif


And then in the body of the code use

  lua_fprintf(stderr, _T("the cat ate my gymsuit"));


Norman

Reply | Threaded
Open this post in threaded view
|

Re: #ifdef considered harmful (was Re: WinCE?)

Michael T. Richter
>> 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

> Please, please, never use #ifdef in code, only in header files.
> It's much better to try, e.g,

[example snipped]

Agreed.  My bad.

-- 
Michael T. Richter    <[hidden email]>    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