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

namespace JinEngine
{
    namespace Lua
    {

        using namespace JinEngine::Time;

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

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

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

    } // namespace Lua
} // namespace JinEngine