Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Scripting Language Question  (Read 7356 times)

0 Members and 1 Guest are viewing this topic.

HoodedSpectre

  • Newbie
  • *
  • Posts: 22
    • View Profile
Scripting Language Question
« on: December 22, 2016, 01:00:33 am »
Which scripting language is your preferred language to use? I've heard a lot of good things about Lua I just don't have a lot of time so I want to make sure I make a good choice.

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Scripting Language Question
« Reply #1 on: December 22, 2016, 07:01:54 am »
Lua is just perfect in almost every way.
  • It's fast (the fastest of them all, especially LuaJIT, but default Lua is very fast too)
  • The language is simple, but powerful enough to implement everything. Writing Lua is similar to writing pseudo code. It just works.
  • Easy to integrate with C++ (see sol2)
  • Runs on almost everything (written in ANSI C)
  • It's possible to control how it uses memory
  • Used by tons of games (AAA and indie), which is not coincidence
I've been working with Lua for 3 years and having a great time with it, so feel free to ask any questions if you have any.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Scripting Language Question
« Reply #2 on: December 22, 2016, 10:16:22 am »
Two more alternatives (in the end it's mostly about which language flavor you'd like to use):
  • Squirrel Script is very similar to Lua regarding integration and implementation details, but its syntax closer resembles C++ and Javascript.
  • Javascript may also be embedded using different libraries (like Google's V8 or Microsoft's ChakraCore), although the big disadvantage here is that some things might be more complicated to do or less documented (but getting a basic engine running is actually pretty easy). On the plus side you get a very popular language with tons of ready to use reusable scripts.
So far I've always used Lua or Squirrel Script simply due to knowing the interfaces and stuff, but right now I'm in the process of trying to integrate ChakraCore into a simple game framework (once I've found enough timeā„¢).

sjaustirni

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
Re: Scripting Language Question
« Reply #3 on: December 22, 2016, 12:46:18 pm »
I'd consider using ChaiScript. C++ like, easy to integrate (header-only, so it comes with elevation of the compile time), easy to read and write. Requires C++14.

Example:
class Rectangle {
  attr height
  attr width
  def Rectangle() { this.height = 10; this.width = 20 }
  def area() { this.height * this.width }
}
var rect = Rectangle()
rect.height = 30
print(rect.area())

HoodedSpectre

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Scripting Language Question
« Reply #4 on: December 22, 2016, 09:26:55 pm »
I've been working with Lua for 3 years and having a great time with it, so feel free to ask any questions if you have any.

Awesome, thank you all for the suggestions. I think I'll try out Lua I've actually been following your top down 2D game Elias and it looks amazing. I'm just starting my Bachelor's Program so I want to study as much as I can outside of class. Do you have any good book suggestions? In regards to Lua?

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Scripting Language Question
« Reply #5 on: December 23, 2016, 10:30:58 pm »
Roberto's book for 5.0 is free: http://www.lua.org/pil/
Also, the official manual lists everything on one page: http://www.lua.org/manual/

I've got few links and notes saved about implementation of 5.1 too but that's not needed to just use it.
Back to C++ gamedev with SFML in May 2023

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Scripting Language Question
« Reply #6 on: December 24, 2016, 10:03:46 am »
I've been working with Lua for 3 years and having a great time with it, so feel free to ask any questions if you have any.
Awesome, thank you all for the suggestions. I think I'll try out Lua I've actually been following your top down 2D game Elias and it looks amazing. I'm just starting my Bachelor's Program so I want to study as much as I can outside of class. Do you have any good book suggestions? In regards to Lua?
You're welcome! And that you as well.
I agree with FRex, Roberto's book is amazing, but I recommend you to pick up the latest edition, it's written for Lua 5.2 which is a bit different from 5.0. http://lua-users.org/wiki/ is great as a learning resource as well.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Scripting Language Question
« Reply #7 on: December 24, 2016, 12:10:32 pm »
Or! You can try to write a smiple one yourself...

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Scripting Language Question
« Reply #8 on: December 24, 2016, 07:11:08 pm »
I recommend you to pick up the latest edition, it's written for Lua 5.2
The latest edition is out (August, this year) for Lua 5.3.

Keep in mind though that if you want to use LuaJIT, it's based on Lua 5.1, with a few backported features.

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Scripting Language Question
« Reply #9 on: December 25, 2016, 09:37:16 am »
I recommend you to pick up the latest edition, it's written for Lua 5.2
The latest edition is out (August, this year) for Lua 5.3.

Keep in mind though that if you want to use LuaJIT, it's based on Lua 5.1, with a few backported features.
Oh, didn't know about that! That's neat, gonna check it out. I had 2013 edition in mind when I wrote this.
And LuaJIT works with some Lua 5.2 features, but yeah, total support of Lua 5.1.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Scripting Language Question
« Reply #10 on: December 25, 2016, 09:04:04 pm »
LuaJIT is like 5.1 with some enhancements that don't break anything and with some optionally enabled ones that can break stuff: http://luajit.org/extensions.html

I personally sticked to 5.1 after learning 5.2 since they are so similar (changes between Lua versions are minor and/or arcane, like env change and fix of hashing algorithm vulnerability between 5.1 and 5.2, etc.) and since anything that you do in 5.1 is 100% doable with LuaJIT if I have problem with speed of Lua code itself.

5.1 was also around the longest. It came in 2006 and 5.2 only at the end of 2011 and 5.3 at the start of 2015. That, incremental GC (5.0 had a stop-the-world collector) and having that wonderful JIT (and for a while - Havok company had its own implementation of 5.1 too) is what made it such an important version, especially for games. I'm writing a paper about Lua 5.1 right now actually so I'm kinda familiar with its internals, design and history.

5.3 disappointed me with the addition of int number "subtype" (I liked that Lua only had floats), binary ops (I don't care, I'm not writing anything that crunches ints in Lua, I'd write a C function for anything like that, I see Lua as embedded language, not a language to do everything in, like Python) and so on.

This forum even has Lua code highlighting if you use that. :P

And speaking of Lua, it inspired another language called Squirrel, Source engine from Valve (Half Life 2, etc.) uses it. There is also the AngelScript that is unique because it's statically typed and looks like C++ (to some people that's a plus, to me it's not, if I wanted a static 'script' I'd use something else, the point of scripting to me is to be dynamically typed). I know Penumbra 1 used AngelScript, maybe next games from Frictional did too. I think it's really easy to use too. And they both look more like C/C++ (to me that's a downside because I want to never ever even think of the other language when coding in either C/C++ or my scripting one but many people like the syntax similarity).

I'm personally sticking to my Lua 5.1, it's like the king of small languages. And I like the syntax. I just hope a groundbreaking 6.0 doesn't happen soon because that'd split the user base so badly compared to just 5.x versions for which you can easily write small bits of code in C and Lua that are compatible with all three.

I also like that it's designed by three guys who clearly know what they are doing and that it was a language to solve real life practical problems from day one (or even day zero or day minus 100 if you consider the predecessors). It just sits in a really sweet spot, it's not a language that you could consider your main skill because it's too small, but in addition to C or when scripting (I've seen designer jobs at Klei, the makers of Shank and Don't Starve that were basically: experienced designer + Lua scripting skills) it's just so damn good.
« Last Edit: December 25, 2016, 09:20:02 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Scripting Language Question
« Reply #11 on: December 26, 2016, 11:31:44 am »
AngelScript can also be mentioned, although I personally haven't worked with it.

In my opinion, Lua is quite decent, even if they made a few awful design decisions (indexes...)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

HoodedSpectre

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Scripting Language Question
« Reply #12 on: December 29, 2016, 08:33:32 pm »
Thank you all for the feedback, taking into consideration everything I've read I think Lua 5.1 is what I will be studying. I plan on focusing primarily on C/C++ so given there are jobs that specifically state + Lua I think It would be a great use of my time, thanks again everyone.

 

anything