ToLua now generates cLuaState::Push() and GetStackValue()
For classes exported through ToLua it generates the cLuaState::Push() and cLuaState::GetStackValue() functions, as well as the supporting forward declarations and typedefs. Renamed virtual_method_hooks.lua to BindingsProcessor.lua since it no longer provides virtual method hooks and instead does additional processing when generating the bindings.
This commit is contained in:
parent
3ddd2f567c
commit
4b97569b3a
|
@ -1,2 +1,4 @@
|
||||||
lua51.dll
|
lua51.dll
|
||||||
LuaState_Call.inc
|
LuaState_Declaration.inc
|
||||||
|
LuaState_Implementation.cpp
|
||||||
|
LuaState_Typedefs.inc
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
:: Regenerate the files:
|
:: Regenerate the files:
|
||||||
echo Regenerating LUA bindings . . .
|
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
|
#!/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:
|
:: Regenerate the files:
|
||||||
echo Regenerating LUA bindings . . .
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
LuaNameLookup.cpp
|
||||||
LuaServerHandle.cpp
|
LuaServerHandle.cpp
|
||||||
LuaState.cpp
|
LuaState.cpp
|
||||||
|
LuaState_Implementation.cpp
|
||||||
LuaTCPLink.cpp
|
LuaTCPLink.cpp
|
||||||
LuaUDPEndpoint.cpp
|
LuaUDPEndpoint.cpp
|
||||||
LuaWindow.cpp
|
LuaWindow.cpp
|
||||||
|
@ -31,6 +32,8 @@ SET (HDRS
|
||||||
LuaNameLookup.h
|
LuaNameLookup.h
|
||||||
LuaServerHandle.h
|
LuaServerHandle.h
|
||||||
LuaState.h
|
LuaState.h
|
||||||
|
LuaState_Declaration.inc
|
||||||
|
LuaState_Typedefs.inc
|
||||||
LuaTCPLink.h
|
LuaTCPLink.h
|
||||||
LuaUDPEndpoint.h
|
LuaUDPEndpoint.h
|
||||||
LuaWindow.h
|
LuaWindow.h
|
||||||
|
@ -46,12 +49,15 @@ SET (HDRS
|
||||||
set (BINDING_OUTPUTS
|
set (BINDING_OUTPUTS
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Bindings.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Bindings.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Bindings.h
|
${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
|
set(BINDING_DEPENDENCIES
|
||||||
tolua
|
tolua
|
||||||
../Bindings/virtual_method_hooks.lua
|
|
||||||
../Bindings/AllToLua.pkg
|
../Bindings/AllToLua.pkg
|
||||||
|
../Bindings/BindingsProcessor.lua
|
||||||
../Bindings/LuaFunctions.h
|
../Bindings/LuaFunctions.h
|
||||||
../Bindings/LuaWindow.h
|
../Bindings/LuaWindow.h
|
||||||
../Bindings/Plugin.h
|
../Bindings/Plugin.h
|
||||||
|
@ -126,7 +132,7 @@ if (NOT MSVC)
|
||||||
OUTPUT ${BINDING_OUTPUTS}
|
OUTPUT ${BINDING_OUTPUTS}
|
||||||
|
|
||||||
# Regenerate bindings:
|
# 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}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
|
||||||
# add any new generation dependencies here
|
# add any new generation dependencies here
|
||||||
|
@ -134,8 +140,7 @@ if (NOT MSVC)
|
||||||
)
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES GENERATED TRUE)
|
set_source_files_properties(${BINDING_OUTPUTS} PROPERTIES GENERATED TRUE)
|
||||||
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.h PROPERTIES GENERATED TRUE)
|
|
||||||
|
|
||||||
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES COMPILE_FLAGS -Wno-error)
|
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)
|
void cLuaState::Push(cEntity * a_Entity)
|
||||||
{
|
{
|
||||||
ASSERT(IsValid());
|
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)
|
void cLuaState::Push(cLuaServerHandle * a_ServerHandle)
|
||||||
{
|
{
|
||||||
ASSERT(IsValid());
|
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)
|
void cLuaState::Push(double a_Value)
|
||||||
{
|
{
|
||||||
ASSERT(IsValid());
|
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)
|
void cLuaState::Push(void * a_Ptr)
|
||||||
{
|
{
|
||||||
UNUSED(a_Ptr);
|
UNUSED(a_Ptr);
|
||||||
|
@ -899,6 +671,10 @@ void cLuaState::Push(void * a_Ptr)
|
||||||
m_NumCurrentFunctionArgs += 1;
|
m_NumCurrentFunctionArgs += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cLuaState::Push(std::chrono::milliseconds a_Value)
|
void cLuaState::Push(std::chrono::milliseconds a_Value)
|
||||||
{
|
{
|
||||||
ASSERT(IsValid());
|
ASSERT(IsValid());
|
||||||
|
@ -911,6 +687,7 @@ void cLuaState::Push(std::chrono::milliseconds a_Value)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void cLuaState::PushUserType(void * a_Object, const char * a_Type)
|
void cLuaState::PushUserType(void * a_Object, const char * a_Type)
|
||||||
{
|
{
|
||||||
ASSERT(IsValid());
|
ASSERT(IsValid());
|
||||||
|
@ -918,6 +695,7 @@ void cLuaState::PushUserType(void * a_Object, const char * a_Type)
|
||||||
tolua_pushusertype(m_LuaState, a_Object, a_Type);
|
tolua_pushusertype(m_LuaState, a_Object, a_Type);
|
||||||
m_NumCurrentFunctionArgs += 1;
|
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)
|
bool cLuaState::CallFunction(int a_NumResults)
|
||||||
{
|
{
|
||||||
ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
|
ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
|
||||||
|
|
|
@ -33,50 +33,12 @@ extern "C"
|
||||||
#include "../Vector3.h"
|
#include "../Vector3.h"
|
||||||
#include "../Defines.h"
|
#include "../Defines.h"
|
||||||
#include "PluginManager.h"
|
#include "PluginManager.h"
|
||||||
|
#include "LuaState_Typedefs.inc"
|
||||||
|
|
||||||
|
// fwd:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cBlockArea;
|
|
||||||
class cBlockEntity;
|
|
||||||
class cBoundingBox;
|
|
||||||
class cChunkDesc;
|
|
||||||
class cClientHandle;
|
|
||||||
class cCraftingGrid;
|
|
||||||
class cCraftingRecipe;
|
|
||||||
class cEntity;
|
|
||||||
class cHopperEntity;
|
|
||||||
class cItem;
|
|
||||||
class cItems;
|
|
||||||
class cLuaServerHandle;
|
class cLuaServerHandle;
|
||||||
class cLuaTCPLink;
|
class cLuaTCPLink;
|
||||||
class cLuaUDPEndpoint;
|
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);
|
||||||
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(bool a_Value);
|
||||||
void Push(cBlockEntity * a_BlockEntity);
|
void Push(double a_Value);
|
||||||
void Push(cChunkDesc * a_ChunkDesc);
|
void Push(int a_Value);
|
||||||
void Push(cClientHandle * a_ClientHandle);
|
void Push(void * a_Ptr);
|
||||||
void Push(cEntity * a_Entity);
|
void Push(std::chrono::milliseconds a_time);
|
||||||
void Push(cHopperEntity * a_Hopper);
|
|
||||||
void Push(cItem * a_Item);
|
|
||||||
void Push(cItems * a_Items);
|
|
||||||
void Push(cLuaServerHandle * a_ServerHandle);
|
void Push(cLuaServerHandle * a_ServerHandle);
|
||||||
void Push(cLuaTCPLink * a_TCPLink);
|
void Push(cLuaTCPLink * a_TCPLink);
|
||||||
void Push(cLuaUDPEndpoint * a_UDPEndpoint);
|
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.
|
// 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.
|
// 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, cPluginManager::CommandResult & a_Result);
|
||||||
void GetStackValue(int a_StackPos, cRef & a_Ref);
|
void GetStackValue(int a_StackPos, cRef & a_Ref);
|
||||||
void GetStackValue(int a_StackPos, double & a_Value);
|
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, eWeather & a_Value);
|
||||||
|
void GetStackValue(int a_StackPos, float & a_ReturnedVal);
|
||||||
void GetStackValue(int a_StackPos, int & a_Value);
|
void GetStackValue(int a_StackPos, int & a_Value);
|
||||||
void GetStackValue(int a_StackPos, pBlockArea & a_Value);
|
|
||||||
void GetStackValue(int a_StackPos, pBoundingBox & a_Value);
|
// Include the auto-generated Push and GetStackValue() functions:
|
||||||
void GetStackValue(int a_StackPos, pClientHandle & a_Value);
|
#include "LuaState_Declaration.inc"
|
||||||
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);
|
|
||||||
|
|
||||||
/** Call the specified Lua function.
|
/** Call the specified Lua function.
|
||||||
Returns true if call succeeded, false if there was an error.
|
Returns true if call succeeded, false if there was an error.
|
||||||
|
@ -441,7 +378,7 @@ protected:
|
||||||
bool PushFunction(const cTableRef & a_TableRef);
|
bool PushFunction(const cTableRef & a_TableRef);
|
||||||
|
|
||||||
/** Pushes a usertype of the specified class type onto the stack */
|
/** 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(),
|
Calls the function that has been pushed onto the stack by PushFunction(),
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
|
|
||||||
-- virtual_method_hooks.lua
|
|
||||||
|
|
||||||
-- Implements additional processing that is done while generating the Lua bindings
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local access = {public = 0, protected = 1, private = 2}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/MCServer/lua51.dll ./lua51.dll
|
||||||
|
|
||||||
# Regenerate bindings:
|
# 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/
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/
|
||||||
|
|
||||||
# add any new generation dependencies here
|
# add any new generation dependencies here
|
||||||
|
|
|
@ -43,6 +43,7 @@ local g_IgnoredFiles =
|
||||||
{
|
{
|
||||||
"Bindings/Bindings.h",
|
"Bindings/Bindings.h",
|
||||||
"Bindings/Bindings.cpp",
|
"Bindings/Bindings.cpp",
|
||||||
|
"Bindings/LuaState_Implementation.cpp",
|
||||||
"LeakFinder.cpp",
|
"LeakFinder.cpp",
|
||||||
"LeakFinder.h",
|
"LeakFinder.h",
|
||||||
"MersenneTwister.h",
|
"MersenneTwister.h",
|
||||||
|
|
Loading…
Reference in New Issue