Possibilities and limitations (?) of the LUA interface

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
tknaps
Posts: 27
Joined: Fri Aug 06, 2004 2:31 pm
Location: Trondheim, Norway

Possibilities and limitations (?) of the LUA interface

Post by tknaps »

Last night I finally got around to download the latest beta, and start playing around with the scripting possibilities. I've read quite a bit of the LUA reference and some of the book, as well as tried to modify some of the supplied lua scripts. Anyway, I'll just try to imtemize some of my thoughts:
  • 1. First off a small bugreport. When I started modyfing one of the scripts I made a copy to a new folder in the scripts/menu/ folder to make it easy to find and distinguish from the "factory defaults". My new folder didn't make it to the menu in Moho though. I assume the "submenus" are hardcoded into Moho, but I think it would be great if the folders could be scanned and added to the menu at runtime, just like the scripts are. Alternatively, maybe there could be a separate top-level menu item for user defined scripts?

    2. I read about interfacing to C functions in the Lua manual, and immediately thought: "Is it possible to write Lua wrappers for C libraries, and make calls to these from Moho Lua scripts?" So, is it? :) That would make the possibilities nearly endless, even though such scripts would have to be supplied with a .dll. My first thought was to wrap parts of the Open Dynamics Engine in Lua, and then create a plugin to allow for bone animation governed by real physics. How cool would that be? Such an undertaking would require both the possibility of making calls to other C libraries, and that the Moho Lua API is fine grained enough.

    3. Has anyone thought of setting up a "Moho script repository"? I initially thought of setting up a Sourceforge project, but SF has had it's share of problems lately, and it would require every contributor to become part of the project, gain CVS write access and so forth. A bit too cumbersome in other words. Are there any plans at Lost Marble to set up a user repository? Or maybe one of the users have the possibility of hosting such a site?

    4. Finally, how long will it be till we can get our dirty hands on a Moho Lua API reference? ;)
Best regards,
Tarjei
User avatar
spasmodic_cheese
Posts: 330
Joined: Wed Aug 04, 2004 2:02 am

Post by spasmodic_cheese »

1) create a new folder inside the menu folder, shows up just fine. dont htinktheres a way to do top level menus.

thats all i can help with :cry:
User avatar
tknaps
Posts: 27
Joined: Fri Aug 06, 2004 2:31 pm
Location: Trondheim, Norway

Post by tknaps »

spasmodic_cheese wrote:1) create a new folder inside the menu folder, shows up just fine. dont htinktheres a way to do top level menus.
Really? Maybe I just forgot to restart last night then... Anyway, that's exactly the functionality I was looking for, thanks. I'll try again tonight.
spasmodic_cheese wrote: thats all i can help with :cry:
Hey, any help appreciated!

Regards,
Tarjei
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Post by Lost Marble »

1. The menu folders are not hard-coded in Moho - you should be able to create your own. I can think of a few reasons your script didn't appear:

A. You need to either restart Moho, or press Ctrl+F5 to reload the scripts.
B. Your script has a bug (syntax error probably) that prevented it from loading. In this case, a Lua error window would appear, so you probably would have noticed that.
C. If you modified an existing script, you need to give it a unique name. For example, if you copy and modify the lm_star.lua script, you need to change all references to LM_Star to a new name. Otherwise, what your script would do is to replace the LM_Star script, instead of loading a new one into Moho.

2. Good question. The answer is, "I'm not sure, but I don't think so." Lua is mostly designed to be embedded into an application. Then, that application can provide additional functions to Lua. This is how Moho works - it contains a Lua interpreter, and it provides functions for Lua to manipulate objects in Moho. I don't believe it is possible to expose C functions to Lua unless it is done by the host application (Moho, in this case).

3. We'll happily make user-created scripts available through the Lost Marble website. There's no place for them right now, but when version 5 is official... If you want to create your own repository, you're welcome to do that as well.

4. The Lua reference will be coming sometime after the manual, and most likely after version 5 is released.
User avatar
tknaps
Posts: 27
Joined: Fri Aug 06, 2004 2:31 pm
Location: Trondheim, Norway

Post by tknaps »

Thanks for the response LM.

1. This must've been A, i.e. I was too tired... :roll:

2. Hmm, maybe I've confused myself here. The way I was thinking about it was for Lua to act as sort of a man-in-the-middle. A host application can expose it's C functions to Lua, but AFAICS so can a host library? Something like: Moho <-> Lua <-> SomeCLibrary. Say SomeCLibrary has a single C function and also a Lua wrapper for this function, and is compiled into a dynamic library. Can said function be called from a Lua script run by the Moho Lua interpreter?

It's quite possible that I've confused myself though ;) but I'll investigate this further as time allows.

3. That sounds great, I'll hold my horses :) Better to collect all in one place if possible.

4. OK, I'll be patient :) A lot can be figured out by the supplied Lua scripts, but it's very cumbersome to hunt for something and then try to guess what it really does :)

Looking forward to 5 final! (as is everybody else I'd assume) :)
Tarjei
Post Reply