简体   繁体   中英

C# LuaInterface / NLua: Route around compiling Lua for multiple objects with same script?

My system consists of entities that may contain a unique name and Lua script which is compiled when the entity spawns, there may be multiple of the same entity spawned at any time.

At the moment I'm instancing a new NLua.Lua() for each entity and re-compiling the script, which takes only ~5-10ms, however if 100 of the exact same entities are created at the same time the main thread will freeze for 0.5-1 second. I'm not able to have all entities reference a single pre-compiled context. If one entity takes damage, they all think they are taking damage.

I'm trying to come up with a solution where similar entities with the same Lua script don't require the context to be compiled individually for every entity yet maintain their own unique script. Is it possible?

May I suggest tables? As in, having a table of entities, where they all have separate values within, in order to share the same space without making you use NLua.Lua() for each one of them.

(cannot comment, so excuse this answer which should've been a comment)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM