├── .gitattributes ├── .github └── workflows │ └── cmake.yml ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── COPYRIGHT ├── HISTORY ├── Proto4z.cs ├── README.md ├── build └── README.md ├── dbHelper.h ├── genProto.tools ├── CMakeLists.txt ├── depends │ ├── log4z.cpp │ ├── log4z.h │ ├── md5 │ │ ├── md5.cpp │ │ └── md5.h │ ├── tinyxml2.cpp │ ├── tinyxml2.h │ ├── utls.cpp │ ├── utls.h │ └── utlsImpl.h ├── genProto.sln ├── genProto.vcxproj ├── genProto.vcxproj.filters ├── genProto.vcxproj.user └── src │ ├── any.h │ ├── common.h │ ├── genBase.cpp │ ├── genBase.h │ ├── genCPP.cpp │ ├── genCPP.h │ ├── genCSharp.cpp │ ├── genCSharp.h │ ├── genLUA.cpp │ ├── genLUA.h │ ├── main.cpp │ ├── parseCache.cpp │ ├── parseCache.h │ ├── parseProto.cpp │ └── parseProto.h ├── luasrc └── lproto4z.c ├── proto4z.h ├── proto4z.lua └── test ├── CMakeLists.txt ├── bin └── main.lua ├── cpp ├── CMakeLists.txt ├── TestWeb.h ├── cpp.vcxproj ├── cpp.vcxproj.filters └── test.cpp ├── csharp ├── App.config ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Proto4z.cs ├── TestProto.cs ├── cshap.csproj ├── cshap.csproj.user └── proto4z.sln ├── genCode ├── C++ │ └── TestProto.h ├── CSharp │ └── TestProto.cs ├── TestProto.xml ├── TestProto.xml.cache ├── genProto.exe └── lua │ └── TestProto.lua ├── lua53 ├── CMakeLists.txt ├── lapi.c ├── lapi.h ├── lauxlib.c ├── lauxlib.h ├── lbaselib.c ├── lbitlib.c ├── lcode.c ├── lcode.h ├── lcorolib.c ├── lctype.c ├── lctype.h ├── ldblib.c ├── ldebug.c ├── ldebug.h ├── ldo.c ├── ldo.h ├── ldump.c ├── lfunc.c ├── lfunc.h ├── lgc.c ├── lgc.h ├── linit.c ├── liolib.c ├── llex.c ├── llex.h ├── llimits.h ├── lmathlib.c ├── lmem.c ├── lmem.h ├── loadlib.c ├── lobject.c ├── lobject.h ├── lopcodes.c ├── lopcodes.h ├── loslib.c ├── lparser.c ├── lparser.h ├── lprefix.h ├── lstate.c ├── lstate.h ├── lstring.c ├── lstring.h ├── lstrlib.c ├── ltable.c ├── ltable.h ├── ltablib.c ├── ltm.c ├── ltm.h ├── lua.c ├── lua.h ├── lua.hpp ├── luaconf.h ├── lualib.h ├── lundump.c ├── lundump.h ├── lutf8lib.c ├── lvm.c ├── lvm.h ├── lzio.c ├── lzio.h └── vc │ ├── lua53.sln │ ├── lua53.vcxproj │ └── lua53.vcxproj.user └── test.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.github/workflows/cmake.yml: -------------------------------------------------------------------------------- 1 | name: CITest 2 | 3 | on: 4 | # push: 5 | # branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | env: 10 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 11 | BUILD_TYPE: Release 12 | 13 | jobs: 14 | build: 15 | strategy: 16 | matrix: 17 | cc: [gcc, clang] 18 | os: [ubuntu-latest, macos-latest] 19 | #exclude: 20 | # - os: macos-latest 21 | # cc: clang 22 | 23 | runs-on: ${{ matrix.os }} 24 | 25 | steps: 26 | - uses: actions/checkout@v2 27 | env: 28 | CC: ${{ matrix.cc }} 29 | - name: config cmake 30 | run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} 31 | 32 | - name: build 33 | # Build your program with the given configuration 34 | run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} 35 | 36 | - name: test base 37 | working-directory: ${{github.workspace}}/test/bin 38 | run: | 39 | ./cpptest 40 | ./lua53 41 | 42 | - name: test genProto 43 | if: runner.os == 'Linux' 44 | working-directory: ${{github.workspace}}/test/genCode 45 | run: | 46 | ./genProto 47 | 48 | - name: test genProtoMac 49 | if: runner.os == 'macOS' 50 | working-directory: ${{github.workspace}}/test/genCode 51 | run: | 52 | ./genProtoMac 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | .svn 9 | bin/ 10 | tmp/ 11 | *.tmp 12 | *.bak 13 | *.swp 14 | *~.nib 15 | local.properties 16 | .classpath 17 | .settings/ 18 | .loadpath 19 | 20 | # External tool builders 21 | .externalToolBuilders/ 22 | 23 | # Locally stored "Eclipse launch configurations" 24 | *.launch 25 | 26 | # CDT-specific 27 | .cproject 28 | 29 | # PDT-specific 30 | .buildpath 31 | 32 | 33 | ################# 34 | ## Visual Studio 35 | ################# 36 | 37 | ## Ignore Visual Studio temporary files, build results, and 38 | ## files generated by popular Visual Studio add-ons. 39 | 40 | # User-specific files 41 | *.suo 42 | *.user 43 | *.sln.docstates 44 | 45 | # Build results 46 | 47 | [Dd]ebug/ 48 | [Rr]elease/ 49 | x64/ 50 | build/ 51 | [Bb]in/ 52 | [Oo]bj/ 53 | 54 | # MSTest test Results 55 | [Tt]est[Rr]esult*/ 56 | [Bb]uild[Ll]og.* 57 | 58 | *_i.c 59 | *_p.c 60 | *.ilk 61 | *.meta 62 | *.obj 63 | *.pch 64 | *.pdb 65 | *.pgc 66 | *.pgd 67 | *.rsp 68 | *.sbr 69 | *.tlb 70 | *.tli 71 | *.tlh 72 | *.tmp 73 | *.tmp_proj 74 | *.log 75 | *.vspscc 76 | *.vssscc 77 | .builds 78 | *.pidb 79 | *.log 80 | *.scc 81 | 82 | # Visual C++ cache files 83 | ipch/ 84 | *.aps 85 | *.ncb 86 | *.opensdf 87 | *.sdf 88 | *.cachefile 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | 102 | # TeamCity is a build add-in 103 | _TeamCity* 104 | 105 | # DotCover is a Code Coverage Tool 106 | *.dotCover 107 | 108 | # NCrunch 109 | *.ncrunch* 110 | .*crunch*.local.xml 111 | 112 | # Installshield output folder 113 | [Ee]xpress/ 114 | 115 | # DocProject is a documentation generator add-in 116 | DocProject/buildhelp/ 117 | DocProject/Help/*.HxT 118 | DocProject/Help/*.HxC 119 | DocProject/Help/*.hhc 120 | DocProject/Help/*.hhk 121 | DocProject/Help/*.hhp 122 | DocProject/Help/Html2 123 | DocProject/Help/html 124 | 125 | # Click-Once directory 126 | publish/ 127 | 128 | # Publish Web Output 129 | *.Publish.xml 130 | *.pubxml 131 | 132 | # NuGet Packages Directory 133 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 134 | #packages/ 135 | 136 | # Windows Azure Build Output 137 | csx 138 | *.build.csdef 139 | 140 | # Windows Store app package directory 141 | AppPackages/ 142 | 143 | # Others 144 | sql/ 145 | *.Cache 146 | ClientBin/ 147 | [Ss]tyle[Cc]op.* 148 | ~$* 149 | *~ 150 | *.dbmdl 151 | *.[Pp]ublish.xml 152 | *.pfx 153 | *.publishsettings 154 | 155 | # RIA/Silverlight projects 156 | Generated_Code/ 157 | 158 | # Backup & report files from converting an old project file to a newer 159 | # Visual Studio version. Backup files are not needed, because we have git ;-) 160 | _UpgradeReport_Files/ 161 | Backup*/ 162 | UpgradeLog*.XML 163 | UpgradeLog*.htm 164 | 165 | # SQL Server files 166 | App_Data/*.mdf 167 | App_Data/*.ldf 168 | 169 | ############# 170 | ## Windows detritus 171 | ############# 172 | 173 | # Windows image file caches 174 | Thumbs.db 175 | ehthumbs.db 176 | 177 | # Folder config file 178 | Desktop.ini 179 | 180 | # Recycle Bin used on file shares 181 | $RECYCLE.BIN/ 182 | 183 | # Mac crap 184 | .DS_Store 185 | 186 | 187 | ############# 188 | ## Python 189 | ############# 190 | 191 | *.py[co] 192 | 193 | # Packages 194 | *.egg 195 | *.egg-info 196 | dist/ 197 | build/ 198 | eggs/ 199 | parts/ 200 | var/ 201 | sdist/ 202 | develop-eggs/ 203 | .installed.cfg 204 | 205 | # Installer logs 206 | pip-log.txt 207 | 208 | # Unit test / coverage reports 209 | .coverage 210 | .tox 211 | 212 | #Translations 213 | *.mo 214 | 215 | #Mr Developer 216 | .mr.developer.cfg 217 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: true 2 | language: cpp 3 | matrix: 4 | include: 5 | 6 | # linux version have unique dependencies, so we set them up individually 7 | - os: linux 8 | dist: trusty 9 | compiler: clang 10 | addons: 11 | apt: 12 | sources: 13 | - ubuntu-toolchain-r-test 14 | packages: 15 | - g++-4.9 16 | sudo: required 17 | env: 18 | - TARGET="trusty" 19 | 20 | # OS X Xcode 21 | - os: osx 22 | osx_image: xcode8.3 23 | env: 24 | - TOOL="xcode-osx" 25 | 26 | 27 | 28 | 29 | before_install: 30 | - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi 31 | - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then sudo apt-get update -qq; fi 32 | 33 | install: 34 | - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then sudo apt-get install -qq cmake; fi 35 | - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then sudo apt-get install -qq g++-4.9; fi 36 | - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then export CXX="g++-4.9"; fi 37 | script: 38 | - cmake --version 39 | - cmake . 40 | - make 41 | - ls test/bin/* 42 | - ls test/genCode/* 43 | - cd test/genCode 44 | - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./genProto; fi 45 | - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ./genProtoMac; fi 46 | - cd ../../ 47 | - cd test/bin 48 | - ./cpptest 49 | - ./lua53 50 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(proto4z) 3 | 4 | set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "") 5 | 6 | set(LIB_SUFFIX "") 7 | 8 | if (CMAKE_BUILD_TYPE STREQUAL "Debug") 9 | add_definitions(-Wall -g -ggdb -O0 ) 10 | set(LIB_SUFFIX "_d") 11 | else() 12 | add_definitions(-Wall -O2 -DNDEBUG ) 13 | endif() 14 | set(CMAKE_CXX_FLAGS -std=c++11) 15 | 16 | 17 | 18 | SET(PROTO4Z_GEN_CODE_PATH ${proto4z_SOURCE_DIR}/test/genCode) 19 | SET(PROTO4Z_BIN_OUT_PATH ${proto4z_SOURCE_DIR}/test/bin) 20 | 21 | add_subdirectory(genProto.tools) 22 | add_subdirectory(test) 23 | 24 | install(FILES 25 | ${proto4z_SOURCE_DIR}/proto4z.h 26 | ${proto4z_SOURCE_DIR}/dbHelper.h 27 | ${proto4z_SOURCE_DIR}/Proto4z.cs 28 | ${proto4z_SOURCE_DIR}/proto4z.lua 29 | ${proto4z_SOURCE_DIR}/README.md 30 | ${proto4z_SOURCE_DIR}/COPYRIGHT 31 | DESTINATION include/proto4z) 32 | 33 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | proto4z License 2 | ----------- 3 | 4 | proto4z is licensed under the terms of the MIT license reproduced below. 5 | This means that proto4z is free software and can be used for both academic 6 | and commercial purposes at absolutely no cost. 7 | 8 | 9 | =============================================================================== 10 | 11 | Copyright (C) 2013-2015 YaweiZhang . 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | 31 | =============================================================================== 32 | 33 | (end of COPYRIGHT) 34 | 35 | -------------------------------------------------------------------------------- /HISTORY: -------------------------------------------------------------------------------- 1 | HISTORY for proto4z 2 | 3 | /* 4 | * UPDATES LOG 5 | * 6 | * VERSION 0.1.0 7 | * create the first project. 8 | * support big-endian or little-endian 9 | * 10 | * VERSION 0.3.0 11 | * support user-defined header 12 | * WriteStream support auto alloc memory or attach exist memory 13 | * proto4z support stl container 14 | * 15 | * VERSION 0.4.0 16 | * Add some useful interface method 17 | * 18 | * VERSION 0.5.0 19 | * Add static buff for optimize 20 | * Add genProto tools 21 | * 22 | * VERSION 1.0.0 23 | * Add HTTP protocol 24 | * 25 | * VERSION 1.1.0 26 | * support HTTP chunked header 27 | * support HTTP decode and encode method 28 | * 29 | * VERSION 1.2.0 30 | * new naming notations 31 | * simplify traits 32 | * 33 | * 34 | */ 35 | 36 | (end of HISTORY) 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Welcome to the proto4z wiki! 2 | ## Introduction: 3 | [![Build](https://github.com/zsummer/proto4z/actions/workflows/cmake.yml/badge.svg)](https://github.com/zsummer/proto4z/actions/workflows/cmake.yml) 4 | proto4z is an efficient serialization library for C++, lua, C#, It's like Google protocol buffers. 5 | proto4z是一个序列化工具库, 可以通过一次编写xml格式的数据结构, 使用genProto工具一键生成对应的C++,lua,C#的原生数据结构和对应的序列化/反序列化代码, 并且通过开关可以额外生成C++使用的MYSQL增删改查的接口代码(和dbHelper.h配合使用). 6 | 7 | 8 | ##example 9 | **这里提供一套简单的模板配置和对应的测试代码. 完整版的测试见项目test/genCode目录下的测试例子.** 10 | 11 | ###xml idl 12 | packet如果携带store属性,则会生成SQL相关代码. 支持的字段tag属性有auto 自增, key 主键(支持多主键), idx普通索引, uni唯一索引, ignore 不存储到数据库也不会在fetch时候进行初始化. 如果字段是自定义packet类型(嵌套类型), 则会调用序列化和反序列化以blob形式存储到数据库. 13 | ``` 14 | 15 | 16 | 30000 17 | 32000 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | ``` 35 | ###lua code 36 | 37 | **test serializable/deserialize code** 38 | ``` 39 | --require 40 | require("proto4z") 41 | require("TestProto") 42 | local pack = {id=10, name="name", createTime=100, moneyTree={lastTime=1,freeCount=5,payCount=5,statSum=0,statCount=0}} 43 | local binMemory = Proto4z.encode(pack, "SimplePack") --序列化 44 | local recvPack = Proto4z.decode(binMemory, Proto4z.getName(Proto4z.SimplePack.__protoID)) --反序列化 45 | Proto4z.dump(recvPack) 46 | ``` 47 | 48 | ###c++ test code 49 | 50 | **test serializable/deserialize code** 51 | ``` 52 | try 53 | { 54 | 55 | SimplePack pack; 56 | pack.id = 10; 57 | pack.name = "aaa"; 58 | pack.createTime = time(NULL); 59 | pack.moneyTree.freeCount = 0; 60 | pack.moneyTree.lastTime = pack.createTime; 61 | pack.moneyTree.statSum = 0; 62 | pack.moneyTree.statCount = 0; 63 | pack.moneyTree.payCount = 0; 64 | 65 | //序列化 66 | WriteStream ws(SimplePack::getProtoID()); 67 | ws << pack; 68 | //反序列化 69 | ReadStream rs(ws.getStream(), ws.getStreamLen()); 70 | rs >> pack; 71 | cout << "success" << endl; 72 | } 73 | catch (const std::exception & e) 74 | { 75 | cout << "error:" << e.what() << endl; 76 | } 77 | ``` 78 | 79 | ###c# code 80 | 81 | **test serializable/deserialize code** 82 | ``` 83 | try 84 | { 85 | SimplePack pk = new SimplePack(10, "name", 100, null); 86 | pk.moneyTree = new MoneyTree(10001, 5, 5, 0, 0); 87 | var binMemory = pk.__encode().ToArray(); //序列化 88 | 89 | SimplePack recvPK = new SimplePack(); 90 | int curPos = 0; 91 | recvPK.__decode(binMemory, ref curPos); 92 | System.Console.Write("success"); 93 | } 94 | catch(Exception e) 95 | { 96 | System.Console.Write("error"); 97 | } 98 | ``` 99 | 100 | ###sql code 101 | **test sql build, load, select, insert, del code** 102 | ``` 103 | SimplePack pack; 104 | pack.id = 10; 105 | pack.name = "aaa"; 106 | pack.createTime = time(NULL); 107 | pack.moneyTree.freeCount = 0; 108 | pack.moneyTree.lastTime = pack.createTime; 109 | pack.moneyTree.statSum = 0; 110 | pack.moneyTree.statCount = 0; 111 | pack.moneyTree.payCount = 0; 112 | 113 | DBHelperPtr dbHelper = std::make_shared(); 114 | dbHelper->init(dbConfig._ip, dbConfig._port, dbConfig._db, dbConfig._user, dbConfig._pwd, true); //最后一个true可以自动创建库如果库不存在 115 | if (!dbHelper->connect()) 116 | { 117 | return false; 118 | } 119 | dbhelper->query(pack.getDBBuild()); //创建对应的表,并自动alter普通字段 . 120 | if (dbhelper->query(pack.getDBInsert())->getErrorCode() != QEC_SUCCESS) 121 | { 122 | return false; 123 | } 124 | if (dbhelper->query(pack.getDBUpdate())->getErrorCode() != QEC_SUCCESS) 125 | { 126 | return false; 127 | } 128 | auto ret = dbhelper->query(pack.getDBSelect()); 129 | if (ret->getErrorCode() == QEC_SUCCESS) 130 | { 131 | if (!pack.fetchFromDBResult(*ret)) 132 | { 133 | return false; 134 | } 135 | } 136 | ``` 137 | 138 | ###http code 139 | **test http serializable/deserialize code. (和模板配置无关)** 140 | ``` 141 | TestHTTP th; 142 | WriteHTTP whGet; 143 | whGet.addHead("Content-Type", "application/x-www-form-urlencoded"); 144 | whGet.addHead("Host", "www.google.com"); 145 | whGet.get("/"); 146 | th.Test(whGet); 147 | 148 | WriteHTTP whPost; 149 | whPost.addHead("Content-Type", "application/x-www-form-urlencoded"); 150 | whPost.addHead("Host", "www.google.com"); 151 | whPost.post("/", "index.php?aaa=333"); 152 | th.Test(whPost); 153 | 154 | WriteHTTP whResult; 155 | whResult.addHead("test", "test"); 156 | whResult.addHead("Content-Type", "application/x-www-form-urlencoded"); 157 | whResult.addHead("Host", "www.google.com"); 158 | whResult.response("200", ""); 159 | th.Test(whResult); 160 | ``` 161 | 162 | 163 | 164 | 165 | #About The Author 166 | Auther: YaweiZhang 167 | Mail: yawei.zhang@foxmail.com 168 | GitHub: https://github.com/zsummer 169 | -------------------------------------------------------------------------------- /build/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsummer/proto4z/f5e2f050dc4d36376fcf9227a631ff92533f6afb/build/README.md -------------------------------------------------------------------------------- /genProto.tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(genProto) 3 | 4 | 5 | add_definitions(-Wall -O0 -g -ggdb -DNDEBUG -std=c++11 -D_GLIBCXX_USE_NANOSLEEP ) 6 | 7 | set(EXECUTABLE_OUTPUT_PATH ${PROTO4Z_GEN_CODE_PATH}) 8 | 9 | aux_source_directory(./src source) 10 | aux_source_directory(./depends depends) 11 | aux_source_directory(./depends/md5 md5) 12 | 13 | if (APPLE) 14 | add_executable(genProtoMac ${source} ${depends} ${md5}) 15 | target_link_libraries(genProtoMac pthread) 16 | else() 17 | add_executable(genProto ${source} ${depends} ${md5}) 18 | target_link_libraries(genProto pthread rt) 19 | endif() 20 | -------------------------------------------------------------------------------- /genProto.tools/depends/md5/md5.cpp: -------------------------------------------------------------------------------- 1 |  2 | #ifndef _CRT_SECURE_NO_WARNINGS 3 | #define _CRT_SECURE_NO_WARNINGS 4 | #endif 5 | #include "md5.h" 6 | #include 7 | #include 8 | #include 9 | 10 | unsigned char PADDING[] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 14 | 15 | void MD5Init(MD5_CTX *context) 16 | { 17 | context->count[0] = 0; 18 | context->count[1] = 0; 19 | context->state[0] = 0x67452301; 20 | context->state[1] = 0xEFCDAB89; 21 | context->state[2] = 0x98BADCFE; 22 | context->state[3] = 0x10325476; 23 | } 24 | void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputlen) 25 | { 26 | unsigned int i = 0, index = 0, partlen = 0; 27 | index = (context->count[0] >> 3) & 0x3F; 28 | partlen = 64 - index; 29 | context->count[0] += inputlen << 3; 30 | if (context->count[0] < (inputlen << 3)) 31 | context->count[1]++; 32 | context->count[1] += inputlen >> 29; 33 | 34 | if (inputlen >= partlen) 35 | { 36 | memcpy(&context->buffer[index], input, partlen); 37 | MD5Transform(context->state, context->buffer); 38 | for (i = partlen; i + 64 <= inputlen; i += 64) 39 | MD5Transform(context->state, &input[i]); 40 | index = 0; 41 | } 42 | else 43 | { 44 | i = 0; 45 | } 46 | memcpy(&context->buffer[index], &input[i], inputlen - i); 47 | } 48 | void MD5Final(MD5_CTX *context, unsigned char digest[16]) 49 | { 50 | unsigned int index = 0, padlen = 0; 51 | unsigned char bits[8]; 52 | index = (context->count[0] >> 3) & 0x3F; 53 | padlen = (index < 56) ? (56 - index) : (120 - index); 54 | MD5Encode(bits, context->count, 8); 55 | MD5Update(context, PADDING, padlen); 56 | MD5Update(context, bits, 8); 57 | MD5Encode(digest, context->state, 16); 58 | } 59 | void MD5Encode(unsigned char *output, unsigned int *input, unsigned int len) 60 | { 61 | unsigned int i = 0, j = 0; 62 | while (j < len) 63 | { 64 | output[j] = input[i] & 0xFF; 65 | output[j + 1] = (input[i] >> 8) & 0xFF; 66 | output[j + 2] = (input[i] >> 16) & 0xFF; 67 | output[j + 3] = (input[i] >> 24) & 0xFF; 68 | i++; 69 | j += 4; 70 | } 71 | } 72 | void MD5Decode(unsigned int *output, unsigned char *input, unsigned int len) 73 | { 74 | unsigned int i = 0, j = 0; 75 | while (j < len) 76 | { 77 | output[i] = (input[j]) | 78 | (input[j + 1] << 8) | 79 | (input[j + 2] << 16) | 80 | (input[j + 3] << 24); 81 | i++; 82 | j += 4; 83 | } 84 | } 85 | void MD5Transform(unsigned int state[4], unsigned char block[64]) 86 | { 87 | unsigned int a = state[0]; 88 | unsigned int b = state[1]; 89 | unsigned int c = state[2]; 90 | unsigned int d = state[3]; 91 | unsigned int x[64]; 92 | MD5Decode(x, block, 64); 93 | FF(a, b, c, d, x[0], 7, 0xd76aa478); /* 1 */ 94 | FF(d, a, b, c, x[1], 12, 0xe8c7b756); /* 2 */ 95 | FF(c, d, a, b, x[2], 17, 0x242070db); /* 3 */ 96 | FF(b, c, d, a, x[3], 22, 0xc1bdceee); /* 4 */ 97 | FF(a, b, c, d, x[4], 7, 0xf57c0faf); /* 5 */ 98 | FF(d, a, b, c, x[5], 12, 0x4787c62a); /* 6 */ 99 | FF(c, d, a, b, x[6], 17, 0xa8304613); /* 7 */ 100 | FF(b, c, d, a, x[7], 22, 0xfd469501); /* 8 */ 101 | FF(a, b, c, d, x[8], 7, 0x698098d8); /* 9 */ 102 | FF(d, a, b, c, x[9], 12, 0x8b44f7af); /* 10 */ 103 | FF(c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */ 104 | FF(b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */ 105 | FF(a, b, c, d, x[12], 7, 0x6b901122); /* 13 */ 106 | FF(d, a, b, c, x[13], 12, 0xfd987193); /* 14 */ 107 | FF(c, d, a, b, x[14], 17, 0xa679438e); /* 15 */ 108 | FF(b, c, d, a, x[15], 22, 0x49b40821); /* 16 */ 109 | 110 | /* Round 2 */ 111 | GG(a, b, c, d, x[1], 5, 0xf61e2562); /* 17 */ 112 | GG(d, a, b, c, x[6], 9, 0xc040b340); /* 18 */ 113 | GG(c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */ 114 | GG(b, c, d, a, x[0], 20, 0xe9b6c7aa); /* 20 */ 115 | GG(a, b, c, d, x[5], 5, 0xd62f105d); /* 21 */ 116 | GG(d, a, b, c, x[10], 9, 0x2441453); /* 22 */ 117 | GG(c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */ 118 | GG(b, c, d, a, x[4], 20, 0xe7d3fbc8); /* 24 */ 119 | GG(a, b, c, d, x[9], 5, 0x21e1cde6); /* 25 */ 120 | GG(d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */ 121 | GG(c, d, a, b, x[3], 14, 0xf4d50d87); /* 27 */ 122 | GG(b, c, d, a, x[8], 20, 0x455a14ed); /* 28 */ 123 | GG(a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */ 124 | GG(d, a, b, c, x[2], 9, 0xfcefa3f8); /* 30 */ 125 | GG(c, d, a, b, x[7], 14, 0x676f02d9); /* 31 */ 126 | GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 */ 127 | 128 | /* Round 3 */ 129 | HH(a, b, c, d, x[5], 4, 0xfffa3942); /* 33 */ 130 | HH(d, a, b, c, x[8], 11, 0x8771f681); /* 34 */ 131 | HH(c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */ 132 | HH(b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */ 133 | HH(a, b, c, d, x[1], 4, 0xa4beea44); /* 37 */ 134 | HH(d, a, b, c, x[4], 11, 0x4bdecfa9); /* 38 */ 135 | HH(c, d, a, b, x[7], 16, 0xf6bb4b60); /* 39 */ 136 | HH(b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */ 137 | HH(a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */ 138 | HH(d, a, b, c, x[0], 11, 0xeaa127fa); /* 42 */ 139 | HH(c, d, a, b, x[3], 16, 0xd4ef3085); /* 43 */ 140 | HH(b, c, d, a, x[6], 23, 0x4881d05); /* 44 */ 141 | HH(a, b, c, d, x[9], 4, 0xd9d4d039); /* 45 */ 142 | HH(d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */ 143 | HH(c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */ 144 | HH(b, c, d, a, x[2], 23, 0xc4ac5665); /* 48 */ 145 | 146 | /* Round 4 */ 147 | II(a, b, c, d, x[0], 6, 0xf4292244); /* 49 */ 148 | II(d, a, b, c, x[7], 10, 0x432aff97); /* 50 */ 149 | II(c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */ 150 | II(b, c, d, a, x[5], 21, 0xfc93a039); /* 52 */ 151 | II(a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */ 152 | II(d, a, b, c, x[3], 10, 0x8f0ccc92); /* 54 */ 153 | II(c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */ 154 | II(b, c, d, a, x[1], 21, 0x85845dd1); /* 56 */ 155 | II(a, b, c, d, x[8], 6, 0x6fa87e4f); /* 57 */ 156 | II(d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */ 157 | II(c, d, a, b, x[6], 15, 0xa3014314); /* 59 */ 158 | II(b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */ 159 | II(a, b, c, d, x[4], 6, 0xf7537e82); /* 61 */ 160 | II(d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */ 161 | II(c, d, a, b, x[2], 15, 0x2ad7d2bb); /* 63 */ 162 | II(b, c, d, a, x[9], 21, 0xeb86d391); /* 64 */ 163 | state[0] += a; 164 | state[1] += b; 165 | state[2] += c; 166 | state[3] += d; 167 | } 168 | 169 | 170 | MD5Data::MD5Data() 171 | { 172 | MD5Init(&_content); 173 | } 174 | MD5Data::~MD5Data(){} 175 | 176 | const std::string & MD5Data::genMD5Bin() 177 | { 178 | if (_bin.empty()) 179 | { 180 | unsigned char buf[16]; 181 | MD5Final(&_content, buf); 182 | _bin.assign((const char *)buf, 16); 183 | } 184 | return _bin; 185 | } 186 | const std::string & MD5Data::genMD5() 187 | { 188 | if (_string.empty()) 189 | { 190 | genMD5Bin(); 191 | for (size_t i = 0; i < _bin.length(); i++) 192 | { 193 | char buf[10]; 194 | sprintf(buf, "%02x", (unsigned char)_bin[i]); 195 | _string += buf; 196 | } 197 | } 198 | return _string; 199 | } 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /genProto.tools/depends/md5/md5.h: -------------------------------------------------------------------------------- 1 |  2 | /* 3 | * MD5 License 4 | * Copyright (C) 2014-2016 YaweiZhang . 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef MD5_H 20 | #define MD5_H 21 | #include 22 | #include 23 | typedef struct 24 | { 25 | unsigned int count[2]; 26 | unsigned int state[4]; 27 | unsigned char buffer[64]; 28 | }MD5_CTX; 29 | 30 | 31 | #define F(x,y,z) ((x & y) | (~x & z)) 32 | #define G(x,y,z) ((x & z) | (y & ~z)) 33 | #define H(x,y,z) (x^y^z) 34 | #define I(x,y,z) (y ^ (x | ~z)) 35 | #define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n))) 36 | #define FF(a,b,c,d,x,s,ac) \ 37 | { \ 38 | a += F(b,c,d) + x + ac; \ 39 | a = ROTATE_LEFT(a,s); \ 40 | a += b; \ 41 | } 42 | #define GG(a,b,c,d,x,s,ac) \ 43 | { \ 44 | a += G(b,c,d) + x + ac; \ 45 | a = ROTATE_LEFT(a,s); \ 46 | a += b; \ 47 | } 48 | #define HH(a,b,c,d,x,s,ac) \ 49 | { \ 50 | a += H(b,c,d) + x + ac; \ 51 | a = ROTATE_LEFT(a,s); \ 52 | a += b; \ 53 | } 54 | #define II(a,b,c,d,x,s,ac) \ 55 | { \ 56 | a += I(b,c,d) + x + ac; \ 57 | a = ROTATE_LEFT(a,s); \ 58 | a += b; \ 59 | } 60 | void MD5Init(MD5_CTX *context); 61 | void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputlen); 62 | void MD5Final(MD5_CTX *context, unsigned char digest[16]); 63 | void MD5Transform(unsigned int state[4], unsigned char block[64]); 64 | void MD5Encode(unsigned char *output, unsigned int *input, unsigned int len); 65 | void MD5Decode(unsigned int *output, unsigned char *input, unsigned int len); 66 | 67 | 68 | class MD5Data 69 | { 70 | public: 71 | MD5Data(); 72 | ~MD5Data(); 73 | const std::string & genMD5Bin(); 74 | const std::string & genMD5(); 75 | inline MD5Data & operator <<(const std::string & org) 76 | { 77 | if (!org.empty()) 78 | { 79 | MD5Update(&_content, (unsigned char *) org.c_str(), (unsigned int)org.length()); 80 | } 81 | return *this; 82 | } 83 | inline void append(const std::string &org) 84 | { 85 | if (!org.empty()) 86 | { 87 | MD5Update(&_content, (unsigned char *)org.c_str(), (unsigned int)org.length()); 88 | } 89 | } 90 | private: 91 | MD5_CTX _content; 92 | std::string _bin; 93 | std::string _string; 94 | }; 95 | 96 | 97 | 98 | 99 | #endif 100 | 101 | -------------------------------------------------------------------------------- /genProto.tools/genProto.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "genProto", "genProto.vcxproj", "{AD368D24-8C2B-4848-822F-0827E725CAD7}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {AD368D24-8C2B-4848-822F-0827E725CAD7}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {AD368D24-8C2B-4848-822F-0827E725CAD7}.Debug|Win32.Build.0 = Debug|Win32 18 | {AD368D24-8C2B-4848-822F-0827E725CAD7}.Debug|x64.ActiveCfg = Debug|x64 19 | {AD368D24-8C2B-4848-822F-0827E725CAD7}.Debug|x64.Build.0 = Debug|x64 20 | {AD368D24-8C2B-4848-822F-0827E725CAD7}.Release|Win32.ActiveCfg = Release|Win32 21 | {AD368D24-8C2B-4848-822F-0827E725CAD7}.Release|Win32.Build.0 = Release|Win32 22 | {AD368D24-8C2B-4848-822F-0827E725CAD7}.Release|x64.ActiveCfg = Release|x64 23 | {AD368D24-8C2B-4848-822F-0827E725CAD7}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /genProto.tools/genProto.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | depends 6 | 7 | 8 | depends 9 | 10 | 11 | depends 12 | 13 | 14 | depends\md5 15 | 16 | 17 | src 18 | 19 | 20 | src 21 | 22 | 23 | src 24 | 25 | 26 | src 27 | 28 | 29 | src 30 | 31 | 32 | src 33 | 34 | 35 | src 36 | 37 | 38 | 39 | 40 | depends 41 | 42 | 43 | depends 44 | 45 | 46 | depends 47 | 48 | 49 | depends 50 | 51 | 52 | depends\md5 53 | 54 | 55 | src 56 | 57 | 58 | src 59 | 60 | 61 | src 62 | 63 | 64 | src 65 | 66 | 67 | src 68 | 69 | 70 | src 71 | 72 | 73 | src 74 | 75 | 76 | src 77 | 78 | 79 | 80 | 81 | {f1d9dc7f-22b7-4cf2-a5be-5904911bfa38} 82 | 83 | 84 | {12df6003-3bb6-45de-8f58-5ad2efbb987b} 85 | 86 | 87 | {c4c353c7-26d4-430c-821f-01bb989526ea} 88 | 89 | 90 | -------------------------------------------------------------------------------- /genProto.tools/genProto.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutDir) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutDir) 9 | WindowsLocalDebugger 10 | 11 | 12 | ..\test\genCode 13 | WindowsLocalDebugger 14 | 15 | -------------------------------------------------------------------------------- /genProto.tools/src/any.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ZSUMMER License 3 | * ----------- 4 | * 5 | * ZSUMMER is licensed under the terms of the MIT license reproduced below. 6 | * This means that ZSUMMER is free software and can be used for both academic 7 | * and commercial purposes at absolutely no cost. 8 | * 9 | * 10 | * =============================================================================== 11 | * 12 | * Copyright (C) 2014-2016 YaweiZhang . 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * =============================================================================== 33 | * 34 | * (end of COPYRIGHT) 35 | */ 36 | 37 | 38 | 39 | #pragma once 40 | #ifndef _ANY_H_ 41 | #define _ANY_H_ 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | 52 | #ifndef WIN32 53 | #include 54 | #else 55 | #include 56 | #endif 57 | 58 | 59 | 60 | //store type enum 61 | enum AnyType : short 62 | { 63 | GT_DataComment, 64 | GT_DataEnum, 65 | GT_DataArray, 66 | GT_DataMap, 67 | GT_DataConstValue, 68 | GT_DataPacket, 69 | }; 70 | 71 | //tag 72 | enum MemberTag : short 73 | { 74 | MT_NORMAL, 75 | MT_DB_KEY, 76 | MT_DB_UNI, 77 | MT_DB_IDX, 78 | MT_DB_AUTO, 79 | MT_DB_IGNORE, 80 | MT_DB_BLOB, 81 | }; 82 | 83 | //comment 84 | struct DataComment 85 | { 86 | std::string desc_; 87 | }; 88 | 89 | 90 | 91 | //array type 92 | struct DataArray 93 | { 94 | std::string type_; 95 | std::string arrayName_; 96 | std::string desc_; 97 | }; 98 | 99 | //dict type 100 | struct DataMap 101 | { 102 | std::string typeKey_; 103 | std::string typeValue_; 104 | std::string mapName_; 105 | std::string desc_; 106 | }; 107 | 108 | //const type 109 | struct DataConstValue 110 | { 111 | std::string type_; 112 | std::string name_; 113 | std::string value_; 114 | std::string desc_; 115 | }; 116 | 117 | //include file name, without suffix 118 | struct DataEnum 119 | { 120 | std::string type_; 121 | std::string name_; 122 | std::string desc_; 123 | std::vector members_; 124 | }; 125 | 126 | //struct type 127 | struct DataStruct 128 | { 129 | std::string name_; 130 | std::string desc_; 131 | std::string store_; 132 | bool hadLog4z_ = false; 133 | struct DataMember 134 | { 135 | std::string type_; 136 | std::string name_; 137 | std::string desc_; 138 | short tag_; //MemberTag 139 | }; 140 | std::vector members_; 141 | }; 142 | 143 | //proto type 144 | struct DataPacket 145 | { 146 | DataConstValue const_; 147 | DataStruct struct_; 148 | }; 149 | 150 | 151 | 152 | //general store type 153 | struct AnyData 154 | { 155 | AnyType type_; 156 | DataComment _comment; 157 | DataConstValue const_; 158 | DataEnum enum_; 159 | DataArray array_; 160 | DataMap map_; 161 | DataPacket proto_; 162 | }; 163 | 164 | 165 | 166 | 167 | #endif 168 | -------------------------------------------------------------------------------- /genProto.tools/src/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ZSUMMER License 3 | * ----------- 4 | * 5 | * ZSUMMER is licensed under the terms of the MIT license reproduced below. 6 | * This means that ZSUMMER is free software and can be used for both academic 7 | * and commercial purposes at absolutely no cost. 8 | * 9 | * 10 | * =============================================================================== 11 | * 12 | * Copyright (C) 2014-2016 YaweiZhang . 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * =============================================================================== 33 | * 34 | * (end of COPYRIGHT) 35 | */ 36 | 37 | 38 | 39 | #pragma once 40 | #ifndef _COMMON_H_ 41 | #define _COMMON_H_ 42 | #ifndef _CRT_SECURE_NO_WARNINGS 43 | #define _CRT_SECURE_NO_WARNINGS 44 | #endif 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include "../depends/utls.h" 57 | #include "../depends/log4z.h" 58 | #include "../depends/tinyxml2.h" 59 | #include "../depends/md5/md5.h" 60 | #ifndef WIN32 61 | #include 62 | #else 63 | #include 64 | #endif 65 | 66 | 67 | //proto id type 68 | const std::string ProtoIDType = "ui16"; 69 | 70 | //lfcr 71 | const std::string LFCR = " \r\n"; 72 | 73 | //parse 74 | enum ParseCode 75 | { 76 | PC_SUCCESS, 77 | PC_NEEDSKIP, 78 | PC_ERROR, 79 | }; 80 | 81 | enum SupportLanguageType 82 | { 83 | SL_NORMAL, 84 | SL_CPP, 85 | SL_LUA, 86 | SL_CSHARP, 87 | SL_XML, 88 | SL_END, 89 | }; 90 | 91 | const char * const SupportLanguageString[] = 92 | { 93 | "", 94 | "cppmd5", 95 | "luamd5", 96 | "csharpmd5", 97 | "xmlmd5", 98 | "" 99 | }; 100 | 101 | const char * const SupportLanguageFileSuffix[] = 102 | { 103 | "", 104 | ".h", 105 | ".lua", 106 | ".cs", 107 | ".xml", 108 | "" 109 | }; 110 | 111 | 112 | const char * const SupportLanguageFilePath[] = 113 | { 114 | "", 115 | "C++", 116 | "lua", 117 | "CSharp", 118 | "C++", 119 | "", 120 | "" 121 | }; 122 | 123 | 124 | 125 | #define E(log)\ 126 | do{\ 127 | char logBuf[LOG4Z_LOG_BUF_SIZE]; \ 128 | zsummer::log4z::Log4zStream ss(logBuf, LOG4Z_LOG_BUF_SIZE); \ 129 | ss << log << " " << __FILE__ << ":" << __LINE__; \ 130 | throw std::runtime_error(logBuf); \ 131 | }while (0) 132 | 133 | 134 | 135 | #endif 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /genProto.tools/src/genBase.cpp: -------------------------------------------------------------------------------- 1 |  2 | 3 | #ifndef _CRT_SECURE_NO_WARNINGS 4 | #define _CRT_SECURE_NO_WARNINGS 5 | #endif 6 | #include "genBase.h" 7 | #include 8 | #include 9 | 10 | 11 | 12 | 13 | GenBase::GenBase() 14 | { 15 | 16 | } 17 | GenBase::~GenBase() 18 | { 19 | 20 | } 21 | 22 | void GenBase::init(std::string fileName, SupportLanguageType t) 23 | { 24 | _filename = fileName; 25 | type_ = t; 26 | std::string path = SupportLanguageFilePath[t]; 27 | if (!isDirectory(path) && !createDirectory(path)) 28 | { 29 | E("CreateDir path [" << path << "] Error. "); 30 | } 31 | } 32 | 33 | std::string GenBase::getRealType(const std::string & xmltype) 34 | { 35 | return xmltype; 36 | } 37 | 38 | std::string GenBase::getTypeDefault(const std::string & xmltype) 39 | { 40 | if (xmltype == "i8") return "0"; 41 | else if (xmltype == "ui8") return "0"; 42 | else if (xmltype == "i16") return "0"; 43 | else if (xmltype == "ui16") return "0"; 44 | else if (xmltype == "i32") return "0"; 45 | else if (xmltype == "ui32") return "0"; 46 | else if (xmltype == "i64") return "0"; 47 | else if (xmltype == "ui64") return "0"; 48 | else if (xmltype == "float") return "0.0"; 49 | else if (xmltype == "double") return "0.0"; 50 | else if (xmltype == "s8") return "0"; 51 | else if (xmltype == "u8") return "0"; 52 | else if (xmltype == "s16") return "0"; 53 | else if (xmltype == "u16") return "0"; 54 | else if (xmltype == "s32") return "0"; 55 | else if (xmltype == "u32") return "0"; 56 | else if (xmltype == "s64") return "0"; 57 | else if (xmltype == "u64") return "0"; 58 | else if (xmltype == "f32") return "0.0"; 59 | 60 | return ""; 61 | } 62 | 63 | std::string GenBase::genRealContent(const std::list & stores) 64 | { 65 | return ""; 66 | } 67 | 68 | 69 | 70 | void GenBase::write(const std::string & content) 71 | { 72 | std::string filename = SupportLanguageFilePath[type_]; 73 | filename += "/"; 74 | filename += _filename; 75 | filename += SupportLanguageFileSuffix[type_]; 76 | if (writeFileContent(filename, content.c_str(), content.length(), false) != content.length()) 77 | { 78 | E("genCppFile open file Error. : " << filename); 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /genProto.tools/src/genBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ZSUMMER License 3 | * ----------- 4 | * 5 | * ZSUMMER is licensed under the terms of the MIT license reproduced below. 6 | * This means that ZSUMMER is free software and can be used for both academic 7 | * and commercial purposes at absolutely no cost. 8 | * 9 | * 10 | * =============================================================================== 11 | * 12 | * Copyright (C) 2014-2016 YaweiZhang . 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * =============================================================================== 33 | * 34 | * (end of COPYRIGHT) 35 | */ 36 | 37 | 38 | 39 | #pragma once 40 | #ifndef _GEN_BASE_H_ 41 | #define _GEN_BASE_H_ 42 | #include "common.h" 43 | #include "any.h" 44 | 45 | class GenBase 46 | { 47 | public: 48 | GenBase(); 49 | virtual ~GenBase(); 50 | virtual void init(std::string fileName, SupportLanguageType t); 51 | virtual std::string getRealType(const std::string & xmltype); 52 | virtual std::string getTypeDefault(const std::string & xmltype); 53 | virtual std::string genRealContent(const std::list & stores); 54 | virtual void write(const std::string & content); 55 | protected: 56 | std::string _filename; 57 | SupportLanguageType type_ = SL_NORMAL; 58 | }; 59 | 60 | 61 | void writeCSharpReflection(std::map & keys, std::map & errCodes); 62 | void writeCPPReflection(std::map & keys, std::map & errCodes); 63 | #endif 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /genProto.tools/src/genCPP.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ZSUMMER License 3 | * ----------- 4 | * 5 | * ZSUMMER is licensed under the terms of the MIT license reproduced below. 6 | * This means that ZSUMMER is free software and can be used for both academic 7 | * and commercial purposes at absolutely no cost. 8 | * 9 | * 10 | * =============================================================================== 11 | * 12 | * Copyright (C) 2014-2016 YaweiZhang . 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * =============================================================================== 33 | * 34 | * (end of COPYRIGHT) 35 | */ 36 | 37 | 38 | #include "genBase.h" 39 | #ifndef _GEN_CPP_ 40 | #define _GEN_CPP_ 41 | class GenCPP : public GenBase 42 | { 43 | public: 44 | virtual std::string getRealType(const std::string & xmltype); 45 | virtual std::string genRealContent(const std::list & stores); 46 | std::string genDataConst(const DataConstValue & dc); 47 | std::string genDataEnum(const DataEnum & de); 48 | std::string genDataArray(const DataArray & da); 49 | std::string genDataMap(const DataMap & dm); 50 | std::string genDataPacket(const DataPacket & dp); 51 | }; 52 | 53 | #endif 54 | 55 | 56 | -------------------------------------------------------------------------------- /genProto.tools/src/genCSharp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ZSUMMER License 3 | * ----------- 4 | * 5 | * ZSUMMER is licensed under the terms of the MIT license reproduced below. 6 | * This means that ZSUMMER is free software and can be used for both academic 7 | * and commercial purposes at absolutely no cost. 8 | * 9 | * 10 | * =============================================================================== 11 | * 12 | * Copyright (C) 2014-2016 YaweiZhang . 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * =============================================================================== 33 | * 34 | * (end of COPYRIGHT) 35 | */ 36 | 37 | #ifndef _GEN_CSHARP_H_ 38 | #define _GEN_CSHARP_H_ 39 | 40 | #include "genBase.h" 41 | #include 42 | #include 43 | 44 | class CSharpType 45 | { 46 | public: 47 | CSharpType(bool b, std::string t, std::string e, std::string d) :isBase(b), realType(t), baseEncode(e), baseDecode(d){} 48 | bool isBase = true; 49 | std::string realType; 50 | std::string baseEncode; 51 | std::string baseDecode; 52 | }; 53 | 54 | class GenCSharp : public GenBase 55 | { 56 | public: 57 | CSharpType getCSharpType(const std::string & xmltype); 58 | virtual std::string getTypeDefault(const std::string & xmltype); 59 | virtual std::string genRealContent(const std::list & stores); 60 | std::string genDataConst(const DataConstValue & dc); 61 | std::string genDataEnum(const DataEnum & de); 62 | std::string genDataArray(const DataArray & da); 63 | std::string genDataMap(const DataMap & dm); 64 | std::string genDataPacket(const DataPacket & dp); 65 | 66 | }; 67 | 68 | 69 | 70 | 71 | #endif 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /genProto.tools/src/genLUA.cpp: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | #include "genLUA.h" 5 | 6 | std::string GenLUA::genRealContent(const std::list & stores) 7 | { 8 | std::string text; 9 | for (auto &info : stores) 10 | { 11 | if (info.type_ == GT_DataConstValue) 12 | { 13 | text += LFCR; 14 | text += genDataConst(info.const_); 15 | } 16 | else if (info.type_ == GT_DataEnum) 17 | { 18 | text += LFCR; 19 | text += genDataEnum(info.enum_); 20 | } 21 | else if (info.type_ == GT_DataArray) 22 | { 23 | text += LFCR; 24 | text += genDataArray(info.array_); 25 | } 26 | else if (info.type_ == GT_DataMap) 27 | { 28 | text += LFCR; 29 | text += genDataMap(info.map_); 30 | } 31 | else if (info.type_ == GT_DataPacket) 32 | { 33 | text += LFCR; 34 | text += genDataPacket(info.proto_); 35 | } 36 | } 37 | 38 | return text; 39 | } 40 | 41 | 42 | 43 | std::string GenLUA::genDataConst(const DataConstValue & dc) 44 | { 45 | std::string text; 46 | text += "Proto4z." + dc.name_ + " = " + dc.value_; 47 | if (!dc.desc_.empty()) 48 | { 49 | text += "--" + dc.desc_; 50 | } 51 | return text; 52 | } 53 | 54 | std::string GenLUA::genDataEnum(const DataEnum & de) 55 | { 56 | std::string text; 57 | for (const auto & m : de.members_) 58 | { 59 | text += "Proto4z." + m.name_ + " = " + m.value_; 60 | if (!m.desc_.empty()) 61 | { 62 | text += "--" + m.desc_; 63 | } 64 | text += LFCR; 65 | } 66 | return text; 67 | } 68 | std::string GenLUA::genDataArray(const DataArray & da) 69 | { 70 | std::string text; 71 | text += "Proto4z." + da.arrayName_ + " = {} "; 72 | if (!da.desc_.empty()) 73 | { 74 | text += "--" + da.desc_; 75 | } 76 | text += LFCR; 77 | 78 | text += "Proto4z." + da.arrayName_ + ".__protoName = \"" + da.arrayName_ + "\"" + LFCR; 79 | text += "Proto4z." + da.arrayName_ + ".__protoDesc = \"array\"" + LFCR; 80 | text += "Proto4z." + da.arrayName_ + ".__protoTypeV = \"" + da.type_ + "\"" + LFCR; 81 | return text; 82 | } 83 | std::string GenLUA::genDataMap(const DataMap & dm) 84 | { 85 | std::string text; 86 | text += "Proto4z." + dm.mapName_ + " = {} "; 87 | if (!dm.desc_.empty()) 88 | { 89 | text += "--" + dm.desc_; 90 | } 91 | text += LFCR; 92 | 93 | text += "Proto4z." + dm.mapName_ + ".__protoName = \"" + dm.mapName_ + "\"" + LFCR; 94 | text += "Proto4z." + dm.mapName_ + ".__protoDesc = \"map\"" + LFCR; 95 | text += "Proto4z." + dm.mapName_ + ".__protoTypeK = \"" + dm.typeKey_ + "\"" + LFCR; 96 | text += "Proto4z." + dm.mapName_ + ".__protoTypeV = \"" + dm.typeValue_ + "\"" + LFCR; 97 | return text; 98 | } 99 | std::string GenLUA::genDataPacket(const DataPacket & dp) 100 | { 101 | std::string text; 102 | 103 | text += "Proto4z.register(" + dp.const_.value_ + ",\"" + dp.struct_.name_ + "\")" + LFCR; 104 | 105 | 106 | text += "Proto4z." + dp.struct_.name_ + " = {} "; 107 | if (!dp.struct_.desc_.empty()) 108 | { 109 | text += "--" + dp.struct_.desc_; 110 | } 111 | text += LFCR; 112 | 113 | 114 | text += "Proto4z." + dp.struct_.name_ + ".__protoID = " + dp.const_.value_ + "" + LFCR; 115 | text += "Proto4z." + dp.struct_.name_ + ".__protoName = \"" + dp.struct_.name_ + "\"" + LFCR; 116 | 117 | for (size_t i = 0; i < dp.struct_.members_.size(); ++i) 118 | { 119 | text += "Proto4z." + dp.struct_.name_ + "[" + toString(i + 1) 120 | + "] = {name=\"" + dp.struct_.members_[i].name_ + "\", type=\"" + dp.struct_.members_[i].type_ + "\""; 121 | text += " } "; 122 | if (!dp.struct_.members_[i].desc_.empty()) 123 | { 124 | text += "--" + dp.struct_.members_[i].desc_; 125 | } 126 | text += LFCR; 127 | } 128 | return text; 129 | } 130 | 131 | 132 | -------------------------------------------------------------------------------- /genProto.tools/src/genLUA.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ZSUMMER License 3 | * ----------- 4 | * 5 | * ZSUMMER is licensed under the terms of the MIT license reproduced below. 6 | * This means that ZSUMMER is free software and can be used for both academic 7 | * and commercial purposes at absolutely no cost. 8 | * 9 | * 10 | * =============================================================================== 11 | * 12 | * Copyright (C) 2014-2016 YaweiZhang . 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * =============================================================================== 33 | * 34 | * (end of COPYRIGHT) 35 | */ 36 | 37 | #include "genBase.h" 38 | #ifndef _GEN_LUA_ 39 | #define _GEN_LUA_ 40 | class GenLUA : public GenBase 41 | { 42 | public: 43 | virtual std::string genRealContent(const std::list & stores); 44 | std::string genDataConst(const DataConstValue & dc); 45 | std::string genDataEnum(const DataEnum & de); 46 | std::string genDataArray(const DataArray & da); 47 | std::string genDataMap(const DataMap & dm); 48 | std::string genDataPacket(const DataPacket & dp); 49 | }; 50 | 51 | #endif 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /genProto.tools/src/main.cpp: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | #include "any.h" 5 | #include "common.h" 6 | #include "genBase.h" 7 | #include "parseCache.h" 8 | #include "parseProto.h" 9 | std::map _cacheKeys; 10 | std::map _errCodes; 11 | //#define __WITH_TAG 12 | int main(int argc, char *argv[]) 13 | { 14 | zsummer::log4z::ILog4zManager::getRef().setLoggerFileLine(LOG4Z_MAIN_LOGGER_ID, false); 15 | zsummer::log4z::ILog4zManager::getRef().setLoggerOutFile(LOG4Z_MAIN_LOGGER_ID, false); 16 | zsummer::log4z::ILog4zManager::getRef().start(); 17 | 18 | 19 | std::vector files; 20 | if (!searchFiles("./*.xml", files, false)) 21 | { 22 | LOGE("searchFiles error."); 23 | return 0; 24 | } 25 | try 26 | { 27 | bool updateReflection = false; 28 | for (auto & file : files) 29 | { 30 | std::string filename = subString(file.filename, ".", true, true).first; 31 | ParseCache cache; 32 | cache.parse(filename); 33 | if (cache.isNeedUpdate()) 34 | { 35 | updateReflection = true; 36 | auto stores = parseProto(filename, cache); 37 | for (int i = SL_NORMAL + 1; i < SL_END; i++) 38 | { 39 | auto gen = createGenerate((SupportLanguageType)i); 40 | if (!gen) 41 | { 42 | continue; 43 | } 44 | gen->init(filename, (SupportLanguageType)i); 45 | auto content = gen->genRealContent(stores); 46 | gen->write(content); 47 | destroyGenerate(gen); 48 | } 49 | cache.write(); 50 | } 51 | if (true) 52 | { 53 | auto stores = parseProto(filename, cache); 54 | for (auto & store : stores) 55 | { 56 | if (store.type_ == GT_DataEnum && trim(store.enum_.name_) == "ERROR_CODE") 57 | { 58 | for (auto & kv : store.enum_.members_) 59 | { 60 | _errCodes[fromString(kv.value_, 0)] = kv.desc_; 61 | } 62 | } 63 | } 64 | for (auto & kv : cache._cacheNumber) 65 | { 66 | _cacheKeys[kv.second] = kv.first; 67 | } 68 | } 69 | } 70 | if (updateReflection) 71 | { 72 | writeCSharpReflection(_cacheKeys, _errCodes); 73 | writeCPPReflection(_cacheKeys, _errCodes); 74 | } 75 | 76 | } 77 | catch (const std::exception & e) 78 | { 79 | LOGE("catch error: " << e.what()); 80 | return -1; 81 | } 82 | 83 | 84 | LOGA("All Success.."); 85 | 86 | return 0; 87 | } 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /genProto.tools/src/parseCache.cpp: -------------------------------------------------------------------------------- 1 |  2 | #ifndef _CRT_SECURE_NO_WARNINGS 3 | #define _CRT_SECURE_NO_WARNINGS 4 | #endif 5 | #include "parseCache.h" 6 | #include 7 | #include 8 | 9 | 10 | 11 | void ParseCache::parse(std::string filename) 12 | { 13 | _configPath = "."; 14 | _configFileName = filename; 15 | _cacheFile = _configPath + "/.cache/" + _configFileName + ".xml.cache"; 16 | if (!isDirectory("./.cache")) 17 | { 18 | createDirectory("./.cache"); 19 | } 20 | if (!accessFile(_cacheFile)) 21 | { 22 | LOGW("ParseCache::parse [" << _cacheFile << " not found."); 23 | return; 24 | } 25 | tinyxml2::XMLDocument doc; 26 | if (doc.LoadFile(_cacheFile.c_str()) != tinyxml2::XML_SUCCESS) 27 | { 28 | E(" ParseCache::parse Error. configFile=" << _cacheFile << ", err1=" << doc.GetErrorStr1() << ", err2" << doc.GetErrorStr2()); 29 | } 30 | 31 | for (int i = SL_NORMAL+1; i < SL_END; i++) 32 | { 33 | XMLElement * md5 = doc.FirstChildElement(SupportLanguageString[i]); 34 | if (md5 && md5->GetText()) 35 | { 36 | _md5Cache[i] = md5->GetText(); 37 | } 38 | } 39 | 40 | XMLElement * cacheEles = doc.FirstChildElement("cacheNumber"); 41 | if (cacheEles == NULL) 42 | { 43 | LOGW("ParseCache::parse can not found cacheNumber. configFile=" << _cacheFile); 44 | return ; 45 | } 46 | 47 | XMLElement * next = cacheEles->FirstChildElement("cache"); 48 | do 49 | { 50 | if (next == NULL) 51 | { 52 | break; 53 | } 54 | const char * key = next->Attribute("key"); 55 | const char * number = next->Attribute("Number"); 56 | if (key == NULL || number == NULL) 57 | { 58 | E("ParseCache::parse cache number is invalid. configFile=" << _cacheFile); 59 | } 60 | 61 | 62 | auto founder = _cacheNumber.find(key); 63 | if (founder != _cacheNumber.end()) 64 | { 65 | E("ParseCache::parse dumplicate key on " << key << " from " << _cacheFile); 66 | } 67 | _cacheNumber[key] = atoi(number); 68 | 69 | if (_currentProtoID <= atoi(number)) 70 | { 71 | _currentProtoID = atoi(number) + 1; 72 | } 73 | 74 | next = next->NextSiblingElement("cache"); 75 | } while (true); 76 | } 77 | bool ParseCache::write() 78 | { 79 | LOGI("writeCache [" << _cacheFile); 80 | 81 | std::string text = "\n\n"; 82 | for (int i = SL_NORMAL + 1; i < SL_END; i++) 83 | { 84 | std::string md5; 85 | if (i != SL_XML) 86 | { 87 | md5 = genFileMD5(_configPath + "/" + SupportLanguageFilePath[i] + "/" + _configFileName + SupportLanguageFileSuffix[i]); 88 | } 89 | else 90 | { 91 | md5 = genFileMD5(_configPath + "/" + _configFileName + SupportLanguageFileSuffix[i]); 92 | } 93 | text += std::string() + "<" + SupportLanguageString[i] + ">"; 94 | text += md5; 95 | text += std::string() + "" + LFCR; 96 | } 97 | 98 | text += "\n"; 99 | 100 | for (auto &pr : _cacheNumber) 101 | { 102 | text += " \n"; 103 | } 104 | text += "\n"; 105 | if (writeFileContent(_cacheFile, text.c_str(), text.length(), false) != text.length()) 106 | { 107 | LOGE("write cache file error. filename=" << _cacheFile); 108 | } 109 | return true; 110 | } 111 | 112 | bool ParseCache::isNeedUpdate() 113 | { 114 | for (int i = SL_NORMAL+1; i < SL_END; i++) 115 | { 116 | if (_md5Cache[i].empty()) 117 | { 118 | return true; 119 | } 120 | std::string md5; 121 | if (i != SL_XML) 122 | { 123 | md5 = genFileMD5(_configPath + "/" + SupportLanguageFilePath[i] + "/" + _configFileName + SupportLanguageFileSuffix[i]); 124 | } 125 | else 126 | { 127 | md5 = genFileMD5(_configPath + "/" + _configFileName + SupportLanguageFileSuffix[i]); 128 | } 129 | 130 | if (md5 != _md5Cache[i]) 131 | { 132 | return true; 133 | } 134 | } 135 | return false; 136 | } 137 | 138 | unsigned short ParseCache::getCacheNumber(std::string key) 139 | { 140 | auto founder = _cacheNumber.find(key); 141 | if (founder == _cacheNumber.end()) 142 | { 143 | return -1; 144 | } 145 | return founder->second; 146 | } 147 | bool ParseCache::setCacheNumber(std::string key, unsigned short number) 148 | { 149 | auto founder = _cacheNumber.find(key); 150 | if (founder != _cacheNumber.end()) 151 | { 152 | return false; 153 | } 154 | _cacheNumber[key] = number; 155 | return true; 156 | } 157 | 158 | unsigned short ParseCache::genProtoID(std::string key, unsigned short minProtoID, unsigned short maxProtoID) 159 | { 160 | unsigned short ret = getCacheNumber(key); 161 | if (ret == (unsigned short)-1) 162 | { 163 | ret = _currentProtoID++; 164 | setCacheNumber(key, ret); 165 | if (ret < minProtoID || ret >= maxProtoID) 166 | { 167 | E("proto number override. key=" << key << ", next number=" << ret); 168 | } 169 | } 170 | return ret; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /genProto.tools/src/parseCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ZSUMMER License 3 | * ----------- 4 | * 5 | * ZSUMMER is licensed under the terms of the MIT license reproduced below. 6 | * This means that ZSUMMER is free software and can be used for both academic 7 | * and commercial purposes at absolutely no cost. 8 | * 9 | * 10 | * =============================================================================== 11 | * 12 | * Copyright (C) 2014-2016 YaweiZhang . 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * =============================================================================== 33 | * 34 | * (end of COPYRIGHT) 35 | */ 36 | 37 | 38 | 39 | #pragma once 40 | #ifndef _PARSE_CACHE_H_ 41 | #define _PARSE_CACHE_H_ 42 | 43 | #include "common.h" 44 | #include "any.h" 45 | 46 | using namespace tinyxml2; 47 | 48 | 49 | 50 | 51 | 52 | struct DataCache 53 | { 54 | std::string proto; 55 | unsigned int number; 56 | }; 57 | 58 | //manager 59 | class ParseCache 60 | { 61 | std::string _configFileName; 62 | std::string _configPath; 63 | std::string _cacheFile; 64 | std::string _md5Cache[SL_END]; 65 | //cache data 66 | unsigned short _currentProtoID = 0; 67 | public: 68 | std::map _cacheNumber; 69 | public: 70 | void parse(std::string filename); 71 | bool write(); 72 | bool isNeedUpdate(); 73 | inline void setCurrentProtoID(unsigned short n){ _currentProtoID = n; } 74 | inline unsigned short getCurrentProtoID(){ return _currentProtoID; } 75 | unsigned short genProtoID(std::string key, unsigned short minProtoID, unsigned short maxProtoID); 76 | protected: 77 | unsigned short getCacheNumber(std::string key); 78 | bool setCacheNumber(std::string key, unsigned short number); 79 | }; 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /genProto.tools/src/parseProto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ZSUMMER License 3 | * ----------- 4 | * 5 | * ZSUMMER is licensed under the terms of the MIT license reproduced below. 6 | * This means that ZSUMMER is free software and can be used for both academic 7 | * and commercial purposes at absolutely no cost. 8 | * 9 | * 10 | * =============================================================================== 11 | * 12 | * Copyright (C) 2014-2016 YaweiZhang . 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | * 32 | * =============================================================================== 33 | * 34 | * (end of COPYRIGHT) 35 | */ 36 | 37 | 38 | 39 | #pragma once 40 | #ifndef _GEN_PROTO_H_ 41 | #define _GEN_PROTO_H_ 42 | 43 | #include "common.h" 44 | #include "any.h" 45 | #include "parseCache.h" 46 | #include "genBase.h" 47 | using namespace tinyxml2; 48 | 49 | 50 | 51 | std::list parseProto(std::string fileName, ParseCache & cache); 52 | 53 | GenBase * createGenerate(SupportLanguageType t); 54 | void destroyGenerate(GenBase *); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(test) 3 | set(EXECUTABLE_OUTPUT_PATH ${PROTO4Z_BIN_OUT_PATH}) 4 | add_subdirectory(cpp) 5 | add_subdirectory(lua53) 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /test/bin/main.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | /* 3 | * proto4z License 4 | * ----------- 5 | * 6 | * proto4z is licensed under the terms of the MIT license reproduced below. 7 | * This means that proto4z is free software and can be used for both academic 8 | * and commercial purposes at absolutely no cost. 9 | * 10 | * 11 | * =============================================================================== 12 | * 13 | * Copyright (C) 2013-2015 YaweiZhang . 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this software and associated documentation files (the "Software"), to deal 17 | * in the Software without restriction, including without limitation the rights 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | * copies of the Software, and to permit persons to whom the Software is 20 | * furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | * THE SOFTWARE. 32 | * 33 | * =============================================================================== 34 | * 35 | * (end of COPYRIGHT) 36 | */ 37 | ]]-- 38 | 39 | -- proto4z test file 40 | -- Author: zhangyawei 41 | -- mail:yawei.zhang@foxmail.com 42 | -- date: 2015-01-12 43 | 44 | package.path =package.path .. ";../../?.lua;../genCode/lua/?.lua" 45 | --require 46 | require("proto4z") 47 | require("TestProto") 48 | dump = Proto4z.dump 49 | local proto = Proto4z 50 | 51 | 52 | local pack = {id=10, name="name", createTime=100, moneyTree={lastTime=1,freeCount=5,payCount=5,statSum=0,statCount=0}} 53 | local binMemory = Proto4z.encode(pack, "SimplePack") 54 | local recvPack = Proto4z.decode(binMemory, Proto4z.getName(Proto4z.SimplePack.__protoID)) 55 | Proto4z.dump(recvPack) 56 | 57 | 58 | local echo = { _iarray = {{_char=1,_uchar=2,_short=3,_ushort=4,_int=5,_uint=6,_i64=12345678.2,_ui64=12345678},{_char=1,_uchar=2,_short=3,_ushort=4,_int=5,_uint=6,_i64="123456789000000.2",_ui64="1123122345678.0"}}, 59 | _farray = {{_float=2.235,_double=235.111},{_float=2.235,_double=235.111},}, 60 | _sarray = {{_string="abcdefg"},{_string="abcdefg"},{_string="abcdefg"}}, 61 | _imap = {[123]={_char=1,_uchar=2,_short=3,_ushort=4,_int=5,_uint=6,_i64="12345678",_ui64="12345678"}, 62 | [223]={_char=1,_uchar=2,_short=3,_ushort=4,_int=5,_uint=6,_i64="12345678",_ui64="12345678"}}, 63 | _fmap = {[123.123123123]={_float=2.235,_double=235.111},[122.123123123]={_float=2.235,_double=235.111}}, 64 | _smap = {k="523", v=4}, 65 | } 66 | 67 | function process(echo, isDebug) 68 | if isDebug then dump(echo, "process") end 69 | local data = proto.encode(echo, "EchoPack") 70 | if isDebug then print(#data) end 71 | local dr = proto.decode(data, proto.getName(proto.EchoPack.__protoID)) 72 | if isDebug then 73 | dump(dr, "decode") 74 | end 75 | end 76 | 77 | process(nil, true) 78 | process({}, true) 79 | process({_iarray={{}}, _farray={{}}, _fmap={{}}}, true) 80 | local now = Proto4zUtil.now() 81 | for i=1, 1 do 82 | process(echo, true) 83 | end 84 | print("used time=" .. (Proto4zUtil.now() - now)) 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /test/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(cpptest) 3 | 4 | include_directories(../../) 5 | include_directories(../genCode) 6 | 7 | set(EXECUTABLE_OUTPUT_PATH ${PROTO4Z_BIN_OUT_PATH}) 8 | 9 | add_executable(cpptest${LIB_SUFFIX} test.cpp) 10 | if(APPLE) 11 | target_link_libraries(cpptest${LIB_SUFFIX} pthread m) 12 | else() 13 | target_link_libraries(cpptest${LIB_SUFFIX} pthread rt m) 14 | endif() 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/cpp/TestWeb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef _TEST_HTTP_H_ 3 | #define _TEST_HTTP_H_ 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | using namespace zsummer::proto4z; 15 | 16 | const int MAX_HTTP_LEN = 1000; 17 | class TestWeb 18 | { 19 | public: 20 | bool Test(WriteWebStream &wh) 21 | { 22 | bool isChunked = false; 23 | std::string method; 24 | std::string methodLine; 25 | std::map head; 26 | std::string body; 27 | if (HasWebRawPacket(wh.GetStream(), wh.GetStreamLen(), 1024, isChunked, method, methodLine, head, body).first == kIntegrityIntact) 28 | { 29 | if (head.find("Host") != head.end() 30 | && (method == "GET" || method == "POST" || methodLine == "200")) 31 | { 32 | cout << "Check HasWebRawPacket Success" << endl; 33 | } 34 | else 35 | { 36 | cout << "Check HasWebRawPacket Data error" << endl; 37 | return false; 38 | } 39 | } 40 | else 41 | { 42 | cout << "Check HasWebRawPacket unpack error. ret =" << (kIntegrityShortage ? "kIntegrityShortage":"kIntegrityCorrupted") << endl; 43 | return false; 44 | } 45 | if (HasWebRawPacket(wh.GetStream(), wh.GetStreamLen() - 1, 1024, isChunked, method, methodLine, head, body).first != kIntegrityShortage) 46 | { 47 | cout << "Check HasWebRawPacket kIntegrityShortage error" << endl; 48 | return false; 49 | } 50 | if (HasWebRawPacket(wh.GetStream(), wh.GetStreamLen(), wh.GetStreamLen() - 1, isChunked, method, methodLine, head, body).first != kIntegrityCorrupted) 51 | { 52 | cout << "Check HasWebRawPacket kIntegrityCorrupted error" << endl; 53 | return false; 54 | } 55 | return true; 56 | } 57 | protected: 58 | private: 59 | }; 60 | 61 | 62 | 63 | 64 | #endif 65 | 66 | 67 | -------------------------------------------------------------------------------- /test/cpp/cpp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | 源文件 16 | 17 | 18 | 19 | 20 | 头文件 21 | 22 | 23 | 源文件 24 | 25 | 26 | -------------------------------------------------------------------------------- /test/cpp/test.cpp: -------------------------------------------------------------------------------- 1 | //! yawei_zhang@foxmail.com 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef WIN32 11 | #include 12 | #else 13 | #include 14 | #endif // WIN32 15 | 16 | #ifdef __APPLE__ 17 | #include 18 | #endif // __APPLE__ 19 | 20 | using namespace std; 21 | using namespace zsummer::proto4z; 22 | 23 | #include "C++/TestProto.h" 24 | #include "TestWeb.h" 25 | 26 | void fillOnePack(EchoPack &pack) 27 | { 28 | IntegerData idata; 29 | idata._char = 'a'; 30 | idata._uchar = 100; 31 | idata._short = 200; 32 | idata._ushort = 300; 33 | idata._int = 400; 34 | idata._uint = 500; 35 | idata._i64 = 600; 36 | idata._ui64 = 700; 37 | 38 | FloatData fdata; 39 | fdata._float = (float)123123.111111; 40 | fdata._double = 12312312.88888; 41 | 42 | StringData sdata; 43 | sdata._string = "abcdefg"; 44 | 45 | pack._iarray.push_back(idata); 46 | pack._iarray.push_back(idata); 47 | pack._farray.push_back(fdata); 48 | pack._farray.push_back(fdata); 49 | pack._sarray.push_back(sdata); 50 | pack._sarray.push_back(sdata); 51 | 52 | 53 | pack._imap.insert(std::make_pair(123, idata)); 54 | pack._imap.insert(std::make_pair(223, idata)); 55 | pack._fmap.insert(std::make_pair(32.3, fdata)); 56 | pack._fmap.insert(std::make_pair(42.3, fdata)); 57 | pack._smap.insert(std::make_pair("523", sdata)); 58 | pack._smap.insert(std::make_pair("623", sdata)); 59 | } 60 | 61 | 62 | unsigned int getSteadyTime(); 63 | 64 | 65 | 66 | int main() 67 | { 68 | 69 | 70 | cout << "check http proto ..." << endl; 71 | TestWeb th; 72 | WriteWebStream whGet; 73 | whGet.addHead("Content-Type", "application/x-www-form-urlencoded"); 74 | whGet.addHead("Host", "www.google.com"); 75 | whGet.get("/"); 76 | th.Test(whGet); 77 | 78 | WriteWebStream whPost; 79 | whPost.addHead("Content-Type", "application/x-www-form-urlencoded"); 80 | whPost.addHead("Host", "www.google.com"); 81 | whPost.post("/", "index.php?aaa=333"); 82 | th.Test(whPost); 83 | 84 | WriteWebStream whResult; 85 | whResult.addHead("test", "test"); 86 | whResult.addHead("Content-Type", "application/x-www-form-urlencoded"); 87 | whResult.addHead("Host", "www.google.com"); 88 | whResult.response("200", ""); 89 | th.Test(whResult); 90 | 91 | cout << "check binary proto" << endl; 92 | try 93 | { 94 | WriteStream wwrap(1); 95 | WriteStream ws(EchoPack::getProtoID()); 96 | EchoPack echo; 97 | fillOnePack(echo); 98 | ws << echo; 99 | wwrap << "3333333333333333333333333333"; 100 | wwrap.AppendRawData(ws.GetStream(), ws.GetStreamLen()); 101 | ReadStream rwrap(wwrap.GetStream(), wwrap.GetStreamLen()); 102 | std::string tmp; 103 | rwrap >> tmp; 104 | ReadStream rs(rwrap.GetStreamUnread(), rwrap.GetStreamUnreadLen()); 105 | rs >> echo; 106 | cout << "success" << endl; 107 | } 108 | catch (const std::exception & e) 109 | { 110 | cout << "error:" << e.what() << endl; 111 | return -1; 112 | } 113 | 114 | try 115 | { 116 | 117 | 118 | SimplePack pack; 119 | pack.id = 10; 120 | pack.name = "aaa"; 121 | pack.createTime = time(NULL); 122 | pack.moneyTree.freeCount = 0; 123 | pack.moneyTree.lastTime = pack.createTime; 124 | pack.moneyTree.statSum = 0; 125 | pack.moneyTree.statCount = 0; 126 | pack.moneyTree.payCount = 0; 127 | 128 | 129 | 130 | //序列化 131 | WriteStream ws(SimplePack::getProtoID()); 132 | ws << pack; 133 | //反序列化 134 | ReadStream rs(ws.GetStream(), ws.GetStreamLen()); 135 | rs >> pack; 136 | cout << "success" << endl; 137 | } 138 | catch (const std::exception & e) 139 | { 140 | cout << "error:" << e.what() << endl; 141 | return -1; 142 | } 143 | 144 | 145 | try 146 | { 147 | using PairString = std::pair; 148 | using PairVector = std::pair, std::vector>; 149 | using DequeVector = std::deque; 150 | using Map = std::map; 151 | using UnorderedMap = std::unordered_map; 152 | 153 | PairString ps = std::make_pair("111", "111"); 154 | std::vector vps; 155 | vps.push_back(ps); 156 | PairVector pv = std::make_pair(vps, vps); 157 | DequeVector dv; 158 | dv.push_back(pv); 159 | 160 | Map m; 161 | m["111"] = dv; 162 | 163 | UnorderedMap um; 164 | um[111] = m; 165 | 166 | WriteStream ws(0); 167 | ws << um; 168 | 169 | UnorderedMap um2; 170 | ReadStream rs(ws.GetStream(), ws.GetStreamLen()); 171 | rs >> um2; 172 | if (um2[111]["111"].at(0).second.at(0).second != "111") 173 | { 174 | std::cout << "error" << std::endl; 175 | return -10; 176 | } 177 | else 178 | { 179 | std::cout << "success" << std::endl; 180 | } 181 | 182 | 183 | 184 | } 185 | catch (const std::exception&) 186 | { 187 | return -1; 188 | } 189 | 190 | 191 | #define StressCount 1*10000000 192 | SimplePack pack; 193 | pack.id = 10; 194 | pack.name = "aaa"; 195 | pack.createTime = time(NULL); 196 | pack.moneyTree.freeCount = 0; 197 | pack.moneyTree.lastTime = pack.createTime; 198 | pack.moneyTree.statSum = 0; 199 | pack.moneyTree.statCount = 0; 200 | pack.moneyTree.payCount = 0; 201 | unsigned long long count = 0; 202 | unsigned int now = getSteadyTime(); 203 | for (int i = 0; i < StressCount; i++) 204 | { 205 | WriteStream ws(100); 206 | ws << pack; 207 | count += ws.GetStreamLen(); 208 | } 209 | std::cout << "writeStream used time: " << getSteadyTime() - now << std::endl; 210 | 211 | now = getSteadyTime(); 212 | for (int i = 0; i < StressCount; i++) 213 | { 214 | WriteStream ws(100); 215 | ws << pack; 216 | ReadStream rs(ws.GetStream(), ws.GetStreamLen()); 217 | rs >> pack; 218 | count += rs.GetStreamLen(); 219 | } 220 | std::cout << "write and read stream used time: " << getSteadyTime() - now << std::endl; 221 | 222 | 223 | 224 | 225 | 226 | 227 | // cout << "press any key to continue." << endl; 228 | // getchar(); 229 | return 0; 230 | } 231 | 232 | 233 | unsigned int getSteadyTime() 234 | { 235 | #ifdef WIN32 236 | return ::GetTickCount(); 237 | #elif defined(__APPLE__) 238 | const int64_t kOneMillion = 1000 * 1000; 239 | mach_timebase_info_data_t timebase_info; 240 | mach_timebase_info(&timebase_info); 241 | return (unsigned int)((mach_absolute_time() * timebase_info.numer) / (kOneMillion * timebase_info.denom)); 242 | #else 243 | timespec ts; 244 | if(clock_gettime(CLOCK_MONOTONIC_RAW, &ts) != 0) 245 | return 0; 246 | return ts.tv_sec * 1000 + (ts.tv_nsec / 1000/1000); 247 | #endif 248 | } 249 | 250 | -------------------------------------------------------------------------------- /test/csharp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /test/csharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的常规信息通过以下 6 | // 特性集控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("ConsoleApplication2")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ConsoleApplication2")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 使此程序集中的类型 18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | // 则将该类型上的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("406c5ef7-62e9-445b-8815-451229a7eb25")] 24 | 25 | // 程序集的版本信息由下面四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /test/csharp/cshap.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0} 8 | Exe 9 | Properties 10 | proto4z 11 | proto4z 12 | v4.5 13 | 512 14 | 发布\ 15 | true 16 | Disk 17 | false 18 | Foreground 19 | 7 20 | Days 21 | false 22 | false 23 | true 24 | 0 25 | 1.0.0.%2a 26 | false 27 | false 28 | true 29 | 30 | 31 | AnyCPU 32 | true 33 | full 34 | false 35 | bin\Debug\ 36 | DEBUG;TRACE 37 | prompt 38 | 4 39 | 40 | 41 | AnyCPU 42 | pdbonly 43 | true 44 | bin\Release\ 45 | TRACE 46 | prompt 47 | 4 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Code 63 | 64 | 65 | Code 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | False 74 | Microsoft .NET Framework 4.5 %28x86 和 x64%29 75 | true 76 | 77 | 78 | False 79 | .NET Framework 3.5 SP1 Client Profile 80 | false 81 | 82 | 83 | False 84 | .NET Framework 3.5 SP1 85 | false 86 | 87 | 88 | 89 | 96 | -------------------------------------------------------------------------------- /test/csharp/cshap.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 发布\ 5 | 6 | 7 | 8 | 9 | 10 | zh-CN 11 | false 12 | 13 | -------------------------------------------------------------------------------- /test/csharp/proto4z.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "proto4z", "proto4z.csproj", "{D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /test/genCode/TestProto.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 30000 5 | 32000 6 | 7 | 8 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /test/genCode/TestProto.xml.cache: -------------------------------------------------------------------------------- 1 | 2 | 3 | 67374b8721ae6336d10bea97832a9487 4 | 32543e8255208ccc3dc73b13c6325e0c 5 | 14b631778b7f8d6fa7021c409bf548ce 6 | 3a78af7f3d015d07dbe5ae03a01a5e07 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/genCode/genProto.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zsummer/proto4z/f5e2f050dc4d36376fcf9227a631ff92533f6afb/test/genCode/genProto.exe -------------------------------------------------------------------------------- /test/genCode/lua/TestProto.lua: -------------------------------------------------------------------------------- 1 | 2 | Proto4z.MAX_SESSIONS = 5000--max session count 3 | Proto4z.SS_NONE = 0--不存在 4 | Proto4z.SS_CREATED = 1--已创建 5 | Proto4z.SS_WORKING = 10--working状态 6 | Proto4z.SS_DESTROY = 11--已销毁 7 | 8 | Proto4z.register(30000,"IntegerData") 9 | Proto4z.IntegerData = {} --测试 10 | Proto4z.IntegerData.__protoID = 30000 11 | Proto4z.IntegerData.__protoName = "IntegerData" 12 | Proto4z.IntegerData[1] = {name="_char", type="i8" } 13 | Proto4z.IntegerData[2] = {name="_uchar", type="ui8" } 14 | Proto4z.IntegerData[3] = {name="_short", type="i16" } 15 | Proto4z.IntegerData[4] = {name="_ushort", type="ui16" } 16 | Proto4z.IntegerData[5] = {name="_int", type="i32" } 17 | Proto4z.IntegerData[6] = {name="_uint", type="ui32" } 18 | Proto4z.IntegerData[7] = {name="_i64", type="i64" } 19 | Proto4z.IntegerData[8] = {name="_ui64", type="ui64" } 20 | 21 | Proto4z.register(30001,"FloatData") 22 | Proto4z.FloatData = {} --测试 23 | Proto4z.FloatData.__protoID = 30001 24 | Proto4z.FloatData.__protoName = "FloatData" 25 | Proto4z.FloatData[1] = {name="_float", type="float" } 26 | Proto4z.FloatData[2] = {name="_double", type="double" } 27 | 28 | Proto4z.register(30002,"StringData") 29 | Proto4z.StringData = {} --测试 30 | Proto4z.StringData.__protoID = 30002 31 | Proto4z.StringData.__protoName = "StringData" 32 | Proto4z.StringData[1] = {name="_string", type="string" } 33 | 34 | Proto4z.IntArray = {} 35 | Proto4z.IntArray.__protoName = "IntArray" 36 | Proto4z.IntArray.__protoDesc = "array" 37 | Proto4z.IntArray.__protoTypeV = "ui32" 38 | 39 | Proto4z.IntegerDataArray = {} 40 | Proto4z.IntegerDataArray.__protoName = "IntegerDataArray" 41 | Proto4z.IntegerDataArray.__protoDesc = "array" 42 | Proto4z.IntegerDataArray.__protoTypeV = "IntegerData" 43 | 44 | Proto4z.FloatDataArray = {} 45 | Proto4z.FloatDataArray.__protoName = "FloatDataArray" 46 | Proto4z.FloatDataArray.__protoDesc = "array" 47 | Proto4z.FloatDataArray.__protoTypeV = "FloatData" 48 | 49 | Proto4z.StringDataArray = {} 50 | Proto4z.StringDataArray.__protoName = "StringDataArray" 51 | Proto4z.StringDataArray.__protoDesc = "array" 52 | Proto4z.StringDataArray.__protoTypeV = "StringData" 53 | 54 | Proto4z.IntegerDataMap = {} 55 | Proto4z.IntegerDataMap.__protoName = "IntegerDataMap" 56 | Proto4z.IntegerDataMap.__protoDesc = "map" 57 | Proto4z.IntegerDataMap.__protoTypeK = "ui32" 58 | Proto4z.IntegerDataMap.__protoTypeV = "IntegerData" 59 | 60 | Proto4z.FloatDataMap = {} 61 | Proto4z.FloatDataMap.__protoName = "FloatDataMap" 62 | Proto4z.FloatDataMap.__protoDesc = "map" 63 | Proto4z.FloatDataMap.__protoTypeK = "double" 64 | Proto4z.FloatDataMap.__protoTypeV = "FloatData" 65 | 66 | Proto4z.StringDataMap = {} 67 | Proto4z.StringDataMap.__protoName = "StringDataMap" 68 | Proto4z.StringDataMap.__protoDesc = "map" 69 | Proto4z.StringDataMap.__protoTypeK = "string" 70 | Proto4z.StringDataMap.__protoTypeV = "StringData" 71 | 72 | Proto4z.register(30003,"EchoPack") 73 | Proto4z.EchoPack = {} 74 | Proto4z.EchoPack.__protoID = 30003 75 | Proto4z.EchoPack.__protoName = "EchoPack" 76 | Proto4z.EchoPack[1] = {name="_iarray", type="IntegerDataArray" } 77 | Proto4z.EchoPack[2] = {name="_farray", type="FloatDataArray" } 78 | Proto4z.EchoPack[3] = {name="_sarray", type="StringDataArray" } 79 | Proto4z.EchoPack[4] = {name="_imap", type="IntegerDataMap" } 80 | Proto4z.EchoPack[5] = {name="_fmap", type="FloatDataMap" } 81 | Proto4z.EchoPack[6] = {name="_smap", type="StringDataMap" } 82 | 83 | Proto4z.register(30004,"MoneyTree") 84 | Proto4z.MoneyTree = {} --摇钱树功能模块 85 | Proto4z.MoneyTree.__protoID = 30004 86 | Proto4z.MoneyTree.__protoName = "MoneyTree" 87 | Proto4z.MoneyTree[1] = {name="lastTime", type="ui32" } --最后一次执行时间 88 | Proto4z.MoneyTree[2] = {name="freeCount", type="ui32" } --今日剩余免费次数 89 | Proto4z.MoneyTree[3] = {name="payCount", type="ui32" } --今日已购买次数 90 | Proto4z.MoneyTree[4] = {name="statSum", type="ui32" } --历史总和 91 | Proto4z.MoneyTree[5] = {name="statCount", type="ui32" } --历史总次数 92 | 93 | Proto4z.register(30005,"SimplePack") 94 | Proto4z.SimplePack = {} --简单示例 95 | Proto4z.SimplePack.__protoID = 30005 96 | Proto4z.SimplePack.__protoName = "SimplePack" 97 | Proto4z.SimplePack[1] = {name="id", type="ui32" } --id, 对应数据库的结构为自增ID,key 98 | Proto4z.SimplePack[2] = {name="name", type="string" } --昵称, 唯一索引 99 | Proto4z.SimplePack[3] = {name="createTime", type="ui32" } --创建时间, 普通索引 100 | Proto4z.SimplePack[4] = {name="moneyTree", type="MoneyTree" } 101 | -------------------------------------------------------------------------------- /test/lua53/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(lua53) 3 | 4 | include_directories(../../luasrc/) 5 | include_directories(./) 6 | aux_source_directory(./ source) 7 | aux_source_directory(../../luasrc/ luasrc) 8 | set(EXECUTABLE_OUTPUT_PATH ${PROTO4Z_BIN_OUT_PATH}) 9 | 10 | 11 | if (CMAKE_BUILD_TYPE STREQUAL "Debug") 12 | add_definitions(-Wall -g -ggdb -O0 -D_GLIBCXX_USE_NANOSLEEP) 13 | else() 14 | add_definitions(-Wall -O2 -DNDEBUG -D_GLIBCXX_USE_NANOSLEEP) 15 | endif() 16 | set(CMAKE_CXX_FLAGS -std=c++11) 17 | 18 | 19 | add_executable(lua53 ${source} ${luasrc}) 20 | 21 | 22 | if(APPLE) 23 | target_link_libraries(lua53 pthread m) 24 | else() 25 | target_link_libraries(lua53 pthread rt m) 26 | endif() 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/lua53/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.8 2014/07/15 21:26:50 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check((n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /test/lua53/lbitlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lbitlib.c,v 1.28 2014/11/02 19:19:04 roberto Exp $ 3 | ** Standard library for bitwise operations 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lbitlib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lua.h" 14 | 15 | #include "lauxlib.h" 16 | #include "lualib.h" 17 | 18 | 19 | #if defined(LUA_COMPAT_BITLIB) /* { */ 20 | 21 | 22 | /* number of bits to consider in a number */ 23 | #if !defined(LUA_NBITS) 24 | #define LUA_NBITS 32 25 | #endif 26 | 27 | 28 | /* 29 | ** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must 30 | ** be made in two parts to avoid problems when LUA_NBITS is equal to the 31 | ** number of bits in a lua_Unsigned.) 32 | */ 33 | #define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) 34 | 35 | 36 | /* macro to trim extra bits */ 37 | #define trim(x) ((x) & ALLONES) 38 | 39 | 40 | /* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ 41 | #define mask(n) (~((ALLONES << 1) << ((n) - 1))) 42 | 43 | 44 | 45 | static lua_Unsigned andaux (lua_State *L) { 46 | int i, n = lua_gettop(L); 47 | lua_Unsigned r = ~(lua_Unsigned)0; 48 | for (i = 1; i <= n; i++) 49 | r &= luaL_checkunsigned(L, i); 50 | return trim(r); 51 | } 52 | 53 | 54 | static int b_and (lua_State *L) { 55 | lua_Unsigned r = andaux(L); 56 | lua_pushunsigned(L, r); 57 | return 1; 58 | } 59 | 60 | 61 | static int b_test (lua_State *L) { 62 | lua_Unsigned r = andaux(L); 63 | lua_pushboolean(L, r != 0); 64 | return 1; 65 | } 66 | 67 | 68 | static int b_or (lua_State *L) { 69 | int i, n = lua_gettop(L); 70 | lua_Unsigned r = 0; 71 | for (i = 1; i <= n; i++) 72 | r |= luaL_checkunsigned(L, i); 73 | lua_pushunsigned(L, trim(r)); 74 | return 1; 75 | } 76 | 77 | 78 | static int b_xor (lua_State *L) { 79 | int i, n = lua_gettop(L); 80 | lua_Unsigned r = 0; 81 | for (i = 1; i <= n; i++) 82 | r ^= luaL_checkunsigned(L, i); 83 | lua_pushunsigned(L, trim(r)); 84 | return 1; 85 | } 86 | 87 | 88 | static int b_not (lua_State *L) { 89 | lua_Unsigned r = ~luaL_checkunsigned(L, 1); 90 | lua_pushunsigned(L, trim(r)); 91 | return 1; 92 | } 93 | 94 | 95 | static int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) { 96 | if (i < 0) { /* shift right? */ 97 | i = -i; 98 | r = trim(r); 99 | if (i >= LUA_NBITS) r = 0; 100 | else r >>= i; 101 | } 102 | else { /* shift left */ 103 | if (i >= LUA_NBITS) r = 0; 104 | else r <<= i; 105 | r = trim(r); 106 | } 107 | lua_pushunsigned(L, r); 108 | return 1; 109 | } 110 | 111 | 112 | static int b_lshift (lua_State *L) { 113 | return b_shift(L, luaL_checkunsigned(L, 1), luaL_checkinteger(L, 2)); 114 | } 115 | 116 | 117 | static int b_rshift (lua_State *L) { 118 | return b_shift(L, luaL_checkunsigned(L, 1), -luaL_checkinteger(L, 2)); 119 | } 120 | 121 | 122 | static int b_arshift (lua_State *L) { 123 | lua_Unsigned r = luaL_checkunsigned(L, 1); 124 | lua_Integer i = luaL_checkinteger(L, 2); 125 | if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1)))) 126 | return b_shift(L, r, -i); 127 | else { /* arithmetic shift for 'negative' number */ 128 | if (i >= LUA_NBITS) r = ALLONES; 129 | else 130 | r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i)); /* add signal bit */ 131 | lua_pushunsigned(L, r); 132 | return 1; 133 | } 134 | } 135 | 136 | 137 | static int b_rot (lua_State *L, lua_Integer d) { 138 | lua_Unsigned r = luaL_checkunsigned(L, 1); 139 | int i = d & (LUA_NBITS - 1); /* i = d % NBITS */ 140 | r = trim(r); 141 | if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ 142 | r = (r << i) | (r >> (LUA_NBITS - i)); 143 | lua_pushunsigned(L, trim(r)); 144 | return 1; 145 | } 146 | 147 | 148 | static int b_lrot (lua_State *L) { 149 | return b_rot(L, luaL_checkinteger(L, 2)); 150 | } 151 | 152 | 153 | static int b_rrot (lua_State *L) { 154 | return b_rot(L, -luaL_checkinteger(L, 2)); 155 | } 156 | 157 | 158 | /* 159 | ** get field and width arguments for field-manipulation functions, 160 | ** checking whether they are valid. 161 | ** ('luaL_error' called without 'return' to avoid later warnings about 162 | ** 'width' being used uninitialized.) 163 | */ 164 | static int fieldargs (lua_State *L, int farg, int *width) { 165 | lua_Integer f = luaL_checkinteger(L, farg); 166 | lua_Integer w = luaL_optinteger(L, farg + 1, 1); 167 | luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); 168 | luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); 169 | if (f + w > LUA_NBITS) 170 | luaL_error(L, "trying to access non-existent bits"); 171 | *width = (int)w; 172 | return (int)f; 173 | } 174 | 175 | 176 | static int b_extract (lua_State *L) { 177 | int w; 178 | lua_Unsigned r = trim(luaL_checkunsigned(L, 1)); 179 | int f = fieldargs(L, 2, &w); 180 | r = (r >> f) & mask(w); 181 | lua_pushunsigned(L, r); 182 | return 1; 183 | } 184 | 185 | 186 | static int b_replace (lua_State *L) { 187 | int w; 188 | lua_Unsigned r = trim(luaL_checkunsigned(L, 1)); 189 | lua_Unsigned v = luaL_checkunsigned(L, 2); 190 | int f = fieldargs(L, 3, &w); 191 | int m = mask(w); 192 | v &= m; /* erase bits outside given width */ 193 | r = (r & ~(m << f)) | (v << f); 194 | lua_pushunsigned(L, r); 195 | return 1; 196 | } 197 | 198 | 199 | static const luaL_Reg bitlib[] = { 200 | {"arshift", b_arshift}, 201 | {"band", b_and}, 202 | {"bnot", b_not}, 203 | {"bor", b_or}, 204 | {"bxor", b_xor}, 205 | {"btest", b_test}, 206 | {"extract", b_extract}, 207 | {"lrotate", b_lrot}, 208 | {"lshift", b_lshift}, 209 | {"replace", b_replace}, 210 | {"rrotate", b_rrot}, 211 | {"rshift", b_rshift}, 212 | {NULL, NULL} 213 | }; 214 | 215 | 216 | 217 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 218 | luaL_newlib(L, bitlib); 219 | return 1; 220 | } 221 | 222 | 223 | #else /* }{ */ 224 | 225 | 226 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 227 | return luaL_error(L, "library 'bit32' has been deprecated"); 228 | } 229 | 230 | #endif /* } */ 231 | -------------------------------------------------------------------------------- /test/lua53/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.63 2013/12/30 20:47:58 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, 28 | OPR_DIV, 29 | OPR_IDIV, 30 | OPR_BAND, OPR_BOR, OPR_BXOR, 31 | OPR_SHL, OPR_SHR, 32 | OPR_CONCAT, 33 | OPR_EQ, OPR_LT, OPR_LE, 34 | OPR_NE, OPR_GT, OPR_GE, 35 | OPR_AND, OPR_OR, 36 | OPR_NOBINOPR 37 | } BinOpr; 38 | 39 | 40 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 41 | 42 | 43 | #define getcode(fs,e) ((fs)->f->code[(e)->u.info]) 44 | 45 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 46 | 47 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 48 | 49 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 50 | 51 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 52 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 53 | LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 54 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 55 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 56 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 57 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 58 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 59 | LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n); 60 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 61 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 62 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 63 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 64 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 65 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 66 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 67 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 68 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 69 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 70 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 71 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 72 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 73 | LUAI_FUNC int luaK_jump (FuncState *fs); 74 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 75 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 76 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 77 | LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 78 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 79 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 80 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 81 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 82 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 83 | expdesc *v2, int line); 84 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 85 | 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /test/lua53/lcorolib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcorolib.c,v 1.9 2014/11/02 19:19:04 roberto Exp $ 3 | ** Coroutine Library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lcorolib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lauxlib.h" 18 | #include "lualib.h" 19 | 20 | 21 | static lua_State *getco (lua_State *L) { 22 | lua_State *co = lua_tothread(L, 1); 23 | luaL_argcheck(L, co, 1, "thread expected"); 24 | return co; 25 | } 26 | 27 | 28 | static int auxresume (lua_State *L, lua_State *co, int narg) { 29 | int status; 30 | if (!lua_checkstack(co, narg)) { 31 | lua_pushliteral(L, "too many arguments to resume"); 32 | return -1; /* error flag */ 33 | } 34 | if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) { 35 | lua_pushliteral(L, "cannot resume dead coroutine"); 36 | return -1; /* error flag */ 37 | } 38 | lua_xmove(L, co, narg); 39 | status = lua_resume(co, L, narg); 40 | if (status == LUA_OK || status == LUA_YIELD) { 41 | int nres = lua_gettop(co); 42 | if (!lua_checkstack(L, nres + 1)) { 43 | lua_pop(co, nres); /* remove results anyway */ 44 | lua_pushliteral(L, "too many results to resume"); 45 | return -1; /* error flag */ 46 | } 47 | lua_xmove(co, L, nres); /* move yielded values */ 48 | return nres; 49 | } 50 | else { 51 | lua_xmove(co, L, 1); /* move error message */ 52 | return -1; /* error flag */ 53 | } 54 | } 55 | 56 | 57 | static int luaB_coresume (lua_State *L) { 58 | lua_State *co = getco(L); 59 | int r; 60 | r = auxresume(L, co, lua_gettop(L) - 1); 61 | if (r < 0) { 62 | lua_pushboolean(L, 0); 63 | lua_insert(L, -2); 64 | return 2; /* return false + error message */ 65 | } 66 | else { 67 | lua_pushboolean(L, 1); 68 | lua_insert(L, -(r + 1)); 69 | return r + 1; /* return true + 'resume' returns */ 70 | } 71 | } 72 | 73 | 74 | static int luaB_auxwrap (lua_State *L) { 75 | lua_State *co = lua_tothread(L, lua_upvalueindex(1)); 76 | int r = auxresume(L, co, lua_gettop(L)); 77 | if (r < 0) { 78 | if (lua_isstring(L, -1)) { /* error object is a string? */ 79 | luaL_where(L, 1); /* add extra info */ 80 | lua_insert(L, -2); 81 | lua_concat(L, 2); 82 | } 83 | return lua_error(L); /* propagate error */ 84 | } 85 | return r; 86 | } 87 | 88 | 89 | static int luaB_cocreate (lua_State *L) { 90 | lua_State *NL; 91 | luaL_checktype(L, 1, LUA_TFUNCTION); 92 | NL = lua_newthread(L); 93 | lua_pushvalue(L, 1); /* move function to top */ 94 | lua_xmove(L, NL, 1); /* move function from L to NL */ 95 | return 1; 96 | } 97 | 98 | 99 | static int luaB_cowrap (lua_State *L) { 100 | luaB_cocreate(L); 101 | lua_pushcclosure(L, luaB_auxwrap, 1); 102 | return 1; 103 | } 104 | 105 | 106 | static int luaB_yield (lua_State *L) { 107 | return lua_yield(L, lua_gettop(L)); 108 | } 109 | 110 | 111 | static int luaB_costatus (lua_State *L) { 112 | lua_State *co = getco(L); 113 | if (L == co) lua_pushliteral(L, "running"); 114 | else { 115 | switch (lua_status(co)) { 116 | case LUA_YIELD: 117 | lua_pushliteral(L, "suspended"); 118 | break; 119 | case LUA_OK: { 120 | lua_Debug ar; 121 | if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ 122 | lua_pushliteral(L, "normal"); /* it is running */ 123 | else if (lua_gettop(co) == 0) 124 | lua_pushliteral(L, "dead"); 125 | else 126 | lua_pushliteral(L, "suspended"); /* initial state */ 127 | break; 128 | } 129 | default: /* some error occurred */ 130 | lua_pushliteral(L, "dead"); 131 | break; 132 | } 133 | } 134 | return 1; 135 | } 136 | 137 | 138 | static int luaB_yieldable (lua_State *L) { 139 | lua_pushboolean(L, lua_isyieldable(L)); 140 | return 1; 141 | } 142 | 143 | 144 | static int luaB_corunning (lua_State *L) { 145 | int ismain = lua_pushthread(L); 146 | lua_pushboolean(L, ismain); 147 | return 2; 148 | } 149 | 150 | 151 | static const luaL_Reg co_funcs[] = { 152 | {"create", luaB_cocreate}, 153 | {"resume", luaB_coresume}, 154 | {"running", luaB_corunning}, 155 | {"status", luaB_costatus}, 156 | {"wrap", luaB_cowrap}, 157 | {"yield", luaB_yield}, 158 | {"isyieldable", luaB_yieldable}, 159 | {NULL, NULL} 160 | }; 161 | 162 | 163 | 164 | LUAMOD_API int luaopen_coroutine (lua_State *L) { 165 | luaL_newlib(L, co_funcs); 166 | return 1; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /test/lua53/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 20 | 0x00, /* EOZ */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 22 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 26 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 27 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 28 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 29 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 30 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 32 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 33 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 34 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 35 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 36 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | }; 54 | 55 | #endif /* } */ 56 | -------------------------------------------------------------------------------- /test/lua53/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /test/lua53/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.12 2014/11/10 14:46:05 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | /* Active Lua function (given call info) */ 21 | #define ci_func(ci) (clLvalue((ci)->func)) 22 | 23 | 24 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 25 | const char *opname); 26 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 29 | const TValue *p2, 30 | const char *msg); 31 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 32 | const TValue *p2); 33 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 34 | const TValue *p2); 35 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 36 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 37 | LUAI_FUNC void luaG_traceexec (lua_State *L); 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /test/lua53/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.21 2014/10/25 11:50:46 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) if (L->stack_last - L->top <= (n)) \ 17 | luaD_growstack(L, n); else condmovestack(L); 18 | 19 | 20 | #define incr_top(L) {L->top++; luaD_checkstack(L,0);} 21 | 22 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 23 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 24 | 25 | 26 | /* type of protected functions, to be ran by 'runprotected' */ 27 | typedef void (*Pfunc) (lua_State *L, void *ud); 28 | 29 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 30 | const char *mode); 31 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 32 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 33 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults, 34 | int allowyield); 35 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 36 | ptrdiff_t oldtop, ptrdiff_t ef); 37 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 38 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 39 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 40 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 41 | 42 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 43 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /test/lua53/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c,v 2.34 2014/11/02 19:19:04 roberto Exp $ 3 | ** save precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ldump_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lobject.h" 18 | #include "lstate.h" 19 | #include "lundump.h" 20 | 21 | 22 | typedef struct { 23 | lua_State *L; 24 | lua_Writer writer; 25 | void *data; 26 | int strip; 27 | int status; 28 | } DumpState; 29 | 30 | 31 | /* 32 | ** All high-level dumps go through DumpVector; you can change it to 33 | ** change the endianness of the result 34 | */ 35 | #define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D) 36 | 37 | #define DumpLiteral(s,D) DumpBlock(s, sizeof(s) - sizeof(char), D) 38 | 39 | 40 | static void DumpBlock (const void *b, size_t size, DumpState *D) { 41 | if (D->status == 0) { 42 | lua_unlock(D->L); 43 | D->status = (*D->writer)(D->L, b, size, D->data); 44 | lua_lock(D->L); 45 | } 46 | } 47 | 48 | 49 | #define DumpVar(x,D) DumpVector(&x,1,D) 50 | 51 | 52 | static void DumpByte (int y, DumpState *D) { 53 | lu_byte x = (lu_byte)y; 54 | DumpVar(x, D); 55 | } 56 | 57 | 58 | static void DumpInt (int x, DumpState *D) { 59 | DumpVar(x, D); 60 | } 61 | 62 | 63 | static void DumpNumber (lua_Number x, DumpState *D) { 64 | DumpVar(x, D); 65 | } 66 | 67 | 68 | static void DumpInteger (lua_Integer x, DumpState *D) { 69 | DumpVar(x, D); 70 | } 71 | 72 | 73 | static void DumpString (const TString *s, DumpState *D) { 74 | if (s == NULL) 75 | DumpByte(0, D); 76 | else { 77 | size_t size = s->len + 1; /* include trailing '\0' */ 78 | if (size < 0xFF) 79 | DumpByte(cast_int(size), D); 80 | else { 81 | DumpByte(0xFF, D); 82 | DumpVar(size, D); 83 | } 84 | DumpVector(getstr(s), size - 1, D); /* no need to save '\0' */ 85 | } 86 | } 87 | 88 | 89 | static void DumpCode (const Proto *f, DumpState *D) { 90 | DumpInt(f->sizecode, D); 91 | DumpVector(f->code, f->sizecode, D); 92 | } 93 | 94 | 95 | static void DumpFunction(const Proto *f, TString *psource, DumpState *D); 96 | 97 | static void DumpConstants (const Proto *f, DumpState *D) { 98 | int i; 99 | int n = f->sizek; 100 | DumpInt(n, D); 101 | for (i = 0; i < n; i++) { 102 | const TValue *o = &f->k[i]; 103 | DumpByte(ttype(o), D); 104 | switch (ttype(o)) { 105 | case LUA_TNIL: 106 | break; 107 | case LUA_TBOOLEAN: 108 | DumpByte(bvalue(o), D); 109 | break; 110 | case LUA_TNUMFLT: 111 | DumpNumber(fltvalue(o), D); 112 | break; 113 | case LUA_TNUMINT: 114 | DumpInteger(ivalue(o), D); 115 | break; 116 | case LUA_TSHRSTR: 117 | case LUA_TLNGSTR: 118 | DumpString(tsvalue(o), D); 119 | break; 120 | default: 121 | lua_assert(0); 122 | } 123 | } 124 | } 125 | 126 | 127 | static void DumpProtos (const Proto *f, DumpState *D) { 128 | int i; 129 | int n = f->sizep; 130 | DumpInt(n, D); 131 | for (i = 0; i < n; i++) 132 | DumpFunction(f->p[i], f->source, D); 133 | } 134 | 135 | 136 | static void DumpUpvalues (const Proto *f, DumpState *D) { 137 | int i, n = f->sizeupvalues; 138 | DumpInt(n, D); 139 | for (i = 0; i < n; i++) { 140 | DumpByte(f->upvalues[i].instack, D); 141 | DumpByte(f->upvalues[i].idx, D); 142 | } 143 | } 144 | 145 | 146 | static void DumpDebug (const Proto *f, DumpState *D) { 147 | int i, n; 148 | n = (D->strip) ? 0 : f->sizelineinfo; 149 | DumpInt(n, D); 150 | DumpVector(f->lineinfo, n, D); 151 | n = (D->strip) ? 0 : f->sizelocvars; 152 | DumpInt(n, D); 153 | for (i = 0; i < n; i++) { 154 | DumpString(f->locvars[i].varname, D); 155 | DumpInt(f->locvars[i].startpc, D); 156 | DumpInt(f->locvars[i].endpc, D); 157 | } 158 | n = (D->strip) ? 0 : f->sizeupvalues; 159 | DumpInt(n, D); 160 | for (i = 0; i < n; i++) 161 | DumpString(f->upvalues[i].name, D); 162 | } 163 | 164 | 165 | static void DumpFunction (const Proto *f, TString *psource, DumpState *D) { 166 | if (D->strip || f->source == psource) 167 | DumpString(NULL, D); /* no debug info or same source as its parent */ 168 | else 169 | DumpString(f->source, D); 170 | DumpInt(f->linedefined, D); 171 | DumpInt(f->lastlinedefined, D); 172 | DumpByte(f->numparams, D); 173 | DumpByte(f->is_vararg, D); 174 | DumpByte(f->maxstacksize, D); 175 | DumpCode(f, D); 176 | DumpConstants(f, D); 177 | DumpUpvalues(f, D); 178 | DumpProtos(f, D); 179 | DumpDebug(f, D); 180 | } 181 | 182 | 183 | static void DumpHeader (DumpState *D) { 184 | DumpLiteral(LUA_SIGNATURE, D); 185 | DumpByte(LUAC_VERSION, D); 186 | DumpByte(LUAC_FORMAT, D); 187 | DumpLiteral(LUAC_DATA, D); 188 | DumpByte(sizeof(int), D); 189 | DumpByte(sizeof(size_t), D); 190 | DumpByte(sizeof(Instruction), D); 191 | DumpByte(sizeof(lua_Integer), D); 192 | DumpByte(sizeof(lua_Number), D); 193 | DumpInteger(LUAC_INT, D); 194 | DumpNumber(LUAC_NUM, D); 195 | } 196 | 197 | 198 | /* 199 | ** dump Lua function as precompiled chunk 200 | */ 201 | int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, 202 | int strip) { 203 | DumpState D; 204 | D.L = L; 205 | D.writer = w; 206 | D.data = data; 207 | D.strip = strip; 208 | D.status = 0; 209 | DumpHeader(&D); 210 | DumpByte(f->sizeupvalues, &D); 211 | DumpFunction(f, NULL, &D); 212 | return D.status; 213 | } 214 | 215 | -------------------------------------------------------------------------------- /test/lua53/lfunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.c,v 2.45 2014/11/02 19:19:04 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lfunc_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lfunc.h" 18 | #include "lgc.h" 19 | #include "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | 23 | 24 | 25 | CClosure *luaF_newCclosure (lua_State *L, int n) { 26 | GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n)); 27 | CClosure *c = gco2ccl(o); 28 | c->nupvalues = cast_byte(n); 29 | return c; 30 | } 31 | 32 | 33 | LClosure *luaF_newLclosure (lua_State *L, int n) { 34 | GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n)); 35 | LClosure *c = gco2lcl(o); 36 | c->p = NULL; 37 | c->nupvalues = cast_byte(n); 38 | while (n--) c->upvals[n] = NULL; 39 | return c; 40 | } 41 | 42 | /* 43 | ** fill a closure with new closed upvalues 44 | */ 45 | void luaF_initupvals (lua_State *L, LClosure *cl) { 46 | int i; 47 | for (i = 0; i < cl->nupvalues; i++) { 48 | UpVal *uv = luaM_new(L, UpVal); 49 | uv->refcount = 1; 50 | uv->v = &uv->u.value; /* make it closed */ 51 | setnilvalue(uv->v); 52 | cl->upvals[i] = uv; 53 | } 54 | } 55 | 56 | 57 | UpVal *luaF_findupval (lua_State *L, StkId level) { 58 | UpVal **pp = &L->openupval; 59 | UpVal *p; 60 | UpVal *uv; 61 | lua_assert(isintwups(L) || L->openupval == NULL); 62 | while (*pp != NULL && (p = *pp)->v >= level) { 63 | lua_assert(upisopen(p)); 64 | if (p->v == level) /* found a corresponding upvalue? */ 65 | return p; /* return it */ 66 | pp = &p->u.open.next; 67 | } 68 | /* not found: create a new upvalue */ 69 | uv = luaM_new(L, UpVal); 70 | uv->refcount = 0; 71 | uv->u.open.next = *pp; /* link it to list of open upvalues */ 72 | uv->u.open.touched = 1; 73 | *pp = uv; 74 | uv->v = level; /* current value lives in the stack */ 75 | if (!isintwups(L)) { /* thread not in list of threads with upvalues? */ 76 | L->twups = G(L)->twups; /* link it to the list */ 77 | G(L)->twups = L; 78 | } 79 | return uv; 80 | } 81 | 82 | 83 | void luaF_close (lua_State *L, StkId level) { 84 | UpVal *uv; 85 | while (L->openupval != NULL && (uv = L->openupval)->v >= level) { 86 | lua_assert(upisopen(uv)); 87 | L->openupval = uv->u.open.next; /* remove from 'open' list */ 88 | if (uv->refcount == 0) /* no references? */ 89 | luaM_free(L, uv); /* free upvalue */ 90 | else { 91 | setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */ 92 | uv->v = &uv->u.value; /* now current value lives here */ 93 | luaC_upvalbarrier(L, uv); 94 | } 95 | } 96 | } 97 | 98 | 99 | Proto *luaF_newproto (lua_State *L) { 100 | GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto)); 101 | Proto *f = gco2p(o); 102 | f->k = NULL; 103 | f->sizek = 0; 104 | f->p = NULL; 105 | f->sizep = 0; 106 | f->code = NULL; 107 | f->cache = NULL; 108 | f->sizecode = 0; 109 | f->lineinfo = NULL; 110 | f->sizelineinfo = 0; 111 | f->upvalues = NULL; 112 | f->sizeupvalues = 0; 113 | f->numparams = 0; 114 | f->is_vararg = 0; 115 | f->maxstacksize = 0; 116 | f->locvars = NULL; 117 | f->sizelocvars = 0; 118 | f->linedefined = 0; 119 | f->lastlinedefined = 0; 120 | f->source = NULL; 121 | return f; 122 | } 123 | 124 | 125 | void luaF_freeproto (lua_State *L, Proto *f) { 126 | luaM_freearray(L, f->code, f->sizecode); 127 | luaM_freearray(L, f->p, f->sizep); 128 | luaM_freearray(L, f->k, f->sizek); 129 | luaM_freearray(L, f->lineinfo, f->sizelineinfo); 130 | luaM_freearray(L, f->locvars, f->sizelocvars); 131 | luaM_freearray(L, f->upvalues, f->sizeupvalues); 132 | luaM_free(L, f); 133 | } 134 | 135 | 136 | /* 137 | ** Look for n-th local variable at line 'line' in function 'func'. 138 | ** Returns NULL if not found. 139 | */ 140 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { 141 | int i; 142 | for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { 143 | if (pc < f->locvars[i].endpc) { /* is variable active? */ 144 | local_number--; 145 | if (local_number == 0) 146 | return getstr(f->locvars[i].varname); 147 | } 148 | } 149 | return NULL; /* not found */ 150 | } 151 | 152 | -------------------------------------------------------------------------------- /test/lua53/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.14 2014/06/19 18:27:20 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** Upvalues for Lua closures 27 | */ 28 | struct UpVal { 29 | TValue *v; /* points to stack or to its own value */ 30 | lu_mem refcount; /* reference counter */ 31 | union { 32 | struct { /* (when open) */ 33 | UpVal *next; /* linked list */ 34 | int touched; /* mark to avoid cycles with dead threads */ 35 | } open; 36 | TValue value; /* the value (when closed) */ 37 | } u; 38 | }; 39 | 40 | #define upisopen(up) ((up)->v != &(up)->u.value) 41 | 42 | 43 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 44 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 45 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 46 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 47 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 48 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 49 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 50 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 51 | int pc); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /test/lua53/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 2.86 2014/10/25 11:50:46 roberto Exp $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | /* 15 | ** Collectable objects may have one of three colors: white, which 16 | ** means the object is not marked; gray, which means the 17 | ** object is marked, but its references may be not marked; and 18 | ** black, which means that the object and all its references are marked. 19 | ** The main invariant of the garbage collector, while marking objects, 20 | ** is that a black object can never point to a white one. Moreover, 21 | ** any gray object must be in a "gray list" (gray, grayagain, weak, 22 | ** allweak, ephemeron) so that it can be visited again before finishing 23 | ** the collection cycle. These lists have no meaning when the invariant 24 | ** is not being enforced (e.g., sweep phase). 25 | */ 26 | 27 | 28 | 29 | /* how much to allocate before next GC step */ 30 | #if !defined(GCSTEPSIZE) 31 | /* ~100 small strings */ 32 | #define GCSTEPSIZE (cast_int(100 * sizeof(TString))) 33 | #endif 34 | 35 | 36 | /* 37 | ** Possible states of the Garbage Collector 38 | */ 39 | #define GCSpropagate 0 40 | #define GCSatomic 1 41 | #define GCSswpallgc 2 42 | #define GCSswpfinobj 3 43 | #define GCSswptobefnz 4 44 | #define GCSswpend 5 45 | #define GCScallfin 6 46 | #define GCSpause 7 47 | 48 | 49 | #define issweepphase(g) \ 50 | (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend) 51 | 52 | 53 | /* 54 | ** macro to tell when main invariant (white objects cannot point to black 55 | ** ones) must be kept. During a collection, the sweep 56 | ** phase may break the invariant, as objects turned white may point to 57 | ** still-black objects. The invariant is restored when sweep ends and 58 | ** all objects are white again. 59 | */ 60 | 61 | #define keepinvariant(g) ((g)->gcstate <= GCSatomic) 62 | 63 | 64 | /* 65 | ** some useful bit tricks 66 | */ 67 | #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) 68 | #define setbits(x,m) ((x) |= (m)) 69 | #define testbits(x,m) ((x) & (m)) 70 | #define bitmask(b) (1<<(b)) 71 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 72 | #define l_setbit(x,b) setbits(x, bitmask(b)) 73 | #define resetbit(x,b) resetbits(x, bitmask(b)) 74 | #define testbit(x,b) testbits(x, bitmask(b)) 75 | 76 | 77 | /* Layout for bit use in 'marked' field: */ 78 | #define WHITE0BIT 0 /* object is white (type 0) */ 79 | #define WHITE1BIT 1 /* object is white (type 1) */ 80 | #define BLACKBIT 2 /* object is black */ 81 | #define FINALIZEDBIT 3 /* object has been marked for finalization */ 82 | /* bit 7 is currently used by tests (luaL_checkmemory) */ 83 | 84 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 85 | 86 | 87 | #define iswhite(x) testbits((x)->marked, WHITEBITS) 88 | #define isblack(x) testbit((x)->marked, BLACKBIT) 89 | #define isgray(x) /* neither white nor black */ \ 90 | (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT))) 91 | 92 | #define tofinalize(x) testbit((x)->marked, FINALIZEDBIT) 93 | 94 | #define otherwhite(g) ((g)->currentwhite ^ WHITEBITS) 95 | #define isdeadm(ow,m) (!(((m) ^ WHITEBITS) & (ow))) 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->marked) 97 | 98 | #define changewhite(x) ((x)->marked ^= WHITEBITS) 99 | #define gray2black(x) l_setbit((x)->marked, BLACKBIT) 100 | 101 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 102 | 103 | 104 | #define luaC_condGC(L,c) \ 105 | {if (G(L)->GCdebt > 0) {c;}; condchangemem(L);} 106 | #define luaC_checkGC(L) luaC_condGC(L, luaC_step(L);) 107 | 108 | 109 | #define luaC_barrier(L,p,v) { \ 110 | if (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) \ 111 | luaC_barrier_(L,obj2gco(p),gcvalue(v)); } 112 | 113 | #define luaC_barrierback(L,p,v) { \ 114 | if (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) \ 115 | luaC_barrierback_(L,p); } 116 | 117 | #define luaC_objbarrier(L,p,o) { \ 118 | if (isblack(p) && iswhite(o)) \ 119 | luaC_barrier_(L,obj2gco(p),obj2gco(o)); } 120 | 121 | #define luaC_upvalbarrier(L,uv) \ 122 | { if (iscollectable((uv)->v) && !upisopen(uv)) \ 123 | luaC_upvalbarrier_(L,uv); } 124 | 125 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 126 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); 127 | LUAI_FUNC void luaC_step (lua_State *L); 128 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 129 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 130 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 131 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 132 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o); 133 | LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); 134 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 135 | LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); 136 | 137 | 138 | #endif 139 | -------------------------------------------------------------------------------- /test/lua53/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove _PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /test/lua53/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.78 2014/10/29 15:38:24 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | #if !defined(LUA_ENV) 18 | #define LUA_ENV "_ENV" 19 | #endif 20 | 21 | 22 | /* 23 | * WARNING: if you change the order of this enumeration, 24 | * grep "ORDER RESERVED" 25 | */ 26 | enum RESERVED { 27 | /* terminal symbols denoted by reserved words */ 28 | TK_AND = FIRST_RESERVED, TK_BREAK, 29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 32 | /* other terminal symbols */ 33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 34 | TK_SHL, TK_SHR, 35 | TK_DBCOLON, TK_EOS, 36 | TK_FLT, TK_INT, TK_NAME, TK_STRING 37 | }; 38 | 39 | /* number of reserved words */ 40 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | lua_Integer i; 46 | TString *ts; 47 | } SemInfo; /* semantics information */ 48 | 49 | 50 | typedef struct Token { 51 | int token; 52 | SemInfo seminfo; 53 | } Token; 54 | 55 | 56 | /* state of the lexer plus state of the parser when shared by all 57 | functions */ 58 | typedef struct LexState { 59 | int current; /* current character (charint) */ 60 | int linenumber; /* input line counter */ 61 | int lastline; /* line of last token 'consumed' */ 62 | Token t; /* current token */ 63 | Token lookahead; /* look ahead token */ 64 | struct FuncState *fs; /* current function (parser) */ 65 | struct lua_State *L; 66 | ZIO *z; /* input stream */ 67 | Mbuffer *buff; /* buffer for tokens */ 68 | Table *h; /* to avoid collection/reuse strings */ 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 70 | TString *source; /* current source name */ 71 | TString *envn; /* environment variable name */ 72 | char decpoint; /* locale decimal point */ 73 | } LexState; 74 | 75 | 76 | LUAI_FUNC void luaX_init (lua_State *L); 77 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 78 | TString *source, int firstchar); 79 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 80 | LUAI_FUNC void luaX_next (LexState *ls); 81 | LUAI_FUNC int luaX_lookahead (LexState *ls); 82 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 83 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 84 | 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /test/lua53/llimits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llimits.h,v 1.125 2014/12/19 13:30:23 roberto Exp $ 3 | ** Limits, basic types, and some other 'installation-dependent' definitions 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llimits_h 8 | #define llimits_h 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | #include "lua.h" 16 | 17 | /* 18 | ** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count 19 | ** the total memory used by Lua (in bytes). Usually, 'size_t' and 20 | ** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines. 21 | */ 22 | #if defined(LUAI_MEM) /* { external definitions? */ 23 | typedef LUAI_UMEM lu_mem; 24 | typedef LUAI_MEM l_mem; 25 | #elif LUAI_BITSINT >= 32 /* }{ */ 26 | typedef size_t lu_mem; 27 | typedef ptrdiff_t l_mem; 28 | #else /* 16-bit ints */ /* }{ */ 29 | typedef unsigned long lu_mem; 30 | typedef long l_mem; 31 | #endif /* } */ 32 | 33 | 34 | /* chars used as small naturals (so that 'char' is reserved for characters) */ 35 | typedef unsigned char lu_byte; 36 | 37 | 38 | /* maximum value for size_t */ 39 | #define MAX_SIZET ((size_t)(~(size_t)0)) 40 | 41 | /* maximum size visible for Lua (must be representable in a lua_Integer */ 42 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ 43 | : (size_t)(LUA_MAXINTEGER)) 44 | 45 | 46 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)) 47 | 48 | #define MAX_LMEM ((l_mem)(MAX_LUMEM >> 1)) 49 | 50 | 51 | #define MAX_INT INT_MAX /* maximum value of an int */ 52 | 53 | 54 | /* 55 | ** conversion of pointer to integer: 56 | ** this is for hashing only; there is no problem if the integer 57 | ** cannot hold the whole pointer value 58 | */ 59 | #define point2int(p) ((unsigned int)((size_t)(p) & UINT_MAX)) 60 | 61 | 62 | 63 | /* type to ensure maximum alignment */ 64 | #if defined(LUAI_USER_ALIGNMENT_T) 65 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; 66 | #else 67 | typedef union { double u; void *s; lua_Integer i; long l; } L_Umaxalign; 68 | #endif 69 | 70 | 71 | 72 | /* types of 'usual argument conversions' for lua_Number and lua_Integer */ 73 | typedef LUAI_UACNUMBER l_uacNumber; 74 | typedef LUAI_UACINT l_uacInt; 75 | 76 | 77 | /* internal assertions for in-house debugging */ 78 | #if defined(lua_assert) 79 | #define check_exp(c,e) (lua_assert(c), (e)) 80 | /* to avoid problems with conditions too long */ 81 | #define lua_longassert(c) { if (!(c)) lua_assert(0); } 82 | #else 83 | #define lua_assert(c) ((void)0) 84 | #define check_exp(c,e) (e) 85 | #define lua_longassert(c) ((void)0) 86 | #endif 87 | 88 | /* 89 | ** assertion for checking API calls 90 | */ 91 | #if defined(LUA_USE_APICHECK) 92 | #include 93 | #define luai_apicheck(e) assert(e) 94 | #else 95 | #define luai_apicheck(e) lua_assert(e) 96 | #endif 97 | 98 | 99 | #define api_check(e,msg) luai_apicheck((e) && msg) 100 | 101 | 102 | #if !defined(UNUSED) 103 | #define UNUSED(x) ((void)(x)) /* to avoid warnings */ 104 | #endif 105 | 106 | 107 | #define cast(t, exp) ((t)(exp)) 108 | 109 | #define cast_void(i) cast(void, (i)) 110 | #define cast_byte(i) cast(lu_byte, (i)) 111 | #define cast_num(i) cast(lua_Number, (i)) 112 | #define cast_int(i) cast(int, (i)) 113 | #define cast_uchar(i) cast(unsigned char, (i)) 114 | 115 | 116 | /* cast a signed lua_Integer to lua_Unsigned */ 117 | #if !defined(l_castS2U) 118 | #define l_castS2U(i) ((lua_Unsigned)(i)) 119 | #endif 120 | 121 | /* 122 | ** cast a lua_Unsigned to a signed lua_Integer; this cast is 123 | ** not strict ISO C, but two-complement architectures should 124 | ** work fine. 125 | */ 126 | #if !defined(l_castU2S) 127 | #define l_castU2S(i) ((lua_Integer)(i)) 128 | #endif 129 | 130 | 131 | /* 132 | ** non-return type 133 | */ 134 | #if defined(__GNUC__) 135 | #define l_noret void __attribute__((noreturn)) 136 | #elif defined(_MSC_VER) && _MSC_VER >= 1200 137 | #define l_noret void __declspec(noreturn) 138 | #else 139 | #define l_noret void 140 | #endif 141 | 142 | 143 | 144 | /* 145 | ** maximum depth for nested C calls and syntactical nested non-terminals 146 | ** in a program. (Value must fit in an unsigned short int.) 147 | */ 148 | #if !defined(LUAI_MAXCCALLS) 149 | #define LUAI_MAXCCALLS 200 150 | #endif 151 | 152 | /* 153 | ** maximum number of upvalues in a closure (both C and Lua). (Value 154 | ** must fit in an unsigned char.) 155 | */ 156 | #define MAXUPVAL UCHAR_MAX 157 | 158 | 159 | /* 160 | ** type for virtual-machine instructions; 161 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 162 | */ 163 | #if LUAI_BITSINT >= 32 164 | typedef unsigned int Instruction; 165 | #else 166 | typedef unsigned long Instruction; 167 | #endif 168 | 169 | 170 | 171 | 172 | /* minimum size for the string table (must be power of 2) */ 173 | #if !defined(MINSTRTABSIZE) 174 | #define MINSTRTABSIZE 64 /* minimum size for "predefined" strings */ 175 | #endif 176 | 177 | 178 | /* minimum size for string buffer */ 179 | #if !defined(LUA_MINBUFFER) 180 | #define LUA_MINBUFFER 32 181 | #endif 182 | 183 | 184 | #if !defined(lua_lock) 185 | #define lua_lock(L) ((void) 0) 186 | #define lua_unlock(L) ((void) 0) 187 | #endif 188 | 189 | #if !defined(luai_threadyield) 190 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 191 | #endif 192 | 193 | 194 | /* 195 | ** these macros allow user-specific actions on threads when you defined 196 | ** LUAI_EXTRASPACE and need to do something extra when a thread is 197 | ** created/deleted/resumed/yielded. 198 | */ 199 | #if !defined(luai_userstateopen) 200 | #define luai_userstateopen(L) ((void)L) 201 | #endif 202 | 203 | #if !defined(luai_userstateclose) 204 | #define luai_userstateclose(L) ((void)L) 205 | #endif 206 | 207 | #if !defined(luai_userstatethread) 208 | #define luai_userstatethread(L,L1) ((void)L) 209 | #endif 210 | 211 | #if !defined(luai_userstatefree) 212 | #define luai_userstatefree(L,L1) ((void)L) 213 | #endif 214 | 215 | #if !defined(luai_userstateresume) 216 | #define luai_userstateresume(L,n) ((void)L) 217 | #endif 218 | 219 | #if !defined(luai_userstateyield) 220 | #define luai_userstateyield(L,n) ((void)L) 221 | #endif 222 | 223 | 224 | 225 | /* 226 | ** macro to control inclusion of some hard tests on stack reallocation 227 | */ 228 | #if !defined(HARDSTACKTESTS) 229 | #define condmovestack(L) ((void)0) 230 | #else 231 | /* realloc stack keeping its size */ 232 | #define condmovestack(L) luaD_reallocstack((L), (L)->stacksize) 233 | #endif 234 | 235 | #if !defined(HARDMEMTESTS) 236 | #define condchangemem(L) condmovestack(L) 237 | #else 238 | #define condchangemem(L) \ 239 | ((void)(!(G(L)->gcrunning) || (luaC_fullgc(L, 0), 1))) 240 | #endif 241 | 242 | #endif 243 | -------------------------------------------------------------------------------- /test/lua53/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.89 2014/11/02 19:33:33 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lmem_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lgc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstate.h" 23 | 24 | 25 | 26 | /* 27 | ** About the realloc function: 28 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 29 | ** ('osize' is the old size, 'nsize' is the new size) 30 | ** 31 | ** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no 32 | ** matter 'x'). 33 | ** 34 | ** * frealloc(ud, p, x, 0) frees the block 'p' 35 | ** (in this specific case, frealloc must return NULL); 36 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 37 | ** (which is equivalent to free(NULL) in ISO C) 38 | ** 39 | ** frealloc returns NULL if it cannot create or reallocate the area 40 | ** (any reallocation to an equal or smaller size cannot fail!) 41 | */ 42 | 43 | 44 | 45 | #define MINSIZEARRAY 4 46 | 47 | 48 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 49 | int limit, const char *what) { 50 | void *newblock; 51 | int newsize; 52 | if (*size >= limit/2) { /* cannot double it? */ 53 | if (*size >= limit) /* cannot grow even a little? */ 54 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); 55 | newsize = limit; /* still have at least one free place */ 56 | } 57 | else { 58 | newsize = (*size)*2; 59 | if (newsize < MINSIZEARRAY) 60 | newsize = MINSIZEARRAY; /* minimum size */ 61 | } 62 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 63 | *size = newsize; /* update only when everything else is OK */ 64 | return newblock; 65 | } 66 | 67 | 68 | l_noret luaM_toobig (lua_State *L) { 69 | luaG_runerror(L, "memory allocation error: block too big"); 70 | } 71 | 72 | 73 | 74 | /* 75 | ** generic allocation routine. 76 | */ 77 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 78 | void *newblock; 79 | global_State *g = G(L); 80 | size_t realosize = (block) ? osize : 0; 81 | lua_assert((realosize == 0) == (block == NULL)); 82 | #if defined(HARDMEMTESTS) 83 | if (nsize > realosize && g->gcrunning) 84 | luaC_fullgc(L, 1); /* force a GC whenever possible */ 85 | #endif 86 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); 87 | if (newblock == NULL && nsize > 0) { 88 | api_check( nsize > realosize, 89 | "realloc cannot fail when shrinking a block"); 90 | luaC_fullgc(L, 1); /* try to free some memory... */ 91 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 92 | if (newblock == NULL) 93 | luaD_throw(L, LUA_ERRMEM); 94 | } 95 | lua_assert((nsize == 0) == (newblock == NULL)); 96 | g->GCdebt = (g->GCdebt + nsize) - realosize; 97 | return newblock; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /test/lua53/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro reallocs a vector 'b' from 'on' to 'n' elements, where 19 | ** each element has size 'e'. In case of arithmetic overflow of the 20 | ** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because 21 | ** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e). 22 | ** 23 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 24 | ** comparison avoids a runtime comparison when overflow cannot occur. 25 | ** The compiler should be able to optimize the real test by itself, but 26 | ** when it does it, it may give a warning about "comparison is always 27 | ** false due to limited range of data type"; the +1 tricks the compiler, 28 | ** avoiding this warning but also this optimization.) 29 | */ 30 | #define luaM_reallocv(L,b,on,n,e) \ 31 | (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \ 32 | ? luaM_toobig(L) : cast_void(0)) , \ 33 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 34 | 35 | /* 36 | ** Arrays of chars do not need any test 37 | */ 38 | #define luaM_reallocvchar(L,b,on,n) \ 39 | cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 40 | 41 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 42 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 43 | #define luaM_freearray(L, b, n) luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0) 44 | 45 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 46 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 47 | #define luaM_newvector(L,n,t) \ 48 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 49 | 50 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 51 | 52 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 53 | if ((nelems)+1 > (size)) \ 54 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 55 | 56 | #define luaM_reallocvector(L, v,oldn,n,t) \ 57 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 58 | 59 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 60 | 61 | /* not to be called directly */ 62 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 63 | size_t size); 64 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 65 | size_t size_elem, int limit, 66 | const char *what); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /test/lua53/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $ 3 | ** Opcodes for Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lopcodes.h" 16 | 17 | 18 | /* ORDER OP */ 19 | 20 | LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { 21 | "MOVE", 22 | "LOADK", 23 | "LOADKX", 24 | "LOADBOOL", 25 | "LOADNIL", 26 | "GETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "SETTABUP", 30 | "SETUPVAL", 31 | "SETTABLE", 32 | "NEWTABLE", 33 | "SELF", 34 | "ADD", 35 | "SUB", 36 | "MUL", 37 | "MOD", 38 | "POW", 39 | "DIV", 40 | "IDIV", 41 | "BAND", 42 | "BOR", 43 | "BXOR", 44 | "SHL", 45 | "SHR", 46 | "UNM", 47 | "BNOT", 48 | "NOT", 49 | "LEN", 50 | "CONCAT", 51 | "JMP", 52 | "EQ", 53 | "LT", 54 | "LE", 55 | "TEST", 56 | "TESTSET", 57 | "CALL", 58 | "TAILCALL", 59 | "RETURN", 60 | "FORLOOP", 61 | "FORPREP", 62 | "TFORCALL", 63 | "TFORLOOP", 64 | "SETLIST", 65 | "CLOSURE", 66 | "VARARG", 67 | "EXTRAARG", 68 | NULL 69 | }; 70 | 71 | 72 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 73 | 74 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 75 | /* T A B C mode opcode */ 76 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 77 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 78 | ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ 79 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 80 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ 81 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 82 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ 83 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 84 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */ 85 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 86 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 87 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 88 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 89 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 90 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 91 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 92 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 93 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 94 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 95 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_IDIV */ 96 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BAND */ 97 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BOR */ 98 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BXOR */ 99 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHL */ 100 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHR */ 101 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 102 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_BNOT */ 103 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 104 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 105 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 106 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 107 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 108 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 109 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 110 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */ 111 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 112 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 113 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 114 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 115 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 116 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 117 | ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */ 118 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */ 119 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 120 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 121 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 122 | ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */ 123 | }; 124 | 125 | -------------------------------------------------------------------------------- /test/lua53/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.74 2014/10/25 11:50:46 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression descriptor 17 | */ 18 | 19 | typedef enum { 20 | VVOID, /* no value */ 21 | VNIL, 22 | VTRUE, 23 | VFALSE, 24 | VK, /* info = index of constant in 'k' */ 25 | VKFLT, /* nval = numerical float value */ 26 | VKINT, /* nval = numerical integer value */ 27 | VNONRELOC, /* info = result register */ 28 | VLOCAL, /* info = local register */ 29 | VUPVAL, /* info = index of upvalue in 'upvalues' */ 30 | VINDEXED, /* t = table register/upvalue; idx = index R/K */ 31 | VJMP, /* info = instruction pc */ 32 | VRELOCABLE, /* info = instruction pc */ 33 | VCALL, /* info = instruction pc */ 34 | VVARARG /* info = instruction pc */ 35 | } expkind; 36 | 37 | 38 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) 39 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) 40 | 41 | typedef struct expdesc { 42 | expkind k; 43 | union { 44 | struct { /* for indexed variables (VINDEXED) */ 45 | short idx; /* index (R/K) */ 46 | lu_byte t; /* table (register or upvalue) */ 47 | lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */ 48 | } ind; 49 | int info; /* for generic use */ 50 | lua_Number nval; /* for VKFLT */ 51 | lua_Integer ival; /* for VKINT */ 52 | } u; 53 | int t; /* patch list of 'exit when true' */ 54 | int f; /* patch list of 'exit when false' */ 55 | } expdesc; 56 | 57 | 58 | /* description of active local variable */ 59 | typedef struct Vardesc { 60 | short idx; /* variable index in stack */ 61 | } Vardesc; 62 | 63 | 64 | /* description of pending goto statements and label statements */ 65 | typedef struct Labeldesc { 66 | TString *name; /* label identifier */ 67 | int pc; /* position in code */ 68 | int line; /* line where it appeared */ 69 | lu_byte nactvar; /* local level where it appears in current block */ 70 | } Labeldesc; 71 | 72 | 73 | /* list of labels or gotos */ 74 | typedef struct Labellist { 75 | Labeldesc *arr; /* array */ 76 | int n; /* number of entries in use */ 77 | int size; /* array size */ 78 | } Labellist; 79 | 80 | 81 | /* dynamic structures used by the parser */ 82 | typedef struct Dyndata { 83 | struct { /* list of active local variables */ 84 | Vardesc *arr; 85 | int n; 86 | int size; 87 | } actvar; 88 | Labellist gt; /* list of pending gotos */ 89 | Labellist label; /* list of active labels */ 90 | } Dyndata; 91 | 92 | 93 | /* control of blocks */ 94 | struct BlockCnt; /* defined in lparser.c */ 95 | 96 | 97 | /* state needed to generate code for a given function */ 98 | typedef struct FuncState { 99 | Proto *f; /* current function header */ 100 | struct FuncState *prev; /* enclosing function */ 101 | struct LexState *ls; /* lexical state */ 102 | struct BlockCnt *bl; /* chain of current blocks */ 103 | int pc; /* next position to code (equivalent to 'ncode') */ 104 | int lasttarget; /* 'label' of last 'jump label' */ 105 | int jpc; /* list of pending jumps to 'pc' */ 106 | int nk; /* number of elements in 'k' */ 107 | int np; /* number of elements in 'p' */ 108 | int firstlocal; /* index of first local var (in Dyndata array) */ 109 | short nlocvars; /* number of elements in 'f->locvars' */ 110 | lu_byte nactvar; /* number of active local variables */ 111 | lu_byte nups; /* number of upvalues */ 112 | lu_byte freereg; /* first free register */ 113 | } FuncState; 114 | 115 | 116 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 117 | Dyndata *dyd, const char *name, int firstchar); 118 | 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /test/lua53/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /test/lua53/lstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstate.h,v 2.119 2014/10/30 18:53:28 roberto Exp $ 3 | ** Global State 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstate_h 8 | #define lstate_h 9 | 10 | #include "lua.h" 11 | 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | #include "lzio.h" 15 | 16 | 17 | /* 18 | 19 | ** Some notes about garbage-collected objects: All objects in Lua must 20 | ** be kept somehow accessible until being freed, so all objects always 21 | ** belong to one (and only one) of these lists, using field 'next' of 22 | ** the 'CommonHeader' for the link: 23 | ** 24 | ** 'allgc': all objects not marked for finalization; 25 | ** 'finobj': all objects marked for finalization; 26 | ** 'tobefnz': all objects ready to be finalized; 27 | ** 'fixedgc': all objects that are not to be collected (currently 28 | ** only small strings, such as reserved words). 29 | 30 | */ 31 | 32 | 33 | struct lua_longjmp; /* defined in ldo.c */ 34 | 35 | 36 | 37 | /* extra stack space to handle TM calls and some other extras */ 38 | #define EXTRA_STACK 5 39 | 40 | 41 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) 42 | 43 | 44 | /* kinds of Garbage Collection */ 45 | #define KGC_NORMAL 0 46 | #define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */ 47 | 48 | 49 | typedef struct stringtable { 50 | TString **hash; 51 | int nuse; /* number of elements */ 52 | int size; 53 | } stringtable; 54 | 55 | 56 | /* 57 | ** Information about a call. 58 | ** When a thread yields, 'func' is adjusted to pretend that the 59 | ** top function has only the yielded values in its stack; in that 60 | ** case, the actual 'func' value is saved in field 'extra'. 61 | ** When a function calls another with a continuation, 'extra' keeps 62 | ** the function index so that, in case of errors, the continuation 63 | ** function can be called with the correct top. 64 | */ 65 | typedef struct CallInfo { 66 | StkId func; /* function index in the stack */ 67 | StkId top; /* top for this function */ 68 | struct CallInfo *previous, *next; /* dynamic call link */ 69 | union { 70 | struct { /* only for Lua functions */ 71 | StkId base; /* base for this function */ 72 | const Instruction *savedpc; 73 | } l; 74 | struct { /* only for C functions */ 75 | lua_KFunction k; /* continuation in case of yields */ 76 | ptrdiff_t old_errfunc; 77 | lua_KContext ctx; /* context info. in case of yields */ 78 | } c; 79 | } u; 80 | ptrdiff_t extra; 81 | short nresults; /* expected number of results from this function */ 82 | lu_byte callstatus; 83 | } CallInfo; 84 | 85 | 86 | /* 87 | ** Bits in CallInfo status 88 | */ 89 | #define CIST_OAH (1<<0) /* original value of 'allowhook' */ 90 | #define CIST_LUA (1<<1) /* call is running a Lua function */ 91 | #define CIST_HOOKED (1<<2) /* call is running a debug hook */ 92 | #define CIST_REENTRY (1<<3) /* call is running on same invocation of 93 | luaV_execute of previous call */ 94 | #define CIST_YPCALL (1<<4) /* call is a yieldable protected call */ 95 | #define CIST_TAIL (1<<5) /* call was tail called */ 96 | #define CIST_HOOKYIELD (1<<6) /* last hook called yielded */ 97 | 98 | #define isLua(ci) ((ci)->callstatus & CIST_LUA) 99 | 100 | /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */ 101 | #define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v)) 102 | #define getoah(st) ((st) & CIST_OAH) 103 | 104 | 105 | /* 106 | ** 'global state', shared by all threads of this state 107 | */ 108 | typedef struct global_State { 109 | lua_Alloc frealloc; /* function to reallocate memory */ 110 | void *ud; /* auxiliary data to 'frealloc' */ 111 | lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */ 112 | l_mem GCdebt; /* bytes allocated not yet compensated by the collector */ 113 | lu_mem GCmemtrav; /* memory traversed by the GC */ 114 | lu_mem GCestimate; /* an estimate of the non-garbage memory in use */ 115 | stringtable strt; /* hash table for strings */ 116 | TValue l_registry; 117 | unsigned int seed; /* randomized seed for hashes */ 118 | lu_byte currentwhite; 119 | lu_byte gcstate; /* state of garbage collector */ 120 | lu_byte gckind; /* kind of GC running */ 121 | lu_byte gcrunning; /* true if GC is running */ 122 | GCObject *allgc; /* list of all collectable objects */ 123 | GCObject **sweepgc; /* current position of sweep in list */ 124 | GCObject *finobj; /* list of collectable objects with finalizers */ 125 | GCObject *gray; /* list of gray objects */ 126 | GCObject *grayagain; /* list of objects to be traversed atomically */ 127 | GCObject *weak; /* list of tables with weak values */ 128 | GCObject *ephemeron; /* list of ephemeron tables (weak keys) */ 129 | GCObject *allweak; /* list of all-weak tables */ 130 | GCObject *tobefnz; /* list of userdata to be GC */ 131 | GCObject *fixedgc; /* list of objects not to be collected */ 132 | struct lua_State *twups; /* list of threads with open upvalues */ 133 | Mbuffer buff; /* temporary buffer for string concatenation */ 134 | unsigned int gcfinnum; /* number of finalizers to call in each GC step */ 135 | int gcpause; /* size of pause between successive GCs */ 136 | int gcstepmul; /* GC 'granularity' */ 137 | lua_CFunction panic; /* to be called in unprotected errors */ 138 | struct lua_State *mainthread; 139 | const lua_Number *version; /* pointer to version number */ 140 | TString *memerrmsg; /* memory-error message */ 141 | TString *tmname[TM_N]; /* array with tag-method names */ 142 | struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ 143 | } global_State; 144 | 145 | 146 | /* 147 | ** 'per thread' state 148 | */ 149 | struct lua_State { 150 | CommonHeader; 151 | lu_byte status; 152 | StkId top; /* first free slot in the stack */ 153 | global_State *l_G; 154 | CallInfo *ci; /* call info for current function */ 155 | const Instruction *oldpc; /* last pc traced */ 156 | StkId stack_last; /* last free slot in the stack */ 157 | StkId stack; /* stack base */ 158 | UpVal *openupval; /* list of open upvalues in this stack */ 159 | GCObject *gclist; 160 | struct lua_State *twups; /* list of threads with open upvalues */ 161 | struct lua_longjmp *errorJmp; /* current error recover point */ 162 | CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ 163 | lua_Hook hook; 164 | ptrdiff_t errfunc; /* current error handling function (stack index) */ 165 | int stacksize; 166 | int basehookcount; 167 | int hookcount; 168 | unsigned short nny; /* number of non-yieldable calls in stack */ 169 | unsigned short nCcalls; /* number of nested C calls */ 170 | lu_byte hookmask; 171 | lu_byte allowhook; 172 | }; 173 | 174 | 175 | #define G(L) (L->l_G) 176 | 177 | 178 | /* 179 | ** Union of all collectable objects (only for conversions) 180 | */ 181 | union GCUnion { 182 | GCObject gc; /* common header */ 183 | struct TString ts; 184 | struct Udata u; 185 | union Closure cl; 186 | struct Table h; 187 | struct Proto p; 188 | struct lua_State th; /* thread */ 189 | }; 190 | 191 | 192 | #define cast_u(o) cast(union GCUnion *, (o)) 193 | 194 | /* macros to convert a GCObject into a specific value */ 195 | #define gco2ts(o) \ 196 | check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts)) 197 | #define gco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u)) 198 | #define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l)) 199 | #define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c)) 200 | #define gco2cl(o) \ 201 | check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl)) 202 | #define gco2t(o) check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h)) 203 | #define gco2p(o) check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p)) 204 | #define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th)) 205 | 206 | 207 | /* macro to convert a Lua object into a GCObject */ 208 | #define obj2gco(v) \ 209 | check_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc))) 210 | 211 | 212 | /* actual number of total bytes allocated */ 213 | #define gettotalbytes(g) ((g)->totalbytes + (g)->GCdebt) 214 | 215 | LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); 216 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 217 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); 218 | LUAI_FUNC void luaE_freeCI (lua_State *L); 219 | LUAI_FUNC void luaE_shrinkCI (lua_State *L); 220 | 221 | 222 | #endif 223 | 224 | -------------------------------------------------------------------------------- /test/lua53/lstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.c,v 2.45 2014/11/02 19:19:04 roberto Exp $ 3 | ** String table (keeps all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lstring_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | #include "lstring.h" 23 | 24 | 25 | 26 | /* 27 | ** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to 28 | ** compute its hash 29 | */ 30 | #if !defined(LUAI_HASHLIMIT) 31 | #define LUAI_HASHLIMIT 5 32 | #endif 33 | 34 | 35 | /* 36 | ** equality for long strings 37 | */ 38 | int luaS_eqlngstr (TString *a, TString *b) { 39 | size_t len = a->len; 40 | lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR); 41 | return (a == b) || /* same instance or... */ 42 | ((len == b->len) && /* equal length and ... */ 43 | (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */ 44 | } 45 | 46 | 47 | unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) { 48 | unsigned int h = seed ^ cast(unsigned int, l); 49 | size_t l1; 50 | size_t step = (l >> LUAI_HASHLIMIT) + 1; 51 | for (l1 = l; l1 >= step; l1 -= step) 52 | h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1])); 53 | return h; 54 | } 55 | 56 | 57 | /* 58 | ** resizes the string table 59 | */ 60 | void luaS_resize (lua_State *L, int newsize) { 61 | int i; 62 | stringtable *tb = &G(L)->strt; 63 | if (newsize > tb->size) { /* grow table if needed */ 64 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); 65 | for (i = tb->size; i < newsize; i++) 66 | tb->hash[i] = NULL; 67 | } 68 | for (i = 0; i < tb->size; i++) { /* rehash */ 69 | TString *p = tb->hash[i]; 70 | tb->hash[i] = NULL; 71 | while (p) { /* for each node in the list */ 72 | TString *hnext = p->hnext; /* save next */ 73 | unsigned int h = lmod(p->hash, newsize); /* new position */ 74 | p->hnext = tb->hash[h]; /* chain it */ 75 | tb->hash[h] = p; 76 | p = hnext; 77 | } 78 | } 79 | if (newsize < tb->size) { /* shrink table if needed */ 80 | /* vanishing slice should be empty */ 81 | lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL); 82 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); 83 | } 84 | tb->size = newsize; 85 | } 86 | 87 | 88 | 89 | /* 90 | ** creates a new string object 91 | */ 92 | static TString *createstrobj (lua_State *L, const char *str, size_t l, 93 | int tag, unsigned int h) { 94 | TString *ts; 95 | GCObject *o; 96 | size_t totalsize; /* total size of TString object */ 97 | totalsize = sizelstring(l); 98 | o = luaC_newobj(L, tag, totalsize); 99 | ts = gco2ts(o); 100 | ts->len = l; 101 | ts->hash = h; 102 | ts->extra = 0; 103 | memcpy(getaddrstr(ts), str, l * sizeof(char)); 104 | getaddrstr(ts)[l] = '\0'; /* ending 0 */ 105 | return ts; 106 | } 107 | 108 | 109 | void luaS_remove (lua_State *L, TString *ts) { 110 | stringtable *tb = &G(L)->strt; 111 | TString **p = &tb->hash[lmod(ts->hash, tb->size)]; 112 | while (*p != ts) /* find previous element */ 113 | p = &(*p)->hnext; 114 | *p = (*p)->hnext; /* remove element from its list */ 115 | tb->nuse--; 116 | } 117 | 118 | 119 | /* 120 | ** checks whether short string exists and reuses it or creates a new one 121 | */ 122 | static TString *internshrstr (lua_State *L, const char *str, size_t l) { 123 | TString *ts; 124 | global_State *g = G(L); 125 | unsigned int h = luaS_hash(str, l, g->seed); 126 | TString **list = &g->strt.hash[lmod(h, g->strt.size)]; 127 | for (ts = *list; ts != NULL; ts = ts->hnext) { 128 | if (l == ts->len && 129 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { 130 | /* found! */ 131 | if (isdead(g, ts)) /* dead (but not collected yet)? */ 132 | changewhite(ts); /* resurrect it */ 133 | return ts; 134 | } 135 | } 136 | if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) { 137 | luaS_resize(L, g->strt.size * 2); 138 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ 139 | } 140 | ts = createstrobj(L, str, l, LUA_TSHRSTR, h); 141 | ts->hnext = *list; 142 | *list = ts; 143 | g->strt.nuse++; 144 | return ts; 145 | } 146 | 147 | 148 | /* 149 | ** new string (with explicit length) 150 | */ 151 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 152 | if (l <= LUAI_MAXSHORTLEN) /* short string? */ 153 | return internshrstr(L, str, l); 154 | else { 155 | if (l + 1 > (MAX_SIZE - sizeof(TString))/sizeof(char)) 156 | luaM_toobig(L); 157 | return createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed); 158 | } 159 | } 160 | 161 | 162 | /* 163 | ** new zero-terminated string 164 | */ 165 | TString *luaS_new (lua_State *L, const char *str) { 166 | return luaS_newlstr(L, str, strlen(str)); 167 | } 168 | 169 | 170 | Udata *luaS_newudata (lua_State *L, size_t s) { 171 | Udata *u; 172 | GCObject *o; 173 | if (s > MAX_SIZE - sizeof(Udata)) 174 | luaM_toobig(L); 175 | o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s)); 176 | u = gco2u(o); 177 | u->len = s; 178 | u->metatable = NULL; 179 | setuservalue(L, u, luaO_nilobject); 180 | return u; 181 | } 182 | 183 | -------------------------------------------------------------------------------- /test/lua53/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.56 2014/07/18 14:46:47 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | #define sizestring(s) sizelstring((s)->len) 17 | 18 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 19 | #define sizeudata(u) sizeludata((u)->len) 20 | 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | 25 | /* 26 | ** test whether a string is a reserved word 27 | */ 28 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 29 | 30 | 31 | /* 32 | ** equality for short strings, which are always internalized 33 | */ 34 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 35 | 36 | 37 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 41 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 42 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 43 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /test/lua53/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.20 2014/09/04 18:15:29 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | #define wgkey(n) (&(n)->i_key.nk) 22 | 23 | #define invalidateTMcache(t) ((t)->flags = 0) 24 | 25 | 26 | /* returns the key, given the value of a table entry */ 27 | #define keyfromval(v) \ 28 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 29 | 30 | 31 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 32 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 33 | TValue *value); 34 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 35 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 36 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 37 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 38 | LUAI_FUNC Table *luaH_new (lua_State *L); 39 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 40 | unsigned int nhsize); 41 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 42 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 43 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 44 | LUAI_FUNC int luaH_getn (Table *t); 45 | 46 | 47 | #if defined(LUA_DEBUG) 48 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 49 | LUAI_FUNC int luaH_isdummy (Node *n); 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /test/lua53/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.33 2014/11/21 12:15:57 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ltm_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lobject.h" 20 | #include "lstate.h" 21 | #include "lstring.h" 22 | #include "ltable.h" 23 | #include "ltm.h" 24 | #include "lvm.h" 25 | 26 | 27 | static const char udatatypename[] = "userdata"; 28 | 29 | LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { 30 | "no value", 31 | "nil", "boolean", udatatypename, "number", 32 | "string", "table", "function", udatatypename, "thread", 33 | "proto" /* this last case is used for tests only */ 34 | }; 35 | 36 | 37 | void luaT_init (lua_State *L) { 38 | static const char *const luaT_eventname[] = { /* ORDER TM */ 39 | "__index", "__newindex", 40 | "__gc", "__mode", "__len", "__eq", 41 | "__add", "__sub", "__mul", "__mod", "__pow", 42 | "__div", "__idiv", 43 | "__band", "__bor", "__bxor", "__shl", "__shr", 44 | "__unm", "__bnot", "__lt", "__le", 45 | "__concat", "__call" 46 | }; 47 | int i; 48 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 50 | luaC_fix(L, obj2gco(G(L)->tmname[i])); /* never collect these names */ 51 | } 52 | } 53 | 54 | 55 | /* 56 | ** function to be used with macro "fasttm": optimized for absence of 57 | ** tag methods 58 | */ 59 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 60 | const TValue *tm = luaH_getstr(events, ename); 61 | lua_assert(event <= TM_EQ); 62 | if (ttisnil(tm)) { /* no tag method? */ 63 | events->flags |= cast_byte(1u<metatable; 75 | break; 76 | case LUA_TUSERDATA: 77 | mt = uvalue(o)->metatable; 78 | break; 79 | default: 80 | mt = G(L)->mt[ttnov(o)]; 81 | } 82 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 83 | } 84 | 85 | 86 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 87 | const TValue *p2, TValue *p3, int hasres) { 88 | ptrdiff_t result = savestack(L, p3); 89 | setobj2s(L, L->top++, f); /* push function (assume EXTRA_STACK) */ 90 | setobj2s(L, L->top++, p1); /* 1st argument */ 91 | setobj2s(L, L->top++, p2); /* 2nd argument */ 92 | if (!hasres) /* no result? 'p3' is third argument */ 93 | setobj2s(L, L->top++, p3); /* 3rd argument */ 94 | /* metamethod may yield only when called from Lua code */ 95 | luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci)); 96 | if (hasres) { /* if has result, move it to its place */ 97 | p3 = restorestack(L, result); 98 | setobjs2s(L, p3, --L->top); 99 | } 100 | } 101 | 102 | 103 | int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 104 | StkId res, TMS event) { 105 | const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ 106 | if (ttisnil(tm)) 107 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ 108 | if (ttisnil(tm)) return 0; 109 | luaT_callTM(L, tm, p1, p2, res, 1); 110 | return 1; 111 | } 112 | 113 | 114 | void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 115 | StkId res, TMS event) { 116 | if (!luaT_callbinTM(L, p1, p2, res, event)) { 117 | switch (event) { 118 | case TM_CONCAT: 119 | luaG_concaterror(L, p1, p2); 120 | case TM_BAND: case TM_BOR: case TM_BXOR: 121 | case TM_SHL: case TM_SHR: case TM_BNOT: { 122 | lua_Number dummy; 123 | if (tonumber(p1, &dummy) && tonumber(p2, &dummy)) 124 | luaG_tointerror(L, p1, p2); 125 | else 126 | luaG_opinterror(L, p1, p2, "perform bitwise operation on"); 127 | /* else go through */ 128 | } 129 | default: 130 | luaG_opinterror(L, p1, p2, "perform arithmetic on"); 131 | } 132 | } 133 | } 134 | 135 | 136 | int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 137 | TMS event) { 138 | if (!luaT_callbinTM(L, p1, p2, L->top, event)) 139 | return -1; /* no metamethod */ 140 | else 141 | return !l_isfalse(L->top); 142 | } 143 | 144 | -------------------------------------------------------------------------------- /test/lua53/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.21 2014/10/25 11:50:46 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | #define objtypename(x) ttypename(ttnov(x)) 55 | 56 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 57 | 58 | 59 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 60 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 61 | TMS event); 62 | LUAI_FUNC void luaT_init (lua_State *L); 63 | 64 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 65 | const TValue *p2, TValue *p3, int hasres); 66 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 67 | StkId res, TMS event); 68 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 69 | StkId res, TMS event); 70 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 71 | const TValue *p2, TMS event); 72 | 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /test/lua53/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /test/lua53/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_UTF8LIBNAME "utf8" 33 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 34 | 35 | #define LUA_BITLIBNAME "bit32" 36 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | 53 | #if !defined(lua_assert) 54 | #define lua_assert(x) ((void)0) 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /test/lua53/lundump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.c,v 2.41 2014/11/02 19:19:04 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lundump_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lfunc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstring.h" 23 | #include "lundump.h" 24 | #include "lzio.h" 25 | 26 | 27 | #if !defined(luai_verifycode) 28 | #define luai_verifycode(L,b,f) /* empty */ 29 | #endif 30 | 31 | 32 | typedef struct { 33 | lua_State *L; 34 | ZIO *Z; 35 | Mbuffer *b; 36 | const char *name; 37 | } LoadState; 38 | 39 | 40 | static l_noret error(LoadState *S, const char *why) { 41 | luaO_pushfstring(S->L, "%s: %s precompiled chunk", S->name, why); 42 | luaD_throw(S->L, LUA_ERRSYNTAX); 43 | } 44 | 45 | 46 | /* 47 | ** All high-level loads go through LoadVector; you can change it to 48 | ** adapt to the endianness of the input 49 | */ 50 | #define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0])) 51 | 52 | static void LoadBlock (LoadState *S, void *b, size_t size) { 53 | if (luaZ_read(S->Z, b, size) != 0) 54 | error(S, "truncated"); 55 | } 56 | 57 | 58 | #define LoadVar(S,x) LoadVector(S,&x,1) 59 | 60 | 61 | static lu_byte LoadByte (LoadState *S) { 62 | lu_byte x; 63 | LoadVar(S, x); 64 | return x; 65 | } 66 | 67 | 68 | static int LoadInt (LoadState *S) { 69 | int x; 70 | LoadVar(S, x); 71 | return x; 72 | } 73 | 74 | 75 | static lua_Number LoadNumber (LoadState *S) { 76 | lua_Number x; 77 | LoadVar(S, x); 78 | return x; 79 | } 80 | 81 | 82 | static lua_Integer LoadInteger (LoadState *S) { 83 | lua_Integer x; 84 | LoadVar(S, x); 85 | return x; 86 | } 87 | 88 | 89 | static TString *LoadString (LoadState *S) { 90 | size_t size = LoadByte(S); 91 | if (size == 0xFF) 92 | LoadVar(S, size); 93 | if (size == 0) 94 | return NULL; 95 | else { 96 | char *s = luaZ_openspace(S->L, S->b, --size); 97 | LoadVector(S, s, size); 98 | return luaS_newlstr(S->L, s, size); 99 | } 100 | } 101 | 102 | 103 | static void LoadCode (LoadState *S, Proto *f) { 104 | int n = LoadInt(S); 105 | f->code = luaM_newvector(S->L, n, Instruction); 106 | f->sizecode = n; 107 | LoadVector(S, f->code, n); 108 | } 109 | 110 | 111 | static void LoadFunction(LoadState *S, Proto *f, TString *psource); 112 | 113 | 114 | static void LoadConstants (LoadState *S, Proto *f) { 115 | int i; 116 | int n = LoadInt(S); 117 | f->k = luaM_newvector(S->L, n, TValue); 118 | f->sizek = n; 119 | for (i = 0; i < n; i++) 120 | setnilvalue(&f->k[i]); 121 | for (i = 0; i < n; i++) { 122 | TValue *o = &f->k[i]; 123 | int t = LoadByte(S); 124 | switch (t) { 125 | case LUA_TNIL: 126 | setnilvalue(o); 127 | break; 128 | case LUA_TBOOLEAN: 129 | setbvalue(o, LoadByte(S)); 130 | break; 131 | case LUA_TNUMFLT: 132 | setfltvalue(o, LoadNumber(S)); 133 | break; 134 | case LUA_TNUMINT: 135 | setivalue(o, LoadInteger(S)); 136 | break; 137 | case LUA_TSHRSTR: 138 | case LUA_TLNGSTR: 139 | setsvalue2n(S->L, o, LoadString(S)); 140 | break; 141 | default: 142 | lua_assert(0); 143 | } 144 | } 145 | } 146 | 147 | 148 | static void LoadProtos (LoadState *S, Proto *f) { 149 | int i; 150 | int n = LoadInt(S); 151 | f->p = luaM_newvector(S->L, n, Proto *); 152 | f->sizep = n; 153 | for (i = 0; i < n; i++) 154 | f->p[i] = NULL; 155 | for (i = 0; i < n; i++) { 156 | f->p[i] = luaF_newproto(S->L); 157 | LoadFunction(S, f->p[i], f->source); 158 | } 159 | } 160 | 161 | 162 | static void LoadUpvalues (LoadState *S, Proto *f) { 163 | int i, n; 164 | n = LoadInt(S); 165 | f->upvalues = luaM_newvector(S->L, n, Upvaldesc); 166 | f->sizeupvalues = n; 167 | for (i = 0; i < n; i++) 168 | f->upvalues[i].name = NULL; 169 | for (i = 0; i < n; i++) { 170 | f->upvalues[i].instack = LoadByte(S); 171 | f->upvalues[i].idx = LoadByte(S); 172 | } 173 | } 174 | 175 | 176 | static void LoadDebug (LoadState *S, Proto *f) { 177 | int i, n; 178 | n = LoadInt(S); 179 | f->lineinfo = luaM_newvector(S->L, n, int); 180 | f->sizelineinfo = n; 181 | LoadVector(S, f->lineinfo, n); 182 | n = LoadInt(S); 183 | f->locvars = luaM_newvector(S->L, n, LocVar); 184 | f->sizelocvars = n; 185 | for (i = 0; i < n; i++) 186 | f->locvars[i].varname = NULL; 187 | for (i = 0; i < n; i++) { 188 | f->locvars[i].varname = LoadString(S); 189 | f->locvars[i].startpc = LoadInt(S); 190 | f->locvars[i].endpc = LoadInt(S); 191 | } 192 | n = LoadInt(S); 193 | for (i = 0; i < n; i++) 194 | f->upvalues[i].name = LoadString(S); 195 | } 196 | 197 | 198 | static void LoadFunction (LoadState *S, Proto *f, TString *psource) { 199 | f->source = LoadString(S); 200 | if (f->source == NULL) /* no source in dump? */ 201 | f->source = psource; /* reuse parent's source */ 202 | f->linedefined = LoadInt(S); 203 | f->lastlinedefined = LoadInt(S); 204 | f->numparams = LoadByte(S); 205 | f->is_vararg = LoadByte(S); 206 | f->maxstacksize = LoadByte(S); 207 | LoadCode(S, f); 208 | LoadConstants(S, f); 209 | LoadUpvalues(S, f); 210 | LoadProtos(S, f); 211 | LoadDebug(S, f); 212 | } 213 | 214 | 215 | static void checkliteral (LoadState *S, const char *s, const char *msg) { 216 | char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */ 217 | size_t len = strlen(s); 218 | LoadVector(S, buff, len); 219 | if (memcmp(s, buff, len) != 0) 220 | error(S, msg); 221 | } 222 | 223 | 224 | static void fchecksize (LoadState *S, size_t size, const char *tname) { 225 | if (LoadByte(S) != size) 226 | error(S, luaO_pushfstring(S->L, "%s size mismatch in", tname)); 227 | } 228 | 229 | 230 | #define checksize(S,t) fchecksize(S,sizeof(t),#t) 231 | 232 | static void checkHeader (LoadState *S) { 233 | checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */ 234 | if (LoadByte(S) != LUAC_VERSION) 235 | error(S, "version mismatch in"); 236 | if (LoadByte(S) != LUAC_FORMAT) 237 | error(S, "format mismatch in"); 238 | checkliteral(S, LUAC_DATA, "corrupted"); 239 | checksize(S, int); 240 | checksize(S, size_t); 241 | checksize(S, Instruction); 242 | checksize(S, lua_Integer); 243 | checksize(S, lua_Number); 244 | if (LoadInteger(S) != LUAC_INT) 245 | error(S, "endianness mismatch in"); 246 | if (LoadNumber(S) != LUAC_NUM) 247 | error(S, "float format mismatch in"); 248 | } 249 | 250 | 251 | /* 252 | ** load precompiled chunk 253 | */ 254 | LClosure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff, 255 | const char *name) { 256 | LoadState S; 257 | LClosure *cl; 258 | if (*name == '@' || *name == '=') 259 | S.name = name + 1; 260 | else if (*name == LUA_SIGNATURE[0]) 261 | S.name = "binary string"; 262 | else 263 | S.name = name; 264 | S.L = L; 265 | S.Z = Z; 266 | S.b = buff; 267 | checkHeader(&S); 268 | cl = luaF_newLclosure(L, LoadByte(&S)); 269 | setclLvalue(L, L->top, cl); 270 | incr_top(L); 271 | cl->p = luaF_newproto(L); 272 | LoadFunction(&S, cl->p, NULL); 273 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); 274 | luai_verifycode(L, buff, cl->p); 275 | return cl; 276 | } 277 | 278 | -------------------------------------------------------------------------------- /test/lua53/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.44 2014/06/19 18:27:20 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, 27 | const char* name); 28 | 29 | /* dump one chunk; from ldump.c */ 30 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 31 | void* data, int strip); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /test/lua53/lutf8lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lutf8lib.c,v 1.13 2014/11/02 19:19:04 roberto Exp $ 3 | ** Standard library for UTF-8 manipulation 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lutf8lib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include "lua.h" 18 | 19 | #include "lauxlib.h" 20 | #include "lualib.h" 21 | 22 | #define MAXUNICODE 0x10FFFF 23 | 24 | #define iscont(p) ((*(p) & 0xC0) == 0x80) 25 | 26 | 27 | /* from strlib */ 28 | /* translate a relative string position: negative means back from end */ 29 | static lua_Integer u_posrelat (lua_Integer pos, size_t len) { 30 | if (pos >= 0) return pos; 31 | else if (0u - (size_t)pos > len) return 0; 32 | else return (lua_Integer)len + pos + 1; 33 | } 34 | 35 | 36 | /* 37 | ** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid. 38 | */ 39 | static const char *utf8_decode (const char *o, int *val) { 40 | static unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF}; 41 | const unsigned char *s = (const unsigned char *)o; 42 | unsigned int c = s[0]; 43 | unsigned int res = 0; /* final result */ 44 | if (c < 0x80) /* ascii? */ 45 | res = c; 46 | else { 47 | int count = 0; /* to count number of continuation bytes */ 48 | while (c & 0x40) { /* still have continuation bytes? */ 49 | int cc = s[++count]; /* read next byte */ 50 | if ((cc & 0xC0) != 0x80) /* not a continuation byte? */ 51 | return NULL; /* invalid byte sequence */ 52 | res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ 53 | c <<= 1; /* to test next bit */ 54 | } 55 | res |= ((c & 0x7F) << (count * 5)); /* add first byte */ 56 | if (count > 3 || res > MAXUNICODE || res <= limits[count]) 57 | return NULL; /* invalid byte sequence */ 58 | s += count; /* skip continuation bytes read */ 59 | } 60 | if (val) *val = res; 61 | return (const char *)s + 1; /* +1 to include first byte */ 62 | } 63 | 64 | 65 | /* 66 | ** utf8len(s [, i [, j]]) --> number of characters that start in the 67 | ** range [i,j], or nil + current position if 's' is not well formed in 68 | ** that interval 69 | */ 70 | static int utflen (lua_State *L) { 71 | int n = 0; 72 | size_t len; 73 | const char *s = luaL_checklstring(L, 1, &len); 74 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); 75 | lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len); 76 | luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2, 77 | "initial position out of string"); 78 | luaL_argcheck(L, --posj < (lua_Integer)len, 3, 79 | "final position out of string"); 80 | while (posi <= posj) { 81 | const char *s1 = utf8_decode(s + posi, NULL); 82 | if (s1 == NULL) { /* conversion error? */ 83 | lua_pushnil(L); /* return nil ... */ 84 | lua_pushinteger(L, posi + 1); /* ... and current position */ 85 | return 2; 86 | } 87 | posi = s1 - s; 88 | n++; 89 | } 90 | lua_pushinteger(L, n); 91 | return 1; 92 | } 93 | 94 | 95 | /* 96 | ** codepoint(s, [i, [j]]) -> returns codepoints for all characters 97 | ** that start in the range [i,j] 98 | */ 99 | static int codepoint (lua_State *L) { 100 | size_t len; 101 | const char *s = luaL_checklstring(L, 1, &len); 102 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); 103 | lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len); 104 | int n; 105 | const char *se; 106 | luaL_argcheck(L, posi >= 1, 2, "out of range"); 107 | luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of range"); 108 | if (posi > pose) return 0; /* empty interval; return no values */ 109 | n = (int)(pose - posi + 1); 110 | if (posi + n <= pose) /* (lua_Integer -> int) overflow? */ 111 | return luaL_error(L, "string slice too long"); 112 | luaL_checkstack(L, n, "string slice too long"); 113 | n = 0; 114 | se = s + pose; 115 | for (s += posi - 1; s < se;) { 116 | int code; 117 | s = utf8_decode(s, &code); 118 | if (s == NULL) 119 | return luaL_error(L, "invalid UTF-8 code"); 120 | lua_pushinteger(L, code); 121 | n++; 122 | } 123 | return n; 124 | } 125 | 126 | 127 | static void pushutfchar (lua_State *L, int arg) { 128 | lua_Integer code = luaL_checkinteger(L, arg); 129 | luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range"); 130 | lua_pushfstring(L, "%U", (long)code); 131 | } 132 | 133 | 134 | /* 135 | ** utfchar(n1, n2, ...) -> char(n1)..char(n2)... 136 | */ 137 | static int utfchar (lua_State *L) { 138 | int n = lua_gettop(L); /* number of arguments */ 139 | if (n == 1) /* optimize common case of single char */ 140 | pushutfchar(L, 1); 141 | else { 142 | int i; 143 | luaL_Buffer b; 144 | luaL_buffinit(L, &b); 145 | for (i = 1; i <= n; i++) { 146 | pushutfchar(L, i); 147 | luaL_addvalue(&b); 148 | } 149 | luaL_pushresult(&b); 150 | } 151 | return 1; 152 | } 153 | 154 | 155 | /* 156 | ** offset(s, n, [i]) -> index where n-th character counting from 157 | ** position 'i' starts; 0 means character at 'i'. 158 | */ 159 | static int byteoffset (lua_State *L) { 160 | size_t len; 161 | const char *s = luaL_checklstring(L, 1, &len); 162 | lua_Integer n = luaL_checkinteger(L, 2); 163 | lua_Integer posi = (n >= 0) ? 1 : len + 1; 164 | posi = u_posrelat(luaL_optinteger(L, 3, posi), len); 165 | luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, 166 | "position out of range"); 167 | if (n == 0) { 168 | /* find beginning of current byte sequence */ 169 | while (posi > 0 && iscont(s + posi)) posi--; 170 | } 171 | else { 172 | if (iscont(s + posi)) 173 | luaL_error(L, "initial position is a continuation byte"); 174 | if (n < 0) { 175 | while (n < 0 && posi > 0) { /* move back */ 176 | do { /* find beginning of previous character */ 177 | posi--; 178 | } while (posi > 0 && iscont(s + posi)); 179 | n++; 180 | } 181 | } 182 | else { 183 | n--; /* do not move for 1st character */ 184 | while (n > 0 && posi < (lua_Integer)len) { 185 | do { /* find beginning of next character */ 186 | posi++; 187 | } while (iscont(s + posi)); /* (cannot pass final '\0') */ 188 | n--; 189 | } 190 | } 191 | } 192 | if (n == 0) /* did it find given character? */ 193 | lua_pushinteger(L, posi + 1); 194 | else /* no such character */ 195 | lua_pushnil(L); 196 | return 1; 197 | } 198 | 199 | 200 | static int iter_aux (lua_State *L) { 201 | size_t len; 202 | const char *s = luaL_checklstring(L, 1, &len); 203 | lua_Integer n = lua_tointeger(L, 2) - 1; 204 | if (n < 0) /* first iteration? */ 205 | n = 0; /* start from here */ 206 | else if (n < (lua_Integer)len) { 207 | n++; /* skip current byte */ 208 | while (iscont(s + n)) n++; /* and its continuations */ 209 | } 210 | if (n >= (lua_Integer)len) 211 | return 0; /* no more codepoints */ 212 | else { 213 | int code; 214 | const char *next = utf8_decode(s + n, &code); 215 | if (next == NULL || iscont(next)) 216 | return luaL_error(L, "invalid UTF-8 code"); 217 | lua_pushinteger(L, n + 1); 218 | lua_pushinteger(L, code); 219 | return 2; 220 | } 221 | } 222 | 223 | 224 | static int iter_codes (lua_State *L) { 225 | luaL_checkstring(L, 1); 226 | lua_pushcfunction(L, iter_aux); 227 | lua_pushvalue(L, 1); 228 | lua_pushinteger(L, 0); 229 | return 3; 230 | } 231 | 232 | 233 | /* pattern to match a single UTF-8 character */ 234 | #define UTF8PATT "[\0-\x7F\xC2-\xF4][\x80-\xBF]*" 235 | 236 | 237 | static struct luaL_Reg funcs[] = { 238 | {"offset", byteoffset}, 239 | {"codepoint", codepoint}, 240 | {"char", utfchar}, 241 | {"len", utflen}, 242 | {"codes", iter_codes}, 243 | /* placeholders */ 244 | {"charpattern", NULL}, 245 | {NULL, NULL} 246 | }; 247 | 248 | 249 | LUAMOD_API int luaopen_utf8 (lua_State *L) { 250 | luaL_newlib(L, funcs); 251 | lua_pushliteral(L, UTF8PATT); 252 | lua_setfield(L, -2, "charpattern"); 253 | return 1; 254 | } 255 | 256 | -------------------------------------------------------------------------------- /test/lua53/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.34 2014/08/01 17:24:02 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #if !defined(LUA_NOCVTN2S) 17 | #define cvt2str(o) ttisnumber(o) 18 | #else 19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */ 20 | #endif 21 | 22 | 23 | #if !defined(LUA_NOCVTS2N) 24 | #define cvt2num(o) ttisstring(o) 25 | #else 26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */ 27 | #endif 28 | 29 | 30 | #define tonumber(o,n) \ 31 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 32 | 33 | #define tointeger(o,i) \ 34 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger_(o,i)) 35 | 36 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 37 | 38 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 39 | 40 | 41 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 42 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 43 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 44 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 45 | LUAI_FUNC int luaV_tointeger_ (const TValue *obj, lua_Integer *p); 46 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 47 | StkId val); 48 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 49 | StkId val); 50 | LUAI_FUNC void luaV_finishOp (lua_State *L); 51 | LUAI_FUNC void luaV_execute (lua_State *L); 52 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 53 | LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); 54 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 55 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 56 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /test/lua53/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.36 2014/11/02 19:19:04 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | /* ------------------------------------------------------------------------ */ 70 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 71 | if (n > buff->buffsize) { 72 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 73 | luaZ_resizebuffer(L, buff, n); 74 | } 75 | return buff->buffer; 76 | } 77 | 78 | 79 | -------------------------------------------------------------------------------- /test/lua53/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.30 2014/12/19 17:26:14 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 48 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 49 | void *data); 50 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; /* reader function */ 60 | void *data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /test/lua53/vc/lua53.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua53", "lua53.vcxproj", "{0459E5F7-73C8-4665-9E5C-355E5ADA243D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|Win32.Build.0 = Debug|Win32 18 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|x64.ActiveCfg = Debug|x64 19 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|x64.Build.0 = Debug|x64 20 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|Win32.ActiveCfg = Release|Win32 21 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|Win32.Build.0 = Release|Win32 22 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|x64.ActiveCfg = Release|x64 23 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /test/lua53/vc/lua53.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutDir) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutDir) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /test/test.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpp", "cpp\cpp.vcxproj", "{6BA80E07-A245-470E-B36C-4A869C401C03}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua51", "lua51\vc\lua51.vcxproj", "{0459E5F7-73C8-4665-9E5C-355E5ADA243D}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua53", "lua53\vc\lua53.vcxproj", "{D9C5C8CF-72D3-46DC-9223-1A16555D78AF}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cshap", "csharp\cshap.csproj", "{D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}" 13 | EndProject 14 | Global 15 | GlobalSection(Performance) = preSolution 16 | HasPerformanceSessions = true 17 | EndGlobalSection 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Debug|Mixed Platforms = Debug|Mixed Platforms 21 | Debug|Win32 = Debug|Win32 22 | Debug|x64 = Debug|x64 23 | Release|Any CPU = Release|Any CPU 24 | Release|Mixed Platforms = Release|Mixed Platforms 25 | Release|Win32 = Release|Win32 26 | Release|x64 = Release|x64 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Debug|Any CPU.ActiveCfg = Debug|Win32 30 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 31 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Debug|Mixed Platforms.Build.0 = Debug|Win32 32 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Debug|Win32.ActiveCfg = Debug|Win32 33 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Debug|Win32.Build.0 = Debug|Win32 34 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Debug|x64.ActiveCfg = Debug|x64 35 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Debug|x64.Build.0 = Debug|x64 36 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Release|Any CPU.ActiveCfg = Release|Win32 37 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Release|Mixed Platforms.ActiveCfg = Release|Win32 38 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Release|Mixed Platforms.Build.0 = Release|Win32 39 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Release|Win32.ActiveCfg = Release|Win32 40 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Release|Win32.Build.0 = Release|Win32 41 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Release|x64.ActiveCfg = Release|x64 42 | {6BA80E07-A245-470E-B36C-4A869C401C03}.Release|x64.Build.0 = Release|x64 43 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|Any CPU.ActiveCfg = Debug|Win32 44 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 45 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|Mixed Platforms.Build.0 = Debug|Win32 46 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|Win32.ActiveCfg = Debug|Win32 47 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|Win32.Build.0 = Debug|Win32 48 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|x64.ActiveCfg = Debug|x64 49 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Debug|x64.Build.0 = Debug|x64 50 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|Any CPU.ActiveCfg = Release|Win32 51 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|Mixed Platforms.ActiveCfg = Release|Win32 52 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|Mixed Platforms.Build.0 = Release|Win32 53 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|Win32.ActiveCfg = Release|Win32 54 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|Win32.Build.0 = Release|Win32 55 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|x64.ActiveCfg = Release|x64 56 | {0459E5F7-73C8-4665-9E5C-355E5ADA243D}.Release|x64.Build.0 = Release|x64 57 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Debug|Any CPU.ActiveCfg = Debug|Win32 58 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 59 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Debug|Mixed Platforms.Build.0 = Debug|Win32 60 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Debug|Win32.ActiveCfg = Debug|Win32 61 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Debug|Win32.Build.0 = Debug|Win32 62 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Debug|x64.ActiveCfg = Debug|x64 63 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Debug|x64.Build.0 = Debug|x64 64 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Release|Any CPU.ActiveCfg = Release|Win32 65 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Release|Mixed Platforms.ActiveCfg = Release|Win32 66 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Release|Mixed Platforms.Build.0 = Release|Win32 67 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Release|Win32.ActiveCfg = Release|Win32 68 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Release|Win32.Build.0 = Release|Win32 69 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Release|x64.ActiveCfg = Release|x64 70 | {D9C5C8CF-72D3-46DC-9223-1A16555D78AF}.Release|x64.Build.0 = Release|x64 71 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 72 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Debug|Any CPU.Build.0 = Debug|Any CPU 73 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 74 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 75 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Debug|Win32.ActiveCfg = Debug|Any CPU 76 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Debug|x64.ActiveCfg = Debug|Any CPU 77 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Release|Any CPU.ActiveCfg = Release|Any CPU 78 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Release|Any CPU.Build.0 = Release|Any CPU 79 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 80 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Release|Mixed Platforms.Build.0 = Release|Any CPU 81 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Release|Win32.ActiveCfg = Release|Any CPU 82 | {D5BDE960-7180-4BB0-BB58-3C4AB6ADA7D0}.Release|x64.ActiveCfg = Release|Any CPU 83 | EndGlobalSection 84 | GlobalSection(SolutionProperties) = preSolution 85 | HideSolutionNode = FALSE 86 | EndGlobalSection 87 | EndGlobal 88 | --------------------------------------------------------------------------------