How to make support for bindings for a scripting language

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.

2

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.

1

To restate your concern, you have a piece of software, the game engine, that supports a particular scripting language, Lua, but are unsure how to expose, access, and interject game objects and events to Lua, or to do the same with your own custom external driver (a C++ based editor).

The game engine itself probably has a set of methods or decorators for exposing objects and events that would allow for tracking through external sources or programs. It also probably has it’s own specific protocol for manipulation by those external sources. Without knowing which particular piece of software or engine you are looking at, it is impossible to give specific guidance.

What I can suggest, is review the documentation of that particular engine. Short of that, look at how known things are exposed to the script, and mimic the method by which those things are exposed and acted upon.

For example, Torque3D offers documentation that shows how to expose objects to script (or an external source like a compiled C++ based editor).

http://www.garagegames.com/products/torque-3d/documentation

http://www.garagegames.com/products/torque-3d/documentation/Scripting/Advanced/EngineInterface.html

The second document shows how to create the call-ins, call-outs, exposed types, and limitations to function definition shape within the game engine.

In order for the script or driver/editor to consume and craft those exposed data types, at some level you will need to be able to create types from within the scripting language (or editor) that can be marshaled, or transformed, onto structures that match the format and conventions of the engine, basically a map. Each language has it’s own way of implementing a structures layout, field order, and sizing. Some follow a particular convention very well, others use their own convention.

The map might be unwieldy or ugly to use in the script, so you may want to create an additional second ‘clean’ type within the scripting language or driver/editor for normal use, with a ‘transform’ method to shape the ‘easy to use type’ into the type that can be marshaled back to the engine.

Lua has their own way of working with other languages, and it’s documentation specifically talks about accessing and consuming C based [compiled] software:
http://www.lua.org/pil/26.html (look at section IV)

1

You could build the scripting language into the engine so that the engine can take some file formatted in your language and invent some grammars for your program to compile these script files during run-time and use a stack to push method calls, variable declarations etc. like a normal running program though I think it limits your scripting language to only the methods your engine is written with, unless you create good grammars for the language that also binds to the original language the engine is written in.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật