Remove /src/lua.c

This commit is contained in:
Fierelier 2023-08-09 21:15:10 +02:00
parent 613ff3b89e
commit 6eb0918624
2 changed files with 1 additions and 153 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/engine
/src/lua.c

153
src/lua.c
View File

@ -1,153 +0,0 @@
#include <lua5.3/lua.h>
#include <lua5.3/lualib.h>
#include <lua5.3/lauxlib.h>
lua_State * engine_lua_state;
#include "lua_manual.c"
int engine_luaf_memory_free(lua_State *L) {
void * ptr = lua_touserdata(L,1);
engine_memory_free(ptr);
return 0;
}
int engine_luaf_event_get(lua_State *L) {
struct ENGINE_EVENT * outvar = engine_event_get();
lua_pushlightuserdata(L,outvar);
return 1;
}
int engine_luaf_event_free(lua_State *L) {
struct ENGINE_EVENT * event = lua_touserdata(L,1);
engine_event_free(event);
return 0;
}
int engine_luaf_texture_create(lua_State *L) {
int width = luaL_checkinteger(L,1);
int height = luaL_checkinteger(L,2);
struct ENGINE_TEXTURE * outvar = engine_texture_create(width,height);
lua_pushlightuserdata(L,outvar);
return 1;
}
int engine_luaf_texture_destroy(lua_State *L) {
struct ENGINE_TEXTURE * texture = lua_touserdata(L,1);
engine_texture_destroy(texture);
return 0;
}
int engine_luaf_color_set(lua_State *L) {
unsigned char r = luaL_checkinteger(L,1);
unsigned char g = luaL_checkinteger(L,2);
unsigned char b = luaL_checkinteger(L,3);
unsigned char a = luaL_checkinteger(L,4);
engine_color_set(r,g,b,a);
return 0;
}
int engine_luaf_rendertarget_set(lua_State *L) {
struct ENGINE_TEXTURE * texture = lua_touserdata(L,1);
engine_rendertarget_set(texture);
return 0;
}
int engine_luaf_rendertarget_draw_point(lua_State *L) {
int x = luaL_checkinteger(L,1);
int y = luaL_checkinteger(L,2);
engine_rendertarget_draw_point(x,y);
return 0;
}
int engine_luaf_rendertarget_draw_texture(lua_State *L) {
struct ENGINE_TEXTURE * texture = lua_touserdata(L,1);
int x = luaL_checkinteger(L,2);
int y = luaL_checkinteger(L,3);
engine_rendertarget_draw_texture(texture,x,y);
return 0;
}
int engine_luaf_rendertarget_draw_file(lua_State *L) {
char * fpath = (char *)luaL_checkstring(L,1);
engine_rendertarget_draw_file(fpath);
return 0;
}
int engine_luaf_time_sleep(lua_State *L) {
int ms = luaL_checkinteger(L,1);
engine_time_sleep(ms);
return 0;
}
int engine_luaf_time_get(lua_State *L) {
long long outvar = engine_time_get();
lua_pushinteger(L,outvar);
return 1;
}
int engine_luaf_window_create(lua_State *L) {
int width = luaL_checkinteger(L,1);
int height = luaL_checkinteger(L,2);
char * title = (char *)luaL_checkstring(L,3);
struct ENGINE_WINDOW * outvar = engine_window_create(width,height,title);
lua_pushlightuserdata(L,outvar);
return 1;
}
int engine_luaf_window_present(lua_State *L) {
struct ENGINE_WINDOW * window = lua_touserdata(L,1);
engine_window_present(window);
return 0;
}
int engine_luaf_window_destroy(lua_State *L) {
struct ENGINE_WINDOW * window = lua_touserdata(L,1);
engine_window_destroy(window);
return 0;
}
void engine_lua_init() {
engine_lua_state = luaL_newstate();
luaL_openlibs(engine_lua_state);
lua_pushinteger(engine_lua_state,ENGINE_EVENT_TYPE_UNKNOWN);
lua_setglobal(engine_lua_state,"ENGINE_EVENT_TYPE_UNKNOWN");
lua_pushinteger(engine_lua_state,ENGINE_EVENT_TYPE_NONE);
lua_setglobal(engine_lua_state,"ENGINE_EVENT_TYPE_NONE");
lua_pushinteger(engine_lua_state,ENGINE_EVENT_TYPE_EXIT);
lua_setglobal(engine_lua_state,"ENGINE_EVENT_TYPE_EXIT");
lua_pushinteger(engine_lua_state,ENGINE_EVENT_TYPE_INPUT_KB);
lua_setglobal(engine_lua_state,"ENGINE_EVENT_TYPE_INPUT_KB");
lua_pushcfunction(engine_lua_state,engine_luaf_memory_free);
lua_setglobal (engine_lua_state,"engine_memory_free");
lua_pushcfunction(engine_lua_state,engine_luaf_event_get);
lua_setglobal (engine_lua_state,"engine_event_get");
lua_pushcfunction(engine_lua_state,engine_luaf_event_free);
lua_setglobal (engine_lua_state,"engine_event_free");
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_color_set);
lua_setglobal (engine_lua_state,"engine_color_set");
lua_pushcfunction(engine_lua_state,engine_luaf_rendertarget_set);
lua_setglobal (engine_lua_state,"engine_rendertarget_set");
lua_pushcfunction(engine_lua_state,engine_luaf_rendertarget_draw_point);
lua_setglobal (engine_lua_state,"engine_rendertarget_draw_point");
lua_pushcfunction(engine_lua_state,engine_luaf_rendertarget_draw_texture);
lua_setglobal (engine_lua_state,"engine_rendertarget_draw_texture");
lua_pushcfunction(engine_lua_state,engine_luaf_rendertarget_draw_file);
lua_setglobal (engine_lua_state,"engine_rendertarget_draw_file");
lua_pushcfunction(engine_lua_state,engine_luaf_time_sleep);
lua_setglobal (engine_lua_state,"engine_time_sleep");
lua_pushcfunction(engine_lua_state,engine_luaf_time_get);
lua_setglobal (engine_lua_state,"engine_time_get");
lua_pushcfunction(engine_lua_state,engine_luaf_window_create);
lua_setglobal (engine_lua_state,"engine_window_create");
lua_pushcfunction(engine_lua_state,engine_luaf_window_present);
lua_setglobal (engine_lua_state,"engine_window_present");
lua_pushcfunction(engine_lua_state,engine_luaf_window_destroy);
lua_setglobal (engine_lua_state,"engine_window_destroy");
engine_lua_init_manual();
luaL_loadfile(engine_lua_state,"mods/main/script/main.lua");
lua_call(engine_lua_state,0,0);
}