LuaEngine/Common.cpp

33 lines
629 B
C++
Raw Permalink Normal View History

2020-05-23 01:11:46 +08:00
#include "include.h"
int common_getplatform(lua_State* L)
{
lua_pushstring(L, SDL_GetPlatform());
return 1;
}
2020-05-24 05:24:13 +08:00
int common_getticks(lua_State* L)
{
lua_pushinteger(L, SDL_GetTicks());
return 1;
}
int common_sleep(lua_State* L)
{
int ms = luaL_checkinteger(L, 1);
SDL_Delay(ms);
return 0;
}
2020-05-23 01:11:46 +08:00
void InitCommon(lua_State* L)
{
2020-05-24 05:24:13 +08:00
lua_getglobal(L, "package");
lua_getfield(L, -1, "loaded");
2020-05-23 01:11:46 +08:00
lua_newtable(L);
lua_setfield_function(L, "getPlatform", common_getplatform);
2020-05-24 05:24:13 +08:00
lua_setfield_function(L, "getTicks", common_getticks);
lua_setfield_function(L, "sleep", common_sleep);
lua_setfield(L, -2, "Common");
lua_pop(L, 2);
2020-05-23 01:11:46 +08:00
}