Exporting Functions to Perl
I've done some searches for perlxs in both the forums and the wiki and didn't really find anything useful to me. Are there any guides out there, or anyone willing to write a guide, on how to export C/C++ functions for use with the perl quest system?
I want to export the bot create and spawn functions (perhaps slightly modified, so the owner can be chosen in the quest script) so quests can reward bots. |
Quote:
I second this motion. |
It is really quite simple, but you will want to know at least a bit of C++ to be able to do it right. Basically, you can look for an existing function that might do something similar to what you are planning to do, and then see how that one was added and normally add the new one in almost the exact same way.
To see what is required for adding quest objects or quest commands, simply look at the changelog here and find one that only mentions adding some new quest object/command: http://code.google.com/p/projecteqemu/source/list Here is a simple one I recently added: http://code.google.com/p/projecteqem.../detail?r=1441 Then, once you find your example, you can click the "Diff" link at the end of each file name one at a time and inspect exactly what was changed/added. Here is a link to the diff of the file from the example link above: http://code.google.com/p/projecteqem...e/perl_mob.cpp In this case, you see the first part of the change starting after line 1482. Then, if you scroll down to the bottom, that is where the second part of the change is. There are a few different files that you might need to change depending on what command you are adding. I don't think bots have their own perl_bot.cpp file yet, which I am guessing is why there aren't perl commands for them yet. I haven't messed with bots at all, but maybe some of their commands would work in perl_mob.cpp, I dunno. You may be able to add commands for them in the questmgr.cpp/questmgr.h/perlparser.cpp files similar to the diff posted in this thread: http://www.eqemulator.org/forums/showthread.php?t=31286 I have learned C++ purely from examples, and the quest stuff is fairly easy to figure out once you read through a few examples to see what is going on. A full guide on how to write them isn't likely to happen, as you might as well be taking a full C++ course if you want everything to be covered. Most of the stuff is the same, but there are a few key points you need to know when adding new quest commands. Honestly, I don't even fully understand every bit of it, but I know enough to make them work just fine the way they should and do it with relative ease now. |
^ this is actually the wrong way and very error prone - it took me a while to figure out how this should work, since nobody documented it =)
see the folder http://code.google.com/p/projecteqem...r/utils/perlxs see the dummy header for client.h for example - put all method signatures in there you want to export after that run ./convert client.h Client it will create perl_client.cpp directly modyfing perl_client.cpp is a bad idea, because everything somebody manually put in there will be overwritten - hence the big fat warning in this file " This file was generated automatically by xsubpp version 1.9508 from the 2 * This file was generated automatically by xsubpp version 1.9508 from the 3 * contents of tmp. Do not edit this file, edit tmp instead." Do not edit.... The plus site of this is, that you can easily remove/add functions you want to export to the dummy header file - you dont need to export every function. setting up the environment for perl is another thing, you need xsubpp, its easier on unix than on cygwin/windows |
LOL, wow, I always wondered what that folder of files were for...
At this point, it would be a bit of a pain to start using that way to generate the perl export files again. Doing them manually is really quick and easy though. Sounds like if someone wanted a particular function to be exported and didn't know how to write it themselves, they could just use that script and then pull out just the 1 function they are wanting and add that to the normal perl_client.cpp manually. By making them manually, you get more flexibility and can set defaults if the function doesn't already have them and make optional fields in the commands. Another nice thing about doing them manually is that the function itself can be changed in the source without having to change the order of the arguments in the perl function, so you don't mess up existing quest scripts. Maybe I should run that script and see how well it works. Might make it easy to add a bunch of the lesser needed functions from mob/client/npc. Then just merge in the stuff that doesn't exist already. |
Using xsubpp will generate incorrect results at this point. It was something that was lost in the conversion to SVN. I had trouble keeping people to keep up the header files so I just gave up.
All for the better really because it allows far more flexibility this way and it really speaks to the utter piece of shit perl's C/C++ interface is that doing it this way is "wrong". |
All times are GMT -4. The time now is 09:16 AM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.