克隆lua状态 [英] Clone a lua state

查看:104
本文介绍了克隆lua状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,在使用C ++和Lua进行开发时遇到了很多困难.我的情况是:由于某种原因,我的C ++程序中可能有成千上万的Lua状态.但是这些状态在初始化后应该是相同的.当然,我可以为每个状态执行luaL_loadlibs()和lua_loadfile(),但这非常繁重(实际上,即使是一个初始状态,对我来说也要花费相当长的时间).因此,我想知道以下模式:保持一个单独的Lua状态(必须初始化的唯一状态),然后将其克隆为其他Lua状态,那有可能吗?

Recently, I have encountered many difficulties when I was developing using C++ and Lua. My situation is: for some reason, there can be thousands of Lua-states in my C++ program. But these states should be same just after initialization. Of course, I can do luaL_loadlibs() and lua_loadfile() for each state, but that is pretty heavy(in fact, it takes a rather long time for me even just initial one state). So, I am wondering the following schema: What about keeping a separate Lua-state(the only state that has to be initialized) which is then cloned for other Lua-states, is that possible?

推荐答案

当我像你一样开始使用Lua时,我曾经写过一个包含数千个州的程序,遇到了同样的问题和想法,直到意识到自己完全做到了错误:)

When I started with Lua, like you I once wrote a program with thousands of states, had the same problem and thoughts, until I realized I was doing it totally wrong :)

Lua具有协程和线程,您需要使用这些功能来完成所需的工作.一开始它们可能会有些棘手,但是几天后您就应该能够理解它们,这很值得您花时间.

Lua has coroutines and threads, you need to use these features to do what you need. They can be a bit tricky at first but you should be able to understand them in a few days, it'll be well worth your time.

这篇关于克隆lua状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆