luac

How to share/reuse a Lua script for multiple entities?

假如想象 提交于 2020-01-01 07:08:13
问题 I'm in the design/skeleton coding phase of my C++ game with Lua scripting, but I have run into a design issue: The game will have many copies of the same kind of entities, with behavior controlled by the same script. Is there a straightforward way I can share the script between entities of the same type in a single lua_state? I have only been able to find this question asked a couple of times on the Internet; I have read mixed feedback on whether or not it's a good idea to load the same

Passing array to C as argument in the stack

大兔子大兔子 提交于 2019-12-13 01:53:15
问题 I use Lua for arrays manipulating; arrays are simple binary data: local ram_ctx = {0,0,0,0,0,0,0,0,0} I want to pass it to GUI written in C. The problem is if I pass it directly like func(ram_ctx), Lua function seems to stop executing after a call. Corresponding C function are not executed (it can be empty). But if I make global array in Lua and access it with lua_getglobal - everything seems to be OK. What I'm doing wrong or is it possible at all? It is not OK to pass array name as argument

How to share/reuse a Lua script for multiple entities?

放肆的年华 提交于 2019-12-03 17:17:33
I'm in the design/skeleton coding phase of my C++ game with Lua scripting, but I have run into a design issue: The game will have many copies of the same kind of entities, with behavior controlled by the same script. Is there a straightforward way I can share the script between entities of the same type in a single lua_state? I have only been able to find this question asked a couple of times on the Internet; I have read mixed feedback on whether or not it's a good idea to load the same script in different lua_state's, and not in-depth feedback on alternatives. It's simple and bullet-proof,