Update Lua implementation

This commit is contained in:
Fierelier 2023-05-14 18:29:55 +02:00
parent 97a8b04c02
commit 4769de1797
2 changed files with 42 additions and 22 deletions

View File

@ -1,6 +1,7 @@
texture = engine_loadTexture("assets/textures/fier0.rgba",8,32) texture = engine_texture_create(8,32)
engine_texture_from_file(texture,"assets/textures/fier0.rgba")
a = 0 a = 0
function engine_onFrame() function engine_onFrame()
engine_renderTexture2D(texture,math.random(-8,102),math.random(-8,72)) engine_texture_render_2d(texture,math.random(-8,102),math.random(-8,72))
end end

View File

@ -4,48 +4,67 @@
lua_State * engine_lua_state; lua_State * engine_lua_state;
int engine_luafSleep(lua_State *L) { // 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); int time = luaL_checkinteger(L,1);
engine_time_sleep(time); engine_time_sleep(time);
return 0; return 0;
} }
int engine_luafTimeGet(lua_State *L) {
lua_pushinteger(L,engine_time_get());
return 1;
}
int engine_luafLoadTexture(lua_State *L) { // TEXTURES
char * fpath = (char *)luaL_checkstring(L,1); int engine_luaf_texture_create(lua_State *L) {
int width = luaL_checkinteger(L,2); int width = luaL_checkinteger(L,1);
int height = luaL_checkinteger(L,3); int height = luaL_checkinteger(L,2);
struct ENGINE_TEXTURE * texture = engine_createTexture(width,height); struct ENGINE_TEXTURE * texture = engine_createTexture(width,height);
engine_texture_from_file(texture,fpath);
lua_pushlightuserdata(L,texture); lua_pushlightuserdata(L,texture);
return 1; return 1;
} }
int engine_luaf_texture_destroy(lua_State *L) {
int engine_luafRenderTexture2D(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); struct ENGINE_TEXTURE * texture = (struct ENGINE_TEXTURE *)lua_touserdata(L,1);
int x = luaL_checkinteger(L,2); int x = luaL_checkinteger(L,2);
int y = luaL_checkinteger(L,3); int y = luaL_checkinteger(L,3);
engine_texture_render_2d(texture,x,y); engine_texture_render_2d(texture,x,y);
return 0; 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() { void engine_luaInit() {
engine_lua_state = luaL_newstate(); engine_lua_state = luaL_newstate();
luaL_openlibs(engine_lua_state); luaL_openlibs(engine_lua_state);
// Functions // // FUNCTIONS
lua_pushcfunction(engine_lua_state,engine_luafSleep); // TIME
lua_setglobal (engine_lua_state,"engine_sleep"); lua_pushcfunction(engine_lua_state,engine_luaf_time_get);
lua_pushcfunction(engine_lua_state,engine_luafLoadTexture); lua_setglobal (engine_lua_state,"engine_time_get");
lua_setglobal (engine_lua_state,"engine_loadTexture"); lua_pushcfunction(engine_lua_state,engine_luaf_time_sleep);
lua_pushcfunction(engine_lua_state,engine_luafRenderTexture2D); lua_setglobal (engine_lua_state,"engine_time_sleep");
lua_setglobal (engine_lua_state,"engine_renderTexture2D");
// Start user script // 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"); luaL_loadfile(engine_lua_state,"assets/scripts/main.lua");
lua_call(engine_lua_state,0,0); lua_call(engine_lua_state,0,0);
} }