开发者

Is it possible/practical to use Lua's hash table outside of Lua?

开发者 https://www.devze.com 2023-02-07 06:58 出处:网络
I find myself needing a hash table container in a C project whic开发者_StackOverflowh includes Lua.I am wondering if it is possible to use the hash table in Lua as a generic container.I have looked at

I find myself needing a hash table container in a C project whic开发者_StackOverflowh includes Lua. I am wondering if it is possible to use the hash table in Lua as a generic container. I have looked at ltable.h and all of the functions require a Lua state and seem tied to the Lua environment so I am guessing this is not practical if the data needs to be independent of Lua.


It is possible and the easiest way is just to use the official C API for Lua. No need to dig into the innards of ltable.h.


You can use luabind or luabridge to specify how a C++ hash (say stl's map) will be represented in Lua; then you'll be able to pass it to the Lua engine. Note that any usage of Lua will require to pass the Lua state, no escape here.

0

精彩评论

暂无评论...
验证码 换一张
取 消