From 5b26bfbd995b12bcb5fd8ff0dee98194fbccc9b1 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Sun, 14 May 2023 21:43:34 +0200 Subject: [PATCH] Add engine_malloc/engine_free to Lua bindings --- modules/engine/FUNCTIONS.toml | 9 +++++++++ modules/engine/addon/lua.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/modules/engine/FUNCTIONS.toml b/modules/engine/FUNCTIONS.toml index d224438..3af692d 100644 --- a/modules/engine/FUNCTIONS.toml +++ b/modules/engine/FUNCTIONS.toml @@ -1,3 +1,12 @@ +# MEMORY +[engine_malloc] +type = "void *" +arguments = ["void *","size_t"] + +[engine_free] +type = "void" +arguments = ["void *"] + # WINDOW [engine_window_init] type = "void" diff --git a/modules/engine/addon/lua.c b/modules/engine/addon/lua.c index 3ecfd93..05ff0d3 100644 --- a/modules/engine/addon/lua.c +++ b/modules/engine/addon/lua.c @@ -3,6 +3,20 @@ #include lua_State * engine_lua_state; +int engine_luaf_malloc(lua_State *L) { + void * invar1 = lua_touserdata(L,1); + size_t invar2 = lua_touserdata(L,2); + void * outvar = engine_malloc(invar1,invar2); + lua_pushlightuserdata(L,outvar); + return 1; +} + +int engine_luaf_free(lua_State *L) { + void * invar1 = lua_touserdata(L,1); + engine_free(invar1); + return 0; +} + int engine_luaf_window_init(lua_State *L) { int invar1 = luaL_checkinteger(L,1); int invar2 = luaL_checkinteger(L,2); @@ -100,6 +114,10 @@ void engine_luaInit() { engine_lua_state = luaL_newstate(); luaL_openlibs(engine_lua_state); + lua_pushcfunction(engine_lua_state,engine_luaf_malloc); + lua_setglobal (engine_lua_state,"engine_malloc"); + lua_pushcfunction(engine_lua_state,engine_luaf_free); + lua_setglobal (engine_lua_state,"engine_free"); lua_pushcfunction(engine_lua_state,engine_luaf_window_init); lua_setglobal (engine_lua_state,"engine_window_init"); lua_pushcfunction(engine_lua_state,engine_luaf_window_present); @@ -112,6 +130,8 @@ void engine_luaInit() { 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"); + lua_pushcfunction(engine_lua_state,engine_luaf_event_get); + lua_setglobal (engine_lua_state,"engine_event_get"); 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_color_set);