Skip to content

Commit

Permalink
[ScriptEngine] Lots of functions exposed to Lua.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Mar 11, 2020
1 parent 6e23d77 commit 2de04da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
6 changes: 3 additions & 3 deletions server/source/core/ServerApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void ServerApplication::init() {
if (m_argumentParser.getArgument("port").isFound)
m_port = std::stoi(m_argumentParser.getArgument("port").parameter);

m_server.init(m_port);
m_server.setRunning(true);

Registry::setInstance(m_registry);

// The id "_:air" is used in CraftingRecipe, update it there if it changes
Expand All @@ -50,9 +53,6 @@ void ServerApplication::init() {

loadMods();

m_server.init(m_port);
m_server.setRunning(true);

m_serverCommandHandler.setupCallbacks();

m_worldController.setServer(m_serverCommandHandler);
Expand Down
30 changes: 28 additions & 2 deletions server/source/lua/ScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,33 @@ void ScriptEngine::init() {

void ScriptEngine::initUsertypes() {
m_lua.new_usertype<Registry>("Registry",
"get_block", &Registry::getBlock,
"get_item", &Registry::getItem,
"get_sky", &Registry::getSky,
"get_tree", &Registry::getTree,
"get_biome", &Registry::getBiome,
"get_recipe", &Registry::getRecipe,

"get_block_from_string", &Registry::getBlockFromStringID,
"get_item_from_string", &Registry::getItemFromStringID,
"get_sky_from_string", &Registry::getSkyFromStringID,
"get_tree_from_string", &Registry::getTreeFromStringID,
"get_biome_from_string", &Registry::getBiomeFromStringID,

"blocks", &Registry::blocks,
"items", &Registry::items
"items", &Registry::items,
"trees", &Registry::trees,
"biomes", &Registry::biomes,
"dimensions", &Registry::dimensions
);

m_lua.new_usertype<World>("World",
"get_block", &World::getBlock,
"set_block", &World::setBlock,

"get_data", &World::getData,
"set_data", &World::setData,

"get_block_data", &World::getBlockData,
"add_block_data", &World::addBlockData
);
Expand All @@ -71,7 +88,11 @@ void ScriptEngine::initUsertypes() {

m_lua.new_usertype<Chunk>("Chunk",
"get_block", &Chunk::getBlock,
"set_block", &Chunk::setBlock,

"get_data", &Chunk::getData,
"set_data", &Chunk::setData,

"get_block_data", &Chunk::getBlockData,
"add_block_data", &Chunk::addBlockData
);
Expand All @@ -83,7 +104,12 @@ void ScriptEngine::initUsertypes() {
);

m_lua.new_usertype<Block>("Block",
"string_id", &Block::stringID
"id", &Block::id,
"data", &Block::data,
"string_id", &Block::stringID,
"label", &Block::label,
"mod_name", &Block::modName,
"is_opaque", &Block::isOpaque
);

m_lua.new_usertype<ServerBlock>("ServerBlock",
Expand Down

0 comments on commit 2de04da

Please sign in to comment.