Monday, August 15, 2022
HomeGame DevelopmentIntegrating callback or occasion features with Lua in C++

Integrating callback or occasion features with Lua in C++


I am loading some objects into C++ with a Lua script, which comprises some ‘actionable gadgets’ like this:

actionItems = {
            door = {
                rect = {56, 50, 30, 74},
                defaultAction = "look",
                isLocked = false,
                minimap = {47, 174},
                vacation spot = "first_hallway",
                dialogs = {
                    look = "It is a heavy picket door with iron hinges."
                },
                onOpen = perform (actionItem)
                    if actionItem.locked then

                    finish

                finish
            },

On the C++ facet:

The Lua perform ‘onOpen’ is saved utilizing an inventory of lambdas:

std::unordered_map<std::string, const std::perform<void()>> actions

As soon as I detect {that a} motion should be executed, I name for instance:

itemValue.actions["open"]();

However the perform simply crashes, and I am undecided methods to method this in any respect. How does a enter argument like ‘actionItem’ on the Lua facet map to the imported C++ perform for instance?
Ideally, I would like easy logic to reside on the Lua facet, triggering occasions on the C++ facet.

Glad to listen to some concepts or get some examples.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments