Sharing global variables between different Lua states through require

前端 未结 3 1829
[愿得一人]
[愿得一人] 2021-01-23 04:30

I\'m trying to find a way to share global variables of a specific Lua script(test.lua in the example) between different Lua states.

Here\'s my simple exampl

3条回答
  •  独厮守ぢ
    2021-01-23 05:17

    Two distinct lua_States are completely and totally independent. One cannot directly affect anything that happens in another. You can expose some C code to one that allows it to modify the other, or they could both access some external resource (a file, for example) that allows them to share data.

    But outside of things like this, no, they cannot interact.

    The preferred method for this is to not make them separate lua_States.

提交回复
热议问题