01 Jan, 2011, RoFAdmin wrote in the 1st comment:
Votes: 0
Hey Everyone-

So today i decided my goal was embedding a nice scripting language into my server. I initially figured i would go with lua, since i have previously written scripts before in lua for other applications. I however had not anticipated the sheer pain in my rear that lua would be to incorporate into my program. So now im thinking perhaps there are better options. So i turn now to you folks an ask you what are you suggestions for a scripting language to put in, and why?

Things im looking for. How easy is it to get the scripting language working in c++? How much overhead is involved in getting my app and the scripting language working together? What are the reasons that would make you personally pick said language over others?

Hope to hear some good ideas.
01 Jan, 2011, Chris Bailey wrote in the 2nd comment:
Votes: 0
I don't have any good advice on the matter, but I know that Ruby plays well with C. There have been a few successes with Lua and from what I have gathered it might be the simplest to integrate.

This article has some information on embedding Lua. Maybe it can help.
01 Jan, 2011, RoFAdmin wrote in the 3rd comment:
Votes: 0
Hey,

Thanks for the link, that will come in handy if i can ever figure out why its complaining about undefined references to the lua functions. :(
The strange thing lua is working fine itself, some im unsure that its the installation. i can start up the lua interpreter and run scripts just fine. Just seems to
be an issue something else.
01 Jan, 2011, Chris Bailey wrote in the 4th comment:
Votes: 0
Random Website said:
IMPORTANT! You need to link you program with libdl besides liblua. I believe the use of luaL_openlibs() are calling dlopen, dlclose, dlerror, dlsym which needs libdl.

Else you may get linking error like this:

/usr/local/lib/liblua.a(loadlib.o): In function `ll_loadfunc':
loadlib.c:(.text+0x917): undefined reference to `dlsym'
loadlib.c:(.text+0x924): undefined reference to `dlerror'
loadlib.c:(.text+0x9fc): undefined reference to `dlopen'
loadlib.c:(.text+0xa11): undefined reference to `dlerror'
/usr/local/lib/liblua.a(loadlib.o): In function `gctm':
loadlib.c:(.text+0x101e): undefined reference to `dlclose'
collect2: ld returned 1 exit status


Stumbled across this…any relevance?
01 Jan, 2011, RoFAdmin wrote in the 5th comment:
Votes: 0
Problem solved by tyche, but im still interested in other peoples input on scripting languages.
01 Jan, 2011, David Haley wrote in the 6th comment:
Votes: 0
Lua is exceedingly easy to embed into C/C++; that's what it was designed for. It's also very lightweight, fitting into several hundred kilobytes rather than megabytes upon megabytes. The language size might or might not matter to you, depending on your application, target platform, etc.

I prefer Python as a language to write whole applications in, but if I were to embed a scripting language (as I have several times now) it would definitely be Lua. I've never worked with Ruby and C so I don't have much to say there.

The amount of overhead for you depends on how tightly and naturally you want the languages to be integrated. For example, the scripting language obviously has no notion of your C++ data structures or object oriented classes. So if you want those to be exposed somehow, you have work to do. This might involve creating a proxy object in the scripting space that hooks into C++ to get results and then forward those back. Of course, you don't necessarily need such tight integration depending on where you're using the scripting language. Mudprog gets along without it, for instance, even though you can see its limitations pretty quickly.

It's worth noting that Lua as a language is realy quite bare-bones. It has no notion of classes, for example. You can easily write the mechanisms yourself, or take any number of the existing implementations out there. But it requires a certain mentality shift in that you're writing low-level mechanisms in a high-level language. (This is one reason why I don't like it for writing entire applications.)
01 Jan, 2011, RoFAdmin wrote in the 7th comment:
Votes: 0
LUA was very easy to embed once it was mention i was forgetting -llua in my makefile.


The down side really seems like handling anything to do with classes in it, there are work aroudns, but they seem hackish at best.

So that leads me to the question are there any languages that make dealing with classes easier?
01 Jan, 2011, David Haley wrote in the 8th comment:
Votes: 0
They're not hackish in the slightest. In fact, you are given the mechanisms to implement any number of OOP approaches from your language of choice. Whether or not this is what you want to do is another story, but it is most certainly not a collection of "hacks". I would encourage you to think about what you actually need; Lua is a tool that addresses a need extremely well, but you obviously need to understand your need first before seeing if Lua is what you want. You might find that once you get over your initial surprise and unfamiliarity, it addresses your needs – or you might not. But don't trust initial impression based on not understanding the mindset.

For example, what will you be using classes for? You have a scripting language inside a host application. The host application will have all sorts of classes. Where will the scripting language use them? Do you actually need classes or something else?

Python and Ruby both provide a class mechanism, as do any number of other languages.

And by the way, it's Lua, not "LUA". It's not an acronym; it means "moon" in Portuguese.
02 Jan, 2011, Tyche wrote in the 9th comment:
Votes: 0
RoFAdmin said:
The down side really seems like handling anything to do with classes in it, there are work aroudns, but they seem hackish at best.

So that leads me to the question are there any languages that make dealing with classes easier?


Not that I know of….perhaps Sigma.
Hell C can't even deal with C++ classes without "hackish" solutions.
However, I've successfully used SWIG in the past with both C and Ruby to build wrappers to C++.
Its supposed to work with LUA.
02 Jan, 2011, chrisd wrote in the 10th comment:
Votes: 0
As David says, Lua was designed specifically for this purpose, and should therefore be recommended.

Python is a neat alternative, though I doubt you'd find it as easy to embed as Lua. NakedMud is a C codebase with embedded Python, if you need an example.
02 Jan, 2011, Davion wrote in the 11th comment:
Votes: 0
chrisd said:
As David says, Lua was designed specifically for this purpose, and should therefore be recommended.

Python is a neat alternative, though I doubt you'd find it as easy to embed as Lua. NakedMud is a C codebase with embedded Python, if you need an example.



If you use something like Boost::Python, it's actually really simple. I was able to expose a whole bunch of ROM to a python interpreter with very minimal code using the boost libs. Of course, Python leaves much to be desired in the sandboxing department. You shouldn't give access to python scripting to someone you don't trust with essentially, total access to the shell.
02 Jan, 2011, JohnnyStarr wrote in the 12th comment:
Votes: 0
Lua is very easy to deal with. I recommend studying up on how Lua works under the hood.
The documentation provided in both the 5.1 book and the reference manual isn't very detailed
on embedding Lua. The examples are enough though to get you going. If you have any specific
questions feel free to PM me. I've been down that road and have enjoyed the challenge.
02 Jan, 2011, David Haley wrote in the 13th comment:
Votes: 0
The sandbox is a very good example of something that Lua does much better than Python and Ruby. You can control exactly what functions are exposed to the environment, and even introduce hooks that interrupt the interpreter every X instructions to make sure that scripting code doesn't run forever.
0.0/13