Embedding Scripting Languages Tutorials

Sage
Posts: 1,066
Joined: 2004.07
Post: #1
I'm trying to figure out which scripting language I want to use with my engine more: Lua or io. Both look good, but I can't for the life of me find any resources on how to embed these into my app to test them out and actually have them working. Any pointers to tutorials? I'm trying to use C/C++ as my programming language and, if you missed it, Lua or io for scripting.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
http://lua.org/
http://iolanguage.com/
no, seriously. It took me all of 2 minutes to find an example on the lua site, and maybe 5 to find it on the io site.
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #3
OneSadCookie Wrote:no, seriously. It took me all of 2 minutes to find an example on the lua site, and maybe 5 to find it on the io site.

Perhaps we need a tutorial on how to do searching Rasp

"When you dream, there are no rules..."
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #5
OneSadCookie Wrote:http://lua.org/
http://iolanguage.com/
no, seriously. It took me all of 2 minutes to find an example on the lua site, and maybe 5 to find it on the io site.
Still haven't found on at the io site (not saying you're a liar), and the one at the Lua site just seemed like they were throwing code out without really explaining what some of it did. Should've mentioned that I'd already seen the one on Lua's page.

Thanks for the link unknown, but that is definitely just some code without explanation.
Quote this message in a reply
Member
Posts: 168
Joined: 2004.10
Nibbie
Posts: 1
Joined: 2010.11
Post: #7
I would recommend Lua from my experience. It took me all of half an hour to imbed it and I've never looked back.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #8
Joseph Duchesne Wrote:I would recommend Lua from my experience. It took me all of half an hour to imbed it and I've never looked back.
And having used both Lua and Io, I recommend Io.

IIRC, the wikibooks page on Io has some info about how to bind C/C++ to Io, and the Io code itself shows how to embed the Io VM into any app (main.c) Smile

Or, alternatively, you can look at my obfuscated code:
http://dog4.dyndns.org:8080/cgi-bin/trac...es/io_vm.h
and http://dog4.dyndns.org:8080/cgi-bin/trac.../io_vm.cpp
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #9
Why do you recommend Io over Lua? Any features that are particularly useful and exclusive to Io?
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #10
Getting bindings done for Lua tends to be a huge pain. You have the choice of various generators which use either templates (luabind) or have you run an additional build phase that generates the bindings code from the prototypes (tolua).

You don't have any tools like that for Io, but the upshot is that you don't need them, because coding the bindings yourself is very manageable.

Also, Io has very little syntax as it is, everything is dynamic messages, which gives you a very flexible environment. Bindings exist for a lot of external libs, such as OpenGL, GLUT, Sockets, etc. Also, the Io garbage collection scheme is very easy to follow, as opposed to Lua's more convoluted methods used with the bindings tools.

So far, I've had no regrets dumping Lua in favour of Io. Io might be a little slower, but it is developed very actively, and getting faster constantly. Overall, Io is a cleaner and leaner language, and lets you get work done more effectively.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #11
What about OSC's favorite: Ruby? I've looked through some of his sample code in his public repository, and frankly, the binding of C++ classes to Ruby classes looks quite nicely done.

What say you, OSC?
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #12
Ruby, huh? I'll have to check into that. If it's cross-platform (which I assume it is) then it's a possibility for me. I'm still trying to figure out which scripting language to use based on the balance of easy to embed/use and speed/functionality. As long as I can find a decent way to script my game, I'll be all set.

So right now I have to look at Ruby, Io, and Lua. I suppose I probably should also look into Python, though I thought that was its own language and not embeddable (though I very well could be wrong). Any other well known, good scripting languages to embed in a C++ game?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #13
Python is perfectly well embeddable.

My feeling about language choice in this situation is that if you're looking for a little language to add flexibility to your project, you want something lightweight like Lua or Io. If you're looking for a high-level language to do the majority of your non-performance-critical code in, you want something more full-featured like Python or Ruby.

Lua and Python have the advantage over Ruby (not sure about Io) that you can ship the "compiled" byte-code, rather than the raw text source. I think Ruby's nice to embed, Python not so much. I agree with DoG that Lua's a bitch.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #14
For anyone else learning Lua embedding into C applications, check out these quick examples. I found them quite useful for a starting point.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #15
> I agree with DoG that Lua's a bitch.

Since there are no real well-known methodologies (that I know of) for hooking Lua into your host, it's a little hard to justify such a generality as `bitch'. I haven't had any problems with it myself, but I'm not trying to make it dance on a dime either.

Lua, Ruby, Python, and Io are the four favorites I have. I'm still with Lua, but they all have advantages and disadvantages. As OSC pointed out, a major one is compiled byte-code. You might not want to have your gamers, or whomever, messing with or cheating through your game logic. Not that byte-code is completely hack-proof though. And also, you can scramble your text files with the other languages anyway. But, still, precompiled byte-code does load faster. There are so many issues to weigh between those languages. I think they're all pretty nice in their own ways.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Suggested Scripting Language Talyn 11 5,198 Dec 31, 2008 03:26 PM
Last Post: Carlos Camacho
  Scripting Language Woes (Lua) Bachus 2 3,697 Oct 14, 2008 09:48 AM
Last Post: Blacktiger
  High and Low Level Languages FlamingHairball 22 10,501 Jan 8, 2008 10:23 PM
Last Post: PowerMacX
  What languages do you need for a MMORPG? Lost22 12 6,048 Nov 20, 2007 01:07 AM
Last Post: Lost22
  Re-introduction of low level languages? Duane 4 3,301 Oct 30, 2007 03:10 AM
Last Post: OneSadCookie