|
||
|
What is Lua Plugin?
Lua Plugin is a REALbasic plugin that allows execution of Lua scripts from within a REALbasic app. For documentation on the Lua language please see www.lua.org. The API is similar to the RBScript API. There is a Print event that is called when Lua wants to print something, and an Input event when Lua needs input from the user. Lua Plugin has been built with Lua 4.0.
Drag Lua Plugin to the Plugins folder in the REALbasic folder that contains the REALbasic app. Launch REALbasic. A new Lua class is now available. There are two ways to instantiate Lua. Either make a subclass that will appear in the project window. Or, command-click in a window and make a new Lua directly. I prefer the second way as Lua will appear in the window's list of controls and creation and deletion is handled automatically. There are two Lua events: Print and Input. Print will be called in response to the print() Lua method. Input will be called in response to a new Lua method that I have added called input(). Note that, at present, the Lua IO library has not been included in the plugin. I plan to include it in the future, but, for technical reasons, I have decided to ship Lua Plugin without IO library support. For those interested in the technical details of the IO library situation, here goes. I have an app I have released in the past called Stella, which is a Lua development environment. I do support some of the IO library in Stella. But that support is a horrible hack. I did it by creating my own console functions to be called by Lua's standard IO calls. The problem with that approach is that when Lua calls a standard IO function, such as fputs(), and control reaches my console function, I have no way to know which instantiation of the Lua class in REALbasic is responsible for the IO call. So I squirrel away in a static variable (VeryBad™) a pointer to the currently executing Lua. Then when my implemention of ReadConsoleChars() gets called, I assume that the saved Lua is the caller. But this just can't work if there are multiple Luas all executing concurrently. This may not be possible given the current state of the code, but it just isn't safe and I don't like it. So in Lua Plugin, I punted on the IO stuff and instead created a new input() Lua method that will cause the Input Lua class event to fire. This mirrors the way RBScript does its thing.
Note that although I have modelled RBScript for Lua Plugin's Input and Print events, I have not implemented the other features of RBScript, such as the ability to execute only part of a script. I will look into that for a future release.
If you have downloaded the version of the plugin that comes with source, here are a few notes:
Acknowledgments Lua 4.0 is copyright © 1994-2002 TeCGraf, PUC-Rio and is being developed by Waldemar Celes, Roberto Ierusalimschy, and Luiz Henrique de Figueiredo (see http://www.lua.org). REALbasic is copyright © 1997-2002 REAL Software, Inc. (see http://realbasic.com/).
|