Search code examples
c++functionlualua-table

What are the functions that look like table in Lua?


I'm a beginner in Lua and I just found out some functions look like table (e.g. function love.update(dt)) in Lua.

I wonder how these functions work. For example, does update function belong to table love? If so, should one construct this table somewhere beforehand?

Lastly, I would like to ask how to call these kind of functions from C++. (Please show me an example how to call love.update() from C++)


Solution

  • Question 1: Does update function belongs to table love?
    Yes. "function love.update(dt)" is equal to "love.update = function (dt)".

    Question 2: Should one construct this table somewhere beforehand?
    Yes.

    Question 3: How to call these kind of functions from C++?
    I assume that "love" can be accessed from global.

    void call_love_update (lua_State* l) {
        lua_getglobal(l, "love");
        lua_getfield(l, -1, "update");
        lua_pushnumber(l, 0.016);
        lua_call(l, 1, LUA_MULTRET);
    }