About NWNX-Leto
NWNX-Leto is a module (plugin) for NWNX2, allowing you to run LetoScript from NWScript. NWNX2 was developed by Ingmar Stieger (Papillon), papillon@blackdagger.com. You will need NWNX2 for NWNX-Leto to be of much use to you. NWNX now has its own site, including forums. (The majority of discussion on NWNX-Leto in particular is on the Leto forums.)
This is build 03 of the plugin, with LetoScript support compiled in from build 4.0.24 of the LetoScript engine. There has been some confusion about the difference between these two numbers / versions / DLLs. The difference between them is in fact quite simple:
nwnx_leto.dll/so is bridge code that is written in C++ (MSVC on Windows, ANSI C on Linux) and accomodates the differences between NWNX's C++ code, and LetoScript's Delphi code. These differences are prototypical, and don't change from release to release - they may never change, for that matter. The code has nothing to do with the LetoScript engine itself, so you don't need a different version for Phoenix or Unicorn. Instead, you need a different LetoScript lib:
LetoScript.dll/so is the entire LetoScript engine (the equivalent of Moneo) in a library. This is what the "+24" in the name means - this version of the library is the same code as for Moneo 4.0.24. (And exactly the same code, with but a wrapper around it so that NWNX!LETO commands can reach it.) If your code uses Phoenix syntax, you need build 18 of this library, instead, which is no longer supported or available on SourceForge (to clear up much confusion). If you need this library, e-mail me and I can send it to you, along with full source code.
To summarize, each platform consists of two library files: DLLs for Windows, and SOs for Linux. If you aren't a developer, all you need to worry about is copying the files files for your platform into your NWN directory (where you have NWNX2 installed) in order to get it to "work".
For the Windows platform, the files you need are nwnx_leto.dll, and LetoScript.dll.
For the Linux platform, the files you need are nwnx_leto.so, and LetoScript.so. Note that nwnx_leto.so was compiled around the new features in beta 5 pre 2, so if you want to recompile it, you will need that source or better. You will also need to initialize NWNX2 with "NWNX!INIT" "1" in your OnModuleLoad event.
NWNX-Leto will create a logfile, nwnx-leto.txt, which can provide you with clues in the event that the plugin does not start.
The namespace for the plugin is LETO. The functions it currently supports are:
void main() { SendMessageToAllDMs("Firing LetoScript test..."); string LetoTest; SetLocalString(GetModule(), "NWNX!LETO!SCRIPT", "<file:open BOB 'g:/nwn/localvault/bob.bic'><FirstName> <LastName>"); LetoTest = GetLocalString(GetModule(), "NWNX!LETO!SCRIPT"); SendMessageToAllDMs("Result: #" + LetoTest + "#"); }
There are a lot of additional details on these mutli-threading functions. Please refer to the documentation for a much more in-depth explanation, and some examples. (If you prefer to learn by practical application, take a look at "zb_queue" in ZombieBench.)
There are three params you can give to LOG, which are Enable, Dir, and File. Setting Enable to "true" or 1 will turn on logging. Likewise, "false" or 0 turns it off again. Dir and File tell NWNX-Leto where you want your logfile. You should probably specify at least a directory, though the filename is optional (defaults to letoscript_log.txt).
Logging examples:
// Turn logging on: SetLocalString(GetModule(), "NWNX!LETO!LOG", "Enable=1, Dir=g:/nwn/leto/logs"); // You can change the dir or file while logging is on: SetLocalString(GetModule(), "NWNX!LETO!LOG", "File=letoscript.log2.txt"); // And this shuts it down: SetLocalString(GetModule(), "NWNX!LETO!LOG", "Enable=0");
Remember that logging comes at a penalty. It involves some rather heavy file I/O, and should only be used for debugging cranky scripts (which is when you put those scripts in Moneo to effectively troubleshoot them). Leave it off for a production server.
Known limitations
Technical details
(These notes are old, and probably need updating.)
There are two libraries (DLLs / SOs) involved because Leto and LetoScript are written in Delphi, whereas NWNX is written in C. This requires a bridge DLL be compiled in the native environment (MSVC on Windows), which is nwnx_leto.dll/so. The bridge DLL talks to the Delphi DLL, LetoScript.dll. Since I don't own a copy of MSVC, I wrote all of the source for nwnx_leto in Notepad, had a volunteer on the APS/NWNX Guild compile it for me (thanks Taryn Winterblade!) and then designed the LetoScriptDll library to talk to it. For Linux, I scoured Google for sufficient examples and then re-wrote the source to compile with gcc. There are still two libraries involved to keep it more aligned with the Windows release, and because a bridge design pattern is actually useful in terms of de-coupled development of each component.
Note how the name of the Delphi library is "LetoScriptDll". This is so there is no confusion with the language, LetoScript, by calling it just "LetoScript". This means that compiling LetoScriptDll.dpr will give you LetoScriptDll.dll / libLetoScriptDll.so, however, and you MUST rename it to LetoScript.dll / LetoScript.so. nwnx_leto.dll/so is very specific about this, it wants a library named LetoScript.dll (on Windows) or LetoScript.so (on Linux).
To recompile nwnx_leto.so and LetoScript.so, you will need the Linux NWNX source. Stick the files in your nwnx-leto-so-linux directory into a subdirectory of nwnx2 such as "letoscript", then edit configure.ac as necessary. Then run autoconf && ./configure && make && make install. If you need help or more information on this, please make a post on the weathersong forums.