Add engine_malloc/engine_free to Lua bindings

This commit is contained in:
Fierelier 2023-05-14 21:43:34 +02:00
parent 4109e89fc2
commit 5b26bfbd99
2 changed files with 29 additions and 0 deletions

View File

@ -1,3 +1,12 @@
# MEMORY
[engine_malloc]
type = "void *"
arguments = ["void *","size_t"]
[engine_free]
type = "void"
arguments = ["void *"]
# WINDOW # WINDOW
[engine_window_init] [engine_window_init]
type = "void" type = "void"

View File

@ -3,6 +3,20 @@
#include <lua5.3/lauxlib.h> #include <lua5.3/lauxlib.h>
lua_State * engine_lua_state; 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 engine_luaf_window_init(lua_State *L) {
int invar1 = luaL_checkinteger(L,1); int invar1 = luaL_checkinteger(L,1);
int invar2 = luaL_checkinteger(L,2); int invar2 = luaL_checkinteger(L,2);
@ -100,6 +114,10 @@ void engine_luaInit() {
engine_lua_state = luaL_newstate(); engine_lua_state = luaL_newstate();
luaL_openlibs(engine_lua_state); 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_pushcfunction(engine_lua_state,engine_luaf_window_init);
lua_setglobal (engine_lua_state,"engine_window_init"); lua_setglobal (engine_lua_state,"engine_window_init");
lua_pushcfunction(engine_lua_state,engine_luaf_window_present); 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_setglobal (engine_lua_state,"engine_time_get");
lua_pushcfunction(engine_lua_state,engine_luaf_time_sleep); lua_pushcfunction(engine_lua_state,engine_luaf_time_sleep);
lua_setglobal (engine_lua_state,"engine_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_pushcfunction(engine_lua_state,engine_luaf_texture_create);
lua_setglobal (engine_lua_state,"engine_texture_create"); lua_setglobal (engine_lua_state,"engine_texture_create");
lua_pushcfunction(engine_lua_state,engine_luaf_texture_color_set); lua_pushcfunction(engine_lua_state,engine_luaf_texture_color_set);