After years of java, javascript, python, I am not only forget C++, but also confuse that syntax.
http://heavycoder.com/tutorials/lua_embed.php
static const luaL_reg lualibs[] =
{
{ "base", luaopen_base },
{ NULL, NULL }
};
lualibs init with a 2D array? luaL_reg is a type, but obviously is not a array,
const luaL_reg *lib;
for (lib = lualibs; lib->func != NULL; lib++)
{
lib->func(l);
lua_settop(l, 0);
}
luaL_regprobably looks something as the below.The members of an object can be set using
{}as in the below example, which will set the membernameto point towards the location of"hello world"andfuncto have the adress ofmy_function.The syntax shown in the previous snippet can also be used when initializing members of an array. In the below snippet a array of const luaL_reg instances is set to contain two objects, the first one having
name="base"andfuncset toluaopen_base.To make things clear; the below is not a 2D array, but an array of
const luaL_reginitialized using{}to set the members of each instance.The last element is used to simplify iterating our array, setting both members to
NULLmakes it easy to see when we have reached the last element.The loop in the upcoming snippet takes advantage of this. As long as the member
funcisn’t equal toNULLwe haven’t gotten to the end of our array.