aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/time/time.cpp
blob: f6e6f26653ba8d3496e840a8241db673a1b46340 (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/modules/luax.h"
#include <SDL2/SDL.h>
#include "libjin/jin.h"

namespace JinEngine
{
    namespace Lua
    {

        using namespace JinEngine::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; 
        }

    } // namespace Lua
} // namespace JinEngine