Merge pull request #2001 from mc-server/BindingsCleanup
Bindings cleanup
This commit is contained in:
commit
0686b55901
@ -7,9 +7,13 @@ export MCSERVER_BUILD_ID=$TRAVIS_JOB_NUMBER
|
||||
export MCSERVER_BUILD_DATETIME=`date`
|
||||
|
||||
cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1;
|
||||
|
||||
echo "Checking basic style..."
|
||||
cd src
|
||||
lua CheckBasicStyle.lua
|
||||
cd ..
|
||||
|
||||
echo "Building..."
|
||||
make -j 2;
|
||||
make -j 2 test ARGS="-V";
|
||||
cd MCServer/;
|
||||
|
@ -54,3 +54,11 @@ string.repl = ogsub
|
||||
|
||||
|
||||
|
||||
-- Lua 5.2+ and LuaJit don't have string.gfind(). Use string.gmatch() instead:
|
||||
if not(string.gfind) then
|
||||
string.gfind = string.gmatch
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
4
src/Bindings/.gitignore
vendored
4
src/Bindings/.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
lua51.dll
|
||||
LuaState_Call.inc
|
||||
LuaState_Declaration.inc
|
||||
LuaState_Implementation.cpp
|
||||
LuaState_Typedefs.inc
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
:: Regenerate the files:
|
||||
echo Regenerating LUA bindings . . .
|
||||
"tolua++.exe" -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
"tolua++.exe" -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
|
||||
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
#!/bin/bash
|
||||
/usr/bin/tolua++ -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
/usr/bin/tolua++ -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
:: Regenerate the files:
|
||||
echo Regenerating LUA bindings . . .
|
||||
lua ..\..\lib\tolua++\src\bin\lua\_driver.lua -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
lua ..\..\lib\tolua++\src\bin\lua\_driver.lua -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
|
||||
|
||||
|
||||
|
161
src/Bindings/BindingsProcessor.lua
Normal file
161
src/Bindings/BindingsProcessor.lua
Normal file
@ -0,0 +1,161 @@
|
||||
|
||||
-- BindingsProcessor.lua
|
||||
|
||||
-- Implements additional processing that is done while generating the Lua bindings
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local access = {public = 0, protected = 1, private = 2}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Defines classes that have a custom manual Push() implementation and should not generate the automatic one
|
||||
-- Map of classname -> true
|
||||
local g_HasCustomPushImplementation =
|
||||
{
|
||||
cEntity = true
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function parser_hook(s)
|
||||
local container = classContainer.curr -- get the current container
|
||||
|
||||
-- process access-specifying labels (public, private, etc)
|
||||
do
|
||||
local b, e, label = string.find(s, "^%s*(%w*)%s*:[^:]") -- we need to check for [^:], otherwise it would match 'namespace::type'
|
||||
if b then
|
||||
|
||||
-- found a label, get the new access value from the global 'access' table
|
||||
if access[label] then
|
||||
container.curr_member_access = access[label]
|
||||
end -- else ?
|
||||
|
||||
return strsub(s, e) -- normally we would use 'e+1', but we need to preserve the [^:]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Outputs the helper files supplementing the cLuaState class
|
||||
-- Writes:
|
||||
-- LuaState_Declaration.inc
|
||||
-- LuaState_Implementation.cpp
|
||||
-- LuaState_Typedefs.inc
|
||||
local function OutputLuaStateHelpers(a_Package)
|
||||
-- Collect all class types from ToLua:
|
||||
local types = {}
|
||||
for idx, item in ipairs(a_Package) do
|
||||
local mt = getmetatable(item) or {}
|
||||
if (mt.classtype == "class") then
|
||||
table.insert(types, {name = item.name, lname = item.lname})
|
||||
end
|
||||
end
|
||||
table.sort(types,
|
||||
function(a_Item1, a_Item2)
|
||||
return (a_Item1.name:lower() < a_Item2.name:lower())
|
||||
end
|
||||
)
|
||||
|
||||
-- Output the typedefs:
|
||||
do
|
||||
local f = assert(io.open("LuaState_Typedefs.inc", "w"))
|
||||
f:write("\n// LuaState_Typedefs.inc\n\n// This file is generated along with the Lua bindings by ToLua. Do not edit manually, do not commit to repo.\n")
|
||||
f:write("// Provides a forward declaration and a typedef for a pointer to each class exported to the Lua API.\n")
|
||||
f:write("\n\n\n\n\n")
|
||||
for _, item in ipairs(types) do
|
||||
if not(item.name:match(".*<.*")) then -- Skip templates altogether
|
||||
-- Classes start with a "c", everything else is a struct:
|
||||
if (item.name:sub(1, 1) == "c") then
|
||||
f:write("class " .. item.name .. ";\n")
|
||||
else
|
||||
f:write("struct " .. item.name .. ";\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
f:write("\n\n\n\n\n")
|
||||
for _, item in ipairs(types) do
|
||||
f:write("typedef " .. item.name .. " * Ptr" .. item.lname .. ";\n")
|
||||
end
|
||||
f:write("\n\n\n\n\n")
|
||||
f:close()
|
||||
end
|
||||
|
||||
-- Output the Push() and GetStackValue() function declarations:
|
||||
do
|
||||
local f = assert(io.open("LuaState_Declaration.inc", "w"))
|
||||
f:write("\n// LuaState_Declaration.inc\n\n// This file is generated along with the Lua bindings by ToLua. Do not edit manually, do not commit to repo.\n")
|
||||
f:write("// Implements a Push() and GetStackValue() function for each class exported to the Lua API.\n")
|
||||
f:write("// This file expects to be included form inside the cLuaState class definition\n")
|
||||
f:write("\n\n\n\n\n")
|
||||
for _, item in ipairs(types) do
|
||||
f:write("void Push(" .. item.name .. " * a_Value);\n")
|
||||
end
|
||||
for _, item in ipairs(types) do
|
||||
f:write("void GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal);\n")
|
||||
end
|
||||
f:write("\n\n\n\n\n")
|
||||
f:close()
|
||||
end
|
||||
|
||||
-- Output the Push() and GetStackValue() function implementations:
|
||||
do
|
||||
local f = assert(io.open("LuaState_Implementation.cpp", "w"))
|
||||
f:write("\n// LuaState_Implementation.cpp\n\n// This file is generated along with the Lua bindings by ToLua. Do not edit manually, do not commit to repo.\n")
|
||||
f:write("// Implements a Push() and GetStackValue() function for each class exported to the Lua API.\n")
|
||||
f:write("// This file expects to be compiled as a separate translation unit\n")
|
||||
f:write("\n\n\n\n\n")
|
||||
f:write("#include \"Globals.h\"\n#include \"LuaState.h\"\n#include \"tolua++/include/tolua++.h\"\n")
|
||||
f:write("\n\n\n\n\n")
|
||||
for _, item in ipairs(types) do
|
||||
if not(g_HasCustomPushImplementation[item.name]) then
|
||||
f:write("void cLuaState::Push(" .. item.name .. " * a_Value)\n{\n\tASSERT(IsValid());\n")
|
||||
f:write("\ttolua_pushusertype(m_LuaState, a_Value, \"" .. item.name .. "\");\n");
|
||||
f:write("\tm_NumCurrentFunctionArgs += 1;\n")
|
||||
f:write("}\n\n\n\n\n\n")
|
||||
end
|
||||
end
|
||||
for _, item in ipairs(types) do
|
||||
f:write("void cLuaState::GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal)\n{\n\tASSERT(IsValid());\n")
|
||||
f:write("\tif (lua_isnil(m_LuaState, a_StackPos))\n\t{\n")
|
||||
f:write("\t a_ReturnedVal = nullptr;\n")
|
||||
f:write("\t return;\n\t}\n")
|
||||
f:write("\ttolua_Error err;\n")
|
||||
f:write("\tif (tolua_isusertype(m_LuaState, a_StackPos, \"" .. item.name .. "\", false, &err))\n")
|
||||
f:write("\t{\n")
|
||||
f:write("\t a_ReturnedVal = *(reinterpret_cast<" .. item.name .. " **>(lua_touserdata(m_LuaState, a_StackPos)));\n")
|
||||
f:write("\t}\n")
|
||||
f:write("}\n\n\n\n\n\n")
|
||||
end
|
||||
f:close()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function pre_output_hook(a_Package)
|
||||
OutputLuaStateHelpers(a_Package)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function post_output_hook()
|
||||
print("Bindings have been generated.")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@ SET (SRCS
|
||||
LuaNameLookup.cpp
|
||||
LuaServerHandle.cpp
|
||||
LuaState.cpp
|
||||
LuaState_Implementation.cpp
|
||||
LuaTCPLink.cpp
|
||||
LuaUDPEndpoint.cpp
|
||||
LuaWindow.cpp
|
||||
@ -31,6 +32,8 @@ SET (HDRS
|
||||
LuaNameLookup.h
|
||||
LuaServerHandle.h
|
||||
LuaState.h
|
||||
LuaState_Declaration.inc
|
||||
LuaState_Typedefs.inc
|
||||
LuaTCPLink.h
|
||||
LuaUDPEndpoint.h
|
||||
LuaWindow.h
|
||||
@ -46,12 +49,15 @@ SET (HDRS
|
||||
set (BINDING_OUTPUTS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Bindings.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Bindings.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/LuaState_Declaration.inc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/LuaState_Implementation.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/LuaState_Typedefs.inc
|
||||
)
|
||||
|
||||
set(BINDING_DEPENDENCIES
|
||||
tolua
|
||||
../Bindings/virtual_method_hooks.lua
|
||||
../Bindings/AllToLua.pkg
|
||||
../Bindings/BindingsProcessor.lua
|
||||
../Bindings/LuaFunctions.h
|
||||
../Bindings/LuaWindow.h
|
||||
../Bindings/Plugin.h
|
||||
@ -126,7 +132,7 @@ if (NOT MSVC)
|
||||
OUTPUT ${BINDING_OUTPUTS}
|
||||
|
||||
# Regenerate bindings:
|
||||
COMMAND tolua -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
COMMAND tolua -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
||||
# add any new generation dependencies here
|
||||
@ -134,8 +140,7 @@ if (NOT MSVC)
|
||||
)
|
||||
endif ()
|
||||
|
||||
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES GENERATED TRUE)
|
||||
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.h PROPERTIES GENERATED TRUE)
|
||||
set_source_files_properties(${BINDING_OUTPUTS} PROPERTIES GENERATED TRUE)
|
||||
|
||||
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES COMPILE_FLAGS -Wno-error)
|
||||
|
||||
|
@ -530,42 +530,6 @@ void cLuaState::Push(bool a_Value)
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cBlockEntity * a_BlockEntity)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_BlockEntity, (a_BlockEntity == nullptr) ? "cBlockEntity" : a_BlockEntity->GetClass());
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cChunkDesc * a_ChunkDesc)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_ChunkDesc, "cChunkDesc");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cClientHandle * a_Client)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Client, "cClientHandle");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cEntity * a_Entity)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
@ -632,42 +596,6 @@ void cLuaState::Push(cEntity * a_Entity)
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cHopperEntity * a_Hopper)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Hopper, "cHopperEntity");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cItem * a_Item)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Item, "cItem");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cItems * a_Items)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Items, "cItems");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cLuaServerHandle * a_ServerHandle)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
@ -704,126 +632,6 @@ void cLuaState::Push(cLuaUDPEndpoint * a_UDPEndpoint)
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cMonster * a_Monster)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Monster, "cMonster");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cPickup * a_Pickup)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Pickup, "cPickup");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cPlayer * a_Player)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cPlugin * a_Plugin)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Plugin, "cPlugin");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cPluginLua * a_Plugin)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Plugin, "cPluginLua");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cProjectileEntity * a_ProjectileEntity)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_ProjectileEntity, "cProjectileEntity");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cTNTEntity * a_TNTEntity)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_TNTEntity, "cTNTEntity");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cWebAdmin * a_WebAdmin)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_WebAdmin, "cWebAdmin");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cWindow * a_Window)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Window, "cWindow");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cWorld * a_World)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_World, "cWorld");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(double a_Value)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
@ -848,42 +656,6 @@ void cLuaState::Push(int a_Value)
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(TakeDamageInfo * a_TDI)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_TDI, "TakeDamageInfo");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(Vector3d * a_Vector)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Vector, "Vector3<double>");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(Vector3i * a_Vector)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Vector, "Vector3<int>");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(void * a_Ptr)
|
||||
{
|
||||
UNUSED(a_Ptr);
|
||||
@ -899,6 +671,10 @@ void cLuaState::Push(void * a_Ptr)
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(std::chrono::milliseconds a_Value)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
@ -911,6 +687,7 @@ void cLuaState::Push(std::chrono::milliseconds a_Value)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void cLuaState::PushUserType(void * a_Object, const char * a_Type)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
@ -918,6 +695,7 @@ void cLuaState::PushUserType(void * a_Object, const char * a_Type)
|
||||
tolua_pushusertype(m_LuaState, a_Object, a_Type);
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -1031,149 +809,6 @@ void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal)
|
||||
|
||||
|
||||
|
||||
void cLuaState::GetStackValue(int a_StackPos, pBlockArea & a_ReturnedVal)
|
||||
{
|
||||
if (lua_isnil(m_LuaState, a_StackPos))
|
||||
{
|
||||
a_ReturnedVal = nullptr;
|
||||
return;
|
||||
}
|
||||
tolua_Error err;
|
||||
if (tolua_isusertype(m_LuaState, a_StackPos, "cBlockArea", false, &err))
|
||||
{
|
||||
a_ReturnedVal = *(reinterpret_cast<cBlockArea **>(lua_touserdata(m_LuaState, a_StackPos)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal)
|
||||
{
|
||||
if (lua_isnil(m_LuaState, a_StackPos))
|
||||
{
|
||||
a_ReturnedVal = nullptr;
|
||||
return;
|
||||
}
|
||||
tolua_Error err;
|
||||
if (tolua_isusertype(m_LuaState, a_StackPos, "cBoundingBox", false, &err))
|
||||
{
|
||||
a_ReturnedVal = *(reinterpret_cast<cBoundingBox **>(lua_touserdata(m_LuaState, a_StackPos)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::GetStackValue(int a_StackPos, pMapManager & a_ReturnedVal)
|
||||
{
|
||||
if (lua_isnil(m_LuaState, a_StackPos))
|
||||
{
|
||||
a_ReturnedVal = nullptr;
|
||||
return;
|
||||
}
|
||||
tolua_Error err;
|
||||
if (tolua_isusertype(m_LuaState, a_StackPos, "cMapManager", false, &err))
|
||||
{
|
||||
a_ReturnedVal = *(reinterpret_cast<cMapManager **>(lua_touserdata(m_LuaState, a_StackPos)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::GetStackValue(int a_StackPos, pPluginManager & a_ReturnedVal)
|
||||
{
|
||||
if (lua_isnil(m_LuaState, a_StackPos))
|
||||
{
|
||||
a_ReturnedVal = nullptr;
|
||||
return;
|
||||
}
|
||||
tolua_Error err;
|
||||
if (tolua_isusertype(m_LuaState, a_StackPos, "cPluginManager", false, &err))
|
||||
{
|
||||
a_ReturnedVal = *(reinterpret_cast<cPluginManager **>(lua_touserdata(m_LuaState, a_StackPos)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::GetStackValue(int a_StackPos, pRoot & a_ReturnedVal)
|
||||
{
|
||||
if (lua_isnil(m_LuaState, a_StackPos))
|
||||
{
|
||||
a_ReturnedVal = nullptr;
|
||||
return;
|
||||
}
|
||||
tolua_Error err;
|
||||
if (tolua_isusertype(m_LuaState, a_StackPos, "cRoot", false, &err))
|
||||
{
|
||||
a_ReturnedVal = *(reinterpret_cast<cRoot **>(lua_touserdata(m_LuaState, a_StackPos)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::GetStackValue(int a_StackPos, pScoreboard & a_ReturnedVal)
|
||||
{
|
||||
if (lua_isnil(m_LuaState, a_StackPos))
|
||||
{
|
||||
a_ReturnedVal = nullptr;
|
||||
return;
|
||||
}
|
||||
tolua_Error err;
|
||||
if (tolua_isusertype(m_LuaState, a_StackPos, "cScoreboard", false, &err))
|
||||
{
|
||||
a_ReturnedVal = *(reinterpret_cast<cScoreboard **>(lua_touserdata(m_LuaState, a_StackPos)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal)
|
||||
{
|
||||
if (lua_isnil(m_LuaState, a_StackPos))
|
||||
{
|
||||
a_ReturnedVal = nullptr;
|
||||
return;
|
||||
}
|
||||
tolua_Error err;
|
||||
if (tolua_isusertype(m_LuaState, a_StackPos, "cWorld", false, &err))
|
||||
{
|
||||
a_ReturnedVal = *(reinterpret_cast<cWorld **>(lua_touserdata(m_LuaState, a_StackPos)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::GetStackValue(int a_StackPos, pClientHandle & a_ReturnedVal)
|
||||
{
|
||||
if (lua_isnil(m_LuaState, a_StackPos))
|
||||
{
|
||||
a_ReturnedVal = nullptr;
|
||||
return;
|
||||
}
|
||||
tolua_Error err;
|
||||
if (tolua_isusertype(m_LuaState, a_StackPos, "cClientHandle", false, &err))
|
||||
{
|
||||
a_ReturnedVal = *(reinterpret_cast<cClientHandle **>(lua_touserdata(m_LuaState, a_StackPos)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool cLuaState::CallFunction(int a_NumResults)
|
||||
{
|
||||
ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
|
||||
|
@ -33,50 +33,12 @@ extern "C"
|
||||
#include "../Vector3.h"
|
||||
#include "../Defines.h"
|
||||
#include "PluginManager.h"
|
||||
#include "LuaState_Typedefs.inc"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cBlockArea;
|
||||
class cBlockEntity;
|
||||
class cBoundingBox;
|
||||
class cChunkDesc;
|
||||
class cClientHandle;
|
||||
class cCraftingGrid;
|
||||
class cCraftingRecipe;
|
||||
class cEntity;
|
||||
class cHopperEntity;
|
||||
class cItem;
|
||||
class cItems;
|
||||
// fwd:
|
||||
class cLuaServerHandle;
|
||||
class cLuaTCPLink;
|
||||
class cLuaUDPEndpoint;
|
||||
class cMapManager;
|
||||
class cMonster;
|
||||
class cPickup;
|
||||
class cPlayer;
|
||||
class cPlugin;
|
||||
class cPluginLua;
|
||||
class cProjectileEntity;
|
||||
class cRoot;
|
||||
class cScoreboard;
|
||||
class cTNTEntity;
|
||||
class cWebAdmin;
|
||||
class cWindow;
|
||||
class cWorld;
|
||||
struct HTTPRequest;
|
||||
struct HTTPTemplateRequest;
|
||||
struct TakeDamageInfo;
|
||||
|
||||
typedef cBlockArea * pBlockArea;
|
||||
typedef cBoundingBox * pBoundingBox;
|
||||
typedef cMapManager * pMapManager;
|
||||
typedef cPluginManager * pPluginManager;
|
||||
typedef cRoot * pRoot;
|
||||
typedef cScoreboard * pScoreboard;
|
||||
typedef cWorld * pWorld;
|
||||
typedef cClientHandle * pClientHandle;
|
||||
|
||||
|
||||
|
||||
@ -214,35 +176,15 @@ public:
|
||||
void Push(const Vector3i & a_Vector);
|
||||
void Push(const Vector3i * a_Vector);
|
||||
|
||||
// Push a value onto the stack (keep alpha-sorted):
|
||||
// Push a simple value onto the stack (keep alpha-sorted):
|
||||
void Push(bool a_Value);
|
||||
void Push(cBlockEntity * a_BlockEntity);
|
||||
void Push(cChunkDesc * a_ChunkDesc);
|
||||
void Push(cClientHandle * a_ClientHandle);
|
||||
void Push(cEntity * a_Entity);
|
||||
void Push(cHopperEntity * a_Hopper);
|
||||
void Push(cItem * a_Item);
|
||||
void Push(cItems * a_Items);
|
||||
void Push(double a_Value);
|
||||
void Push(int a_Value);
|
||||
void Push(void * a_Ptr);
|
||||
void Push(std::chrono::milliseconds a_time);
|
||||
void Push(cLuaServerHandle * a_ServerHandle);
|
||||
void Push(cLuaTCPLink * a_TCPLink);
|
||||
void Push(cLuaUDPEndpoint * a_UDPEndpoint);
|
||||
void Push(cMonster * a_Monster);
|
||||
void Push(cPickup * a_Pickup);
|
||||
void Push(cPlayer * a_Player);
|
||||
void Push(cPlugin * a_Plugin);
|
||||
void Push(cPluginLua * a_Plugin);
|
||||
void Push(cProjectileEntity * a_ProjectileEntity);
|
||||
void Push(cTNTEntity * a_TNTEntity);
|
||||
void Push(cWebAdmin * a_WebAdmin);
|
||||
void Push(cWindow * a_Window);
|
||||
void Push(cWorld * a_World);
|
||||
void Push(double a_Value);
|
||||
void Push(int a_Value);
|
||||
void Push(TakeDamageInfo * a_TDI);
|
||||
void Push(Vector3d * a_Vector);
|
||||
void Push(Vector3i * a_Vector);
|
||||
void Push(void * a_Ptr);
|
||||
void Push(std::chrono::milliseconds a_time);
|
||||
|
||||
// GetStackValue() retrieves the value at a_StackPos, if it is a valid type. If not, a_Value is unchanged.
|
||||
// Enum values are clamped to their allowed range.
|
||||
@ -252,17 +194,12 @@ public:
|
||||
void GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result);
|
||||
void GetStackValue(int a_StackPos, cRef & a_Ref);
|
||||
void GetStackValue(int a_StackPos, double & a_Value);
|
||||
void GetStackValue(int a_StackPos, float & a_ReturnedVal);
|
||||
void GetStackValue(int a_StackPos, eWeather & a_Value);
|
||||
void GetStackValue(int a_StackPos, float & a_ReturnedVal);
|
||||
void GetStackValue(int a_StackPos, int & a_Value);
|
||||
void GetStackValue(int a_StackPos, pBlockArea & a_Value);
|
||||
void GetStackValue(int a_StackPos, pBoundingBox & a_Value);
|
||||
void GetStackValue(int a_StackPos, pClientHandle & a_Value);
|
||||
void GetStackValue(int a_StackPos, pMapManager & a_Value);
|
||||
void GetStackValue(int a_StackPos, pPluginManager & a_Value);
|
||||
void GetStackValue(int a_StackPos, pRoot & a_Value);
|
||||
void GetStackValue(int a_StackPos, pScoreboard & a_Value);
|
||||
void GetStackValue(int a_StackPos, pWorld & a_Value);
|
||||
|
||||
// Include the auto-generated Push and GetStackValue() functions:
|
||||
#include "LuaState_Declaration.inc"
|
||||
|
||||
/** Call the specified Lua function.
|
||||
Returns true if call succeeded, false if there was an error.
|
||||
@ -441,7 +378,7 @@ protected:
|
||||
bool PushFunction(const cTableRef & a_TableRef);
|
||||
|
||||
/** Pushes a usertype of the specified class type onto the stack */
|
||||
void PushUserType(void * a_Object, const char * a_Type);
|
||||
// void PushUserType(void * a_Object, const char * a_Type);
|
||||
|
||||
/**
|
||||
Calls the function that has been pushed onto the stack by PushFunction(),
|
||||
|
@ -1,518 +0,0 @@
|
||||
-- flags
|
||||
local disable_virtual_hooks = true
|
||||
local enable_pure_virtual = true
|
||||
local default_private_access = false
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local access = {public = 0, protected = 1, private = 2}
|
||||
|
||||
function preparse_hook(p)
|
||||
|
||||
if default_private_access then
|
||||
-- we need to make all structs 'public' by default
|
||||
p.code = string.gsub(p.code, "(struct[^;]*{)", "%1\npublic:\n")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function parser_hook(s)
|
||||
|
||||
local container = classContainer.curr -- get the current container
|
||||
|
||||
if default_private_access then
|
||||
if not container.curr_member_access and container.classtype == 'class' then
|
||||
-- default access for classes is private
|
||||
container.curr_member_access = access.private
|
||||
end
|
||||
end
|
||||
|
||||
-- try labels (public, private, etc)
|
||||
do
|
||||
local b,e,label = string.find(s, "^%s*(%w*)%s*:[^:]") -- we need to check for [^:], otherwise it would match 'namespace::type'
|
||||
if b then
|
||||
|
||||
-- found a label, get the new access value from the global 'access' table
|
||||
if access[label] then
|
||||
container.curr_member_access = access[label]
|
||||
end -- else ?
|
||||
|
||||
return strsub(s, e) -- normally we would use 'e+1', but we need to preserve the [^:]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local ret = nil
|
||||
|
||||
if disable_virtual_hooks then
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
local b,e,decl,arg = string.find(s, "^%s*virtual%s+([^%({~]+)(%b())")
|
||||
local const
|
||||
if b then
|
||||
local ret = string.sub(s, e+1)
|
||||
if string.find(ret, "^%s*const") then
|
||||
const = "const"
|
||||
ret = string.gsub(ret, "^%s*const", "")
|
||||
end
|
||||
local purev = false
|
||||
if string.find(ret, "^%s*=%s*0") then
|
||||
purev = true
|
||||
ret = string.gsub(ret, "^%s*=%s*0", "")
|
||||
end
|
||||
ret = string.gsub(ret, "^%s*%b{}", "")
|
||||
|
||||
local func = Function(decl, arg, const)
|
||||
func.pure_virtual = purev
|
||||
--func.access = access
|
||||
func.original_sig = decl
|
||||
|
||||
local curflags = classContainer.curr.flags
|
||||
if not curflags.virtual_class then
|
||||
|
||||
curflags.virtual_class = VirtualClass()
|
||||
end
|
||||
curflags.virtual_class:add(func)
|
||||
curflags.pure_virtual = curflags.pure_virtual or purev
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
-- class VirtualClass
|
||||
classVirtualClass = {
|
||||
classtype = 'class',
|
||||
name = '',
|
||||
base = '',
|
||||
type = '',
|
||||
btype = '',
|
||||
ctype = '',
|
||||
}
|
||||
classVirtualClass.__index = classVirtualClass
|
||||
setmetatable(classVirtualClass,classClass)
|
||||
|
||||
function classVirtualClass:add(f)
|
||||
|
||||
local parent = classContainer.curr
|
||||
pop()
|
||||
|
||||
table.insert(self.methods, {f=f})
|
||||
|
||||
local name,sig
|
||||
|
||||
-- doble negative means positive
|
||||
if f.name == 'new' and ((not self.flags.parent_object.flags.pure_virtual) or (enable_pure_virtual)) then
|
||||
|
||||
name = self.original_name
|
||||
elseif f.name == 'delete' then
|
||||
name = '~'..self.original_name
|
||||
else
|
||||
if f.access ~= 2 and (not f.pure_virtual) and f.name ~= 'new' and f.name ~= 'delete' then
|
||||
name = f.mod.." "..f.type..f.ptr.." "..self.flags.parent_object.lname.."__"..f.name
|
||||
end
|
||||
end
|
||||
|
||||
if name then
|
||||
sig = name..self:get_arg_list(f, true)..";\n"
|
||||
push(self)
|
||||
sig = preprocess(sig)
|
||||
self:parse(sig)
|
||||
pop()
|
||||
end
|
||||
|
||||
push(parent)
|
||||
end
|
||||
|
||||
function preprocess(sig)
|
||||
|
||||
sig = gsub(sig,"([^%w_])void%s*%*","%1_userdata ") -- substitute 'void*'
|
||||
sig = gsub(sig,"([^%w_])void%s*%*","%1_userdata ") -- substitute 'void*'
|
||||
sig = gsub(sig,"([^%w_])char%s*%*","%1_cstring ") -- substitute 'char*'
|
||||
sig = gsub(sig,"([^%w_])lua_State%s*%*","%1_lstate ") -- substitute 'lua_State*'
|
||||
|
||||
return sig
|
||||
end
|
||||
|
||||
function classVirtualClass:get_arg_list(f, decl)
|
||||
|
||||
local ret = ""
|
||||
local sep = ""
|
||||
local i=1
|
||||
while f.args[i] do
|
||||
|
||||
local arg = f.args[i]
|
||||
if decl then
|
||||
local ptr
|
||||
if arg.ret ~= '' then
|
||||
ptr = arg.ret
|
||||
else
|
||||
ptr = arg.ptr
|
||||
end
|
||||
local def = ""
|
||||
if arg.def and arg.def ~= "" then
|
||||
|
||||
def = " = "..arg.def
|
||||
end
|
||||
ret = ret..sep..arg.mod.." "..arg.type..ptr.." "..arg.name..def
|
||||
else
|
||||
ret = ret..sep..arg.name
|
||||
end
|
||||
|
||||
sep = ","
|
||||
i = i+1
|
||||
end
|
||||
|
||||
return "("..ret..")"
|
||||
end
|
||||
|
||||
function classVirtualClass:add_parent_virtual_methods(parent)
|
||||
|
||||
parent = parent or _global_classes[self.flags.parent_object.btype]
|
||||
|
||||
if not parent then return end
|
||||
|
||||
if parent.flags.virtual_class then
|
||||
|
||||
local vclass = parent.flags.virtual_class
|
||||
for k,v in ipairs(vclass.methods) do
|
||||
if v.f.name ~= 'new' and v.f.name ~= 'delete' and (not self:has_method(v.f)) then
|
||||
table.insert(self.methods, {f=v.f})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
parent = _global_classes[parent.btype]
|
||||
if parent then
|
||||
self:add_parent_virtual_methods(parent)
|
||||
end
|
||||
end
|
||||
|
||||
function classVirtualClass:has_method(f)
|
||||
|
||||
for k,v in pairs(self.methods) do
|
||||
-- just match name for now
|
||||
if v.f.name == f.name then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function classVirtualClass:add_constructors()
|
||||
|
||||
local i=1
|
||||
while self.flags.parent_object[i] do
|
||||
|
||||
local v = self.flags.parent_object[i]
|
||||
if getmetatable(v) == classFunction and (v.name == 'new' or v.name == 'delete') then
|
||||
|
||||
self:add(v)
|
||||
end
|
||||
|
||||
i = i+1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[
|
||||
function classVirtualClass:requirecollection(t)
|
||||
|
||||
self:add_constructors()
|
||||
local req = classClass.requirecollection(self, t)
|
||||
if req then
|
||||
output('class ',self.name,";")
|
||||
end
|
||||
return req
|
||||
end
|
||||
--]]
|
||||
|
||||
function classVirtualClass:supcode()
|
||||
|
||||
-- pure virtual classes can have no default constructors on gcc 4
|
||||
|
||||
if self.flags.parent_object.flags.pure_virtual and not enable_pure_virtual then
|
||||
output('#if (__GNUC__ == 4) || (__GNUC__ > 4 ) // I hope this works on Microsoft Visual studio .net server 2003 XP Compiler\n')
|
||||
end
|
||||
|
||||
local ns
|
||||
if self.prox.classtype == 'namespace' then
|
||||
output('namespace ',self.prox.name, " {")
|
||||
ns = true
|
||||
end
|
||||
|
||||
output("class "..self.original_name.." : public "..self.btype..", public ToluaBase {")
|
||||
|
||||
output("public:\n")
|
||||
|
||||
self:add_parent_virtual_methods()
|
||||
|
||||
self:output_methods(self.btype)
|
||||
self:output_parent_methods()
|
||||
|
||||
self:add_constructors()
|
||||
|
||||
-- no constructor for pure virtual classes
|
||||
if (not self.flags.parent_object.flags.pure_virtual) or enable_pure_virtual then
|
||||
|
||||
self:output_constructors()
|
||||
end
|
||||
|
||||
output("};\n\n")
|
||||
|
||||
if ns then
|
||||
output("};")
|
||||
end
|
||||
|
||||
classClass.supcode(self)
|
||||
|
||||
if self.flags.parent_object.flags.pure_virtual and not enable_pure_virtual then
|
||||
output('#endif // __GNUC__ >= 4\n')
|
||||
end
|
||||
|
||||
-- output collector for custom class if required
|
||||
if self:requirecollection(_collect) and _collect[self.type] then
|
||||
|
||||
output('\n')
|
||||
output('/* function to release collected object via destructor */')
|
||||
output('#ifdef __cplusplus\n')
|
||||
--for i,v in pairs(collect) do
|
||||
i,v = self.type, _collect[self.type]
|
||||
output('\nstatic int '..v..' (lua_State* tolua_S)')
|
||||
output('{')
|
||||
output(' '..i..'* self = ('..i..'*) tolua_tousertype(tolua_S,1,0);')
|
||||
output(' delete self;')
|
||||
output(' return 0;')
|
||||
output('}')
|
||||
--end
|
||||
output('#endif\n\n')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function classVirtualClass:register(pre)
|
||||
|
||||
-- pure virtual classes can have no default constructors on gcc 4
|
||||
if self.flags.parent_object.flags.pure_virtual and not enable_pure_virtual then
|
||||
output('#if (__GNUC__ == 4) || (__GNUC__ > 4 )\n')
|
||||
end
|
||||
|
||||
classClass.register(self, pre)
|
||||
|
||||
if self.flags.parent_object.flags.pure_virtual and not enable_pure_virtual then
|
||||
output('#endif // __GNUC__ >= 4\n')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--function classVirtualClass:requirecollection(_c)
|
||||
-- if self.flags.parent_object.flags.pure_virtual then
|
||||
-- return false
|
||||
-- end
|
||||
-- return classClass.requirecollection(self, _c)
|
||||
--end
|
||||
|
||||
function classVirtualClass:output_parent_methods()
|
||||
|
||||
for k,v in ipairs(self.methods) do
|
||||
|
||||
if v.f.access ~= 2 and (not v.f.pure_virtual) and v.f.name ~= 'new' and v.f.name ~= 'delete' then
|
||||
|
||||
local rettype = v.f.mod.." "..v.f.type..v.f.ptr.." "
|
||||
local parent_name = rettype..self.btype.."__"..v.f.name
|
||||
|
||||
local par_list = self:get_arg_list(v.f, true)
|
||||
local var_list = self:get_arg_list(v.f, false)
|
||||
|
||||
-- the parent's virtual function
|
||||
output("\t"..parent_name..par_list.." {")
|
||||
|
||||
output("\t\treturn (",rettype,")"..self.btype.."::"..v.f.name..var_list..";")
|
||||
output("\t};")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function classVirtualClass:output_methods(btype)
|
||||
|
||||
for k,v in ipairs(self.methods) do
|
||||
|
||||
if v.f.name ~= 'new' and v.f.name ~= 'delete' then
|
||||
|
||||
self:output_method(v.f, btype)
|
||||
end
|
||||
end
|
||||
output("\n")
|
||||
end
|
||||
|
||||
function classVirtualClass:output_constructors()
|
||||
|
||||
for k,v in ipairs(self.methods) do
|
||||
|
||||
if v.f.name == 'new' then
|
||||
|
||||
local par_list = self:get_arg_list(v.f, true)
|
||||
local var_list = self:get_arg_list(v.f, false)
|
||||
|
||||
output("\t",self.original_name,par_list,":",self.btype,var_list,"{};")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function classVirtualClass:output_method(f, btype)
|
||||
|
||||
if f.access == 2 then -- private
|
||||
return
|
||||
end
|
||||
|
||||
local ptr
|
||||
if f.ret ~= '' then
|
||||
ptr = f.ret
|
||||
else
|
||||
ptr = f.ptr
|
||||
end
|
||||
|
||||
local rettype = f.mod.." "..f.type..f.ptr.." "
|
||||
local par_list = self:get_arg_list(f, true)
|
||||
local var_list = self:get_arg_list(f, false)
|
||||
|
||||
if string.find(rettype, "%s*LuaQtGenericFlags%s*") then
|
||||
|
||||
_,_,rettype = string.find(f.original_sig, "^%s*([^%s]+)%s+")
|
||||
end
|
||||
|
||||
-- the caller of the lua method
|
||||
output("\t"..rettype.." "..f.name..par_list..f.const.." {")
|
||||
local fn = f.cname
|
||||
if f.access == 1 then
|
||||
fn = "NULL"
|
||||
end
|
||||
output('\t\tif (push_method("',f.lname,'", ',fn,')) {')
|
||||
|
||||
--if f.type ~= 'void' then
|
||||
-- output("\t\t\tint top = lua_gettop(lua_state)-1;")
|
||||
--end
|
||||
|
||||
-- push the parameters
|
||||
local argn = 0
|
||||
for i,arg in ipairs(f.args) do
|
||||
if arg.type ~= 'void' then
|
||||
local t,ct = isbasic(arg.type)
|
||||
if t and t ~= '' then
|
||||
if arg.ret == "*" then
|
||||
t = 'userdata'
|
||||
ct = 'void*'
|
||||
end
|
||||
output("\t\t\ttolua_push"..t.."(lua_state, ("..ct..")"..arg.name..");");
|
||||
else
|
||||
local m = arg.ptr
|
||||
if m and m~= "" then
|
||||
if m == "*" then m = "" end
|
||||
output("\t\t\ttolua_pushusertype(lua_state, (void*)"..m..arg.name..", \""..arg.type.."\");")
|
||||
else
|
||||
output("\t\t\tvoid* tolua_obj" .. argn .." = (void*)new "..arg.type.."("..arg.name..");\n")
|
||||
output('\t\t\ttolua_pushusertype_and_takeownership(lua_state, tolua_obj' .. argn .. ', "'..arg.type..'");\n')
|
||||
end
|
||||
end
|
||||
argn = argn+1
|
||||
end
|
||||
end
|
||||
|
||||
-- call the function
|
||||
output("\t\t\tToluaBase::dbcall(lua_state, ",argn+1,", ")
|
||||
|
||||
-- return value
|
||||
if f.type ~= 'void' then
|
||||
output("1);")
|
||||
|
||||
local t,ct = isbasic(f.type)
|
||||
if t and t ~= '' then
|
||||
--output("\t\t\treturn ("..rettype..")tolua_to"..t.."(lua_state, top, 0);")
|
||||
output("\t\t\t",rettype,"tolua_ret = ("..rettype..")tolua_to"..t.."(lua_state, -1, 0);")
|
||||
else
|
||||
|
||||
local mod = ""
|
||||
if f.ptr ~= "*" then
|
||||
mod = "*("..f.type.."*)"
|
||||
end
|
||||
|
||||
--output("\t\t\treturn ("..rettype..")"..mod.."tolua_tousertype(lua_state, top, 0);")
|
||||
output("\t\t\t",rettype,"tolua_ret = ("..rettype..")"..mod.."tolua_tousertype(lua_state, -1, 0);")
|
||||
end
|
||||
output("\t\t\tlua_pop(lua_state, 1);")
|
||||
output("\t\t\treturn tolua_ret;")
|
||||
else
|
||||
output("0);")
|
||||
end
|
||||
|
||||
-- handle non-implemeted function
|
||||
output("\t\t} else {")
|
||||
|
||||
if f.pure_virtual then
|
||||
|
||||
output('\t\t\tif (lua_state)')
|
||||
--output('\t\t\t\ttolua_error(lua_state, "pure-virtual method '..btype.."::"..f.name..' not implemented.", NULL);')
|
||||
output('\t\t\t\tLOG("pure-virtual method '..btype.."::"..f.name..' not implemented.");')
|
||||
output('\t\t\telse {')
|
||||
output('\t\t\t\tLOG("pure-virtual method '..btype.."::"..f.name..' called with no lua_state. Aborting");')
|
||||
output('\t\t\t\t::abort();')
|
||||
output('\t\t\t};')
|
||||
if( rettype == " std::string " ) then
|
||||
output('\t\t\treturn "";')
|
||||
else
|
||||
output('\t\t\treturn (',rettype,')0;')
|
||||
end
|
||||
else
|
||||
|
||||
output('\t\t\treturn (',rettype,')',btype,'::',f.name,var_list,';')
|
||||
end
|
||||
|
||||
output("\t\t};")
|
||||
|
||||
output("\t};")
|
||||
end
|
||||
|
||||
function VirtualClass()
|
||||
|
||||
local parent = classContainer.curr
|
||||
pop()
|
||||
|
||||
local name = "Lua__"..parent.original_name
|
||||
|
||||
local c = _Class(_Container{name=name, base=parent.name, extra_bases=nil})
|
||||
setmetatable(c, classVirtualClass)
|
||||
|
||||
local ft = getnamespace(c.parent)..c.original_name
|
||||
append_global_type(ft, c)
|
||||
|
||||
push(parent)
|
||||
|
||||
c.flags.parent_object = parent
|
||||
c.methods = {}
|
||||
|
||||
push(c)
|
||||
c:parse("\nvoid tolua__set_instance(_lstate L, lua_Object lo);\n")
|
||||
pop()
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function post_output_hook()
|
||||
print("Bindings have been generated.")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
@ -278,7 +278,7 @@ if (MSVC)
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/MCServer/lua51.dll ./lua51.dll
|
||||
|
||||
# Regenerate bindings:
|
||||
COMMAND tolua -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
COMMAND tolua -L BindingsProcessor.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/
|
||||
|
||||
# add any new generation dependencies here
|
||||
|
@ -43,6 +43,7 @@ local g_IgnoredFiles =
|
||||
{
|
||||
"Bindings/Bindings.h",
|
||||
"Bindings/Bindings.cpp",
|
||||
"Bindings/LuaState_Implementation.cpp",
|
||||
"LeakFinder.cpp",
|
||||
"LeakFinder.h",
|
||||
"MersenneTwister.h",
|
||||
|
Loading…
Reference in New Issue
Block a user