Scripting language for C game

Member
Posts: 28
Joined: 2006.12
Post: #1
Is there a way to easily combine a scripting language with C? I want to be able to call C functions that I right thru the scripting language and vice versa. Is it even possible to call your own C functions from a scripting language?

What is the ultimate answer to Life, the Universe, and Everything?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Yes . . .
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #3
. . . That's what scripting languages are all about. I learned how to do it initially from a book called Game Scripting Mastery (not Mac-oriented, but still applicable, and all C). This subject has been beat up plenty already. Search the forums for more info on how to do it.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
Im not sure why those two are trying to make you feel like youve asked a silly question, but take it from me you havent. Doing that kind of thing can really improve the efficency of writing a game (think compile & test vs quit & test Wink )

This is a great language for exactly that purpose
http://www.lua.org/

Its really easy to get set up with, and you can integrate it with your game engine for speed & efficiency.

This game I wrote
http://fax.twilightcoders.net/N0x35C49E/
the engine is C and the game logic is lua, it worked out really well. (and the source code is available as well)

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 715
Joined: 2003.04
Post: #5
We use C with Lua too.
Have a peak at the innards of this _ iFly_Universal012207app.zip

Somewhere on lua.org is a list of products using it, astounding.

Did I see that 70% of Adobe Lightbox is coded in LUA? I think so.
Quote this message in a reply
Member
Posts: 37
Joined: 2006.08
Post: #6
I third a vote for Lua.

I think the combination of Lua and C is something that is better than C++ for making games. C gives you the flexibility to tie in with practically any OS and call OpenGL natively, as well as use libraries like libpng and OpenAL. It's also fast as heck. All of the logic in Psychonauts was done in Lua. Only the rendering/sound engine was done in C++.

I <3 Lua.

I have successfully replicated the basic functionality of Processing with C and Lua as of yesterday (setup, draw, keydown, stroke, fill, line, rect, beginShape, etc.). It's good stuff! I've got some great ideas with Lua that I think could work really well.
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2010.11
Post: #7
I have to say, I'm most happy with C and Lua. I had full lua support in my game inside of 4 hours. It's flexible, powerful, fast and easy to pick up. Give it a shot Wink It's worth the money Rasp *




*it's free
Quote this message in a reply
Member
Posts: 104
Joined: 2007.01
Post: #8
djork Wrote:C gives you the flexibility to tie in with practically any OS and call OpenGL natively, as well as use libraries like libpng and OpenAL. It's also fast as heck.

C++ works with every OS that C does.

And I'm not sure what you mean by "natively". A C++ program can use OpenGL, OpenAL, or any other C library without any problems at all. There's no performance penalty for calling C functions from C++ programs. In fact, the resulting machine code is the same regardless of whether you're you're writing C or C++.

As far as speed goes, modern C++ compilers generate very efficient machine code, so there really isn't any difference in speed between C or C++. Granted, an object-oriented C++ program can be slow if it isn't well written, but I've seen many badly written C programs that are slow. It all comes down to knowing what you're doing; it has nothing to do with C versus C++.
Quote this message in a reply
Member
Posts: 37
Joined: 2006.08
Post: #9
GolfHacker Wrote:C++ works with every OS that C does.

And I'm not sure what you mean by "natively". A C++ program can use OpenGL, OpenAL, or any other C library without any problems at all. There's no performance penalty for calling C functions from C++ programs. In fact, the resulting machine code is the same regardless of whether you're you're writing C or C++.

As far as speed goes, modern C++ compilers generate very efficient machine code, so there really isn't any difference in speed between C or C++. Granted, an object-oriented C++ program can be slow if it isn't well written, but I've seen many badly written C programs that are slow. It all comes down to knowing what you're doing; it has nothing to do with C versus C++.

I wasn't saying that C was better than C++ for making games. I was saying that C with Lua scripting is better for making games than C++. Smile

Trust me, I know the difference between C and C++, and I know what they share as well.
Quote this message in a reply
Member
Posts: 28
Joined: 2006.12
Post: #10
Thanks I guess it is just Lua as far as scripting goes. I'll check it out.

What is the ultimate answer to Life, the Universe, and Everything?
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #11
unknown Wrote:Im not sure why those two are trying to make you feel like youve asked a silly question, but take it from me you havent...

I'm surprised I missed this bit of your response earlier, but I take it `those two' includes me. I'm a little offended by your insinuation that I implied he was being silly. My `. . .' prefix was to denote that I wished to add at least a little more to OSC's curt response without going into exhaustive elaboration. Yeah, sometimes I restrain myself from blabbering believe it or not. However, if I were to blabber a bit more about it, I'd say Lua is my preferred language of choice as well.Wink
Quote this message in a reply
Member
Posts: 28
Joined: 2006.12
Post: #12
Oops I didn't realize I was posting to Porting. I thought I was posting to Programming Languages. I'm very sorry.

What is the ultimate answer to Life, the Universe, and Everything?
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #13
Are you all happy with Lua as a language? I bought PIL a year or so ago and read through it ( and did some testing of my own ) and by the end I was thinking: "I wouldn't touch this language with a 10 foot clown pole".

Python & Ruby are beautiful languages. Lua may be practical, but it smells to me.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #14
I much prefer lua over python and ruby especially for this purpose, but overall as well. You might be confusing a language with the libraries it has, its important to make the distinction.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #15
Agreeing with Shamyl here, Lua's syntax is downright dysmal.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Ruby for scripting my game engine... djork 13 9,145 Aug 20, 2006 06:48 PM
Last Post: OneSadCookie
  RGSS: Ruby Game Scripting System Carlos Camacho 5 9,819 Jul 31, 2005 06:26 PM
Last Post: Carlos Camacho