#include #include #include lua_State * engine_lua_state; // TIME int engine_luaf_time_get(lua_State *L) { lua_pushinteger(L,engine_time_get()); return 1; } int engine_luaf_time_sleep(lua_State *L) { int time = luaL_checkinteger(L,1); engine_time_sleep(time); return 0; } // TEXTURES int engine_luaf_texture_create(lua_State *L) { int width = luaL_checkinteger(L,1); int height = luaL_checkinteger(L,2); struct ENGINE_TEXTURE * texture = engine_createTexture(width,height); lua_pushlightuserdata(L,texture); return 1; } int engine_luaf_texture_destroy(lua_State *L) { struct ENGINE_TEXTURE * texture = (struct ENGINE_TEXTURE *)lua_touserdata(L,1); engine_texture_destroy(texture); return 0; } int engine_luaf_texture_render_2d(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; } int engine_luaf_texture_from_file(lua_State *L) { struct ENGINE_TEXTURE * texture = (struct ENGINE_TEXTURE *)lua_touserdata(L,1); char * fpath = (char *)luaL_checkstring(L,2); engine_texture_from_file(texture,fpath); return 0; } void engine_luaInit() { engine_lua_state = luaL_newstate(); luaL_openlibs(engine_lua_state); // // FUNCTIONS // TIME lua_pushcfunction(engine_lua_state,engine_luaf_time_get); lua_setglobal (engine_lua_state,"engine_time_get"); lua_pushcfunction(engine_lua_state,engine_luaf_time_sleep); lua_setglobal (engine_lua_state,"engine_time_sleep"); // TEXTURES lua_pushcfunction(engine_lua_state,engine_luaf_texture_create); lua_setglobal (engine_lua_state,"engine_texture_create"); lua_pushcfunction(engine_lua_state,engine_luaf_texture_destroy); lua_setglobal (engine_lua_state,"engine_texture_destroy"); lua_pushcfunction(engine_lua_state,engine_luaf_texture_render_2d); lua_setglobal (engine_lua_state,"engine_texture_render_2d"); lua_pushcfunction(engine_lua_state,engine_luaf_texture_from_file); lua_setglobal (engine_lua_state,"engine_texture_from_file"); // // USER SCRIPT luaL_loadfile(engine_lua_state,"assets/scripts/main.lua"); lua_call(engine_lua_state,0,0); }