Dear Everyone,
I STRONGLY disagree with always defaulting to the C API. While it's good for quick things and hobby projects, the C API lacks the ability to scale. Writing large applications where you're writing -- and re-writing (or copy-pasting) -- the same code over and over again with slight tweaks just to call a function or something is not okay. For example, consider some basic lua code to call a function:
function f ( a, b, c )
print("adding b and c, and string arg " .. a)
return b + c
end
f( "bark", 2.5, 3.5 )
From the Lua Reference Manual (
http://www.lua.org/manual/5.3/manual.html#lua_call), this turns into this:
lua_getglobal(L, "f"); /* function to be called */
lua_pushliteral(L, "bark"); /* 1st argument */
lua_pushnumber(L, 2.5); /* 3rd argument */
lua_pushnumber(L, 3.5); /* 3rd argument */
lua_call(L, 3, 1); /* call 'f' with 3 arguments and 1 result */