Page 1 of 1

Optional arguments in the API

Posted: Fri Aug 02, 2013 9:25 am
by jseb
Hello,

Seeking how i could get the currently played notes and instruments in a soundtrack module, i've landed on this page:

https://www.love2d.org/wiki/Source:tell

It seems a bit high-level for what i want to get, but i've noticed that the argument is optional (i was reading source at the same time).

Code: Select all


int w_Source_tell(lua_State *L)
{
        Source *t = luax_checksource(L, 1);
        const char *unit = luaL_optstring(L, 2, "seconds");
        Source::Unit u;
        t->getConstant(unit, u);
        lua_pushnumber(L, t->tell(u));
        return 1;
}

Or may be we should understand that the string in parenthesis is used by default ?
TimeUnit unit ("seconds")
The type of unit for the return value.


See you.

Re: Optional arguments in the API

Posted: Fri Aug 02, 2013 1:38 pm
by bartbes
Yes, that is used all over the wiki.