add lua binding generator tools, changes in pch header

master
Eduardo Bart 12 years ago
parent f548825faf
commit d2d8a0097a

@ -218,7 +218,7 @@ TARGET_LINK_LIBRARIES(
)
IF(USE_PCH)
ADD_PRECOMPILED_HEADER(otclient ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.h)
ADD_PRECOMPILED_HEADER(otclient ${CMAKE_CURRENT_SOURCE_DIR}/src/framework/pch.h)
ENDIF(USE_PCH)
# installation

@ -28,3 +28,4 @@ make lua/c++ logger more friendly
bind every global lua function in a static class
use metatable for Point,Rect,Color,Size lua classes
lua binder generator
restore win32 platform

@ -23,42 +23,8 @@
#ifndef FRAMEWORK_GLOBAL_H
#define FRAMEWORK_GLOBAL_H
// common C headers
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <ctime>
#include <cmath>
#include <csignal>
// common STL headers
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <algorithm>
#include <exception>
#include <memory>
#include <type_traits>
#include <tuple>
#include <functional>
#include <typeinfo>
#include <array>
#include <iomanip>
#include <unordered_map>
#include <random>
#include <chrono>
// boost utilities
#include <boost/algorithm/string.hpp>
#include <boost/any.hpp>
// common C/C++ headers
#include "pch.h"
// global constants
#include "const.h"

@ -0,0 +1,62 @@
/*
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef PCH_H
#define PCH_H
// common C headers
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <ctime>
#include <cmath>
#include <csignal>
// common STL headers
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <algorithm>
#include <exception>
#include <memory>
#include <type_traits>
#include <tuple>
#include <functional>
#include <typeinfo>
#include <array>
#include <iomanip>
#include <unordered_map>
#include <random>
#include <chrono>
// boost utilities
#include <boost/algorithm/string.hpp>
#endif

@ -25,6 +25,7 @@
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <exception>

@ -28,7 +28,7 @@
namespace Otc
{
static const char* AppName = "OTClient";
static const char* AppIdentifierName = "otclient";
static const char* AppCompactName = "otclient";
static const char* AppVersion = "0.4.0";
static const char* CipsoftPublicRSA = "1321277432058722840622950990822933849527763264961655079678763618"

@ -1,3 +1,25 @@
/*
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "otclient.h"
OTClient g_otclient;
@ -6,5 +28,5 @@ Application& g_app = g_otclient;
void OTClient::init(const std::vector<std::string>& args)
{
logInfo(Otc::AppName, " ", Otc::AppVersion);
Application::init(Otc::AppName, args);
Application::init(Otc::AppCompactName, args);
}

@ -1,3 +1,25 @@
/*
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef OTCLIENT_H
#define OTCLIENT_H

@ -0,0 +1,94 @@
#!/usr/bin/lua
if not (#arg >= 1 and #arg <= 4) then
print('usage: ' .. arg[0] .. ' <cpp class header> [class name] [cpp class instance] [lua class instance]')
return false
end
cppclassheader = arg[1]
cppclassname = arg[2]
cppclassinstance = arg[3]
luaclassname = arg[3] or luaclassname
if not io.open(cppclassheader, 'r') then
print('could not open ' .. cppclassheader)
return false
end
function string.matchcount(str, pattern)
local count = 0
for w in str:gmatch(pattern) do count = count + 1 end
return count
end
function string.splitlines(str)
local t = {}
local function helper(line) table.insert(t, line) return "" end
helper((str:gsub("(.-)\r?\n", helper)))
return t
end
classfound = false
publicmethods = false
for line in io.lines(cppclassheader) do
foundclassname = line:match('^class ([%w_]+)')
if foundclassname then
if not cppclassname then
guessedclassname = cppclassheader:match('([%w_]+).h'):lower()
if foundclassname:lower() == guessedclassname then
cppclassname = foundclassname
end
end
if foundclassname == cppclassname then
classfound = true
publicmethods = false
if cppclassinstance then
print('g_lua.registerStaticClass("' .. luaclassname .. '");')
else
baseclassname = line:match(': public ([%w_]+)')
bindline = 'g_lua.registerClass<' .. cppclassname
if baseclassname and baseclassname ~= 'LuaObject' then
bindline = bindline .. ', ' .. baseclassname
end
bindline = bindline .. '>();'
print(bindline)
bindline = 'g_lua.bindClassStaticFunction<' .. cppclassname .. '>("create", &' .. cppclassname .. '::create);'
print(bindline)
end
elseif classfound then
return true
end
end
if classfound then
if line:match('public:') then
publicmethods = true
elseif line:match('private:') or line:match('protected:') then
publicmethods = false
elseif publicmethods then
for funcname,args in line:gmatch(' *[%w :_]* ([%w_]+)%(([^%(]*%)) *[;{].*$') do
if funcname ~= cppclassname then
numargs = args:matchcount('[^,)]+[,)]')
if cppclassinstance then
bindline = 'g_lua.bindClassStaticFunction("' .. luaclassname .. '", "' .. funcname .. '", ' ..
'std::bind(&' .. cppclassname .. "::" .. funcname .. ', &' .. cppclassinstance
for i=1,numargs do
bindline = bindline .. ', _' .. i
end
bindline = bindline .. '));'
else
bindline = 'g_lua.bindClassMemberFunction<' .. cppclassname .. '>("' .. funcname .. '", &' ..
cppclassname .. '::' .. funcname .. ');'
end
print(bindline)
end
end
end
end
end
return true
Loading…
Cancel
Save