diff --git a/CMakeLists.txt b/CMakeLists.txt index f8ad02e9..5738f94f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/TODO b/TODO index 3692be58..0398e081 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/src/framework/global.h b/src/framework/global.h index da93f93d..e53d22f4 100644 --- a/src/framework/global.h +++ b/src/framework/global.h @@ -23,42 +23,8 @@ #ifndef FRAMEWORK_GLOBAL_H #define FRAMEWORK_GLOBAL_H -// common C headers -#include -#include -#include -#include -#include -#include -#include - -// common STL headers -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// boost utilities -#include -#include +// common C/C++ headers +#include "pch.h" // global constants #include "const.h" diff --git a/src/framework/pch.h b/src/framework/pch.h new file mode 100644 index 00000000..f2e201e3 --- /dev/null +++ b/src/framework/pch.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2010-2011 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 +#include +#include +#include +#include +#include +#include + +// common STL headers +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// boost utilities +#include + +#endif diff --git a/src/framework/util/tools.h b/src/framework/util/tools.h index 159cd1fc..03ff0ed4 100644 --- a/src/framework/util/tools.h +++ b/src/framework/util/tools.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/src/otclient/const.h b/src/otclient/const.h index 23b7feb2..554f65a2 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -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" diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index e0734bae..8cf39c2d 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2010-2011 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& args) { logInfo(Otc::AppName, " ", Otc::AppVersion); - Application::init(Otc::AppName, args); + Application::init(Otc::AppCompactName, args); } diff --git a/src/otclient/otclient.h b/src/otclient/otclient.h index c40321a3..381a610f 100644 --- a/src/otclient/otclient.h +++ b/src/otclient/otclient.h @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2010-2011 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 diff --git a/tools/lua-binding-generator/generate_lua_bindings.lua b/tools/lua-binding-generator/generate_lua_bindings.lua new file mode 100755 index 00000000..b77022d2 --- /dev/null +++ b/tools/lua-binding-generator/generate_lua_bindings.lua @@ -0,0 +1,94 @@ +#!/usr/bin/lua + +if not (#arg >= 1 and #arg <= 4) then + print('usage: ' .. arg[0] .. ' [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