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.
精彩评论