aboutsummaryrefslogtreecommitdiff
path: root/src/lua/time/luaopen_time.cpp
blob: d77b71330c0d10ee7b2f70f5c2819b2c8c48d783 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "lua/luax.h"
#include <SDL2/SDL.h>
#include "libjin/jin.h"

namespace jin
{
namespace lua
{

    using namespace jin::time;

    static int l_sec(lua_State* L)
    {
        luax_pushnumber(L, getSecond()); 
        return 1;
    }

    static int l_sleep(lua_State* L)
    {
        double sec = luax_checknumber(L, 1); 
        sleep(sec * 1000.0f);
        return 0; 
    }

    static const luaL_Reg f[] = {
        { "second", l_sec   },
        { "sleep",  l_sleep },
        { 0,        0       },
    };
    
    int luaopen_time(lua_State* L)
    {
        luax_newlib(L, f); 
        return 1; 
    }

} // lua
} // jin