Lua running on PalmOS!

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

Lua running on PalmOS!

Lenny Palozzi-4
I hacked a version of Lua to run on PalmOS.

In short
* used latest gcc tools
* compiled with PalmOS v2 SDK
* running on PalmOS 3.1 (that's all I have), should run on PalmOS 2!
* followed LTN 2 for a minimal version
* rewrote Lua's generic memory allocator
  - used memory handles so memory is not allocated in the limited dynamic heap
  - memory allocation is the most difficult issue of this port. Different
    versions of PalmOS have different limitations. 
  - different strategies could be used to support each version
* commented a few calls to unsupported functions (fgetc, etc...)
* test app(very limited) and Lua compiled as single executable.
~33K prc.
* am able to register a C function and call it from lua, manipulate global
variables (and opening and closing of Lua states of course)

Not sure where I will go with this, a stable port maybe? Comments?

Thanks,
-Lenny.

Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Terence Martin-2
Hey this sounds awesome. I just got myself a Prism a couple of days ago and
have been meaning to try something like this (course, I got Sudden Strike at
the same time, so free time seems a bit limited ;).

Do you have what you've done so far available for download anywhere? I'd
love to give it a try.


----- Original Message -----
From: "Lenny Palozzi" <[hidden email]>
To: "Multiple recipients of list" <[hidden email]>
Sent: Saturday, March 03, 2001 10:46 PM
Subject: Lua running on PalmOS!


> I hacked a version of Lua to run on PalmOS.
>
> In short
> * used latest gcc tools
> * compiled with PalmOS v2 SDK
> * running on PalmOS 3.1 (that's all I have), should run on PalmOS 2!
> * followed LTN 2 for a minimal version
> * rewrote Lua's generic memory allocator
>   - used memory handles so memory is not allocated in the limited dynamic
heap
>   - memory allocation is the most difficult issue of this port. Different
>     versions of PalmOS have different limitations.
>   - different strategies could be used to support each version
> * commented a few calls to unsupported functions (fgetc, etc...)
> * test app(very limited) and Lua compiled as single executable.
> ~33K prc.
> * am able to register a C function and call it from lua, manipulate global
> variables (and opening and closing of Lua states of course)
>
> Not sure where I will go with this, a stable port maybe? Comments?
>
> Thanks,
> -Lenny.


Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Jean-Claude Wippler
In reply to this post by Lenny Palozzi-4
Lenny Palozzi <[hidden email]> wrote:

>I hacked a version of Lua to run on PalmOS.

Bravo!  This is terrific news.

>* rewrote Lua's generic memory allocator

What are the limits of such an approach?  Once an application is built
this way, does it have the ability to deal with reasonable amounts of
data, well over 64 Kb, that is?

>Not sure where I will go with this, a stable port maybe? Comments?n
Yes, please.  As Palm owner, I'd be very interested to try this and build
on top of it.   One month from now there will be an announcement which
could make this port quite, ehm, interesting...

-jcw


Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Russell Y. Webb
In reply to this post by Lenny Palozzi-4
Messa
?ÃhD: <B6C802AB.250F%[hidden email]>
In-Reply-To: <20010304014648.A2157@...>
Mime-version: 1.0
Content-type: text/plain; charset="US-ASCII"
Content-transfer-encoding: 7bit

Handles in PalmOS are allocated out of dynamic memory.

If you do allocated memory from the storage heap then you generally have to
write to the memory using DmWrite and not through pointer assignment (*ptr =
value).  If you do the later then a hardware memory exception is raised by
the DMA.  In short you'd either have hack PalmOS, grab the memory semaphore
(a dangerous proposition and not officially something developers should do)
or change every *ptr = value in the Lua source.

My guess is that you are still using the "limited" dynamic heap.

Russ Webb
PalmOS Engineer

> From: Lenny Palozzi <[hidden email]>
> Reply-To: [hidden email]
> Date: Sun, 4 Mar 2001 01:46:48 -0500
> To: Multiple recipients of list <[hidden email]>
> Subject: Lua running on PalmOS!
> 
> I hacked a version of Lua to run on PalmOS.
> 
> In short
> * used latest gcc tools
> * compiled with PalmOS v2 SDK
> * running on PalmOS 3.1 (that's all I have), should run on PalmOS 2!
> * followed LTN 2 for a minimal version
> * rewrote Lua's generic memory allocator
> - used memory handles so memory is not allocated in the limited dynamic heap
> - memory allocation is the most difficult issue of this port. Different
> versions of PalmOS have different limitations.
> - different strategies could be used to su
?Ãht each version
> * commented a few calls to unsupported functions (fgetc, etc...)
> * test app(very limited) and Lua compiled as single executable.
> ~33K prc.
> * am able to register a C function and call it from lua, manipulate global
> variables (and opening and closing of Lua states of course)
> 
> Not sure where I will go with this, a stable port maybe? Comments?
> 
> Thanks,
> -Lenny.


Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Lenny Palozzi-4
On Sun, Mar 04, 2001 at 02:33:16PM -0800, Russell Y. Webb wrote:
> 
> My guess is that you are still using the "limited" dynamic heap.
>
Yes, you are correct. I got the impression that it was the other way around, went back and read the docs, and now agree with you 100%.

-Lenny. 

Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Lenny Palozzi-4
In reply to this post by Jean-Claude Wippler
On Sun, Mar 04, 2001 at 09:22:21AM -0800, Jean-Claude Wippler wrote:
> >* rewrote Lua's generic memory allocator
> 
> What are the limits of such an approach?  Once an application is built
> this way, does it have the ability to deal with reasonable amounts of
> data, well over 64 Kb, that is?

The implementation still suffers from the memory limits of the PalmOS. Memory allocated via MemPtrNew or MemHandleNew is limited to 64K, so are database records. Any blocks of data that Lua allocates cannot be larger than that, or ca-boom!

The dynamic heap(where memory is allocated from) is roughly 96K, at runtime its usually less. So Lua and your app share that remaining amount of memory. 

I basically replaced Lua's memory allocator to allocate and free memory with MemHandleNew/Free and MemHandleLock/Unlock. I used memory handles because during a reallocation of memory, if there is no free space at the end of the chunk the PalmOS will relocate the entire chunk if possible, unlike a regular pointer where the reallocation would fail.

> Not sure where I will go with this, a stable port maybe? Comments?n
> Yes, please.  As Palm owner, I'd be very interested to try this and build
> on top of it.   One month from now there will be an announcement which
> could make this port quite, ehm, interesting...

And what annoucement would that be?

-Lenny

Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Lenny Palozzi-4
In reply to this post by Terence Martin-2
On Sat, Mar 03, 2001 at 10:58:07PM -0800, Terence Martin wrote:
> 
> Do you have what you've done so far available for download anywhere? I'd
> love to give it a try.

No, I apologize, but I will soon. Stay tuned.

-Lenny.

Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Russell Y. Webb
In reply to this post by Lenny Palozzi-4
> The implementation still suffers from the memory limits of the PalmOS. Memory
> allocated via MemPtrNew or MemHandleNew is limited to 64K, so are database
> records. Any blocks of data that Lua allocates cannot be larger than that, or
> ca-boom!

FtrPtrNew allocates arbitrary sized memory chunks from the storage heap.
There's also a lower level allocation from the Storage heap that has nothing
to do with features and can allocate >64k (can't recall it's name, something
like MemNewChunk).  So you could allocate say 4Megs and then sub-allocate
from that.

Of course you still have to use DmWrite to write to the memory.  Seems like
the Lua source would have to be extensively modified to fix that (perhaps
though some macros so you could revert back to normal pointer writing on
another platform).  Reading memory is fine of course.  Lot's of small writes
are likely to have a serious speed hit so some sort of memory swapping
architecture might be  in order.  You could try MemSemaphoreReserve and
MemSemaphoreRelease before and after each ptr write but then you're starting
to play with fire since unbalancing those is BAD and holding that semaphore
allows you to trash the storage heap (where the user data is).

Ah, the joys of strange memory models.

Also note that you have a VERY limited C stack in PalmOS.  Say about 2-4k.
In recent versions you can bump that up but only by consuming dynamic heap
so you are still effectively limited to about 16k (at most).

Russ


Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Lenny Palozzi-4
On Sun, Mar 04, 2001 at 11:32:38PM -0800, Russell Y. Webb wrote:
> 
> FtrPtrNew allocates arbitrary sized memory chunks from the storage heap.
> There's also a lower level allocation from the Storage heap that has nothing
> to do with features and can allocate >64k (can't recall it's name, something
> like MemNewChunk).  So you could allocate say 4Megs and then sub-allocate
> from that.
> 
> Of course you still have to use DmWrite to write to the memory.  Seems like
> the Lua source would have to be extensively modified to fix that (perhaps

I don't think I want to do all that work. :) 

I would like to keep it simple and possibly change a few of Lua's default settings, like lowering the number of default stack "positions", having the gc run more frequently to reclaim memory, etc...

Maybe the Lua developers would have some tips?

Thanks,
-Lenny.

Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Alan Watson-4
In reply to this post by Russell Y. Webb
I know very little about programming under PalmOS, but ...
rather than hacking all of the memory accesses in the Lua
source, might it not be possible to define a set of "smart
pointers" that automagically use the arcane PalmOS
incantations to access memory, change the *definitions* (not
the usages) of the objects access memory, and compile the
whole thing with a C++ compiler? Just a though.

Regards,

Alan
-- 
Dr Alan Watson
Instituto de Astronomía UNAM

Reply | Threaded
Open this post in threaded view
|

RES: Lua running on PalmOS!

Renato Crivano
In reply to this post by Lenny Palozzi-4
Hi,

> Maybe the Lua developers would have some tips?

My company has ported Lua to PalmOS too, we have an almost ready version
of it that we are going to make available for download soon.

Some useful tips would be:

- You should increase the size of the stack or Lua will crash when it
  reports compilation errors. Palm stack is really very limited;

- You can't use the StrVPrintF function, because Lua needs more advanced
  formats then %s and %u;

- There is some trouble with the character comparison functions and the
  new PalmOSGlueLibrary;

- Changing some constants in llimits.h would reduce memory needs;

- Floating point manipulation and formatting will give you some headaches;

- Be careful with the longjump/setjump implementation, in our first
  release it compiled perfectly, but it didn't work.

Anyway, I can say that once it's done, it works very well. And if you use
PalmOS 3.5 then you'll see that memory limitations are not that much
critical.

[]s,

Renato Crivano
CTO - Hands Mobile Solutions
Tel +55 21 223-3399
Fax +55 21 223-3370
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Lenny Palozzi-4
In reply to this post by Lenny Palozzi-4
On Mon, Mar 05, 2001 at 12:26:20AM -0500, Lenny Palozzi wrote:
> On Sat, Mar 03, 2001 at 10:58:07PM -0800, Terence Martin wrote:
> > 
> > Do you have what you've done so far available for download anywhere? I'd
> > love to give it a try.
> 
> No, I apologize, but I will soon. Stay tuned.
>

You can grab the code here

	http://24.43.133.77/code/luapilot.tar.gz

You need the GCC toolchain. Type make to build the static lualib.a library, then make again in the test directory to build the test program. (use sdk v2)   

-Lenny. 

Reply | Threaded
Open this post in threaded view
|

Re: RES: Lua running on PalmOS!

Lenny Palozzi-4
In reply to this post by Renato Crivano
Good news! What license will it be under?

Thanks for the tips. (I did run into the jmp_buf problem but have not tested it)

-Lenny.

Reply | Threaded
Open this post in threaded view
|

RES: RES: Lua running on PalmOS!

Renato Crivano
> Good news! What license will it be under?

I'm not sure, but I think that it will be using the same license that Lua
uses.

> Thanks for the tips. (I did run into the jmp_buf problem but have not
tested it)

You are welcome.

[]s,

Renato Crivano
CTO - Hands Mobile Solutions
Tel +55 21 223-3399
Fax +55 21 223-3370
[hidden email]

-----Mensagem original-----
De: [hidden email]
[[hidden email] nome de Lenny Palozzi
Enviada em: Tuesday, March 06, 2001 4:22 PM
Para: Multiple recipients of list
Assunto: Re: RES: Lua running on PalmOS!


Good news! What license will it be under?

Thanks for the tips. (I did run into the jmp_buf problem but have not tested
it)

-Lenny.


Reply | Threaded
Open this post in threaded view
|

Re: Lua running on PalmOS!

Terence Martin-2
In reply to this post by Lenny Palozzi-4
Cool, thanks! I'll check this out tonight. 

Reply | Threaded
Open this post in threaded view
|

Embedding Lua for use in a MUD.

falknor1
In reply to this post by Lenny Palozzi-4
Greetings list:

I am new around here and have looked through the archives on egroups a tad
bit, but did not find much.  I found a few threads talking about just how
suitable Lua is for this operation, but never did I see any mention of
available examples. Does anyone know of a freely available example one could
look at that involves embedding Lua into a C application?  I am looking to
use this language as scripting for my builders/designers.  I look at it like
this:  they are the one's designing it, if they can script it then it's more
likely that it will come out exactly as they saw it than if I were forced to
do it off of sometimes inadequate descriptions.  The scripts will need to
modify game data real-time. Such as changing values of various things in the
game and adding new functionality such as commands.  If anyone has any
input, ideas, or links please feel free to send them my way.

Cordially,
JD


Reply | Threaded
Open this post in threaded view
|

RE: Embedding Lua for use in a MUD.

Samson-3
I have some skeleton code for a LUA MUD somewhere, I'll dig it up it you
like.



-----Original Message-----
From: falknor1 [[hidden email]]
Sent: Tuesday, March 13, 2001 4:38 PM
To: Multiple recipients of list
Subject: Embedding Lua for use in a MUD.


Greetings list:

I am new around here and have looked through the archives on egroups a tad
bit, but did not find much.  I found a few threads talking about just how
suitable Lua is for this operation, but never did I see any mention of
available examples. Does anyone know of a freely available example one could
look at that involves embedding Lua into a C application?  I am looking to
use this language as scripting for my builders/designers.  I look at it like
this:  they are the one's designing it, if they can script it then it's more
likely that it will come out exactly as they saw it than if I were forced to
do it off of sometimes inadequate descriptions.  The scripts will need to
modify game data real-time. Such as changing values of various things in the
game and adding new functionality such as commands.  If anyone has any
input, ideas, or links please feel free to send them my way.

Cordially,
JD

Reply | Threaded
Open this post in threaded view
|

RE: Embedding Lua for use in a MUD.

falknor1
Aye, Please do. :)

- JD

-----Original Message-----
From: [hidden email]
[[hidden email] Behalf Of Samson, Lyndon [IT]
Sent: Tuesday, March 13, 2001 10:43 AM
To: Multiple recipients of list
Subject: RE: Embedding Lua for use in a MUD.


I have some skeleton code for a LUA MUD somewhere, I'll dig it up it you
like.



-----Original Message-----
From: falknor1 [[hidden email]]
Sent: Tuesday, March 13, 2001 4:38 PM
To: Multiple recipients of list
Subject: Embedding Lua for use in a MUD.


Greetings list:

I am new around here and have looked through the archives on egroups a tad
bit, but did not find much.  I found a few threads talking about just how
suitable Lua is for this operation, but never did I see any mention of
available examples. Does anyone know of a freely available example one could
look at that involves embedding Lua into a C application?  I am looking to
use this language as scripting for my builders/designers.  I look at it like
this:  they are the one's designing it, if they can script it then it's more
likely that it will come out exactly as they saw it than if I were forced to
do it off of sometimes inadequate descriptions.  The scripts will need to
modify game data real-time. Such as changing values of various things in the
game and adding new functionality such as commands.  If anyone has any
input, ideas, or links please feel free to send them my way.

Cordially,
JD


Reply | Threaded
Open this post in threaded view
|

Re: Embedding Lua for use in a MUD.

Magnus Lie Hetland
In reply to this post by Samson-3
----- Original Message ----- 
From: "Samson, Lyndon [IT]" <[hidden email]>

> I have some skeleton code for a LUA MUD somewhere, I'll dig it up it you
> like.
> 

Could you post a URL on the list or something? It sounds
like fun... :)

--

  Magnus Lie Hetland          http://www.hetland.org

 "Reality is what refuses to disappear when you stop
  believing in it"                 -- Philip K. Dick


Reply | Threaded
Open this post in threaded view
|

Re: Embedding Lua for use in a MUD.

Jason Clow
In reply to this post by falknor1
If you are using a Diku (or one of its derivatives) as your codebase, then you can snoop around on ftp.circlemud.com; there is an example of using Lua for triggers.
If you want to use Lua for scripting, I suggest you use Lua 3.2. It is much easier to embed than 4.0, IMO

--- "falknor1" <[hidden email]>
> wrote:
>Greetings list:
>
>I am new around here and have looked through the archives on egroups a tad
>bit, but did not find much.  I found a few threads talking about just how
>suitable Lua is for this operation, but never did I see any mention of
>available examples. Does anyone know of a freely available example one could
>look at that involves embedding Lua into a C application?  I am looking to
>use this language as scripting for my builders/designers.  I look at it like
>this:  they are the one's designing it, if they can script it then it's more
>likely that it will come out exactly as they saw it than if I were forced to
>do it off of sometimes inadequate descriptions.  The scripts will need to
>modify game data real-time. Such as changing values of various things in the
>game and adding new functionality such as commands.  If anyone has any
>input, ideas, or links please feel free to send them my way.
>
>Cordially,
>JD

==
|    ._  _   Lune MUW Server
|_(_)| )(/_  http://lune.sourceforge.net/

_____________________________________________________________


12