View previous topic :: View next topic |
Author |
Message |
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Sat Jan 02, 2010 4:03 Post subject: NWNX Ruby |
|
|
I've ported NWNX Ruby to NWNX4.
You can download it here:
http://nwn.virusman.ru/trac/nwnx4/downloads
NWN2 1.23.1765 ONLY at the moment.
And it requires the new NWNX Core (also available at the above link).
No documentation yet.
NSS library: http://nwn.virusman.ru/trac/nwnx4/browser/trunk/bin/dist/nss/nwnx_ruby.nss?rev=82
An example:
Code: | # In NWNX Ruby, you can use almost all NWScript functions
# for example:
oPC = GetFirstPC()
SendMessageToPC(oPC, "This is a test message")
# also, you can define custom functions
def HappyNewYear
oPC = GetFirstPC()
while GetIsObjectValid(oPC)
SendMessageToPC(oPC, "Happy new year!")
oPC = GetNextPC()
end
end
# all other features (like OO, arrays, blocks, etc.) are also available
# you can use any of the Ruby libraries, including Sequel (ORM library for databases)
# and nwn-lib (it can open and edit GFF, ERF, TLK, BIF files - complete replacement for LetoScript) |
One of the main advantages is that Ruby code can be updated/generated without updating the module or restarting the server. _________________ In Soviet Russia, NWN plays you! |
|
Back to top |
|
|
PNJ
Joined: 30 Jun 2007 Posts: 67
|
Posted: Sat Jan 02, 2010 20:04 Post subject: |
|
|
Nice, i hope to found some documentation for bic editing |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Sat Jan 02, 2010 20:45 Post subject: |
|
|
nwn-lib docs:
http://nwn-lib.elv.es/ _________________ In Soviet Russia, NWN plays you! |
|
Back to top |
|
|
kuscotopia
Joined: 10 Aug 2009 Posts: 11
|
Posted: Wed Apr 07, 2010 1:38 Post subject: |
|
|
You probably could of guessed I would be back with more questions .
First, thank you virusman for pointing me towards your ruby plugin & nwn-lib. The proper bits are installed and xp-ruby.txt reports that the plugin is successfully initialized.
Onto the question, I would like to verify some assumptions (as I haven't found any documentation yet). In the example below:
Code: |
string NWNXRuby_Eval(string sCode);
string NWNXRuby_Eval(string sCode)
{
SetLocalString(GetModule(), "NWNX!RUBY!EVAL", sCode);
return GetLocalString(GetModule(), "NWNX!RUBY!EVAL");
}
|
What is sCode? A line of ruby code to be interpreted? Name of a ruby script? If it is a segment of ruby, does nwnx4-ruby cause the script to block until ruby has finished interpreting the code? Or is there a race condition between evaluating the ruby expression and checking its return value? |
|
Back to top |
|
|
kuscotopia
Joined: 10 Aug 2009 Posts: 11
|
|
Back to top |
|
|
Hialmar
Joined: 15 Jun 2005 Posts: 32
|
Posted: Sat Nov 27, 2010 16:41 Post subject: |
|
|
ALFA is currently trying to have the ruby plugin working with the last version of Ruby (1.9.2-p0).
We have some crashes in the NWN2 server when initializing ruby.
It happens only in the NWN2server.exe. If I try to load the plugin in another program everything works and I can run ruby code in it (but obviously no NWScript code).
Anyone have ideas how to debug this problem ?
I have tried debugging nwn2server.exe before it crashes but it's a pain in the neck without the PDB.
If nothing works I will try to have the ruby interpreter in another process and use some kind of RPC over shared memory to make it work.
- The plugin would call Eval(ruby_code) in the Ruby interpreter process ;
- The Ruby interpreter process would then call back NWScript functions in the plugin so that they are executed in the nwn2server.exe.
It's quite complex and might have efficiency issues so debugging the plugin with the last version of Ruby is my priority here. _________________ Hialmar, A Land Far Away Infrastructure Administrator |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Sat Nov 27, 2010 17:41 Post subject: |
|
|
What do you need 1.9 for? _________________ In Soviet Russia, NWN plays you! |
|
Back to top |
|
|
Hialmar
Joined: 15 Jun 2005 Posts: 32
|
Posted: Sat Nov 27, 2010 19:49 Post subject: |
|
|
Regalis (one of our members) woul like some stuff from Ruby on Rails that seem only available in recent versions.
What is the last version of Ruby that works with the plugin ?
Thanks _________________ Hialmar, A Land Far Away Infrastructure Administrator |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Sun Nov 28, 2010 19:26 Post subject: |
|
|
The only version I've compiled and tested it with was 1.8.6.
A couple of weeks ago Basileus contacted me and asked to switch NWNX4 Ruby to 1.9 or 1.8.7-mingw32. I recompiled with 1.8.7, but it didn't work on his server.
Some header editing is required for 1.9 upgrade, and obviously testing/debugging will be necessary.
If you've successfully compiled the plugin with 1.9 and need help with debugging, branch the existing code into /branches/xp_ruby-1.9 and upload your code there.
Unfortunately, I won't have enough time to do full testing for at least 2 weeks, but I might look at the code and suggest something. _________________ In Soviet Russia, NWN plays you! |
|
Back to top |
|
|
Hialmar
Joined: 15 Jun 2005 Posts: 32
|
Posted: Sun Nov 28, 2010 22:31 Post subject: |
|
|
Did it.
You'll find everything in /branches/xp_ruby-1.9 as you requested.
In order to link with ruby1.9.2-p0 you'll need to comment out the DLLMain function in the ruby.c file.
I have included the ruby.c file I modified.
If you want the static lib and its pdb please ask and I'll put it on one of my websites.
Thanks a lot for your help.
I'll continue to debug it. I have found a way to debug it with vs2008 by generating an exception right before I want to debug and attaching to nwn2server.exe
Edit: Basileus and Regalis are the same person. _________________ Hialmar, A Land Far Away Infrastructure Administrator |
|
Back to top |
|
|
Hialmar
Joined: 15 Jun 2005 Posts: 32
|
Posted: Sun Nov 28, 2010 23:25 Post subject: |
|
|
I have found the issues I think.
Here is the code that causes problem:
In io.c:
Code: |
rb_define_variable("$stdin", &rb_stdin);
rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO, "<STDIN>");
|
The prep_stdio does:
Code: |
static VALUE
prep_stdio(FILE *f, int fmode, VALUE klass, const char *path)
{
rb_io_t *fptr;
VALUE io = prep_io(fileno(f), fmode|FMODE_PREP, klass, path);
GetOpenFile(io, fptr);
fptr->stdio_file = f;
return io;
}
|
GetOpenFile does the following:
Code: | void
rb_io_check_closed(rb_io_t *fptr)
{
rb_io_check_initialized(fptr);
if (fptr->fd < 0) {
rb_raise(rb_eIOError, "closed stream");
}
}
|
Which raises the exception as stdin is obviously closed in nwn2server.exe.
I will try to modify this behavior. _________________ Hialmar, A Land Far Away Infrastructure Administrator |
|
Back to top |
|
|
Hialmar
Joined: 15 Jun 2005 Posts: 32
|
Posted: Sun Dec 05, 2010 15:05 Post subject: |
|
|
It works now.
I disabled stdin/stdout/stderr in io.c using a global int variable.
The two files that do that are ruby.c and io.c and they are in the ruby1.9modifications folder. _________________ Hialmar, A Land Far Away Infrastructure Administrator |
|
Back to top |
|
|
Hialmar
Joined: 15 Jun 2005 Posts: 32
|
Posted: Sat Dec 11, 2010 16:23 Post subject: |
|
|
We found a bug with strings like the following,
"SendMessageToPC(GetFirstPC(), %q'Hello World')"
which crashed the plugin because of the %q and the fact that xp_ruby.dll logs strings to eval to the xp_ruby.txt log file using fprintf which interprets all % commands and crashes on the %q.
I have made a log method that outputs code to eval with a fputs in order not to interpret the % commands.
I have committed the files the svn as well. _________________ Hialmar, A Land Far Away Infrastructure Administrator
Last edited by Hialmar on Sat Jan 08, 2011 23:02; edited 1 time in total |
|
Back to top |
|
|
Hialmar
Joined: 15 Jun 2005 Posts: 32
|
Posted: Sat Jan 08, 2011 23:02 Post subject: |
|
|
I have corrected a bug that caused crashes when loading ruby files.
It's in the SVN now.
There is one more file (win32.c in the win32 sub-directory) that needs to be modified in the ruby distribution. _________________ Hialmar, A Land Far Away Infrastructure Administrator |
|
Back to top |
|
|
Dethia
Joined: 01 Oct 2009 Posts: 23
|
Posted: Sun Mar 06, 2011 20:51 Post subject: |
|
|
Is anyone using this for nwn2 along with elven's nwn-lib?
I am trying to do so but the first trouble I come across is loading the required libraries. Note I am not too familiar with ruby syntax though I did read some of the book.
In short I need to do:
require 'rubygems'
require 'nwn/all'
to load the libraries but get the following error:
Code: | NWNX4 Ruby Plugin V.0.1.0
(c) 2010 by virusman (virusman@virusman.ru)
visit us at http://www.nwnx.org
* Module loaded successfully.
(S) Request: "EVAL"
(S) Params: "require 'rubygems'"
Error 6 while evaluating a Ruby expression: require 'rubygems'
(S) Request: "EVAL"
(S) Params: "require 'nwn/all'"
Error 6 while evaluating a Ruby expression: require 'nwn/all'
* Plugin unloaded.
|
My guess is there is a pathing issue, as in the plug-in doesn't know where the ruby bin directory is, but how do I specify it? any help is appreciated. |
|
Back to top |
|
|
|