Question

Good day

I have a specific task to give an access of c++ std::map to lua scripts. Desired script syntax is glob["tag"] = "value" or glob("tag") = "value"

In research, have tried luabind binding

std::string & glob(const std::string &tag)
{
    static std::string value;
    return value;
}

...

luabind::module(&state)
[
    def("glob", &glob, luabind::return_reference_to(result))
]

but after run of script listed below

glob("tag") = "asdasd"
print(glob("tag"))

got error [string "glob("tag") = "asdasd"..."]:1: unexpected symbol near '='

So, i'm waiting for your suggestions and opinions.

Thanks

Update 2lhf: Global variables data stored and serialized via c++ part and has to be accessed from lua. luaState is created per script execution, and doesn't exist between executions. One of solution is create and fill global variables table before script execution and sync it with map after execution, but, i think it is slow enough. So, access via c-function with mentioned syntax will be appreciated.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top