Can someone explain how bindings work exactly?

Started by
4 comments, last by kop0113 10 years, 8 months ago

I'm mainly interested in Lua so for this thread I'll explain in Lua. If SDL, C++ and such have Lua bindings, What's the difference between using a Lua game engine compared to using a Lua binding? What is a binding even I don't quite understand. Are game engines that use Lua, in a way, just Lua bindings that have extra features developed on top of the, like IDE's and Deployment tools etc? Am I getting this all wrong? Can someone please explain in retard mode because I think I've been reading the wrong stuff or I'm mentally ill because I'm really confused atm. Thanks a lot for any help

Advertisement

When people say "binding" in this way they mean that the library has a wrapper that exposes library functionality in the bound language. For example, SFML is written entirely in C++, which means that users would need to be able to read and code in C++ to use it. However, it also has bindings that let users access SFML's features through language-specific interfaces. I code in C#, so I use the C# binding and use SFML just like it was written in C# instead. If you like Lua, you can use the Lua binding.

Does that help?

-------R.I.P.-------

Selective Quote

~Too Late - Too Soon~

Not exactly tongue.png

What I mean is, so I don't even know any type of C but as far as I've heard, you can go in visual studio, code in C# and then build? So if you add a Lua binding to it, can I go in visual studio, go to lua.org and use the api to start coding in Lua? If that's true, and I feel like it's not that easy, then that's why I was asking about what's different between binding and game engine, besides IDE's and building tools or whatever they have bonus. I dont know if I'm getting my question across properly, sorry =(

Lua's internal working is different than C or C++'s internal working, so for you to call a C++ function from Lua, you have to "bind" the function. Binding means to create a Lua function that wraps around the C++ function, so the C++ function can be called from Lua.

Game Engines that use Lua mean they are engines that bind certain of the game functions to Lua, so you can access then engine's features from within Lua.

Game Engines don't have to have IDEs. Some game engines do, but not all of them.

The game engines are usually written in C++ or C# or C, or some other language. They either expose some engine functions so Lua can be used as script files, and it mostly goes:

[engine does most of the logic] [engine needs to call user script to customize the logic] [engine -> lua -> user script]

...or they provide a complete interface of the engine, so the game logic is written in the scripting language.

[script does most the logic] [script needs to call engine function to do some heavy lifting] [userscript -> lua -> engine function]

Binding, in this context, means making one language (like Lua) talk to another language (like C++).

I was typing a new attempt, but Servant's is much better than what I was writing.

-------R.I.P.-------

Selective Quote

~Too Late - Too Soon~

The game engines are usually written in C++ or C# or C, or some other language.

Whilst I don't really know of any games engines written entirely in C#, it is a classic example of a language that has bindings created so it can interact with other (usually native) languages.

For example, monogame can use OpenGL via the C# bindings (OpenTk) and then MonoGame is an XNA replica wrapping the OpenTk framework.

Then again, an engine made in C++ (such as Unreal) is effectively just (admittedly very fat) bindings to C and OpenGL / DirectX ;) (Though DirectX does have C++ elements in it natively)

I personally find writing bindings very time consuming and fiddly and for the last project we developed a way to simply inline Android Java into C++ so we could use functionality only exposed by Java without spending time on writing actual bindings.

(Very similar to this one to inline Javascript into C++ -> http://www.mutiny3d.org/doku.php?id=iffe)

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

This topic is closed to new replies.

Advertisement