Scripting Language – How to Make Support for Bindings in a Scripting Language

bindingclanguage-designscripting

Main

I'm making a scripting language using C++. I plan to use it with a simple test game editor. But I have to make a support for bindings to call game engine's nodes' methods to update positions, rotations, etc.

What are the main approaches for this?

The game engine I plan to use also supports lua, so maybe I can also use this fact.

Details

The problem I have faced lies in the fact of how can I call library C++ object methods within a script. English is not my native language and the lack of knowledge in that sphere prevents me from making a good query on the topic. So I don't know what to search. Google shows me information on how to make bindings to some scripting languages not the fundamentals by search phrases like "how to make bindings support to a scripting language", "scripting bindings".

At this time I came up to the following things. I have to inherit all objects that will be used in script from a service class, ex. CLangObject. With its help I can identify the object's type within a C++ library objects' methods. Then I have to define the most general pointer to method types. I have also define a callback service class to pass it to a byte machine when C++ library method returns value. The game engine I want to use has bindning to lua, so maybe I can use its LuaObject and LuaCallback classes. At this time I don't know if this approach will lead to a normal result.

Best Answer

I think the better search term for this might be "bridge", have a try with that.

The simplest approach is to use a C function to dispatch from the scripting language into your engine. Imagine a function msgSend(target, message, arg0, ...); if you can write the scripting language engine such that it can call msgSend with arbitrary arguments, you can see how from that you can call target's message method with arg0, ....

Since you mention Lua, have a look at https://github.com/vinniefalco/LuaBridge . You can see in the sample how he passes in classes and function addresses -- on the Lua end these will be wrapped as some kind of Lua object and calling that function will enter a message dispatch function that will unwrap the target and arguments (if necessary) and proceed to call the function from the address.

Related Topic