52 lines
1.4 KiB
C
52 lines
1.4 KiB
C
#include <lua5.3/lua.h>
|
|
#include <lua5.3/lualib.h>
|
|
#include <lua5.3/lauxlib.h>
|
|
|
|
lua_State * engine_lua_state;
|
|
|
|
int engine_luafSleep(lua_State *L) {
|
|
int time = luaL_checkinteger(L,1);
|
|
engine_time_sleep(time);
|
|
return 0;
|
|
}
|
|
|
|
int engine_luafTimeGet(lua_State *L) {
|
|
lua_pushinteger(L,engine_time_get());
|
|
return 1;
|
|
}
|
|
|
|
int engine_luafLoadTexture(lua_State *L) {
|
|
char * fpath = (char *)luaL_checkstring(L,1);
|
|
int width = luaL_checkinteger(L,2);
|
|
int height = luaL_checkinteger(L,3);
|
|
struct ENGINE_TEXTURE * texture = engine_createTexture(width,height);
|
|
engine_texture_from_file(texture,fpath);
|
|
lua_pushlightuserdata(L,texture);
|
|
return 1;
|
|
}
|
|
|
|
int engine_luafRenderTexture2D(lua_State *L) {
|
|
struct ENGINE_TEXTURE * texture = (struct ENGINE_TEXTURE *)lua_touserdata(L,1);
|
|
int x = luaL_checkinteger(L,2);
|
|
int y = luaL_checkinteger(L,3);
|
|
engine_texture_render_2d(texture,x,y);
|
|
return 0;
|
|
}
|
|
|
|
void engine_luaInit() {
|
|
engine_lua_state = luaL_newstate();
|
|
luaL_openlibs(engine_lua_state);
|
|
|
|
// Functions
|
|
lua_pushcfunction(engine_lua_state,engine_luafSleep);
|
|
lua_setglobal (engine_lua_state,"engine_sleep");
|
|
lua_pushcfunction(engine_lua_state,engine_luafLoadTexture);
|
|
lua_setglobal (engine_lua_state,"engine_loadTexture");
|
|
lua_pushcfunction(engine_lua_state,engine_luafRenderTexture2D);
|
|
lua_setglobal (engine_lua_state,"engine_renderTexture2D");
|
|
|
|
// Start user script
|
|
luaL_loadfile(engine_lua_state,"assets/scripts/main.lua");
|
|
lua_call(engine_lua_state,0,0);
|
|
}
|