Scripting WIP (#70)

* Scripting introduced

* AppImage workflow fixes

* AppImage workflow simplified

* README.md update

* README.md update

* small fix
This commit is contained in:
MihailRis
2023-12-25 05:26:03 +03:00
committed by GitHub
parent ce26f0c227
commit acce49f188
35 changed files with 649 additions and 138 deletions
+65
View File
@@ -0,0 +1,65 @@
#include "api_lua.h"
#include "scripting.h"
#include "../../world/Level.h"
#include "../../content/Content.h"
#include "../../voxels/Block.h"
#include "../../voxels/Chunks.h"
#include "../../voxels/voxel.h"
int l_block_name(lua_State* L) {
int id = lua_tointeger(L, 1);
lua_pushstring(L, scripting::content->indices->getBlockDef(id)->name.c_str());
return 1;
}
int l_is_solid_at(lua_State* L) {
int x = lua_tointeger(L, 1);
int y = lua_tointeger(L, 2);
int z = lua_tointeger(L, 3);
lua_pushboolean(L, scripting::level->chunks->isSolid(x, y, z));
return 1;
}
int l_blocks_count(lua_State* L) {
lua_pushinteger(L, scripting::content->indices->countBlockDefs());
return 1;
}
int l_block_index(lua_State* L) {
auto name = lua_tostring(L, 1);
lua_pushinteger(L, scripting::content->requireBlock(name)->rt.id);
return 1;
}
int l_set_block(lua_State* L) {
int x = lua_tointeger(L, 1);
int y = lua_tointeger(L, 2);
int z = lua_tointeger(L, 3);
int id = lua_tointeger(L, 4);
scripting::level->chunks->set(x, y, z, id, 0);
return 0;
}
int l_get_block(lua_State* L) {
int x = lua_tointeger(L, 1);
int y = lua_tointeger(L, 2);
int z = lua_tointeger(L, 3);
voxel* vox = scripting::level->chunks->get(x, y, z);
int id = vox == nullptr ? -1 : vox->id;
lua_pushinteger(L, id);
return 1;
}
#define lua_addfunc(L, FUNC, NAME) (lua_pushcfunction(L, FUNC),\
lua_setglobal(L, NAME))
void apilua::create_funcs(lua_State* L) {
lua_addfunc(L, l_block_index, "block_index");
lua_addfunc(L, l_block_name, "block_name");
lua_addfunc(L, l_blocks_count, "blocks_count");
lua_addfunc(L, l_is_solid_at, "is_solid_at");
lua_addfunc(L, l_set_block, "set_block");
lua_addfunc(L, l_get_block, "get_block");
}