mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Async environment for mods to do concurrent tasks (#11131)
This commit is contained in:
parent
663c936428
commit
e7659883cc
38 changed files with 1646 additions and 48 deletions
|
@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "lua_api/l_internal.h"
|
||||
#include "common/c_converter.h"
|
||||
#include "common/c_content.h"
|
||||
#include "common/c_packer.h"
|
||||
#include "itemdef.h"
|
||||
#include "nodedef.h"
|
||||
#include "server.h"
|
||||
|
@ -441,6 +442,7 @@ int LuaItemStack::create_object(lua_State *L)
|
|||
lua_setmetatable(L, -2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Not callable from Lua
|
||||
int LuaItemStack::create(lua_State *L, const ItemStack &item)
|
||||
{
|
||||
|
@ -457,6 +459,20 @@ LuaItemStack *LuaItemStack::checkobject(lua_State *L, int narg)
|
|||
return *(LuaItemStack **)luaL_checkudata(L, narg, className);
|
||||
}
|
||||
|
||||
void *LuaItemStack::packIn(lua_State *L, int idx)
|
||||
{
|
||||
LuaItemStack *o = checkobject(L, idx);
|
||||
return new ItemStack(o->getItem());
|
||||
}
|
||||
|
||||
void LuaItemStack::packOut(lua_State *L, void *ptr)
|
||||
{
|
||||
ItemStack *stack = reinterpret_cast<ItemStack*>(ptr);
|
||||
if (L)
|
||||
create(L, *stack);
|
||||
delete stack;
|
||||
}
|
||||
|
||||
void LuaItemStack::Register(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
@ -488,6 +504,8 @@ void LuaItemStack::Register(lua_State *L)
|
|||
|
||||
// Can be created from Lua (ItemStack(itemstack or itemstring or table or nil))
|
||||
lua_register(L, className, create_object);
|
||||
|
||||
script_register_packer(L, className, packIn, packOut);
|
||||
}
|
||||
|
||||
const char LuaItemStack::className[] = "ItemStack";
|
||||
|
@ -673,3 +691,10 @@ void ModApiItemMod::Initialize(lua_State *L, int top)
|
|||
API_FCT(get_content_id);
|
||||
API_FCT(get_name_from_content_id);
|
||||
}
|
||||
|
||||
void ModApiItemMod::InitializeAsync(lua_State *L, int top)
|
||||
{
|
||||
// all read-only functions
|
||||
API_FCT(get_content_id);
|
||||
API_FCT(get_name_from_content_id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue