Tag Archives: Lua

a generic c++ lua stack crawler

Sometimes one needs to walk the Lua stack on the C++ side, for example, if passing tables to C++ via the new extended LuaBridge functionality.
For that I’ve started luastackcrawler (see on github). The small test shows that it works at least in principle.
A possible use case – configuration. If the layout of a stack entry, such as a table is known, one can write own wrappers around those to easily access the values. Right now one can iterate through stack and Lua table values, which can be of several types, represented by a boost::variant.

Example, lua:

assert( ArraySize { 1, 2, 5, bla='7' } == 3 )

and the c++ implementation of ArraySize:

int ArraySize(boost::shared_ptr<LuaTable> T)
{
    if (!T)
        return 0;

    return std::count_if(
        T->begin(),
        T->end(),
        [](std::pair<LuaMultiValue,LuaMultiValue> const& entry) {
            return GetType(entry.first) == LuaType::NUMBER;
        });
}

lua + pugixml via LuaBridge

Started working on a binding of pugixml for lua: https://github.com/d-led/pugilua

pugixml supports utf-8, so, using icu4lua one could, in principle, have a nice lua-style processing of XML files. The interface is right now kept almost one-to-one to the original. It shows, at least for me, how easy it is to make bindings to C++ using LuaBridge and how easy the usage of pugixml is.