├── vscext ├── CHANGELOG.md ├── .vscodeignore ├── images │ ├── sn1.png │ └── icon.png ├── .vscode │ ├── extensions.json │ └── launch.json ├── jsconfig.json ├── test │ ├── suite │ │ ├── extension.test.js │ │ └── index.js │ └── runTest.js ├── README.md ├── LICENSE ├── extension.js ├── bin │ ├── vscaux.lua │ └── debugger.lua ├── vsc-extension-quickstart.md └── package.json ├── 3rd ├── lua │ ├── doc │ │ ├── logo.gif │ │ ├── osi-certified-72x60.png │ │ ├── index.css │ │ ├── manual.css │ │ ├── lua.1 │ │ ├── lua.css │ │ └── luac.1 │ ├── src │ │ ├── lua.hpp │ │ ├── lapi.h │ │ ├── lundump.h │ │ ├── lprefix.h │ │ ├── lualib.h │ │ ├── ldebug.h │ │ ├── lstring.h │ │ ├── lzio.c │ │ ├── lzio.h │ │ ├── lfunc.h │ │ ├── linit.c │ │ ├── ltm.h │ │ ├── lctype.h │ │ ├── ldo.h │ │ ├── ltable.h │ │ ├── lctype.c │ │ ├── llex.h │ │ ├── lmem.h │ │ ├── lmem.c │ │ ├── lcode.h │ │ ├── lopcodes.c │ │ ├── lvm.h │ │ ├── lfunc.c │ │ ├── lcorolib.c │ │ ├── lparser.h │ │ ├── lgc.h │ │ ├── ltm.c │ │ ├── ldump.c │ │ ├── lbitlib.c │ │ ├── lundump.c │ │ ├── lstring.c │ │ ├── Makefile │ │ ├── lutf8lib.c │ │ ├── llimits.h │ │ ├── lauxlib.h │ │ └── lstate.h │ └── Makefile └── lua-cjson │ ├── fpconv.h │ ├── LICENSE │ ├── dtoa_config.h │ ├── g_fmt.c │ ├── Makefile │ ├── strbuf.h │ ├── fpconv.c │ └── strbuf.c ├── .gitignore ├── Makefile ├── LICENSE ├── src └── main.c └── README.md /vscext/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | v0.9.0(2020-2-20) 2 | ---------------------------- 3 | - 第1个发布版本 -------------------------------------------------------------------------------- /3rd/lua/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/colinsusie/skynetda/HEAD/3rd/lua/doc/logo.gif -------------------------------------------------------------------------------- /vscext/.vscodeignore: -------------------------------------------------------------------------------- 1 | **/debug.log 2 | **/.vscode 3 | **/vsc-extension-quickstart.md 4 | **/test -------------------------------------------------------------------------------- /vscext/images/sn1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/colinsusie/skynetda/HEAD/vscext/images/sn1.png -------------------------------------------------------------------------------- /vscext/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/colinsusie/skynetda/HEAD/vscext/images/icon.png -------------------------------------------------------------------------------- /3rd/lua/doc/osi-certified-72x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/colinsusie/skynetda/HEAD/3rd/lua/doc/osi-certified-72x60.png -------------------------------------------------------------------------------- /vscext/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint" 6 | ] 7 | } -------------------------------------------------------------------------------- /3rd/lua/src/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 | -------------------------------------------------------------------------------- /vscext/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "checkJs": false, /* Typecheck .js files. */ 6 | "lib": [ 7 | "es6" 8 | ] 9 | }, 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /3rd/lua/doc/index.css: -------------------------------------------------------------------------------- 1 | ul { 2 | list-style-type: none ; 3 | } 4 | 5 | ul.contents { 6 | padding: 0 ; 7 | } 8 | 9 | table { 10 | border: none ; 11 | border-spacing: 0 ; 12 | border-collapse: collapse ; 13 | } 14 | 15 | td { 16 | vertical-align: top ; 17 | padding: 0 ; 18 | text-align: left ; 19 | line-height: 1.25 ; 20 | width: 15% ; 21 | } 22 | -------------------------------------------------------------------------------- /3rd/lua/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | color: gray ; 12 | float: right ; 13 | font-family: inherit ; 14 | font-style: normal ; 15 | font-size: small ; 16 | } 17 | 18 | h2:before { 19 | content: "" ; 20 | padding-right: 0em ; 21 | } 22 | -------------------------------------------------------------------------------- /vscext/test/suite/extension.test.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | const vscode = require('vscode'); 6 | // const myExtension = require('../extension'); 7 | 8 | suite('Extension Test Suite', () => { 9 | vscode.window.showInformationMessage('Start all tests.'); 10 | 11 | test('Sample test', () => { 12 | assert.equal(-1, [1, 2, 3].indexOf(5)); 13 | assert.equal(-1, [1, 2, 3].indexOf(0)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /vscext/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that launches the extension inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "skynet-debugger", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ] 16 | }, 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /3rd/lua-cjson/fpconv.h: -------------------------------------------------------------------------------- 1 | /* Lua CJSON floating point conversion routines */ 2 | 3 | /* Buffer required to store the largest string representation of a double. 4 | * 5 | * Longest double printed with %.14g is 21 characters long: 6 | * -1.7976931348623e+308 */ 7 | # define FPCONV_G_FMT_BUFSIZE 32 8 | 9 | #ifdef USE_INTERNAL_FPCONV 10 | static inline void fpconv_init() 11 | { 12 | /* Do nothing - not required */ 13 | } 14 | #else 15 | extern void fpconv_init(); 16 | #endif 17 | 18 | extern int fpconv_g_fmt(char*, double, int); 19 | extern double fpconv_strtod(const char*, char**); 20 | 21 | /* vi:ai et sw=4 ts=4: 22 | */ 23 | -------------------------------------------------------------------------------- /3rd/lua/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 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, 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(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /vscext/README.md: -------------------------------------------------------------------------------- 1 | Skynet 调试器 2 | 3 | ## 屏幕快照 4 | 5 | ![sn1.png](https://github.com/colinsusie/skynetda/raw/master/vscext/images/sn1.png) 6 | 7 | ## 功能特性 8 | 9 | 这是一个基于skynet框架的Lua调试器,它提供如下特性: 10 | 11 | - 将skynet.error输出到`DEBUG CONSOLE`面板,点击日志可跳转到代码行。 12 | - 设置断点:除了普通断点,还支持以下几种: 13 | - 条件断点:当表达式为true时停下来。 14 | - Hit Count断点:命中一定次数后停下来。 15 | - 日志断点:命中时输出日志。 16 | - 当程序停下来时可以: 17 | - 查看调用堆栈。 18 | - 查看每一层栈帧的局部变量,自由变量。 19 | - 通过`WATCH`面板增加监控的表达式。 20 | - 可在`DEBUG CONSOLE`底部输入表达式,甚至可以修改局部变量。 21 | - 支持`Step into`, `Step over`, `Step out`, `Continue`等调试命令。 22 | 23 | ## 使用指南 24 | 25 | 请移步这里阅读:[https://github.com/colinsusie/skynetda](https://github.com/colinsusie/skynetda) 26 | 27 | **Enjoy!** 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # other 55 | skynetda 56 | node_modules/ 57 | -------------------------------------------------------------------------------- /vscext/test/runTest.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | const { runTests } = require('vscode-test'); 4 | 5 | async function main() { 6 | try { 7 | // The folder containing the Extension Manifest package.json 8 | // Passed to `--extensionDevelopmentPath` 9 | const extensionDevelopmentPath = path.resolve(__dirname, '../'); 10 | 11 | // The path to the extension test script 12 | // Passed to --extensionTestsPath 13 | const extensionTestsPath = path.resolve(__dirname, './suite/index'); 14 | 15 | // Download VS Code, unzip it and run the integration test 16 | await runTests({ extensionDevelopmentPath, extensionTestsPath }); 17 | } catch (err) { 18 | console.error('Failed to run tests'); 19 | process.exit(1); 20 | } 21 | } 22 | 23 | main(); 24 | -------------------------------------------------------------------------------- /3rd/lua/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45.1.1 2017/04/19 17:20:42 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, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /vscext/test/suite/index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const Mocha = require('mocha'); 3 | const glob = require('glob'); 4 | 5 | function run() { 6 | // Create the mocha test 7 | const mocha = new Mocha({ 8 | ui: 'tdd' 9 | }); 10 | // Use any mocha API 11 | mocha.useColors(true); 12 | 13 | const testsRoot = path.resolve(__dirname, '..'); 14 | 15 | return new Promise((c, e) => { 16 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { 17 | if (err) { 18 | return e(err); 19 | } 20 | 21 | // Add files to the test suite 22 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); 23 | 24 | try { 25 | // Run the mocha test 26 | mocha.run(failures => { 27 | if (failures > 0) { 28 | e(new Error(`${failures} tests failed.`)); 29 | } else { 30 | c(); 31 | } 32 | }); 33 | } catch (err) { 34 | e(err); 35 | } 36 | }); 37 | }); 38 | } 39 | 40 | module.exports = { 41 | run 42 | }; 43 | -------------------------------------------------------------------------------- /3rd/lua/src/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2.1.1 2017/04/19 17:20:42 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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PLAT ?= none 2 | PLATS = linux macosx 3 | 4 | .PHONY: $(PLATS) clean cleanall lua cjson 5 | 6 | none: 7 | @echo "usage: make " 8 | @echo " PLAT is one of: $(PLATS)" 9 | 10 | $(PLATS): 11 | $(MAKE) all PLAT=$@ 12 | 13 | CC= gcc 14 | IPATH= -I3rd/lua/src 15 | LPATH= -L3rd/lua/src 16 | 17 | ifeq ($(PLAT), macosx) 18 | MYFLAGS := -std=gnu99 -O2 -Wall $(IPATH) 19 | else 20 | MYFLAGS := -std=gnu99 -O2 -Wall -Wl,-E $(IPATH) 21 | endif 22 | 23 | LIBS= -llua $(LPATH) -ldl -lm 24 | HEADER = $(wildcard src/*.h) 25 | SRCS= $(wildcard src/*.c) 26 | BINROOT= vscext/bin/$(PLAT) 27 | PROG= $(BINROOT)/skynetda 28 | 29 | all: lua cjson $(PROG) 30 | 31 | lua: 32 | $(MAKE) -C 3rd/lua $(PLAT) 33 | 34 | cjson: 35 | $(MAKE) -C 3rd/lua-cjson install PLAT=$(PLAT) 36 | 37 | $(PROG): $(SRCS) $(HEADER) 38 | $(CC) $(MYFLAGS) -o $@ $(SRCS) $(LIBS) 39 | 40 | clean: 41 | rm -f vscext/bin/linux/skynetda 42 | rm -f vscext/bin/macosx/skynetda 43 | 44 | cleanall: clean 45 | $(MAKE) -C 3rd/lua clean 46 | $(MAKE) -C 3rd/lua-cjson clean 47 | rm -f vscext/bin/linux/*.so 48 | rm -f vscext/bin/macosx/*.so -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 colin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vscext/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 colin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /3rd/lua-cjson/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2012 Mark Pulford 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vscext/extension.js: -------------------------------------------------------------------------------- 1 | // The module 'vscode' contains the VS Code extensibility API 2 | // Import the module and reference it with the alias vscode in your code below 3 | const vscode = require('vscode'); 4 | 5 | // this method is called when your extension is activated 6 | // your extension is activated the very first time the command is executed 7 | 8 | /** 9 | * @param {vscode.ExtensionContext} context 10 | */ 11 | function activate(context) { 12 | 13 | // Use the console to output diagnostic information (console.log) and errors (console.error) 14 | // This line of code will only be executed once when your extension is activated 15 | console.log('Congratulations, your extension "vscext" is now active!'); 16 | 17 | // The command has been defined in the package.json file 18 | // Now provide the implementation of the command with registerCommand 19 | // The commandId parameter must match the command field in package.json 20 | let disposable = vscode.commands.registerCommand('extension.helloWorld', function () { 21 | // The code you place here will be executed every time your command is executed 22 | 23 | // Display a message box to the user 24 | vscode.window.showInformationMessage('Hello World!'); 25 | }); 26 | 27 | context.subscriptions.push(disposable); 28 | } 29 | exports.activate = activate; 30 | 31 | // this method is called when your extension is deactivated 32 | function deactivate() {} 33 | 34 | module.exports = { 35 | activate, 36 | deactivate 37 | } 38 | -------------------------------------------------------------------------------- /3rd/lua/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 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 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_BITLIBNAME "bit32" 39 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 40 | 41 | #define LUA_MATHLIBNAME "math" 42 | LUAMOD_API int (luaopen_math) (lua_State *L); 43 | 44 | #define LUA_DBLIBNAME "debug" 45 | LUAMOD_API int (luaopen_debug) (lua_State *L); 46 | 47 | #define LUA_LOADLIBNAME "package" 48 | LUAMOD_API int (luaopen_package) (lua_State *L); 49 | 50 | 51 | /* open all previous libraries */ 52 | LUALIB_API void (luaL_openlibs) (lua_State *L); 53 | 54 | 55 | 56 | #if !defined(lua_assert) 57 | #define lua_assert(x) ((void)0) 58 | #endif 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /3rd/lua/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14.1.1 2017/04/19 17:20:42 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 | 21 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 24 | const TValue *p2); 25 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 26 | const TValue *p2, 27 | const char *msg); 28 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 29 | const TValue *p2); 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 31 | const TValue *p2); 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 34 | TString *src, int line); 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /3rd/lua/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61.1.1 2017/04/19 17:20:42 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 | 17 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 18 | #define sizeudata(u) sizeludata((u)->len) 19 | 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 21 | (sizeof(s)/sizeof(char))-1)) 22 | 23 | 24 | /* 25 | ** test whether a string is a reserved word 26 | */ 27 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 28 | 29 | 30 | /* 31 | ** equality for short strings, which are always internalized 32 | */ 33 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 34 | 35 | 36 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 37 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 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_clearcache (global_State *g); 41 | LUAI_FUNC void luaS_init (lua_State *L); 42 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 43 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 44 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 45 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 46 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /3rd/lua/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37.1.1 2017/04/19 17:20:42 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 | -------------------------------------------------------------------------------- /3rd/lua/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31.1.1 2017/04/19 17:20:42 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 void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /3rd/lua/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15.1.1 2017/04/19 17:39:34 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 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /3rd/lua/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 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, LUA_PRELOAD_TABLE); 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 | -------------------------------------------------------------------------------- /3rd/lua/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.22.1.1 2017/04/19 17:20:42 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 | 55 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 56 | 57 | 58 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 59 | 60 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 61 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 62 | TMS event); 63 | LUAI_FUNC void luaT_init (lua_State *L); 64 | 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 66 | const TValue *p2, TValue *p3, int hasres); 67 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 68 | StkId res, TMS event); 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 70 | StkId res, TMS event); 71 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 72 | const TValue *p2, TMS event); 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /3rd/lua-cjson/dtoa_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _DTOA_CONFIG_H 2 | #define _DTOA_CONFIG_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /* Ensure dtoa.c does not USE_LOCALE. Lua CJSON must not use locale 9 | * aware conversion routines. */ 10 | #undef USE_LOCALE 11 | 12 | /* dtoa.c should not touch errno, Lua CJSON does not use it, and it 13 | * may not be threadsafe */ 14 | #define NO_ERRNO 15 | 16 | #define Long int32_t 17 | #define ULong uint32_t 18 | #define Llong int64_t 19 | #define ULLong uint64_t 20 | 21 | #ifdef IEEE_BIG_ENDIAN 22 | #define IEEE_MC68k 23 | #else 24 | #define IEEE_8087 25 | #endif 26 | 27 | #define MALLOC(n) xmalloc(n) 28 | 29 | static void *xmalloc(size_t size) 30 | { 31 | void *p; 32 | 33 | p = malloc(size); 34 | if (!p) { 35 | fprintf(stderr, "Out of memory"); 36 | abort(); 37 | } 38 | 39 | return p; 40 | } 41 | 42 | #ifdef MULTIPLE_THREADS 43 | 44 | /* Enable locking to support multi-threaded applications */ 45 | 46 | #include 47 | 48 | static pthread_mutex_t private_dtoa_lock[2] = { 49 | PTHREAD_MUTEX_INITIALIZER, 50 | PTHREAD_MUTEX_INITIALIZER 51 | }; 52 | 53 | #define ACQUIRE_DTOA_LOCK(n) do { \ 54 | int r = pthread_mutex_lock(&private_dtoa_lock[n]); \ 55 | if (r) { \ 56 | fprintf(stderr, "pthread_mutex_lock failed with %d\n", r); \ 57 | abort(); \ 58 | } \ 59 | } while (0) 60 | 61 | #define FREE_DTOA_LOCK(n) do { \ 62 | int r = pthread_mutex_unlock(&private_dtoa_lock[n]); \ 63 | if (r) { \ 64 | fprintf(stderr, "pthread_mutex_unlock failed with %d\n", r);\ 65 | abort(); \ 66 | } \ 67 | } while (0) 68 | 69 | #endif /* MULTIPLE_THREADS */ 70 | 71 | #endif /* _DTOA_CONFIG_H */ 72 | 73 | /* vi:ai et sw=4 ts=4: 74 | */ 75 | -------------------------------------------------------------------------------- /3rd/lua/src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 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 | -------------------------------------------------------------------------------- /3rd/lua/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.29.1.1 2017/04/19 17:20:42 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 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 21 | ** at every check. 22 | */ 23 | #define luaD_checkstackaux(L,n,pre,pos) \ 24 | if (L->stack_last - L->top <= (n)) \ 25 | { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); } 26 | 27 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 28 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 29 | 30 | 31 | 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 33 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 34 | 35 | 36 | /* type of protected functions, to be ran by 'runprotected' */ 37 | typedef void (*Pfunc) (lua_State *L, void *ud); 38 | 39 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 40 | const char *mode); 41 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 45 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 46 | ptrdiff_t oldtop, ptrdiff_t ef); 47 | LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 48 | int nres); 49 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 50 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 51 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 52 | LUAI_FUNC void luaD_inctop (lua_State *L); 53 | 54 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 55 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /vscext/bin/vscaux.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 与VSCode通讯的模块 3 | by colin 4 | ]] 5 | local cjson = require "cjson" 6 | local vscaux = {} 7 | local seq = 0 8 | 9 | -- 发送消息 10 | function vscaux.send(msg) 11 | local output = io.stdout 12 | local ok, content = pcall(cjson.encode, msg) 13 | if ok then 14 | local data = string.format("Content-Length: %s\r\n\r\n%s\n", #content, content) 15 | if output:write(data) then 16 | output:flush() 17 | return true 18 | end 19 | end 20 | end 21 | 22 | -- 发送事件 23 | function vscaux.send_event(event, body) 24 | seq = seq + 1 25 | local res = { 26 | seq = seq, 27 | type = "event", 28 | event = event, 29 | body = body, 30 | } 31 | return vscaux.send(res) 32 | end 33 | 34 | -- 获得请求 35 | function vscaux.recv_request() 36 | local input = io.stdin 37 | -- -- TODO 测试 38 | -- local msg = input:read() 39 | -- local ok, req = pcall(cjson.decode, msg) 40 | -- if ok then 41 | -- return req 42 | -- else 43 | -- print(req) 44 | -- end 45 | -- do return end 46 | 47 | local header = input:read() 48 | if header:find("Content-Length: ", 1, true) then 49 | local rd = input:read() 50 | if rd then 51 | local len = tonumber(header:match("(%d+)")) 52 | local sreq = input:read(len) 53 | if sreq then 54 | local ok, req = pcall(cjson.decode, sreq) 55 | if ok then 56 | return req 57 | end 58 | end 59 | end 60 | end 61 | end 62 | 63 | -- 发送响应 64 | function vscaux.send_response(cmd, rseq, body) 65 | seq = seq + 1 66 | local res = { 67 | seq = seq, 68 | type = "response", 69 | success = true, 70 | request_seq = rseq, 71 | command = cmd, 72 | body = body, 73 | } 74 | vscaux.send(res) 75 | end 76 | 77 | -- 错误响应 78 | function vscaux.send_error_response(cmd, rseq, msg) 79 | seq = seq + 1 80 | local res = { 81 | seq = seq, 82 | type = "response", 83 | success = false, 84 | request_seq = rseq, 85 | command = cmd, 86 | message = msg, 87 | } 88 | vscaux.send(res) 89 | end 90 | 91 | return vscaux -------------------------------------------------------------------------------- /3rd/lua/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.23.1.2 2018/05/24 19:39:05 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 | /* 22 | ** writable version of 'gkey'; allows updates to individual fields, 23 | ** but not to the whole (which has incompatible type) 24 | */ 25 | #define wgkey(n) (&(n)->i_key.nk) 26 | 27 | #define invalidateTMcache(t) ((t)->flags = 0) 28 | 29 | 30 | /* true when 't' is using 'dummynode' as its hash part */ 31 | #define isdummy(t) ((t)->lastfree == NULL) 32 | 33 | 34 | /* allocated size for hash nodes */ 35 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 36 | 37 | 38 | /* returns the key, given the value of a table entry */ 39 | #define keyfromval(v) \ 40 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 41 | 42 | 43 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 44 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 45 | TValue *value); 46 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 47 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 48 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 49 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 50 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 51 | LUAI_FUNC Table *luaH_new (lua_State *L); 52 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 53 | unsigned int nhsize); 54 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 55 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 56 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 57 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 58 | 59 | 60 | #if defined(LUA_DEBUG) 61 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 62 | LUAI_FUNC int luaH_isdummy (const Table *t); 63 | #endif 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /3rd/lua/src/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12.1.1 2017/04/19 17:20:42 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 | -------------------------------------------------------------------------------- /vscext/vsc-extension-quickstart.md: -------------------------------------------------------------------------------- 1 | # Welcome to your VS Code Extension 2 | 3 | ## What's in the folder 4 | 5 | * This folder contains all of the files necessary for your extension. 6 | * `package.json` - this is the manifest file in which you declare your extension and command. 7 | * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. 8 | * `extension.js` - this is the main file where you will provide the implementation of your command. 9 | * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. 10 | * We pass the function containing the implementation of the command as the second parameter to `registerCommand`. 11 | 12 | ## Get up and running straight away 13 | 14 | * Press `F5` to open a new window with your extension loaded. 15 | * Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. 16 | * Set breakpoints in your code inside `extension.js` to debug your extension. 17 | * Find output from your extension in the debug console. 18 | 19 | ## Make changes 20 | 21 | * You can relaunch the extension from the debug toolbar after changing code in `extension.js`. 22 | * You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. 23 | 24 | ## Explore the API 25 | 26 | * You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. 27 | 28 | ## Run tests 29 | 30 | * Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`. 31 | * Press `F5` to run the tests in a new window with your extension loaded. 32 | * See the output of the test result in the debug console. 33 | * Make changes to `src/test/suite/extension.test.js` or create new test files inside the `test/suite` folder. 34 | * The provided test runner will only consider files matching the name pattern `**.test.ts`. 35 | * You can create folders inside the `test` folder to structure your tests any way you want. 36 | ## Go further 37 | 38 | * [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace. 39 | * Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration). 40 | -------------------------------------------------------------------------------- /3rd/lua/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.79.1.1 2017/04/19 17:20:42 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 | } LexState; 73 | 74 | 75 | LUAI_FUNC void luaX_init (lua_State *L); 76 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 77 | TString *source, int firstchar); 78 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 79 | LUAI_FUNC void luaX_next (LexState *ls); 80 | LUAI_FUNC int luaX_lookahead (LexState *ls); 81 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 82 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /3rd/lua/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43.1.1 2017/04/19 17:20:42 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 | -------------------------------------------------------------------------------- /3rd/lua/doc/lua.1: -------------------------------------------------------------------------------- 1 | .\" $Id: lua.man,v 1.14 2016/10/17 15:43:50 lhf Exp $ 2 | .TH LUA 1 "$Date: 2016/10/17 15:43:50 $" 3 | .SH NAME 4 | lua \- Lua interpreter 5 | .SH SYNOPSIS 6 | .B lua 7 | [ 8 | .I options 9 | ] 10 | [ 11 | .I script 12 | [ 13 | .I args 14 | ] 15 | ] 16 | .SH DESCRIPTION 17 | .B lua 18 | is the standalone Lua interpreter. 19 | It loads and executes Lua programs, 20 | either in textual source form or 21 | in precompiled binary form. 22 | (Precompiled binaries are output by 23 | .BR luac , 24 | the Lua compiler.) 25 | .B lua 26 | can be used as a batch interpreter and also interactively. 27 | .LP 28 | The given 29 | .I options 30 | are handled in order and then 31 | the Lua program in file 32 | .I script 33 | is loaded and executed. 34 | The given 35 | .I args 36 | are available to 37 | .I script 38 | as strings in a global table named 39 | .BR arg . 40 | If no options or arguments are given, 41 | then 42 | .B "\-v \-i" 43 | is assumed when the standard input is a terminal; 44 | otherwise, 45 | .B "\-" 46 | is assumed. 47 | .LP 48 | In interactive mode, 49 | .B lua 50 | prompts the user, 51 | reads lines from the standard input, 52 | and executes them as they are read. 53 | If the line contains an expression or list of expressions, 54 | then the line is evaluated and the results are printed. 55 | If a line does not contain a complete statement, 56 | then a secondary prompt is displayed and 57 | lines are read until a complete statement is formed or 58 | a syntax error is found. 59 | .LP 60 | At the very start, 61 | before even handling the command line, 62 | .B lua 63 | checks the contents of the environment variables 64 | .B LUA_INIT_5_3 65 | or 66 | .BR LUA_INIT , 67 | in that order. 68 | If the contents is of the form 69 | .RI '@ filename ', 70 | then 71 | .I filename 72 | is executed. 73 | Otherwise, the string is assumed to be a Lua statement and is executed. 74 | .SH OPTIONS 75 | .TP 76 | .BI \-e " stat" 77 | execute statement 78 | .IR stat . 79 | .TP 80 | .B \-i 81 | enter interactive mode after executing 82 | .IR script . 83 | .TP 84 | .BI \-l " name" 85 | execute the equivalent of 86 | .IB name =require(' name ') 87 | before executing 88 | .IR script . 89 | .TP 90 | .B \-v 91 | show version information. 92 | .TP 93 | .B \-E 94 | ignore environment variables. 95 | .TP 96 | .B \-\- 97 | stop handling options. 98 | .TP 99 | .B \- 100 | stop handling options and execute the standard input as a file. 101 | .SH "SEE ALSO" 102 | .BR luac (1) 103 | .br 104 | The documentation at lua.org, 105 | especially section 7 of the reference manual. 106 | .SH DIAGNOSTICS 107 | Error messages should be self explanatory. 108 | .SH AUTHORS 109 | R. Ierusalimschy, 110 | L. H. de Figueiredo, 111 | W. Celes 112 | .\" EOF 113 | -------------------------------------------------------------------------------- /vscext/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "skynet-debugger", 3 | "displayName": "Skynet Debugger", 4 | "description": "A Lua debugger for skynet", 5 | "version": "1.0.1", 6 | "publisher": "colinsusie", 7 | "author": { 8 | "name": "colin", 9 | "url": "https://github.com/colinsusie" 10 | }, 11 | "license": "MIT", 12 | "icon": "images/icon.png", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/colinsusie/skynetda" 16 | }, 17 | "bugs": { 18 | "url": "https://github.com/colinsusie/skynetda/issues" 19 | }, 20 | "engines": { 21 | "vscode": "^1.41.0" 22 | }, 23 | "categories": [ 24 | "Debuggers" 25 | ], 26 | "private": true, 27 | "extensionKind": [ 28 | "workspace" 29 | ], 30 | "scripts": {}, 31 | "main": "./extension.js", 32 | "activationEvents": [ 33 | "onDebug" 34 | ], 35 | "keywords": [ 36 | "debugger", 37 | "lua", 38 | "skynet" 39 | ], 40 | "devDependencies": { 41 | "@types/glob": "^7.1.1", 42 | "@types/mocha": "^5.2.7", 43 | "@types/node": "^12.11.7", 44 | "@types/vscode": "^1.41.0", 45 | "eslint": "^6.6.0", 46 | "glob": "^7.1.5", 47 | "mocha": "^6.2.2", 48 | "typescript": "^3.6.4", 49 | "vscode-test": "^1.2.2" 50 | }, 51 | "contributes": { 52 | "breakpoints": [ 53 | { 54 | "language": "lua" 55 | } 56 | ], 57 | "debuggers": [ 58 | { 59 | "type": "lua", 60 | "label": "skynet debugger", 61 | "languages": [ 62 | "lua" 63 | ], 64 | "linux": { 65 | "program": "./bin/linux/skynetda" 66 | }, 67 | "osx": { 68 | "program": "./bin/macosx/skynetda" 69 | }, 70 | "initialConfigurations": [ 71 | { 72 | "name": "skynet debugger", 73 | "type": "lua", 74 | "request": "launch", 75 | "workdir": "${workspaceFolder}", 76 | "program": "./skynet", 77 | "config": "./examples/config_vsc", 78 | "service": "./service" 79 | } 80 | ], 81 | "configurationAttributes": { 82 | "launch": { 83 | "required": [ 84 | "program" 85 | ], 86 | "properties": { 87 | "workdir": { 88 | "type": "string", 89 | "description": "Set the work directory", 90 | "default": "${workspaceFolder}" 91 | }, 92 | "program": { 93 | "type": "string", 94 | "description": "Set the path of skynet program, the path is relative to workdir", 95 | "default": "./skynet" 96 | }, 97 | "config": { 98 | "type": "string", 99 | "description": "skynet config path", 100 | "default": "./examples/config_vsc" 101 | }, 102 | "service": { 103 | "type": "string", 104 | "description": "Set the path of skynet service, the path is relative to workdir", 105 | "default": "./service" 106 | } 107 | } 108 | } 109 | } 110 | } 111 | ] 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /3rd/lua-cjson/g_fmt.c: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * 3 | * The author of this software is David M. Gay. 4 | * 5 | * Copyright (c) 1991, 1996 by Lucent Technologies. 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose without fee is hereby granted, provided that this entire notice 9 | * is included in all copies of any software which is or includes a copy 10 | * or modification of this software and in all copies of the supporting 11 | * documentation for such software. 12 | * 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY 15 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 16 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | * 18 | ***************************************************************/ 19 | 20 | /* g_fmt(buf,x) stores the closest decimal approximation to x in buf; 21 | * it suffices to declare buf 22 | * char buf[32]; 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | extern char *dtoa(double, int, int, int *, int *, char **); 29 | extern int g_fmt(char *, double, int); 30 | extern void freedtoa(char*); 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | int 36 | fpconv_g_fmt(char *b, double x, int precision) 37 | { 38 | register int i, k; 39 | register char *s; 40 | int decpt, j, sign; 41 | char *b0, *s0, *se; 42 | 43 | b0 = b; 44 | #ifdef IGNORE_ZERO_SIGN 45 | if (!x) { 46 | *b++ = '0'; 47 | *b = 0; 48 | goto done; 49 | } 50 | #endif 51 | s = s0 = dtoa(x, 2, precision, &decpt, &sign, &se); 52 | if (sign) 53 | *b++ = '-'; 54 | if (decpt == 9999) /* Infinity or Nan */ { 55 | while((*b++ = *s++)); 56 | /* "b" is used to calculate the return length. Decrement to exclude the 57 | * Null terminator from the length */ 58 | b--; 59 | goto done0; 60 | } 61 | if (decpt <= -4 || decpt > precision) { 62 | *b++ = *s++; 63 | if (*s) { 64 | *b++ = '.'; 65 | while((*b = *s++)) 66 | b++; 67 | } 68 | *b++ = 'e'; 69 | /* sprintf(b, "%+.2d", decpt - 1); */ 70 | if (--decpt < 0) { 71 | *b++ = '-'; 72 | decpt = -decpt; 73 | } 74 | else 75 | *b++ = '+'; 76 | for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10); 77 | for(;;) { 78 | i = decpt / k; 79 | *b++ = i + '0'; 80 | if (--j <= 0) 81 | break; 82 | decpt -= i*k; 83 | decpt *= 10; 84 | } 85 | *b = 0; 86 | } 87 | else if (decpt <= 0) { 88 | *b++ = '0'; 89 | *b++ = '.'; 90 | for(; decpt < 0; decpt++) 91 | *b++ = '0'; 92 | while((*b++ = *s++)); 93 | b--; 94 | } 95 | else { 96 | while((*b = *s++)) { 97 | b++; 98 | if (--decpt == 0 && *s) 99 | *b++ = '.'; 100 | } 101 | for(; decpt > 0; decpt--) 102 | *b++ = '0'; 103 | *b = 0; 104 | } 105 | done0: 106 | freedtoa(s0); 107 | #ifdef IGNORE_ZERO_SIGN 108 | done: 109 | #endif 110 | return b - b0; 111 | } 112 | -------------------------------------------------------------------------------- /3rd/lua/doc/lua.css: -------------------------------------------------------------------------------- 1 | html { 2 | background-color: #F8F8F8 ; 3 | } 4 | 5 | body { 6 | background-color: #FFFFFF ; 7 | color: #000000 ; 8 | font-family: Helvetica, Arial, sans-serif ; 9 | text-align: justify ; 10 | line-height: 1.25 ; 11 | margin: 16px auto ; 12 | padding: 32px ; 13 | border: solid #ccc 1px ; 14 | border-radius: 20px ; 15 | max-width: 70em ; 16 | width: 90% ; 17 | } 18 | 19 | h1, h2, h3, h4 { 20 | color: #000080 ; 21 | font-family: Verdana, Geneva, sans-serif ; 22 | font-weight: normal ; 23 | font-style: normal ; 24 | text-align: left ; 25 | } 26 | 27 | h1 { 28 | font-size: 28pt ; 29 | } 30 | 31 | h1 img { 32 | vertical-align: text-bottom ; 33 | } 34 | 35 | h2:before { 36 | content: "\2756" ; 37 | padding-right: 0.5em ; 38 | } 39 | 40 | a { 41 | text-decoration: none ; 42 | } 43 | 44 | a:link { 45 | color: #000080 ; 46 | } 47 | 48 | a:link:hover, a:visited:hover { 49 | background-color: #D0D0FF ; 50 | color: #000080 ; 51 | border-radius: 4px ; 52 | } 53 | 54 | a:link:active, a:visited:active { 55 | color: #FF0000 ; 56 | } 57 | 58 | div.menubar { 59 | padding-bottom: 0.5em ; 60 | } 61 | 62 | p.menubar { 63 | margin-left: 2.5em ; 64 | } 65 | 66 | .menubar a:hover { 67 | margin: -3px -3px -3px -3px ; 68 | padding: 3px 3px 3px 3px ; 69 | border-radius: 4px ; 70 | } 71 | 72 | :target { 73 | background-color: #F0F0F0 ; 74 | margin: -8px ; 75 | padding: 8px ; 76 | border-radius: 8px ; 77 | outline: none ; 78 | } 79 | 80 | hr { 81 | display: none ; 82 | } 83 | 84 | table hr { 85 | background-color: #a0a0a0 ; 86 | color: #a0a0a0 ; 87 | border: 0 ; 88 | height: 1px ; 89 | display: block ; 90 | } 91 | 92 | .footer { 93 | color: gray ; 94 | font-size: x-small ; 95 | text-transform: lowercase ; 96 | } 97 | 98 | input[type=text] { 99 | border: solid #a0a0a0 2px ; 100 | border-radius: 2em ; 101 | background-image: url('images/search.png') ; 102 | background-repeat: no-repeat ; 103 | background-position: 4px center ; 104 | padding-left: 20px ; 105 | height: 2em ; 106 | } 107 | 108 | pre.session { 109 | background-color: #F8F8F8 ; 110 | padding: 1em ; 111 | border-radius: 8px ; 112 | } 113 | 114 | table { 115 | border: none ; 116 | border-spacing: 0 ; 117 | border-collapse: collapse ; 118 | } 119 | 120 | td { 121 | padding: 0 ; 122 | margin: 0 ; 123 | } 124 | 125 | td.gutter { 126 | width: 4% ; 127 | } 128 | 129 | table.columns td { 130 | vertical-align: top ; 131 | padding-bottom: 1em ; 132 | text-align: justify ; 133 | line-height: 1.25 ; 134 | } 135 | 136 | table.book td { 137 | vertical-align: top ; 138 | } 139 | 140 | table.book td.cover { 141 | padding-right: 1em ; 142 | } 143 | 144 | table.book img { 145 | border: solid #000080 1px ; 146 | } 147 | 148 | table.book span { 149 | font-size: small ; 150 | text-align: left ; 151 | display: block ; 152 | margin-top: 0.25em ; 153 | } 154 | 155 | p.logos a:link:hover, p.logos a:visited:hover { 156 | background-color: inherit ; 157 | } 158 | 159 | img { 160 | background-color: white ; 161 | } 162 | -------------------------------------------------------------------------------- /3rd/lua/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.91.1.1 2017/04/19 17:20:42 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 | lua_assert(nsize > realosize); /* cannot fail when shrinking a block */ 89 | if (g->version) { /* is state fully built? */ 90 | luaC_fullgc(L, 1); /* try to free some memory... */ 91 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 92 | } 93 | if (newblock == NULL) 94 | luaD_throw(L, LUA_ERRMEM); 95 | } 96 | lua_assert((nsize == 0) == (newblock == NULL)); 97 | g->GCdebt = (g->GCdebt + nsize) - realosize; 98 | return newblock; 99 | } 100 | 101 | -------------------------------------------------------------------------------- /vscext/bin/debugger.lua: -------------------------------------------------------------------------------- 1 | local cjson = require "cjson" 2 | cjson.encode_empty_table_as_array(true) 3 | local vscaux = require "vscaux" 4 | 5 | local workdir = "" 6 | local skynet = "" 7 | local config = "" 8 | local service = "" 9 | local open_debug = true 10 | 11 | local reqfuncs = {} 12 | local breakpoints = {} 13 | 14 | function reqfuncs.initialize(req) 15 | vscaux.send_response(req.command, req.seq, { 16 | supportsConfigurationDoneRequest = true, 17 | supportsSetVariable = false, 18 | supportsConditionalBreakpoints = true, 19 | supportsHitConditionalBreakpoints = true, 20 | }) 21 | vscaux.send_event("initialized") 22 | vscaux.send_event("output", { 23 | category = "console", 24 | output = "skynet debugger start!\n", 25 | }) 26 | end 27 | 28 | local function calc_hitcount(hitexpr) 29 | if not hitexpr then return 0 end 30 | 31 | local f, msg = load("return " .. hitexpr, "=hitexpr") 32 | if not f then return 0 end 33 | 34 | local ok, ret = pcall(f) 35 | if not ok then return 0 end 36 | 37 | return tonumber(ret) or 0 38 | end 39 | 40 | function reqfuncs.setBreakpoints(req) 41 | local args = req.arguments 42 | local src = args.source.path 43 | local bpinfos = {} 44 | local bps = {} 45 | for _, bp in ipairs(args.breakpoints) do 46 | local logmsg 47 | if bp.logMessage and bp.logMessage ~= "" then 48 | logmsg = bp.logMessage .. '\n' 49 | end 50 | bpinfos[#bpinfos+1] = { 51 | source = {path = src}, 52 | line = bp.line, 53 | logMessage = logmsg, 54 | condition = bp.condition, 55 | hitCount = calc_hitcount(bp.hitCondition), 56 | currHitCount = 0, 57 | } 58 | bps[#bps+1] = { 59 | verified = true, 60 | source = {path = src}, 61 | line = bp.line, 62 | } 63 | end 64 | breakpoints[src] = bpinfos 65 | vscaux.send_response(req.command, req.seq, { 66 | breakpoints = bps, 67 | }) 68 | end 69 | 70 | function reqfuncs.setExceptionBreakpoints(req) 71 | vscaux.send_response(req.command, req.seq) 72 | end 73 | 74 | function reqfuncs.configurationDone(req) 75 | vscaux.send_response(req.command, req.seq) 76 | end 77 | 78 | function reqfuncs.launch(req) 79 | workdir = req.arguments.workdir or "." 80 | if workdir:sub(-1) == "/" then 81 | workdir = workdir:sub(1, -2) 82 | end 83 | skynet = req.arguments.program 84 | config = req.arguments.config 85 | service = req.arguments.service 86 | open_debug = not req.arguments.noDebug 87 | return true 88 | end 89 | 90 | function handle_request() 91 | while true do 92 | local req = vscaux.recv_request() 93 | if not req or not req.command then 94 | return false 95 | end 96 | local func = reqfuncs[req.command] 97 | if func and func(req) then 98 | break 99 | elseif not func then 100 | vscaux.send_error_response(req.command, req.seq, string.format("%s not yet implemented", req.command)) 101 | end 102 | end 103 | return true 104 | end 105 | 106 | if handle_request() then 107 | return workdir, skynet, config, service, open_debug, cjson.encode(breakpoints) 108 | else 109 | error("launch error") 110 | end 111 | -------------------------------------------------------------------------------- /3rd/lua/src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.64.1.1 2017/04/19 17:20:42 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 | /* get (pointer to) instruction of given 'expdesc' */ 44 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) 45 | 46 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 47 | 48 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 49 | 50 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 51 | 52 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 53 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 54 | LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 55 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 56 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 57 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 58 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 59 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 60 | LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n); 61 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 62 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 63 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 64 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 65 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 66 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 67 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 68 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 69 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 70 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 71 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 72 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 73 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 74 | LUAI_FUNC int luaK_jump (FuncState *fs); 75 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 76 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 77 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 78 | LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 79 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 80 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 81 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 82 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 83 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 84 | expdesc *v2, int line); 85 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 86 | 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /3rd/lua/doc/luac.1: -------------------------------------------------------------------------------- 1 | .\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $ 2 | .TH LUAC 1 "$Date: 2011/11/16 13:53:40 $" 3 | .SH NAME 4 | luac \- Lua compiler 5 | .SH SYNOPSIS 6 | .B luac 7 | [ 8 | .I options 9 | ] [ 10 | .I filenames 11 | ] 12 | .SH DESCRIPTION 13 | .B luac 14 | is the Lua compiler. 15 | It translates programs written in the Lua programming language 16 | into binary files containing precompiled chunks 17 | that can be later loaded and executed. 18 | .LP 19 | The main advantages of precompiling chunks are: 20 | faster loading, 21 | protecting source code from accidental user changes, 22 | and 23 | off-line syntax checking. 24 | Precompiling does not imply faster execution 25 | because in Lua chunks are always compiled into bytecodes before being executed. 26 | .B luac 27 | simply allows those bytecodes to be saved in a file for later execution. 28 | Precompiled chunks are not necessarily smaller than the corresponding source. 29 | The main goal in precompiling is faster loading. 30 | .LP 31 | In the command line, 32 | you can mix 33 | text files containing Lua source and 34 | binary files containing precompiled chunks. 35 | .B luac 36 | produces a single output file containing the combined bytecodes 37 | for all files given. 38 | Executing the combined file is equivalent to executing the given files. 39 | By default, 40 | the output file is named 41 | .BR luac.out , 42 | but you can change this with the 43 | .B \-o 44 | option. 45 | .LP 46 | Precompiled chunks are 47 | .I not 48 | portable across different architectures. 49 | Moreover, 50 | the internal format of precompiled chunks 51 | is likely to change when a new version of Lua is released. 52 | Make sure you save the source files of all Lua programs that you precompile. 53 | .LP 54 | .SH OPTIONS 55 | .TP 56 | .B \-l 57 | produce a listing of the compiled bytecode for Lua's virtual machine. 58 | Listing bytecodes is useful to learn about Lua's virtual machine. 59 | If no files are given, then 60 | .B luac 61 | loads 62 | .B luac.out 63 | and lists its contents. 64 | Use 65 | .B \-l \-l 66 | for a full listing. 67 | .TP 68 | .BI \-o " file" 69 | output to 70 | .IR file , 71 | instead of the default 72 | .BR luac.out . 73 | (You can use 74 | .B "'\-'" 75 | for standard output, 76 | but not on platforms that open standard output in text mode.) 77 | The output file may be one of the given files because 78 | all files are loaded before the output file is written. 79 | Be careful not to overwrite precious files. 80 | .TP 81 | .B \-p 82 | load files but do not generate any output file. 83 | Used mainly for syntax checking and for testing precompiled chunks: 84 | corrupted files will probably generate errors when loaded. 85 | If no files are given, then 86 | .B luac 87 | loads 88 | .B luac.out 89 | and tests its contents. 90 | No messages are displayed if the file loads without errors. 91 | .TP 92 | .B \-s 93 | strip debug information before writing the output file. 94 | This saves some space in very large chunks, 95 | but if errors occur when running a stripped chunk, 96 | then the error messages may not contain the full information they usually do. 97 | In particular, 98 | line numbers and names of local variables are lost. 99 | .TP 100 | .B \-v 101 | show version information. 102 | .TP 103 | .B \-\- 104 | stop handling options. 105 | .TP 106 | .B \- 107 | stop handling options and process standard input. 108 | .SH "SEE ALSO" 109 | .BR lua (1) 110 | .br 111 | The documentation at lua.org. 112 | .SH DIAGNOSTICS 113 | Error messages should be self explanatory. 114 | .SH AUTHORS 115 | R. Ierusalimschy, 116 | L. H. de Figueiredo, 117 | W. Celes 118 | .\" EOF 119 | -------------------------------------------------------------------------------- /3rd/lua/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for installing Lua 2 | # See doc/readme.html for installation and customization instructions. 3 | 4 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= 5 | 6 | # Your platform. See PLATS for possible values. 7 | PLAT= none 8 | 9 | # Where to install. The installation starts in the src and doc directories, 10 | # so take care if INSTALL_TOP is not an absolute path. See the local target. 11 | # You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with 12 | # LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h. 13 | INSTALL_TOP= /usr/local 14 | INSTALL_BIN= $(INSTALL_TOP)/bin 15 | INSTALL_INC= $(INSTALL_TOP)/include 16 | INSTALL_LIB= $(INSTALL_TOP)/lib 17 | INSTALL_MAN= $(INSTALL_TOP)/man/man1 18 | INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V 19 | INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V 20 | 21 | # How to install. If your install program does not support "-p", then 22 | # you may have to run ranlib on the installed liblua.a. 23 | INSTALL= install -p 24 | INSTALL_EXEC= $(INSTALL) -m 0755 25 | INSTALL_DATA= $(INSTALL) -m 0644 26 | # 27 | # If you don't have "install" you can use "cp" instead. 28 | # INSTALL= cp -p 29 | # INSTALL_EXEC= $(INSTALL) 30 | # INSTALL_DATA= $(INSTALL) 31 | 32 | # Other utilities. 33 | MKDIR= mkdir -p 34 | RM= rm -f 35 | 36 | # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= 37 | 38 | # Convenience platforms targets. 39 | PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris 40 | 41 | # What to install. 42 | TO_BIN= lua luac 43 | TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp 44 | TO_LIB= liblua.a 45 | TO_MAN= lua.1 luac.1 46 | 47 | # Lua version and release. 48 | V= 5.3 49 | R= $V.4 50 | 51 | # Targets start here. 52 | all: $(PLAT) 53 | 54 | $(PLATS) clean: 55 | cd src && $(MAKE) $@ 56 | 57 | test: dummy 58 | src/lua -v 59 | 60 | install: dummy 61 | cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) 62 | cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) 63 | cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) 64 | cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) 65 | cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) 66 | 67 | uninstall: 68 | cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN) 69 | cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC) 70 | cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB) 71 | cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN) 72 | 73 | local: 74 | $(MAKE) install INSTALL_TOP=../install 75 | 76 | none: 77 | @echo "Please do 'make PLATFORM' where PLATFORM is one of these:" 78 | @echo " $(PLATS)" 79 | @echo "See doc/readme.html for complete instructions." 80 | 81 | # make may get confused with test/ and install/ 82 | dummy: 83 | 84 | # echo config parameters 85 | echo: 86 | @cd src && $(MAKE) -s echo 87 | @echo "PLAT= $(PLAT)" 88 | @echo "V= $V" 89 | @echo "R= $R" 90 | @echo "TO_BIN= $(TO_BIN)" 91 | @echo "TO_INC= $(TO_INC)" 92 | @echo "TO_LIB= $(TO_LIB)" 93 | @echo "TO_MAN= $(TO_MAN)" 94 | @echo "INSTALL_TOP= $(INSTALL_TOP)" 95 | @echo "INSTALL_BIN= $(INSTALL_BIN)" 96 | @echo "INSTALL_INC= $(INSTALL_INC)" 97 | @echo "INSTALL_LIB= $(INSTALL_LIB)" 98 | @echo "INSTALL_MAN= $(INSTALL_MAN)" 99 | @echo "INSTALL_LMOD= $(INSTALL_LMOD)" 100 | @echo "INSTALL_CMOD= $(INSTALL_CMOD)" 101 | @echo "INSTALL_EXEC= $(INSTALL_EXEC)" 102 | @echo "INSTALL_DATA= $(INSTALL_DATA)" 103 | 104 | # echo pkg-config data 105 | pc: 106 | @echo "version=$R" 107 | @echo "prefix=$(INSTALL_TOP)" 108 | @echo "libdir=$(INSTALL_LIB)" 109 | @echo "includedir=$(INSTALL_INC)" 110 | 111 | # list targets that do not create files (but not all makes understand .PHONY) 112 | .PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho 113 | 114 | # (end of Makefile) 115 | -------------------------------------------------------------------------------- /3rd/lua/src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.55.1.1 2017/04/19 17:20:42 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 | -------------------------------------------------------------------------------- /3rd/lua/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.41.1.1 2017/04/19 17:20:42 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 | /* 31 | ** You can define LUA_FLOORN2I if you want to convert floats to integers 32 | ** by flooring them (instead of raising an error if they are not 33 | ** integral values) 34 | */ 35 | #if !defined(LUA_FLOORN2I) 36 | #define LUA_FLOORN2I 0 37 | #endif 38 | 39 | 40 | #define tonumber(o,n) \ 41 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 42 | 43 | #define tointeger(o,i) \ 44 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I)) 45 | 46 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 47 | 48 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 49 | 50 | 51 | /* 52 | ** fast track for 'gettable': if 't' is a table and 't[k]' is not nil, 53 | ** return 1 with 'slot' pointing to 't[k]' (final result). Otherwise, 54 | ** return 0 (meaning it will have to check metamethod) with 'slot' 55 | ** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise). 56 | ** 'f' is the raw get function to use. 57 | */ 58 | #define luaV_fastget(L,t,k,slot,f) \ 59 | (!ttistable(t) \ 60 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 61 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ 62 | !ttisnil(slot))) /* result not nil? */ 63 | 64 | /* 65 | ** standard implementation for 'gettable' 66 | */ 67 | #define luaV_gettable(L,t,k,v) { const TValue *slot; \ 68 | if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \ 69 | else luaV_finishget(L,t,k,v,slot); } 70 | 71 | 72 | /* 73 | ** Fast track for set table. If 't' is a table and 't[k]' is not nil, 74 | ** call GC barrier, do a raw 't[k]=v', and return true; otherwise, 75 | ** return false with 'slot' equal to NULL (if 't' is not a table) or 76 | ** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro 77 | ** returns true, there is no need to 'invalidateTMcache', because the 78 | ** call is not creating a new entry. 79 | */ 80 | #define luaV_fastset(L,t,k,slot,f,v) \ 81 | (!ttistable(t) \ 82 | ? (slot = NULL, 0) \ 83 | : (slot = f(hvalue(t), k), \ 84 | ttisnil(slot) ? 0 \ 85 | : (luaC_barrierback(L, hvalue(t), v), \ 86 | setobj2t(L, cast(TValue *,slot), v), \ 87 | 1))) 88 | 89 | 90 | #define luaV_settable(L,t,k,v) { const TValue *slot; \ 91 | if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \ 92 | luaV_finishset(L,t,k,v,slot); } 93 | 94 | 95 | 96 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 97 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 98 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 99 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 100 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); 101 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 102 | StkId val, const TValue *slot); 103 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 104 | StkId val, const TValue *slot); 105 | LUAI_FUNC void luaV_finishOp (lua_State *L); 106 | LUAI_FUNC void luaV_execute (lua_State *L); 107 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 108 | LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); 109 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 110 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 111 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /3rd/lua/src/lfunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.c,v 2.45.1.1 2017/04/19 17:39:34 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 | -------------------------------------------------------------------------------- /3rd/lua-cjson/Makefile: -------------------------------------------------------------------------------- 1 | ##### Available defines for CJSON_CFLAGS ##### 2 | ## 3 | ## USE_INTERNAL_ISINF: Workaround for Solaris platforms missing isinf(). 4 | ## DISABLE_INVALID_NUMBERS: Permanently disable invalid JSON numbers: 5 | ## NaN, Infinity, hex. 6 | ## 7 | ## Optional built-in number conversion uses the following defines: 8 | ## USE_INTERNAL_FPCONV: Use builtin strtod/dtoa for numeric conversions. 9 | ## IEEE_BIG_ENDIAN: Required on big endian architectures. 10 | ## MULTIPLE_THREADS: Must be set when Lua CJSON may be used in a 11 | ## multi-threaded application. Requries _pthreads_. 12 | 13 | ##### Build defaults ##### 14 | LUA_VERSION = 5.3 15 | TARGET = cjson.so 16 | PREFIX = ../../vscext/bin 17 | #CFLAGS = -g -Wall -pedantic -fno-inline 18 | CFLAGS = -O3 -Wall -pedantic -DNDEBUG 19 | CJSON_CFLAGS = -std=gnu99 -fPIC 20 | CJSON_LDFLAGS = -shared 21 | DESTDIR= . 22 | LUA_INCLUDE_DIR = ../lua/src 23 | LUA_CMODULE_DIR = $(PREFIX)/$(PLAT) 24 | LUA_MODULE_DIR = $(PREFIX)/$(PLAT) 25 | LUA_BIN_DIR = $(PREFIX)/$(PLAT) 26 | 27 | CC= gcc 28 | AR= gcc -o 29 | 30 | ##### Platform overrides ##### 31 | ## 32 | ## Tweak one of the platform sections below to suit your situation. 33 | ## 34 | ## See http://lua-users.org/wiki/BuildingModules for further platform 35 | ## specific details. 36 | 37 | ## Linux 38 | 39 | ## FreeBSD 40 | #LUA_INCLUDE_DIR = $(PREFIX)/include/lua51 41 | 42 | ## MacOSX (Macports) 43 | #PREFIX = /opt/local 44 | ifeq ($(PLAT), macosx) 45 | CJSON_LDFLAGS := -bundle -undefined dynamic_lookup 46 | endif 47 | #CJSON_LDFLAGS = -bundle -undefined dynamic_lookup 48 | 49 | ## Solaris 50 | #PREFIX = /home/user/opt 51 | #CC = gcc 52 | #CJSON_CFLAGS = -fpic -DUSE_INTERNAL_ISINF 53 | 54 | ## Windows (MinGW) 55 | #TARGET = cjson.dll 56 | #PREFIX = /home/user/opt 57 | #CJSON_CFLAGS = -DDISABLE_INVALID_NUMBERS 58 | #CJSON_LDFLAGS = -shared -L$(PREFIX)/lib -llua51 59 | #LUA_BIN_SUFFIX = .lua 60 | 61 | ##### Number conversion configuration ##### 62 | 63 | ## Use Libc support for number conversion (default) 64 | FPCONV_OBJS = fpconv.o 65 | 66 | ## Use built in number conversion 67 | #FPCONV_OBJS = g_fmt.o dtoa.o 68 | #CJSON_CFLAGS += -DUSE_INTERNAL_FPCONV 69 | 70 | ## Compile built in number conversion for big endian architectures 71 | #CJSON_CFLAGS += -DIEEE_BIG_ENDIAN 72 | 73 | ## Compile built in number conversion to support multi-threaded 74 | ## applications (recommended) 75 | #CJSON_CFLAGS += -pthread -DMULTIPLE_THREADS 76 | #CJSON_LDFLAGS += -pthread 77 | 78 | ##### End customisable sections ##### 79 | 80 | TEST_FILES = README bench.lua genutf8.pl test.lua octets-escaped.dat \ 81 | example1.json example2.json example3.json example4.json \ 82 | example5.json numbers.json rfc-example1.json \ 83 | rfc-example2.json types.json 84 | DATAPERM = 644 85 | EXECPERM = 755 86 | 87 | ASCIIDOC = asciidoc 88 | 89 | BUILD_CFLAGS = -I$(LUA_INCLUDE_DIR) $(CJSON_CFLAGS) 90 | OBJS = lua_cjson.o strbuf.o $(FPCONV_OBJS) 91 | 92 | .PHONY: all clean install install-extra doc 93 | 94 | .SUFFIXES: .html .adoc 95 | 96 | .c.o: 97 | $(CC) -c $(CFLAGS) $(CPPFLAGS) $(BUILD_CFLAGS) -o $@ $< 98 | 99 | .adoc.html: 100 | $(ASCIIDOC) -n -a toc $< 101 | 102 | all: $(TARGET) 103 | 104 | doc: manual.html performance.html 105 | 106 | $(TARGET): $(OBJS) 107 | $(AR) $@ $(LDFLAGS) $(CJSON_LDFLAGS) $(OBJS) 108 | 109 | install: $(TARGET) 110 | mkdir -p $(DESTDIR)/$(LUA_CMODULE_DIR) 111 | mv $(TARGET) $(DESTDIR)/$(LUA_CMODULE_DIR) 112 | chmod $(EXECPERM) $(DESTDIR)/$(LUA_CMODULE_DIR)/$(TARGET) 113 | 114 | install-extra: 115 | mkdir -p $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/tests \ 116 | $(DESTDIR)/$(LUA_BIN_DIR) 117 | cp lua/cjson/util.lua $(DESTDIR)/$(LUA_MODULE_DIR)/cjson 118 | chmod $(DATAPERM) $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/util.lua 119 | cp lua/lua2json.lua $(DESTDIR)/$(LUA_BIN_DIR)/lua2json$(LUA_BIN_SUFFIX) 120 | chmod $(EXECPERM) $(DESTDIR)/$(LUA_BIN_DIR)/lua2json$(LUA_BIN_SUFFIX) 121 | cp lua/json2lua.lua $(DESTDIR)/$(LUA_BIN_DIR)/json2lua$(LUA_BIN_SUFFIX) 122 | chmod $(EXECPERM) $(DESTDIR)/$(LUA_BIN_DIR)/json2lua$(LUA_BIN_SUFFIX) 123 | cd tests; cp $(TEST_FILES) $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/tests 124 | cd tests; chmod $(DATAPERM) $(TEST_FILES); chmod $(EXECPERM) *.lua *.pl 125 | 126 | clean: 127 | rm -f *.o $(TARGET) 128 | -------------------------------------------------------------------------------- /3rd/lua/src/lcorolib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcorolib.c,v 1.10.1.1 2017/04/19 17:20:42 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_type(L, -1) == LUA_TSTRING) { /* 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 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * skynet debug adpater 3 | * by colin 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "lua.h" 14 | #include "lualib.h" 15 | #include "lauxlib.h" 16 | 17 | FILE *logger = NULL; 18 | 19 | static void error_exit(const char* format, ...) { 20 | va_list ap; 21 | va_start(ap, format); 22 | vfprintf(logger, format, ap); 23 | va_end(ap); 24 | fflush(stdout); 25 | exit(1); 26 | } 27 | 28 | static bool init_debuglog() { 29 | if (!logger) { 30 | logger = fopen("debug.log", "w"); 31 | if (logger == NULL) 32 | return false; 33 | setbuf(logger, NULL); 34 | 35 | // stderr -> logger 36 | int fd = fileno(logger); 37 | if (dup2(fd, STDERR_FILENO) == -1) { 38 | error_exit("dup2: %s", strerror(errno)); 39 | } 40 | } 41 | return true; 42 | } 43 | 44 | static void debuglog(const char* format, ...) { 45 | va_list ap; 46 | va_start(ap, format); 47 | vfprintf(logger, format, ap); 48 | va_end(ap); 49 | } 50 | 51 | static int sigign() { 52 | struct sigaction sa; 53 | sa.sa_handler = SIG_IGN; 54 | sa.sa_flags = 0; 55 | sigemptyset(&sa.sa_mask); 56 | sigaction(SIGHUP, &sa, 0); 57 | return 0; 58 | } 59 | 60 | static void change_workdir(const char *path) { 61 | const char *pos = strrchr(path, '/'); 62 | if (pos) { 63 | int n = pos - path; 64 | char *wdir = malloc(n+1); 65 | strncpy(wdir, path, n); 66 | wdir[n+1] = '\0'; 67 | chdir(wdir); 68 | free(wdir); 69 | } 70 | } 71 | 72 | static void init_lua_path(lua_State *dL) { 73 | lua_getglobal(dL, "package"); // [pkg] 74 | lua_getfield(dL, -1, "path"); // [pkg|path] 75 | lua_pushstring(dL, "path"); // [pkg|path|pathkey] 76 | lua_pushfstring(dL, "../?.lua;../?.luac;%s", lua_tostring(dL, -2)); // [pkg|path|pathkey|pathval] 77 | lua_settable(dL, -4); // [pkg|path] 78 | lua_pop(dL, 1); // [pkg] 79 | 80 | lua_getfield(dL, -1, "cpath"); // [pkg|cpath] 81 | lua_pushstring(dL, "cpath"); // [pkg|cpath|cpathkey] 82 | lua_pushfstring(dL, "./?.so;%s", lua_tostring(dL, -2)); // [pkg|cpath|cpathkey|cpathval] 83 | lua_settable(dL, -4); // [pkg|path] 84 | lua_pop(dL, 2); // [] 85 | } 86 | 87 | static bool run_script(lua_State *L) { 88 | int err = (luaL_loadfile(L, "../debugger.lua") || lua_pcall(L, 0, 6, 0)); 89 | if (err) { 90 | fprintf(logger, "%s\n", lua_tostring(L, -1)); 91 | return false; 92 | } 93 | return true; 94 | } 95 | 96 | static void run_skynet(const char *workdir, const char *skynet, const char *config, const char *service, 97 | bool debug, const char *breakpoints) { 98 | if (debug) 99 | setenv("vscdbg_open", "on", 1); 100 | else 101 | setenv("vscdbg_open", "off", 1); 102 | 103 | setenv("vscdbg_workdir", workdir, 1); 104 | setenv("vscdbg_bps", breakpoints, 1); 105 | setenv("vscdbg_service", service, 1); 106 | 107 | debuglog("workdir: %s\n", workdir); 108 | debuglog("skynet path: %s\n", skynet); 109 | debuglog("config path: %s\n", config); 110 | debuglog("service path: %s\n", service); 111 | 112 | if (chdir(workdir) != 0) { 113 | error_exit("run_skynet - chdir: %s\n", strerror(errno)); 114 | } 115 | 116 | execl(skynet, skynet, config, NULL); 117 | error_exit("execl: %s\n", strerror(errno)); 118 | } 119 | 120 | int main(int argc, char const *argv[]) { 121 | sigign(); 122 | if (argc > 0) 123 | change_workdir(argv[0]); 124 | if (!init_debuglog()) 125 | error_exit("debug log failed"); 126 | 127 | lua_State *L = luaL_newstate(); 128 | luaL_openlibs(L); 129 | init_lua_path(L); 130 | if (!run_script(L)) { 131 | error_exit("script error\n"); 132 | } 133 | 134 | const char *workdir = lua_tostring(L, -6); 135 | const char *skynet = lua_tostring(L, -5); 136 | const char *config = lua_tostring(L, -4); 137 | const char *service = lua_tostring(L, -3); 138 | bool debug = lua_toboolean(L, -2); 139 | const char *breakpoints = lua_tostring(L, -1); 140 | 141 | int pid = fork(); 142 | if (pid == -1) { 143 | error_exit("fork: %s\n", strerror(errno)); 144 | } else if (pid != 0) { 145 | int state; 146 | if (wait(&state) == -1) 147 | error_exit("wait: %s\n", strerror(errno)); 148 | debuglog("child exit: %d\n", state); 149 | } else { 150 | debuglog("run_skynet\n"); 151 | run_skynet(workdir, skynet, config, service, debug, breakpoints); 152 | } 153 | 154 | lua_close(L); 155 | return 0; 156 | } 157 | -------------------------------------------------------------------------------- /3rd/lua/src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.76.1.1 2017/04/19 17:20:42 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 and variable descriptor. 17 | ** Code generation for variables and expressions can be delayed to allow 18 | ** optimizations; An 'expdesc' structure describes a potentially-delayed 19 | ** variable/expression. It has a description of its "main" value plus a 20 | ** list of conditional jumps that can also produce its value (generated 21 | ** by short-circuit operators 'and'/'or'). 22 | */ 23 | 24 | /* kinds of variables/expressions */ 25 | typedef enum { 26 | VVOID, /* when 'expdesc' describes the last expression a list, 27 | this kind means an empty list (so, no expression) */ 28 | VNIL, /* constant nil */ 29 | VTRUE, /* constant true */ 30 | VFALSE, /* constant false */ 31 | VK, /* constant in 'k'; info = index of constant in 'k' */ 32 | VKFLT, /* floating constant; nval = numerical float value */ 33 | VKINT, /* integer constant; nval = numerical integer value */ 34 | VNONRELOC, /* expression has its value in a fixed register; 35 | info = result register */ 36 | VLOCAL, /* local variable; info = local register */ 37 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ 38 | VINDEXED, /* indexed variable; 39 | ind.vt = whether 't' is register or upvalue; 40 | ind.t = table register or upvalue; 41 | ind.idx = key's R/K index */ 42 | VJMP, /* expression is a test/comparison; 43 | info = pc of corresponding jump instruction */ 44 | VRELOCABLE, /* expression can put result in any register; 45 | info = instruction pc */ 46 | VCALL, /* expression is a function call; info = instruction pc */ 47 | VVARARG /* vararg expression; info = instruction pc */ 48 | } expkind; 49 | 50 | 51 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) 52 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) 53 | 54 | typedef struct expdesc { 55 | expkind k; 56 | union { 57 | lua_Integer ival; /* for VKINT */ 58 | lua_Number nval; /* for VKFLT */ 59 | int info; /* for generic use */ 60 | struct { /* for indexed variables (VINDEXED) */ 61 | short idx; /* index (R/K) */ 62 | lu_byte t; /* table (register or upvalue) */ 63 | lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */ 64 | } ind; 65 | } u; 66 | int t; /* patch list of 'exit when true' */ 67 | int f; /* patch list of 'exit when false' */ 68 | } expdesc; 69 | 70 | 71 | /* description of active local variable */ 72 | typedef struct Vardesc { 73 | short idx; /* variable index in stack */ 74 | } Vardesc; 75 | 76 | 77 | /* description of pending goto statements and label statements */ 78 | typedef struct Labeldesc { 79 | TString *name; /* label identifier */ 80 | int pc; /* position in code */ 81 | int line; /* line where it appeared */ 82 | lu_byte nactvar; /* local level where it appears in current block */ 83 | } Labeldesc; 84 | 85 | 86 | /* list of labels or gotos */ 87 | typedef struct Labellist { 88 | Labeldesc *arr; /* array */ 89 | int n; /* number of entries in use */ 90 | int size; /* array size */ 91 | } Labellist; 92 | 93 | 94 | /* dynamic structures used by the parser */ 95 | typedef struct Dyndata { 96 | struct { /* list of active local variables */ 97 | Vardesc *arr; 98 | int n; 99 | int size; 100 | } actvar; 101 | Labellist gt; /* list of pending gotos */ 102 | Labellist label; /* list of active labels */ 103 | } Dyndata; 104 | 105 | 106 | /* control of blocks */ 107 | struct BlockCnt; /* defined in lparser.c */ 108 | 109 | 110 | /* state needed to generate code for a given function */ 111 | typedef struct FuncState { 112 | Proto *f; /* current function header */ 113 | struct FuncState *prev; /* enclosing function */ 114 | struct LexState *ls; /* lexical state */ 115 | struct BlockCnt *bl; /* chain of current blocks */ 116 | int pc; /* next position to code (equivalent to 'ncode') */ 117 | int lasttarget; /* 'label' of last 'jump label' */ 118 | int jpc; /* list of pending jumps to 'pc' */ 119 | int nk; /* number of elements in 'k' */ 120 | int np; /* number of elements in 'p' */ 121 | int firstlocal; /* index of first local var (in Dyndata array) */ 122 | short nlocvars; /* number of elements in 'f->locvars' */ 123 | lu_byte nactvar; /* number of active local variables */ 124 | lu_byte nups; /* number of upvalues */ 125 | lu_byte freereg; /* first free register */ 126 | } FuncState; 127 | 128 | 129 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 130 | Dyndata *dyd, const char *name, int firstchar); 131 | 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 这是一个 VSCode 的调试插件,用于调试`Skynet`中的Lua程序。 2 | 3 | ## 更新说明 4 | 5 | 最新版的插件增加了工作目录(workdir)的设置,需要配合最新的skynet版本,请看下面的详细说明。 6 | 7 | 如果有用 skynet debugger 1.0.0 版的,升级到 skynet debugger 1.0.1 之后可能无法调试,需作如下处理: 8 | 9 | - 升级到最新的[skynet](https://github.com/colinsusie/skynet) 10 | - 把原工程的 launch.json 删除掉,重新在 VSCode 下创建launch.json,并设置相关的路径。 11 | 12 | ## 构建skynet 13 | 14 | 要想支持调试功能,你必须使用这个skynet版本: 15 | 16 | [https://github.com/colinsusie/skynet](https://github.com/colinsusie/skynet) 17 | 18 | 这个版本和[官方的版本](https://github.com/cloudwu/skynet)完全一致,并且会一直合并最新的修改;由于skynet极其精简的内核,所以实现这个调试器并没有修改框架的代码,只是增加了几个额外的模块。skynet的构建方法请看[WIKI](https://github.com/cloudwu/skynet/wiki/Build)。 19 | 20 | 21 | ## 安装扩展 22 | 23 | 接下来在VSCode的`Extensions`面板中搜索`Skynet Debugger`安装这个插件,**该插件不支持Windows,如果你在Windows下工作,那么可以通过VSCode的[Remote SSH](https://code.visualstudio.com/docs/remote/ssh)打开远程服务器上的skynet工程,然后再安装`Skynet Debugger`,此时插件会安装在服务器上,这样就可以在Windows下编辑和调试服务器上的skynet工程。** 24 | 25 | 插件的发布版只包含了在`Debian GNU/Linux 10 (buster)`和`macOS 10.15.2(Catalina)`下编译的可执行程序,在这两个系统中应该是可以运行起来的。 26 | 27 | 其他平台先试试是否可以调试,如果不能则需要自己重新构建插件的执行程序: 28 | 29 | - 克隆代码:`git clone https://github.com/colinsusie/skynetda.git` 30 | - 构建:`cd skynetda; make linux` 31 | - 完成之后在`vscext/bin/linux`中有`skynetda`和`cjson.so`两个文件,需要将这两个文件拷贝到插件的安装目录去: 32 | - 如果是SSH远程服务器,插件目录应该在:`~/.vscode-server/extensions/colinsusie.skynet-debugger-x.x.x/bin/linux/` 33 | - 如果是本地Linux,则应该在:`~/.vscode/extensions/colinsusie.skynet-debugger-x.x.x/bin/linux/` 34 | - 如果是MacOS,则应该是:`~/.vscode/extensions/colinsusie.skynet-debugger-x.x.x/bin/macosx/` 35 | - 上面的x.x.x替换为具体的版本号 36 | 37 | ## 配置launch.json 38 | 39 | 插件安装完毕之后,用VSCode打开skynet工程,在`Run and Debug`面板中创建一个`launch.json`文件,内容如下: 40 | 41 | ```json 42 | { 43 | "name": "skynet debugger", 44 | "type": "lua", 45 | "request": "launch", 46 | "workdir": "${workspaceFolder}", 47 | "program": "./skynet", 48 | "config": "./examples/config_vsc", 49 | "service": "./service" 50 | } 51 | ``` 52 | 53 | - `workdir` 是当前的工作目录,默认为 VSCode 打开的这个目录;这个目录就是程序运行起来的工作目录。 54 | - `program` 是skynet可执行程序的路径,相对于workdir;也可以用绝对路径。注意是可执行文件的路径,不是目录;这和旧版本的含义不同。 55 | - `config` 是skynet运行的配置文件,相对于workdir;也可以用绝对路径。 56 | - `service` 是skynet内部服务的路径,相对于workdir,配置这个是为了过滤掉skynet内部服务的调试。 57 | 58 | config_vsc文件的内容如下: 59 | 60 | ```lua 61 | root = "./" 62 | thread = 4 63 | logger = "vscdebuglog" -- 将默认logger指定为`vscdebuglog` 64 | logservice = "snlua" 65 | 66 | logpath = "." 67 | harbor = 0 68 | start = "testvscdebug" -- main script 69 | bootstrap = "snlua bootstrap" -- The service for bootstrap 70 | 71 | luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua;"..root.."test/?/init.lua" 72 | lualoader = root .. "lualib/loader.lua" 73 | lua_path = root.."lualib/?.lua;"..root.."lualib/?/init.lua" 74 | lua_cpath = root .. "luaclib/?.so" 75 | snax = root.."examples/?.lua;"..root.."test/?.lua" 76 | cpath = root.."cservice/?.so" 77 | ``` 78 | 79 | - 指定 logger 为 vscdebuglog,这样在 VSCode 的 `DEBUG CONSOLE` 才能看到日志输出。 80 | - root 为skynet的根目录,这个目录是相对于上面 workdir 的。 81 | - 这一份配置一般用于开发期的调试使用,发布的版本要用正式的config。 82 | 83 | ## 开始调试 84 | 85 | 到这里准备工作已经完毕,你可以在代码(比如:testvscdebug)中设置断点,然后按`F5`开始调试,效果如下图所示: 86 | 87 | ![sn1.png](vscext/images/sn1.png) 88 | 89 | 该插件只能调试外部写的服务,`skynet/sevice` 目录中的服务不可调试。 90 | 91 | 如果F5之后没有成功调试,你可以CD到插件目录,比如: 92 | 93 | - `~/.vscode-server/extensions/colinsusie.skynet-debugger-x.x.x/bin/linux/` 或 94 | - `~/.vscode/extensions/colinsusie.skynet-debugger-x.x.x/bin/linux/`或 95 | - `~/.vscode/extensions/colinsusie.skynet-debugger-x.x.x/bin/macosx/` 96 | 97 | 里面有一个debug.log文件,查看里面的文件,查找错误原因。 98 | 99 | ## vscdebug的功能 100 | 101 | vscdebug实现了大多数常用的调试功能: 102 | 103 | - 它可以将skynet.error输出到`DEBUG CONSOLE`面板,点击日志还可跳转到相应的代码行;但是`print, io.stdout`就不行,调用这两个函数什么也不会输出。 104 | - 除了可以设置普通断点外,还支持以下几种断点: 105 | - 条件断点:当表达式为true时停下来。 106 | - Hit Count断点:命中一定次数后停下来。 107 | - 日志断点:命中时输出日志。 108 | - 当程序命中断点后停了下来,你就可以: 109 | - 查看调用堆栈。 110 | - 查看每一层栈帧的局部变量,自由变量。 111 | - 通过`WATCH`面板增加监控的表达式。 112 | - 可在`DEBUG CONSOLE`底部输入表达式,该表达式会在当前栈帧环境中执行,并得到结果输出。 113 | - 支持`Step into`, `Step over`, `Step out`, `Continue`等调试命令。 114 | 115 | ## vscdebug怎么工作 116 | 117 | 编写skynet调试器的难点在于:skynet里面有很多个Lua虚拟机,并且这些虚拟机是在多个线程中运行的。要像原生调试器那样把整个程序冻住似乎有些难度,我最后决定像skynet的`DebugConsole`那样,让它在同一时刻只能调试Lua服务的一个协程,除了这个被调试的协程会停住,其他协程还是照常执行。所以断点命中后,看起来像是停下来了,其实它还在快速的处理消息。 118 | 119 | 它的实现是这样的:当一个协程的调试Hook回调时,如果命中断点,那么Hook函数会调用lua_yield停掉这个协程;接下来就可以对这个协程进行各种”观察”。此后执行`单步调试`,会使该协程执行一行后又被yield,如此重复,直到执行`继续`命令。 120 | 121 | 由于Lua服务的主协程不能yield,所以主协程不可以调试。但这个限制没什么大问题,因为skynet的主协程主要用于派发消息,具体的消息处理都在其他协程完成的。 122 | 123 | 在开发过程中,我发现了Lua的一个BUG,就是被Hook函数调用lua_yield的协程,它的CallInfo的savedpc会往前退一条指令,这就导致那一层的行数和局部变量不正确,修正方法是在`ldebug.c`: 124 | 125 | ```c 126 | static int currentpc (CallInfo *ci) { 127 | lua_assert(isLua(ci)); 128 | // 如果处于CIST_HOOKYIELD状态,应该加1。 129 | const Instruction *pc = (ci->callstatus & CIST_HOOKYIELD) ? ci->u.l.savedpc + 1 : ci->u.l.savedpc; 130 | return pcRel(pc, ci_func(ci)->p); 131 | } 132 | ``` 133 | 134 | 修改后问题解决了,这也是唯一修改过的底层代码。 135 | 136 | Enjoy!!! 137 | -------------------------------------------------------------------------------- /3rd/lua-cjson/strbuf.h: -------------------------------------------------------------------------------- 1 | /* strbuf - String buffer routines 2 | * 3 | * Copyright (c) 2010-2012 Mark Pulford 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | /* Size: Total bytes allocated to *buf 29 | * Length: String length, excluding optional NULL terminator. 30 | * Increment: Allocation increments when resizing the string buffer. 31 | * Dynamic: True if created via strbuf_new() 32 | */ 33 | 34 | typedef struct { 35 | char *buf; 36 | int size; 37 | int length; 38 | int increment; 39 | int dynamic; 40 | int reallocs; 41 | int debug; 42 | } strbuf_t; 43 | 44 | #ifndef STRBUF_DEFAULT_SIZE 45 | #define STRBUF_DEFAULT_SIZE 1023 46 | #endif 47 | #ifndef STRBUF_DEFAULT_INCREMENT 48 | #define STRBUF_DEFAULT_INCREMENT -2 49 | #endif 50 | 51 | /* Initialise */ 52 | extern strbuf_t *strbuf_new(int len); 53 | extern void strbuf_init(strbuf_t *s, int len); 54 | extern void strbuf_set_increment(strbuf_t *s, int increment); 55 | 56 | /* Release */ 57 | extern void strbuf_free(strbuf_t *s); 58 | extern char *strbuf_free_to_string(strbuf_t *s, int *len); 59 | 60 | /* Management */ 61 | extern void strbuf_resize(strbuf_t *s, int len); 62 | static int strbuf_empty_length(strbuf_t *s); 63 | static int strbuf_length(strbuf_t *s); 64 | static char *strbuf_string(strbuf_t *s, int *len); 65 | static void strbuf_ensure_empty_length(strbuf_t *s, int len); 66 | static char *strbuf_empty_ptr(strbuf_t *s); 67 | static void strbuf_extend_length(strbuf_t *s, int len); 68 | 69 | /* Update */ 70 | extern void strbuf_append_fmt(strbuf_t *s, int len, const char *fmt, ...); 71 | extern void strbuf_append_fmt_retry(strbuf_t *s, const char *format, ...); 72 | static void strbuf_append_mem(strbuf_t *s, const char *c, int len); 73 | extern void strbuf_append_string(strbuf_t *s, const char *str); 74 | static void strbuf_append_char(strbuf_t *s, const char c); 75 | static void strbuf_ensure_null(strbuf_t *s); 76 | 77 | /* Reset string for before use */ 78 | static inline void strbuf_reset(strbuf_t *s) 79 | { 80 | s->length = 0; 81 | } 82 | 83 | static inline int strbuf_allocated(strbuf_t *s) 84 | { 85 | return s->buf != NULL; 86 | } 87 | 88 | /* Return bytes remaining in the string buffer 89 | * Ensure there is space for a NULL terminator. */ 90 | static inline int strbuf_empty_length(strbuf_t *s) 91 | { 92 | return s->size - s->length - 1; 93 | } 94 | 95 | static inline void strbuf_ensure_empty_length(strbuf_t *s, int len) 96 | { 97 | if (len > strbuf_empty_length(s)) 98 | strbuf_resize(s, s->length + len); 99 | } 100 | 101 | static inline char *strbuf_empty_ptr(strbuf_t *s) 102 | { 103 | return s->buf + s->length; 104 | } 105 | 106 | static inline void strbuf_extend_length(strbuf_t *s, int len) 107 | { 108 | s->length += len; 109 | } 110 | 111 | static inline int strbuf_length(strbuf_t *s) 112 | { 113 | return s->length; 114 | } 115 | 116 | static inline void strbuf_append_char(strbuf_t *s, const char c) 117 | { 118 | strbuf_ensure_empty_length(s, 1); 119 | s->buf[s->length++] = c; 120 | } 121 | 122 | static inline void strbuf_append_char_unsafe(strbuf_t *s, const char c) 123 | { 124 | s->buf[s->length++] = c; 125 | } 126 | 127 | static inline void strbuf_append_mem(strbuf_t *s, const char *c, int len) 128 | { 129 | strbuf_ensure_empty_length(s, len); 130 | memcpy(s->buf + s->length, c, len); 131 | s->length += len; 132 | } 133 | 134 | static inline void strbuf_append_mem_unsafe(strbuf_t *s, const char *c, int len) 135 | { 136 | memcpy(s->buf + s->length, c, len); 137 | s->length += len; 138 | } 139 | 140 | static inline void strbuf_ensure_null(strbuf_t *s) 141 | { 142 | s->buf[s->length] = 0; 143 | } 144 | 145 | static inline char *strbuf_string(strbuf_t *s, int *len) 146 | { 147 | if (len) 148 | *len = s->length; 149 | 150 | return s->buf; 151 | } 152 | 153 | /* vi:ai et sw=4 ts=4: 154 | */ 155 | -------------------------------------------------------------------------------- /3rd/lua/src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 2.91.1.1 2017/04/19 17:39:34 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 | /* 105 | ** Does one step of collection when debt becomes positive. 'pre'/'pos' 106 | ** allows some adjustments to be done only when needed. macro 107 | ** 'condchangemem' is used only for heavy tests (forcing a full 108 | ** GC cycle on every opportunity) 109 | */ 110 | #define luaC_condGC(L,pre,pos) \ 111 | { if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \ 112 | condchangemem(L,pre,pos); } 113 | 114 | /* more often than not, 'pre'/'pos' are empty */ 115 | #define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0) 116 | 117 | 118 | #define luaC_barrier(L,p,v) ( \ 119 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 120 | luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0)) 121 | 122 | #define luaC_barrierback(L,p,v) ( \ 123 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 124 | luaC_barrierback_(L,p) : cast_void(0)) 125 | 126 | #define luaC_objbarrier(L,p,o) ( \ 127 | (isblack(p) && iswhite(o)) ? \ 128 | luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0)) 129 | 130 | #define luaC_upvalbarrier(L,uv) ( \ 131 | (iscollectable((uv)->v) && !upisopen(uv)) ? \ 132 | luaC_upvalbarrier_(L,uv) : cast_void(0)) 133 | 134 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 135 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); 136 | LUAI_FUNC void luaC_step (lua_State *L); 137 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 138 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 139 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 140 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 141 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o); 142 | LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); 143 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 144 | LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); 145 | 146 | 147 | #endif 148 | -------------------------------------------------------------------------------- /3rd/lua/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.38.1.1 2017/04/19 17:39:34 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_getshortstr(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_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject); 83 | } 84 | 85 | 86 | /* 87 | ** Return the name of the type of an object. For tables and userdata 88 | ** with metatable, use their '__name' metafield, if present. 89 | */ 90 | const char *luaT_objtypename (lua_State *L, const TValue *o) { 91 | Table *mt; 92 | if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) || 93 | (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) { 94 | const TValue *name = luaH_getshortstr(mt, luaS_new(L, "__name")); 95 | if (ttisstring(name)) /* is '__name' a string? */ 96 | return getstr(tsvalue(name)); /* use it as type name */ 97 | } 98 | return ttypename(ttnov(o)); /* else use standard type name */ 99 | } 100 | 101 | 102 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 103 | const TValue *p2, TValue *p3, int hasres) { 104 | ptrdiff_t result = savestack(L, p3); 105 | StkId func = L->top; 106 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 107 | setobj2s(L, func + 1, p1); /* 1st argument */ 108 | setobj2s(L, func + 2, p2); /* 2nd argument */ 109 | L->top += 3; 110 | if (!hasres) /* no result? 'p3' is third argument */ 111 | setobj2s(L, L->top++, p3); /* 3rd argument */ 112 | /* metamethod may yield only when called from Lua code */ 113 | if (isLua(L->ci)) 114 | luaD_call(L, func, hasres); 115 | else 116 | luaD_callnoyield(L, func, hasres); 117 | if (hasres) { /* if has result, move it to its place */ 118 | p3 = restorestack(L, result); 119 | setobjs2s(L, p3, --L->top); 120 | } 121 | } 122 | 123 | 124 | int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 125 | StkId res, TMS event) { 126 | const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ 127 | if (ttisnil(tm)) 128 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ 129 | if (ttisnil(tm)) return 0; 130 | luaT_callTM(L, tm, p1, p2, res, 1); 131 | return 1; 132 | } 133 | 134 | 135 | void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 136 | StkId res, TMS event) { 137 | if (!luaT_callbinTM(L, p1, p2, res, event)) { 138 | switch (event) { 139 | case TM_CONCAT: 140 | luaG_concaterror(L, p1, p2); 141 | /* call never returns, but to avoid warnings: *//* FALLTHROUGH */ 142 | case TM_BAND: case TM_BOR: case TM_BXOR: 143 | case TM_SHL: case TM_SHR: case TM_BNOT: { 144 | lua_Number dummy; 145 | if (tonumber(p1, &dummy) && tonumber(p2, &dummy)) 146 | luaG_tointerror(L, p1, p2); 147 | else 148 | luaG_opinterror(L, p1, p2, "perform bitwise operation on"); 149 | } 150 | /* calls never return, but to avoid warnings: *//* FALLTHROUGH */ 151 | default: 152 | luaG_opinterror(L, p1, p2, "perform arithmetic on"); 153 | } 154 | } 155 | } 156 | 157 | 158 | int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 159 | TMS event) { 160 | if (!luaT_callbinTM(L, p1, p2, L->top, event)) 161 | return -1; /* no metamethod */ 162 | else 163 | return !l_isfalse(L->top); 164 | } 165 | 166 | -------------------------------------------------------------------------------- /3rd/lua/src/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c,v 2.37.1.1 2017/04/19 17:20:42 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 && size > 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 = tsslen(s) + 1; /* include trailing '\0' */ 78 | const char *str = getstr(s); 79 | if (size < 0xFF) 80 | DumpByte(cast_int(size), D); 81 | else { 82 | DumpByte(0xFF, D); 83 | DumpVar(size, D); 84 | } 85 | DumpVector(str, size - 1, D); /* no need to save '\0' */ 86 | } 87 | } 88 | 89 | 90 | static void DumpCode (const Proto *f, DumpState *D) { 91 | DumpInt(f->sizecode, D); 92 | DumpVector(f->code, f->sizecode, D); 93 | } 94 | 95 | 96 | static void DumpFunction(const Proto *f, TString *psource, DumpState *D); 97 | 98 | static void DumpConstants (const Proto *f, DumpState *D) { 99 | int i; 100 | int n = f->sizek; 101 | DumpInt(n, D); 102 | for (i = 0; i < n; i++) { 103 | const TValue *o = &f->k[i]; 104 | DumpByte(ttype(o), D); 105 | switch (ttype(o)) { 106 | case LUA_TNIL: 107 | break; 108 | case LUA_TBOOLEAN: 109 | DumpByte(bvalue(o), D); 110 | break; 111 | case LUA_TNUMFLT: 112 | DumpNumber(fltvalue(o), D); 113 | break; 114 | case LUA_TNUMINT: 115 | DumpInteger(ivalue(o), D); 116 | break; 117 | case LUA_TSHRSTR: 118 | case LUA_TLNGSTR: 119 | DumpString(tsvalue(o), D); 120 | break; 121 | default: 122 | lua_assert(0); 123 | } 124 | } 125 | } 126 | 127 | 128 | static void DumpProtos (const Proto *f, DumpState *D) { 129 | int i; 130 | int n = f->sizep; 131 | DumpInt(n, D); 132 | for (i = 0; i < n; i++) 133 | DumpFunction(f->p[i], f->source, D); 134 | } 135 | 136 | 137 | static void DumpUpvalues (const Proto *f, DumpState *D) { 138 | int i, n = f->sizeupvalues; 139 | DumpInt(n, D); 140 | for (i = 0; i < n; i++) { 141 | DumpByte(f->upvalues[i].instack, D); 142 | DumpByte(f->upvalues[i].idx, D); 143 | } 144 | } 145 | 146 | 147 | static void DumpDebug (const Proto *f, DumpState *D) { 148 | int i, n; 149 | n = (D->strip) ? 0 : f->sizelineinfo; 150 | DumpInt(n, D); 151 | DumpVector(f->lineinfo, n, D); 152 | n = (D->strip) ? 0 : f->sizelocvars; 153 | DumpInt(n, D); 154 | for (i = 0; i < n; i++) { 155 | DumpString(f->locvars[i].varname, D); 156 | DumpInt(f->locvars[i].startpc, D); 157 | DumpInt(f->locvars[i].endpc, D); 158 | } 159 | n = (D->strip) ? 0 : f->sizeupvalues; 160 | DumpInt(n, D); 161 | for (i = 0; i < n; i++) 162 | DumpString(f->upvalues[i].name, D); 163 | } 164 | 165 | 166 | static void DumpFunction (const Proto *f, TString *psource, DumpState *D) { 167 | if (D->strip || f->source == psource) 168 | DumpString(NULL, D); /* no debug info or same source as its parent */ 169 | else 170 | DumpString(f->source, D); 171 | DumpInt(f->linedefined, D); 172 | DumpInt(f->lastlinedefined, D); 173 | DumpByte(f->numparams, D); 174 | DumpByte(f->is_vararg, D); 175 | DumpByte(f->maxstacksize, D); 176 | DumpCode(f, D); 177 | DumpConstants(f, D); 178 | DumpUpvalues(f, D); 179 | DumpProtos(f, D); 180 | DumpDebug(f, D); 181 | } 182 | 183 | 184 | static void DumpHeader (DumpState *D) { 185 | DumpLiteral(LUA_SIGNATURE, D); 186 | DumpByte(LUAC_VERSION, D); 187 | DumpByte(LUAC_FORMAT, D); 188 | DumpLiteral(LUAC_DATA, D); 189 | DumpByte(sizeof(int), D); 190 | DumpByte(sizeof(size_t), D); 191 | DumpByte(sizeof(Instruction), D); 192 | DumpByte(sizeof(lua_Integer), D); 193 | DumpByte(sizeof(lua_Number), D); 194 | DumpInteger(LUAC_INT, D); 195 | DumpNumber(LUAC_NUM, D); 196 | } 197 | 198 | 199 | /* 200 | ** dump Lua function as precompiled chunk 201 | */ 202 | int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, 203 | int strip) { 204 | DumpState D; 205 | D.L = L; 206 | D.writer = w; 207 | D.data = data; 208 | D.strip = strip; 209 | D.status = 0; 210 | DumpHeader(&D); 211 | DumpByte(f->sizeupvalues, &D); 212 | DumpFunction(f, NULL, &D); 213 | return D.status; 214 | } 215 | 216 | -------------------------------------------------------------------------------- /3rd/lua/src/lbitlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lbitlib.c,v 1.30.1.1 2017/04/19 17:20:42 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 | #define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n)) 23 | #define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i)) 24 | 25 | 26 | /* number of bits to consider in a number */ 27 | #if !defined(LUA_NBITS) 28 | #define LUA_NBITS 32 29 | #endif 30 | 31 | 32 | /* 33 | ** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must 34 | ** be made in two parts to avoid problems when LUA_NBITS is equal to the 35 | ** number of bits in a lua_Unsigned.) 36 | */ 37 | #define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) 38 | 39 | 40 | /* macro to trim extra bits */ 41 | #define trim(x) ((x) & ALLONES) 42 | 43 | 44 | /* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ 45 | #define mask(n) (~((ALLONES << 1) << ((n) - 1))) 46 | 47 | 48 | 49 | static lua_Unsigned andaux (lua_State *L) { 50 | int i, n = lua_gettop(L); 51 | lua_Unsigned r = ~(lua_Unsigned)0; 52 | for (i = 1; i <= n; i++) 53 | r &= checkunsigned(L, i); 54 | return trim(r); 55 | } 56 | 57 | 58 | static int b_and (lua_State *L) { 59 | lua_Unsigned r = andaux(L); 60 | pushunsigned(L, r); 61 | return 1; 62 | } 63 | 64 | 65 | static int b_test (lua_State *L) { 66 | lua_Unsigned r = andaux(L); 67 | lua_pushboolean(L, r != 0); 68 | return 1; 69 | } 70 | 71 | 72 | static int b_or (lua_State *L) { 73 | int i, n = lua_gettop(L); 74 | lua_Unsigned r = 0; 75 | for (i = 1; i <= n; i++) 76 | r |= checkunsigned(L, i); 77 | pushunsigned(L, trim(r)); 78 | return 1; 79 | } 80 | 81 | 82 | static int b_xor (lua_State *L) { 83 | int i, n = lua_gettop(L); 84 | lua_Unsigned r = 0; 85 | for (i = 1; i <= n; i++) 86 | r ^= checkunsigned(L, i); 87 | pushunsigned(L, trim(r)); 88 | return 1; 89 | } 90 | 91 | 92 | static int b_not (lua_State *L) { 93 | lua_Unsigned r = ~checkunsigned(L, 1); 94 | pushunsigned(L, trim(r)); 95 | return 1; 96 | } 97 | 98 | 99 | static int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) { 100 | if (i < 0) { /* shift right? */ 101 | i = -i; 102 | r = trim(r); 103 | if (i >= LUA_NBITS) r = 0; 104 | else r >>= i; 105 | } 106 | else { /* shift left */ 107 | if (i >= LUA_NBITS) r = 0; 108 | else r <<= i; 109 | r = trim(r); 110 | } 111 | pushunsigned(L, r); 112 | return 1; 113 | } 114 | 115 | 116 | static int b_lshift (lua_State *L) { 117 | return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2)); 118 | } 119 | 120 | 121 | static int b_rshift (lua_State *L) { 122 | return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2)); 123 | } 124 | 125 | 126 | static int b_arshift (lua_State *L) { 127 | lua_Unsigned r = checkunsigned(L, 1); 128 | lua_Integer i = luaL_checkinteger(L, 2); 129 | if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1)))) 130 | return b_shift(L, r, -i); 131 | else { /* arithmetic shift for 'negative' number */ 132 | if (i >= LUA_NBITS) r = ALLONES; 133 | else 134 | r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i)); /* add signal bit */ 135 | pushunsigned(L, r); 136 | return 1; 137 | } 138 | } 139 | 140 | 141 | static int b_rot (lua_State *L, lua_Integer d) { 142 | lua_Unsigned r = checkunsigned(L, 1); 143 | int i = d & (LUA_NBITS - 1); /* i = d % NBITS */ 144 | r = trim(r); 145 | if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ 146 | r = (r << i) | (r >> (LUA_NBITS - i)); 147 | pushunsigned(L, trim(r)); 148 | return 1; 149 | } 150 | 151 | 152 | static int b_lrot (lua_State *L) { 153 | return b_rot(L, luaL_checkinteger(L, 2)); 154 | } 155 | 156 | 157 | static int b_rrot (lua_State *L) { 158 | return b_rot(L, -luaL_checkinteger(L, 2)); 159 | } 160 | 161 | 162 | /* 163 | ** get field and width arguments for field-manipulation functions, 164 | ** checking whether they are valid. 165 | ** ('luaL_error' called without 'return' to avoid later warnings about 166 | ** 'width' being used uninitialized.) 167 | */ 168 | static int fieldargs (lua_State *L, int farg, int *width) { 169 | lua_Integer f = luaL_checkinteger(L, farg); 170 | lua_Integer w = luaL_optinteger(L, farg + 1, 1); 171 | luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); 172 | luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); 173 | if (f + w > LUA_NBITS) 174 | luaL_error(L, "trying to access non-existent bits"); 175 | *width = (int)w; 176 | return (int)f; 177 | } 178 | 179 | 180 | static int b_extract (lua_State *L) { 181 | int w; 182 | lua_Unsigned r = trim(checkunsigned(L, 1)); 183 | int f = fieldargs(L, 2, &w); 184 | r = (r >> f) & mask(w); 185 | pushunsigned(L, r); 186 | return 1; 187 | } 188 | 189 | 190 | static int b_replace (lua_State *L) { 191 | int w; 192 | lua_Unsigned r = trim(checkunsigned(L, 1)); 193 | lua_Unsigned v = trim(checkunsigned(L, 2)); 194 | int f = fieldargs(L, 3, &w); 195 | lua_Unsigned m = mask(w); 196 | r = (r & ~(m << f)) | ((v & m) << f); 197 | pushunsigned(L, r); 198 | return 1; 199 | } 200 | 201 | 202 | static const luaL_Reg bitlib[] = { 203 | {"arshift", b_arshift}, 204 | {"band", b_and}, 205 | {"bnot", b_not}, 206 | {"bor", b_or}, 207 | {"bxor", b_xor}, 208 | {"btest", b_test}, 209 | {"extract", b_extract}, 210 | {"lrotate", b_lrot}, 211 | {"lshift", b_lshift}, 212 | {"replace", b_replace}, 213 | {"rrotate", b_rrot}, 214 | {"rshift", b_rshift}, 215 | {NULL, NULL} 216 | }; 217 | 218 | 219 | 220 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 221 | luaL_newlib(L, bitlib); 222 | return 1; 223 | } 224 | 225 | 226 | #else /* }{ */ 227 | 228 | 229 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 230 | return luaL_error(L, "library 'bit32' has been deprecated"); 231 | } 232 | 233 | #endif /* } */ 234 | -------------------------------------------------------------------------------- /3rd/lua-cjson/fpconv.c: -------------------------------------------------------------------------------- 1 | /* fpconv - Floating point conversion routines 2 | * 3 | * Copyright (c) 2011-2012 Mark Pulford 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /* JSON uses a '.' decimal separator. strtod() / sprintf() under C libraries 26 | * with locale support will break when the decimal separator is a comma. 27 | * 28 | * fpconv_* will around these issues with a translation buffer if required. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "fpconv.h" 37 | 38 | /* Lua CJSON assumes the locale is the same for all threads within a 39 | * process and doesn't change after initialisation. 40 | * 41 | * This avoids the need for per thread storage or expensive checks 42 | * for call. */ 43 | static char locale_decimal_point = '.'; 44 | 45 | /* In theory multibyte decimal_points are possible, but 46 | * Lua CJSON only supports UTF-8 and known locales only have 47 | * single byte decimal points ([.,]). 48 | * 49 | * localconv() may not be thread safe (=>crash), and nl_langinfo() is 50 | * not supported on some platforms. Use sprintf() instead - if the 51 | * locale does change, at least Lua CJSON won't crash. */ 52 | static void fpconv_update_locale() 53 | { 54 | char buf[8]; 55 | 56 | snprintf(buf, sizeof(buf), "%g", 0.5); 57 | 58 | /* Failing this test might imply the platform has a buggy dtoa 59 | * implementation or wide characters */ 60 | if (buf[0] != '0' || buf[2] != '5' || buf[3] != 0) { 61 | fprintf(stderr, "Error: wide characters found or printf() bug."); 62 | abort(); 63 | } 64 | 65 | locale_decimal_point = buf[1]; 66 | } 67 | 68 | /* Check for a valid number character: [-+0-9a-yA-Y.] 69 | * Eg: -0.6e+5, infinity, 0xF0.F0pF0 70 | * 71 | * Used to find the probable end of a number. It doesn't matter if 72 | * invalid characters are counted - strtod() will find the valid 73 | * number if it exists. The risk is that slightly more memory might 74 | * be allocated before a parse error occurs. */ 75 | static inline int valid_number_character(char ch) 76 | { 77 | char lower_ch; 78 | 79 | if ('0' <= ch && ch <= '9') 80 | return 1; 81 | if (ch == '-' || ch == '+' || ch == '.') 82 | return 1; 83 | 84 | /* Hex digits, exponent (e), base (p), "infinity",.. */ 85 | lower_ch = ch | 0x20; 86 | if ('a' <= lower_ch && lower_ch <= 'y') 87 | return 1; 88 | 89 | return 0; 90 | } 91 | 92 | /* Calculate the size of the buffer required for a strtod locale 93 | * conversion. */ 94 | static int strtod_buffer_size(const char *s) 95 | { 96 | const char *p = s; 97 | 98 | while (valid_number_character(*p)) 99 | p++; 100 | 101 | return p - s; 102 | } 103 | 104 | /* Similar to strtod(), but must be passed the current locale's decimal point 105 | * character. Guaranteed to be called at the start of any valid number in a string */ 106 | double fpconv_strtod(const char *nptr, char **endptr) 107 | { 108 | char localbuf[FPCONV_G_FMT_BUFSIZE]; 109 | char *buf, *endbuf, *dp; 110 | int buflen; 111 | double value; 112 | 113 | /* System strtod() is fine when decimal point is '.' */ 114 | if (locale_decimal_point == '.') 115 | return strtod(nptr, endptr); 116 | 117 | buflen = strtod_buffer_size(nptr); 118 | if (!buflen) { 119 | /* No valid characters found, standard strtod() return */ 120 | *endptr = (char *)nptr; 121 | return 0; 122 | } 123 | 124 | /* Duplicate number into buffer */ 125 | if (buflen >= FPCONV_G_FMT_BUFSIZE) { 126 | /* Handle unusually large numbers */ 127 | buf = (char *)malloc(buflen + 1); 128 | if (!buf) { 129 | fprintf(stderr, "Out of memory"); 130 | abort(); 131 | } 132 | } else { 133 | /* This is the common case.. */ 134 | buf = localbuf; 135 | } 136 | memcpy(buf, nptr, buflen); 137 | buf[buflen] = 0; 138 | 139 | /* Update decimal point character if found */ 140 | dp = strchr(buf, '.'); 141 | if (dp) 142 | *dp = locale_decimal_point; 143 | 144 | value = strtod(buf, &endbuf); 145 | *endptr = (char *)&nptr[endbuf - buf]; 146 | if (buflen >= FPCONV_G_FMT_BUFSIZE) 147 | free(buf); 148 | 149 | return value; 150 | } 151 | 152 | /* "fmt" must point to a buffer of at least 6 characters */ 153 | static void set_number_format(char *fmt, int precision) 154 | { 155 | int d1, d2, i; 156 | 157 | assert(1 <= precision && precision <= 14); 158 | 159 | /* Create printf format (%.14g) from precision */ 160 | d1 = precision / 10; 161 | d2 = precision % 10; 162 | fmt[0] = '%'; 163 | fmt[1] = '.'; 164 | i = 2; 165 | if (d1) { 166 | fmt[i++] = '0' + d1; 167 | } 168 | fmt[i++] = '0' + d2; 169 | fmt[i++] = 'g'; 170 | fmt[i] = 0; 171 | } 172 | 173 | /* Assumes there is always at least 32 characters available in the target buffer */ 174 | int fpconv_g_fmt(char *str, double num, int precision) 175 | { 176 | char buf[FPCONV_G_FMT_BUFSIZE]; 177 | char fmt[6]; 178 | int len; 179 | char *b; 180 | 181 | set_number_format(fmt, precision); 182 | 183 | /* Pass through when decimal point character is dot. */ 184 | if (locale_decimal_point == '.') 185 | return snprintf(str, FPCONV_G_FMT_BUFSIZE, fmt, num); 186 | 187 | /* snprintf() to a buffer then translate for other decimal point characters */ 188 | len = snprintf(buf, FPCONV_G_FMT_BUFSIZE, fmt, num); 189 | 190 | /* Copy into target location. Translate decimal point if required */ 191 | b = buf; 192 | do { 193 | *str++ = (*b == locale_decimal_point ? '.' : *b); 194 | } while(*b++); 195 | 196 | return len; 197 | } 198 | 199 | void fpconv_init() 200 | { 201 | fpconv_update_locale(); 202 | } 203 | 204 | /* vi:ai et sw=4 ts=4: 205 | */ 206 | -------------------------------------------------------------------------------- /3rd/lua-cjson/strbuf.c: -------------------------------------------------------------------------------- 1 | /* strbuf - String buffer routines 2 | * 3 | * Copyright (c) 2010-2012 Mark Pulford 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "strbuf.h" 31 | 32 | static void die(const char *fmt, ...) 33 | { 34 | va_list arg; 35 | 36 | va_start(arg, fmt); 37 | vfprintf(stderr, fmt, arg); 38 | va_end(arg); 39 | fprintf(stderr, "\n"); 40 | 41 | exit(-1); 42 | } 43 | 44 | void strbuf_init(strbuf_t *s, int len) 45 | { 46 | int size; 47 | 48 | if (len <= 0) 49 | size = STRBUF_DEFAULT_SIZE; 50 | else 51 | size = len + 1; /* \0 terminator */ 52 | 53 | s->buf = NULL; 54 | s->size = size; 55 | s->length = 0; 56 | s->increment = STRBUF_DEFAULT_INCREMENT; 57 | s->dynamic = 0; 58 | s->reallocs = 0; 59 | s->debug = 0; 60 | 61 | s->buf = (char *)malloc(size); 62 | if (!s->buf) 63 | die("Out of memory"); 64 | 65 | strbuf_ensure_null(s); 66 | } 67 | 68 | strbuf_t *strbuf_new(int len) 69 | { 70 | strbuf_t *s; 71 | 72 | s = (strbuf_t*)malloc(sizeof(strbuf_t)); 73 | if (!s) 74 | die("Out of memory"); 75 | 76 | strbuf_init(s, len); 77 | 78 | /* Dynamic strbuf allocation / deallocation */ 79 | s->dynamic = 1; 80 | 81 | return s; 82 | } 83 | 84 | void strbuf_set_increment(strbuf_t *s, int increment) 85 | { 86 | /* Increment > 0: Linear buffer growth rate 87 | * Increment < -1: Exponential buffer growth rate */ 88 | if (increment == 0 || increment == -1) 89 | die("BUG: Invalid string increment"); 90 | 91 | s->increment = increment; 92 | } 93 | 94 | static inline void debug_stats(strbuf_t *s) 95 | { 96 | if (s->debug) { 97 | fprintf(stderr, "strbuf(%lx) reallocs: %d, length: %d, size: %d\n", 98 | (long)s, s->reallocs, s->length, s->size); 99 | } 100 | } 101 | 102 | /* If strbuf_t has not been dynamically allocated, strbuf_free() can 103 | * be called any number of times strbuf_init() */ 104 | void strbuf_free(strbuf_t *s) 105 | { 106 | debug_stats(s); 107 | 108 | if (s->buf) { 109 | free(s->buf); 110 | s->buf = NULL; 111 | } 112 | if (s->dynamic) 113 | free(s); 114 | } 115 | 116 | char *strbuf_free_to_string(strbuf_t *s, int *len) 117 | { 118 | char *buf; 119 | 120 | debug_stats(s); 121 | 122 | strbuf_ensure_null(s); 123 | 124 | buf = s->buf; 125 | if (len) 126 | *len = s->length; 127 | 128 | if (s->dynamic) 129 | free(s); 130 | 131 | return buf; 132 | } 133 | 134 | static int calculate_new_size(strbuf_t *s, int len) 135 | { 136 | int reqsize, newsize; 137 | 138 | if (len <= 0) 139 | die("BUG: Invalid strbuf length requested"); 140 | 141 | /* Ensure there is room for optional NULL termination */ 142 | reqsize = len + 1; 143 | 144 | /* If the user has requested to shrink the buffer, do it exactly */ 145 | if (s->size > reqsize) 146 | return reqsize; 147 | 148 | newsize = s->size; 149 | if (s->increment < 0) { 150 | /* Exponential sizing */ 151 | while (newsize < reqsize) 152 | newsize *= -s->increment; 153 | } else { 154 | /* Linear sizing */ 155 | newsize = ((newsize + s->increment - 1) / s->increment) * s->increment; 156 | } 157 | 158 | return newsize; 159 | } 160 | 161 | 162 | /* Ensure strbuf can handle a string length bytes long (ignoring NULL 163 | * optional termination). */ 164 | void strbuf_resize(strbuf_t *s, int len) 165 | { 166 | int newsize; 167 | 168 | newsize = calculate_new_size(s, len); 169 | 170 | if (s->debug > 1) { 171 | fprintf(stderr, "strbuf(%lx) resize: %d => %d\n", 172 | (long)s, s->size, newsize); 173 | } 174 | 175 | s->size = newsize; 176 | s->buf = (char *)realloc(s->buf, s->size); 177 | if (!s->buf) 178 | die("Out of memory"); 179 | s->reallocs++; 180 | } 181 | 182 | void strbuf_append_string(strbuf_t *s, const char *str) 183 | { 184 | int space, i; 185 | 186 | space = strbuf_empty_length(s); 187 | 188 | for (i = 0; str[i]; i++) { 189 | if (space < 1) { 190 | strbuf_resize(s, s->length + 1); 191 | space = strbuf_empty_length(s); 192 | } 193 | 194 | s->buf[s->length] = str[i]; 195 | s->length++; 196 | space--; 197 | } 198 | } 199 | 200 | /* strbuf_append_fmt() should only be used when an upper bound 201 | * is known for the output string. */ 202 | void strbuf_append_fmt(strbuf_t *s, int len, const char *fmt, ...) 203 | { 204 | va_list arg; 205 | int fmt_len; 206 | 207 | strbuf_ensure_empty_length(s, len); 208 | 209 | va_start(arg, fmt); 210 | fmt_len = vsnprintf(s->buf + s->length, len, fmt, arg); 211 | va_end(arg); 212 | 213 | if (fmt_len < 0) 214 | die("BUG: Unable to convert number"); /* This should never happen.. */ 215 | 216 | s->length += fmt_len; 217 | } 218 | 219 | /* strbuf_append_fmt_retry() can be used when the there is no known 220 | * upper bound for the output string. */ 221 | void strbuf_append_fmt_retry(strbuf_t *s, const char *fmt, ...) 222 | { 223 | va_list arg; 224 | int fmt_len; 225 | int empty_len; 226 | int t; 227 | 228 | /* If the first attempt to append fails, resize the buffer appropriately 229 | * and try again */ 230 | for (t = 0; ; t++) { 231 | va_start(arg, fmt); 232 | /* Append the new formatted string */ 233 | /* fmt_len is the length of the string required, excluding the 234 | * trailing NULL */ 235 | empty_len = strbuf_empty_length(s); 236 | /* Add 1 since there is also space to store the terminating NULL. */ 237 | fmt_len = vsnprintf(s->buf + s->length, empty_len + 1, fmt, arg); 238 | va_end(arg); 239 | 240 | if (fmt_len <= empty_len) 241 | break; /* SUCCESS */ 242 | if (t > 0) 243 | die("BUG: length of formatted string changed"); 244 | 245 | strbuf_resize(s, s->length + fmt_len); 246 | } 247 | 248 | s->length += fmt_len; 249 | } 250 | 251 | /* vi:ai et sw=4 ts=4: 252 | */ 253 | -------------------------------------------------------------------------------- /3rd/lua/src/lundump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.c,v 2.44.1.1 2017/04/19 17:20:42 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 | const char *name; 36 | } LoadState; 37 | 38 | 39 | static l_noret error(LoadState *S, const char *why) { 40 | luaO_pushfstring(S->L, "%s: %s precompiled chunk", S->name, why); 41 | luaD_throw(S->L, LUA_ERRSYNTAX); 42 | } 43 | 44 | 45 | /* 46 | ** All high-level loads go through LoadVector; you can change it to 47 | ** adapt to the endianness of the input 48 | */ 49 | #define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0])) 50 | 51 | static void LoadBlock (LoadState *S, void *b, size_t size) { 52 | if (luaZ_read(S->Z, b, size) != 0) 53 | error(S, "truncated"); 54 | } 55 | 56 | 57 | #define LoadVar(S,x) LoadVector(S,&x,1) 58 | 59 | 60 | static lu_byte LoadByte (LoadState *S) { 61 | lu_byte x; 62 | LoadVar(S, x); 63 | return x; 64 | } 65 | 66 | 67 | static int LoadInt (LoadState *S) { 68 | int x; 69 | LoadVar(S, x); 70 | return x; 71 | } 72 | 73 | 74 | static lua_Number LoadNumber (LoadState *S) { 75 | lua_Number x; 76 | LoadVar(S, x); 77 | return x; 78 | } 79 | 80 | 81 | static lua_Integer LoadInteger (LoadState *S) { 82 | lua_Integer x; 83 | LoadVar(S, x); 84 | return x; 85 | } 86 | 87 | 88 | static TString *LoadString (LoadState *S) { 89 | size_t size = LoadByte(S); 90 | if (size == 0xFF) 91 | LoadVar(S, size); 92 | if (size == 0) 93 | return NULL; 94 | else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ 95 | char buff[LUAI_MAXSHORTLEN]; 96 | LoadVector(S, buff, size); 97 | return luaS_newlstr(S->L, buff, size); 98 | } 99 | else { /* long string */ 100 | TString *ts = luaS_createlngstrobj(S->L, size); 101 | LoadVector(S, getstr(ts), size); /* load directly in final place */ 102 | return ts; 103 | } 104 | } 105 | 106 | 107 | static void LoadCode (LoadState *S, Proto *f) { 108 | int n = LoadInt(S); 109 | f->code = luaM_newvector(S->L, n, Instruction); 110 | f->sizecode = n; 111 | LoadVector(S, f->code, n); 112 | } 113 | 114 | 115 | static void LoadFunction(LoadState *S, Proto *f, TString *psource); 116 | 117 | 118 | static void LoadConstants (LoadState *S, Proto *f) { 119 | int i; 120 | int n = LoadInt(S); 121 | f->k = luaM_newvector(S->L, n, TValue); 122 | f->sizek = n; 123 | for (i = 0; i < n; i++) 124 | setnilvalue(&f->k[i]); 125 | for (i = 0; i < n; i++) { 126 | TValue *o = &f->k[i]; 127 | int t = LoadByte(S); 128 | switch (t) { 129 | case LUA_TNIL: 130 | setnilvalue(o); 131 | break; 132 | case LUA_TBOOLEAN: 133 | setbvalue(o, LoadByte(S)); 134 | break; 135 | case LUA_TNUMFLT: 136 | setfltvalue(o, LoadNumber(S)); 137 | break; 138 | case LUA_TNUMINT: 139 | setivalue(o, LoadInteger(S)); 140 | break; 141 | case LUA_TSHRSTR: 142 | case LUA_TLNGSTR: 143 | setsvalue2n(S->L, o, LoadString(S)); 144 | break; 145 | default: 146 | lua_assert(0); 147 | } 148 | } 149 | } 150 | 151 | 152 | static void LoadProtos (LoadState *S, Proto *f) { 153 | int i; 154 | int n = LoadInt(S); 155 | f->p = luaM_newvector(S->L, n, Proto *); 156 | f->sizep = n; 157 | for (i = 0; i < n; i++) 158 | f->p[i] = NULL; 159 | for (i = 0; i < n; i++) { 160 | f->p[i] = luaF_newproto(S->L); 161 | LoadFunction(S, f->p[i], f->source); 162 | } 163 | } 164 | 165 | 166 | static void LoadUpvalues (LoadState *S, Proto *f) { 167 | int i, n; 168 | n = LoadInt(S); 169 | f->upvalues = luaM_newvector(S->L, n, Upvaldesc); 170 | f->sizeupvalues = n; 171 | for (i = 0; i < n; i++) 172 | f->upvalues[i].name = NULL; 173 | for (i = 0; i < n; i++) { 174 | f->upvalues[i].instack = LoadByte(S); 175 | f->upvalues[i].idx = LoadByte(S); 176 | } 177 | } 178 | 179 | 180 | static void LoadDebug (LoadState *S, Proto *f) { 181 | int i, n; 182 | n = LoadInt(S); 183 | f->lineinfo = luaM_newvector(S->L, n, int); 184 | f->sizelineinfo = n; 185 | LoadVector(S, f->lineinfo, n); 186 | n = LoadInt(S); 187 | f->locvars = luaM_newvector(S->L, n, LocVar); 188 | f->sizelocvars = n; 189 | for (i = 0; i < n; i++) 190 | f->locvars[i].varname = NULL; 191 | for (i = 0; i < n; i++) { 192 | f->locvars[i].varname = LoadString(S); 193 | f->locvars[i].startpc = LoadInt(S); 194 | f->locvars[i].endpc = LoadInt(S); 195 | } 196 | n = LoadInt(S); 197 | for (i = 0; i < n; i++) 198 | f->upvalues[i].name = LoadString(S); 199 | } 200 | 201 | 202 | static void LoadFunction (LoadState *S, Proto *f, TString *psource) { 203 | f->source = LoadString(S); 204 | if (f->source == NULL) /* no source in dump? */ 205 | f->source = psource; /* reuse parent's source */ 206 | f->linedefined = LoadInt(S); 207 | f->lastlinedefined = LoadInt(S); 208 | f->numparams = LoadByte(S); 209 | f->is_vararg = LoadByte(S); 210 | f->maxstacksize = LoadByte(S); 211 | LoadCode(S, f); 212 | LoadConstants(S, f); 213 | LoadUpvalues(S, f); 214 | LoadProtos(S, f); 215 | LoadDebug(S, f); 216 | } 217 | 218 | 219 | static void checkliteral (LoadState *S, const char *s, const char *msg) { 220 | char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */ 221 | size_t len = strlen(s); 222 | LoadVector(S, buff, len); 223 | if (memcmp(s, buff, len) != 0) 224 | error(S, msg); 225 | } 226 | 227 | 228 | static void fchecksize (LoadState *S, size_t size, const char *tname) { 229 | if (LoadByte(S) != size) 230 | error(S, luaO_pushfstring(S->L, "%s size mismatch in", tname)); 231 | } 232 | 233 | 234 | #define checksize(S,t) fchecksize(S,sizeof(t),#t) 235 | 236 | static void checkHeader (LoadState *S) { 237 | checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */ 238 | if (LoadByte(S) != LUAC_VERSION) 239 | error(S, "version mismatch in"); 240 | if (LoadByte(S) != LUAC_FORMAT) 241 | error(S, "format mismatch in"); 242 | checkliteral(S, LUAC_DATA, "corrupted"); 243 | checksize(S, int); 244 | checksize(S, size_t); 245 | checksize(S, Instruction); 246 | checksize(S, lua_Integer); 247 | checksize(S, lua_Number); 248 | if (LoadInteger(S) != LUAC_INT) 249 | error(S, "endianness mismatch in"); 250 | if (LoadNumber(S) != LUAC_NUM) 251 | error(S, "float format mismatch in"); 252 | } 253 | 254 | 255 | /* 256 | ** load precompiled chunk 257 | */ 258 | LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) { 259 | LoadState S; 260 | LClosure *cl; 261 | if (*name == '@' || *name == '=') 262 | S.name = name + 1; 263 | else if (*name == LUA_SIGNATURE[0]) 264 | S.name = "binary string"; 265 | else 266 | S.name = name; 267 | S.L = L; 268 | S.Z = Z; 269 | checkHeader(&S); 270 | cl = luaF_newLclosure(L, LoadByte(&S)); 271 | setclLvalue(L, L->top, cl); 272 | luaD_inctop(L); 273 | cl->p = luaF_newproto(L); 274 | LoadFunction(&S, cl->p, NULL); 275 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); 276 | luai_verifycode(L, buff, cl->p); 277 | return cl; 278 | } 279 | 280 | -------------------------------------------------------------------------------- /3rd/lua/src/lstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.c,v 2.56.1.1 2017/04/19 17:20:42 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 | #define MEMERRMSG "not enough memory" 26 | 27 | 28 | /* 29 | ** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to 30 | ** compute its hash 31 | */ 32 | #if !defined(LUAI_HASHLIMIT) 33 | #define LUAI_HASHLIMIT 5 34 | #endif 35 | 36 | 37 | /* 38 | ** equality for long strings 39 | */ 40 | int luaS_eqlngstr (TString *a, TString *b) { 41 | size_t len = a->u.lnglen; 42 | lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR); 43 | return (a == b) || /* same instance or... */ 44 | ((len == b->u.lnglen) && /* equal length and ... */ 45 | (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */ 46 | } 47 | 48 | 49 | unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) { 50 | unsigned int h = seed ^ cast(unsigned int, l); 51 | size_t step = (l >> LUAI_HASHLIMIT) + 1; 52 | for (; l >= step; l -= step) 53 | h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1])); 54 | return h; 55 | } 56 | 57 | 58 | unsigned int luaS_hashlongstr (TString *ts) { 59 | lua_assert(ts->tt == LUA_TLNGSTR); 60 | if (ts->extra == 0) { /* no hash? */ 61 | ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash); 62 | ts->extra = 1; /* now it has its hash */ 63 | } 64 | return ts->hash; 65 | } 66 | 67 | 68 | /* 69 | ** resizes the string table 70 | */ 71 | void luaS_resize (lua_State *L, int newsize) { 72 | int i; 73 | stringtable *tb = &G(L)->strt; 74 | if (newsize > tb->size) { /* grow table if needed */ 75 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); 76 | for (i = tb->size; i < newsize; i++) 77 | tb->hash[i] = NULL; 78 | } 79 | for (i = 0; i < tb->size; i++) { /* rehash */ 80 | TString *p = tb->hash[i]; 81 | tb->hash[i] = NULL; 82 | while (p) { /* for each node in the list */ 83 | TString *hnext = p->u.hnext; /* save next */ 84 | unsigned int h = lmod(p->hash, newsize); /* new position */ 85 | p->u.hnext = tb->hash[h]; /* chain it */ 86 | tb->hash[h] = p; 87 | p = hnext; 88 | } 89 | } 90 | if (newsize < tb->size) { /* shrink table if needed */ 91 | /* vanishing slice should be empty */ 92 | lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL); 93 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); 94 | } 95 | tb->size = newsize; 96 | } 97 | 98 | 99 | /* 100 | ** Clear API string cache. (Entries cannot be empty, so fill them with 101 | ** a non-collectable string.) 102 | */ 103 | void luaS_clearcache (global_State *g) { 104 | int i, j; 105 | for (i = 0; i < STRCACHE_N; i++) 106 | for (j = 0; j < STRCACHE_M; j++) { 107 | if (iswhite(g->strcache[i][j])) /* will entry be collected? */ 108 | g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */ 109 | } 110 | } 111 | 112 | 113 | /* 114 | ** Initialize the string table and the string cache 115 | */ 116 | void luaS_init (lua_State *L) { 117 | global_State *g = G(L); 118 | int i, j; 119 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ 120 | /* pre-create memory-error message */ 121 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); 122 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ 123 | for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ 124 | for (j = 0; j < STRCACHE_M; j++) 125 | g->strcache[i][j] = g->memerrmsg; 126 | } 127 | 128 | 129 | 130 | /* 131 | ** creates a new string object 132 | */ 133 | static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) { 134 | TString *ts; 135 | GCObject *o; 136 | size_t totalsize; /* total size of TString object */ 137 | totalsize = sizelstring(l); 138 | o = luaC_newobj(L, tag, totalsize); 139 | ts = gco2ts(o); 140 | ts->hash = h; 141 | ts->extra = 0; 142 | getstr(ts)[l] = '\0'; /* ending 0 */ 143 | return ts; 144 | } 145 | 146 | 147 | TString *luaS_createlngstrobj (lua_State *L, size_t l) { 148 | TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed); 149 | ts->u.lnglen = l; 150 | return ts; 151 | } 152 | 153 | 154 | void luaS_remove (lua_State *L, TString *ts) { 155 | stringtable *tb = &G(L)->strt; 156 | TString **p = &tb->hash[lmod(ts->hash, tb->size)]; 157 | while (*p != ts) /* find previous element */ 158 | p = &(*p)->u.hnext; 159 | *p = (*p)->u.hnext; /* remove element from its list */ 160 | tb->nuse--; 161 | } 162 | 163 | 164 | /* 165 | ** checks whether short string exists and reuses it or creates a new one 166 | */ 167 | static TString *internshrstr (lua_State *L, const char *str, size_t l) { 168 | TString *ts; 169 | global_State *g = G(L); 170 | unsigned int h = luaS_hash(str, l, g->seed); 171 | TString **list = &g->strt.hash[lmod(h, g->strt.size)]; 172 | lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */ 173 | for (ts = *list; ts != NULL; ts = ts->u.hnext) { 174 | if (l == ts->shrlen && 175 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { 176 | /* found! */ 177 | if (isdead(g, ts)) /* dead (but not collected yet)? */ 178 | changewhite(ts); /* resurrect it */ 179 | return ts; 180 | } 181 | } 182 | if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) { 183 | luaS_resize(L, g->strt.size * 2); 184 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ 185 | } 186 | ts = createstrobj(L, l, LUA_TSHRSTR, h); 187 | memcpy(getstr(ts), str, l * sizeof(char)); 188 | ts->shrlen = cast_byte(l); 189 | ts->u.hnext = *list; 190 | *list = ts; 191 | g->strt.nuse++; 192 | return ts; 193 | } 194 | 195 | 196 | /* 197 | ** new string (with explicit length) 198 | */ 199 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 200 | if (l <= LUAI_MAXSHORTLEN) /* short string? */ 201 | return internshrstr(L, str, l); 202 | else { 203 | TString *ts; 204 | if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char)) 205 | luaM_toobig(L); 206 | ts = luaS_createlngstrobj(L, l); 207 | memcpy(getstr(ts), str, l * sizeof(char)); 208 | return ts; 209 | } 210 | } 211 | 212 | 213 | /* 214 | ** Create or reuse a zero-terminated string, first checking in the 215 | ** cache (using the string address as a key). The cache can contain 216 | ** only zero-terminated strings, so it is safe to use 'strcmp' to 217 | ** check hits. 218 | */ 219 | TString *luaS_new (lua_State *L, const char *str) { 220 | unsigned int i = point2uint(str) % STRCACHE_N; /* hash */ 221 | int j; 222 | TString **p = G(L)->strcache[i]; 223 | for (j = 0; j < STRCACHE_M; j++) { 224 | if (strcmp(str, getstr(p[j])) == 0) /* hit? */ 225 | return p[j]; /* that is it */ 226 | } 227 | /* normal route */ 228 | for (j = STRCACHE_M - 1; j > 0; j--) 229 | p[j] = p[j - 1]; /* move out last element */ 230 | /* new element is first in the list */ 231 | p[0] = luaS_newlstr(L, str, strlen(str)); 232 | return p[0]; 233 | } 234 | 235 | 236 | Udata *luaS_newudata (lua_State *L, size_t s) { 237 | Udata *u; 238 | GCObject *o; 239 | if (s > MAX_SIZE - sizeof(Udata)) 240 | luaM_toobig(L); 241 | o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s)); 242 | u = gco2u(o); 243 | u->len = s; 244 | u->metatable = NULL; 245 | setuservalue(L, u, luaO_nilobject); 246 | return u; 247 | } 248 | 249 | -------------------------------------------------------------------------------- /3rd/lua/src/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building Lua 2 | # See ../doc/readme.html for installation and customization instructions. 3 | 4 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= 5 | 6 | # Your platform. See PLATS for possible values. 7 | PLAT= none 8 | 9 | CC= gcc -std=gnu99 10 | CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS) 11 | LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) 12 | LIBS= -lm $(SYSLIBS) $(MYLIBS) 13 | 14 | AR= ar rcu 15 | RANLIB= ranlib 16 | RM= rm -f 17 | 18 | SYSCFLAGS= 19 | SYSLDFLAGS= 20 | SYSLIBS= 21 | 22 | MYCFLAGS= 23 | MYLDFLAGS= 24 | MYLIBS= 25 | MYOBJS= 26 | 27 | # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= 28 | 29 | PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris 30 | 31 | LUA_A= liblua.a 32 | CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \ 33 | lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \ 34 | ltm.o lundump.o lvm.o lzio.o 35 | LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \ 36 | lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o 37 | BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) 38 | 39 | LUA_T= lua 40 | LUA_O= lua.o 41 | 42 | LUAC_T= luac 43 | LUAC_O= luac.o 44 | 45 | ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O) 46 | ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) 47 | ALL_A= $(LUA_A) 48 | 49 | # Targets start here. 50 | default: $(PLAT) 51 | 52 | all: $(ALL_T) 53 | 54 | o: $(ALL_O) 55 | 56 | a: $(ALL_A) 57 | 58 | $(LUA_A): $(BASE_O) 59 | $(AR) $@ $(BASE_O) 60 | $(RANLIB) $@ 61 | 62 | $(LUA_T): $(LUA_O) $(LUA_A) 63 | $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) 64 | 65 | $(LUAC_T): $(LUAC_O) $(LUA_A) 66 | $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) 67 | 68 | clean: 69 | $(RM) $(ALL_T) $(ALL_O) 70 | 71 | depend: 72 | @$(CC) $(CFLAGS) -MM l*.c 73 | 74 | echo: 75 | @echo "PLAT= $(PLAT)" 76 | @echo "CC= $(CC)" 77 | @echo "CFLAGS= $(CFLAGS)" 78 | @echo "LDFLAGS= $(SYSLDFLAGS)" 79 | @echo "LIBS= $(LIBS)" 80 | @echo "AR= $(AR)" 81 | @echo "RANLIB= $(RANLIB)" 82 | @echo "RM= $(RM)" 83 | 84 | # Convenience targets for popular platforms 85 | ALL= a 86 | 87 | none: 88 | @echo "Please do 'make PLATFORM' where PLATFORM is one of these:" 89 | @echo " $(PLATS)" 90 | 91 | aix: 92 | $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall" 93 | 94 | bsd: 95 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E" 96 | 97 | c89: 98 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC="gcc -std=c89" 99 | @echo '' 100 | @echo '*** C89 does not guarantee 64-bit integers for Lua.' 101 | @echo '' 102 | 103 | 104 | freebsd: 105 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc" 106 | 107 | generic: $(ALL) 108 | 109 | linux: 110 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline" 111 | 112 | macosx: 113 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" 114 | 115 | mingw: 116 | $(MAKE) "LUA_A=lua53.dll" "LUA_T=lua.exe" \ 117 | "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ 118 | "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe 119 | $(MAKE) "LUAC_T=luac.exe" luac.exe 120 | 121 | posix: 122 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX" 123 | 124 | solaris: 125 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT" SYSLIBS="-ldl" 126 | 127 | # list targets that do not create files (but not all makes understand .PHONY) 128 | .PHONY: all $(PLATS) default o a clean depend echo none 129 | 130 | # DO NOT DELETE 131 | 132 | lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 133 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \ 134 | ltable.h lundump.h lvm.h 135 | lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h 136 | lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 137 | lbitlib.o: lbitlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 138 | lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ 139 | llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ 140 | ldo.h lgc.h lstring.h ltable.h lvm.h 141 | lcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 142 | lctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h 143 | ldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 144 | ldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 145 | lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \ 146 | ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h 147 | ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 148 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \ 149 | lparser.h lstring.h ltable.h lundump.h lvm.h 150 | ldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \ 151 | ltm.h lzio.h lmem.h lundump.h 152 | lfunc.o: lfunc.c lprefix.h lua.h luaconf.h lfunc.h lobject.h llimits.h \ 153 | lgc.h lstate.h ltm.h lzio.h lmem.h 154 | lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 155 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h 156 | linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h 157 | liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 158 | llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \ 159 | lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \ 160 | lstring.h ltable.h 161 | lmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 162 | lmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 163 | llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h 164 | loadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 165 | lobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \ 166 | ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \ 167 | lvm.h 168 | lopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h 169 | loslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 170 | lparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ 171 | llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ 172 | ldo.h lfunc.h lstring.h lgc.h ltable.h 173 | lstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 174 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \ 175 | lstring.h ltable.h 176 | lstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ 177 | lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h 178 | lstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 179 | ltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 180 | llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h 181 | ltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 182 | ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 183 | llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h 184 | lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 185 | luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lobject.h llimits.h \ 186 | lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h 187 | lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ 188 | lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \ 189 | lundump.h 190 | lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 191 | lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 192 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \ 193 | ltable.h lvm.h 194 | lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \ 195 | lobject.h ltm.h lzio.h 196 | 197 | # (end of Makefile) 198 | -------------------------------------------------------------------------------- /3rd/lua/src/lutf8lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lutf8lib.c,v 1.16.1.1 2017/04/19 17:29:57 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 | #include 17 | 18 | #include "lua.h" 19 | 20 | #include "lauxlib.h" 21 | #include "lualib.h" 22 | 23 | #define MAXUNICODE 0x10FFFF 24 | 25 | #define iscont(p) ((*(p) & 0xC0) == 0x80) 26 | 27 | 28 | /* from strlib */ 29 | /* translate a relative string position: negative means back from end */ 30 | static lua_Integer u_posrelat (lua_Integer pos, size_t len) { 31 | if (pos >= 0) return pos; 32 | else if (0u - (size_t)pos > len) return 0; 33 | else return (lua_Integer)len + pos + 1; 34 | } 35 | 36 | 37 | /* 38 | ** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid. 39 | */ 40 | static const char *utf8_decode (const char *o, int *val) { 41 | static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF}; 42 | const unsigned char *s = (const unsigned char *)o; 43 | unsigned int c = s[0]; 44 | unsigned int res = 0; /* final result */ 45 | if (c < 0x80) /* ascii? */ 46 | res = c; 47 | else { 48 | int count = 0; /* to count number of continuation bytes */ 49 | while (c & 0x40) { /* still have continuation bytes? */ 50 | int cc = s[++count]; /* read next byte */ 51 | if ((cc & 0xC0) != 0x80) /* not a continuation byte? */ 52 | return NULL; /* invalid byte sequence */ 53 | res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ 54 | c <<= 1; /* to test next bit */ 55 | } 56 | res |= ((c & 0x7F) << (count * 5)); /* add first byte */ 57 | if (count > 3 || res > MAXUNICODE || res <= limits[count]) 58 | return NULL; /* invalid byte sequence */ 59 | s += count; /* skip continuation bytes read */ 60 | } 61 | if (val) *val = res; 62 | return (const char *)s + 1; /* +1 to include first byte */ 63 | } 64 | 65 | 66 | /* 67 | ** utf8len(s [, i [, j]]) --> number of characters that start in the 68 | ** range [i,j], or nil + current position if 's' is not well formed in 69 | ** that interval 70 | */ 71 | static int utflen (lua_State *L) { 72 | int n = 0; 73 | size_t len; 74 | const char *s = luaL_checklstring(L, 1, &len); 75 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); 76 | lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len); 77 | luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2, 78 | "initial position out of string"); 79 | luaL_argcheck(L, --posj < (lua_Integer)len, 3, 80 | "final position out of string"); 81 | while (posi <= posj) { 82 | const char *s1 = utf8_decode(s + posi, NULL); 83 | if (s1 == NULL) { /* conversion error? */ 84 | lua_pushnil(L); /* return nil ... */ 85 | lua_pushinteger(L, posi + 1); /* ... and current position */ 86 | return 2; 87 | } 88 | posi = s1 - s; 89 | n++; 90 | } 91 | lua_pushinteger(L, n); 92 | return 1; 93 | } 94 | 95 | 96 | /* 97 | ** codepoint(s, [i, [j]]) -> returns codepoints for all characters 98 | ** that start in the range [i,j] 99 | */ 100 | static int codepoint (lua_State *L) { 101 | size_t len; 102 | const char *s = luaL_checklstring(L, 1, &len); 103 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); 104 | lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len); 105 | int n; 106 | const char *se; 107 | luaL_argcheck(L, posi >= 1, 2, "out of range"); 108 | luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of range"); 109 | if (posi > pose) return 0; /* empty interval; return no values */ 110 | if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */ 111 | return luaL_error(L, "string slice too long"); 112 | n = (int)(pose - posi) + 1; 113 | luaL_checkstack(L, n, "string slice too long"); 114 | n = 0; 115 | se = s + pose; 116 | for (s += posi - 1; s < se;) { 117 | int code; 118 | s = utf8_decode(s, &code); 119 | if (s == NULL) 120 | return luaL_error(L, "invalid UTF-8 code"); 121 | lua_pushinteger(L, code); 122 | n++; 123 | } 124 | return n; 125 | } 126 | 127 | 128 | static void pushutfchar (lua_State *L, int arg) { 129 | lua_Integer code = luaL_checkinteger(L, arg); 130 | luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range"); 131 | lua_pushfstring(L, "%U", (long)code); 132 | } 133 | 134 | 135 | /* 136 | ** utfchar(n1, n2, ...) -> char(n1)..char(n2)... 137 | */ 138 | static int utfchar (lua_State *L) { 139 | int n = lua_gettop(L); /* number of arguments */ 140 | if (n == 1) /* optimize common case of single char */ 141 | pushutfchar(L, 1); 142 | else { 143 | int i; 144 | luaL_Buffer b; 145 | luaL_buffinit(L, &b); 146 | for (i = 1; i <= n; i++) { 147 | pushutfchar(L, i); 148 | luaL_addvalue(&b); 149 | } 150 | luaL_pushresult(&b); 151 | } 152 | return 1; 153 | } 154 | 155 | 156 | /* 157 | ** offset(s, n, [i]) -> index where n-th character counting from 158 | ** position 'i' starts; 0 means character at 'i'. 159 | */ 160 | static int byteoffset (lua_State *L) { 161 | size_t len; 162 | const char *s = luaL_checklstring(L, 1, &len); 163 | lua_Integer n = luaL_checkinteger(L, 2); 164 | lua_Integer posi = (n >= 0) ? 1 : len + 1; 165 | posi = u_posrelat(luaL_optinteger(L, 3, posi), len); 166 | luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, 167 | "position out of range"); 168 | if (n == 0) { 169 | /* find beginning of current byte sequence */ 170 | while (posi > 0 && iscont(s + posi)) posi--; 171 | } 172 | else { 173 | if (iscont(s + posi)) 174 | return luaL_error(L, "initial position is a continuation byte"); 175 | if (n < 0) { 176 | while (n < 0 && posi > 0) { /* move back */ 177 | do { /* find beginning of previous character */ 178 | posi--; 179 | } while (posi > 0 && iscont(s + posi)); 180 | n++; 181 | } 182 | } 183 | else { 184 | n--; /* do not move for 1st character */ 185 | while (n > 0 && posi < (lua_Integer)len) { 186 | do { /* find beginning of next character */ 187 | posi++; 188 | } while (iscont(s + posi)); /* (cannot pass final '\0') */ 189 | n--; 190 | } 191 | } 192 | } 193 | if (n == 0) /* did it find given character? */ 194 | lua_pushinteger(L, posi + 1); 195 | else /* no such character */ 196 | lua_pushnil(L); 197 | return 1; 198 | } 199 | 200 | 201 | static int iter_aux (lua_State *L) { 202 | size_t len; 203 | const char *s = luaL_checklstring(L, 1, &len); 204 | lua_Integer n = lua_tointeger(L, 2) - 1; 205 | if (n < 0) /* first iteration? */ 206 | n = 0; /* start from here */ 207 | else if (n < (lua_Integer)len) { 208 | n++; /* skip current byte */ 209 | while (iscont(s + n)) n++; /* and its continuations */ 210 | } 211 | if (n >= (lua_Integer)len) 212 | return 0; /* no more codepoints */ 213 | else { 214 | int code; 215 | const char *next = utf8_decode(s + n, &code); 216 | if (next == NULL || iscont(next)) 217 | return luaL_error(L, "invalid UTF-8 code"); 218 | lua_pushinteger(L, n + 1); 219 | lua_pushinteger(L, code); 220 | return 2; 221 | } 222 | } 223 | 224 | 225 | static int iter_codes (lua_State *L) { 226 | luaL_checkstring(L, 1); 227 | lua_pushcfunction(L, iter_aux); 228 | lua_pushvalue(L, 1); 229 | lua_pushinteger(L, 0); 230 | return 3; 231 | } 232 | 233 | 234 | /* pattern to match a single UTF-8 character */ 235 | #define UTF8PATT "[\0-\x7F\xC2-\xF4][\x80-\xBF]*" 236 | 237 | 238 | static const luaL_Reg funcs[] = { 239 | {"offset", byteoffset}, 240 | {"codepoint", codepoint}, 241 | {"char", utfchar}, 242 | {"len", utflen}, 243 | {"codes", iter_codes}, 244 | /* placeholders */ 245 | {"charpattern", NULL}, 246 | {NULL, NULL} 247 | }; 248 | 249 | 250 | LUAMOD_API int luaopen_utf8 (lua_State *L) { 251 | luaL_newlib(L, funcs); 252 | lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1); 253 | lua_setfield(L, -2, "charpattern"); 254 | return 1; 255 | } 256 | 257 | -------------------------------------------------------------------------------- /3rd/lua/src/llimits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llimits.h,v 1.141.1.1 2017/04/19 17:20:42 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 unsigned integer: 56 | ** this is for hashing only; there is no problem if the integer 57 | ** cannot hold the whole pointer value 58 | */ 59 | #define point2uint(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 { 68 | lua_Number n; 69 | double u; 70 | void *s; 71 | lua_Integer i; 72 | long l; 73 | } L_Umaxalign; 74 | #endif 75 | 76 | 77 | 78 | /* types of 'usual argument conversions' for lua_Number and lua_Integer */ 79 | typedef LUAI_UACNUMBER l_uacNumber; 80 | typedef LUAI_UACINT l_uacInt; 81 | 82 | 83 | /* internal assertions for in-house debugging */ 84 | #if defined(lua_assert) 85 | #define check_exp(c,e) (lua_assert(c), (e)) 86 | /* to avoid problems with conditions too long */ 87 | #define lua_longassert(c) ((c) ? (void)0 : lua_assert(0)) 88 | #else 89 | #define lua_assert(c) ((void)0) 90 | #define check_exp(c,e) (e) 91 | #define lua_longassert(c) ((void)0) 92 | #endif 93 | 94 | /* 95 | ** assertion for checking API calls 96 | */ 97 | #if !defined(luai_apicheck) 98 | #define luai_apicheck(l,e) lua_assert(e) 99 | #endif 100 | 101 | #define api_check(l,e,msg) luai_apicheck(l,(e) && msg) 102 | 103 | 104 | /* macro to avoid warnings about unused variables */ 105 | #if !defined(UNUSED) 106 | #define UNUSED(x) ((void)(x)) 107 | #endif 108 | 109 | 110 | /* type casts (a macro highlights casts in the code) */ 111 | #define cast(t, exp) ((t)(exp)) 112 | 113 | #define cast_void(i) cast(void, (i)) 114 | #define cast_byte(i) cast(lu_byte, (i)) 115 | #define cast_num(i) cast(lua_Number, (i)) 116 | #define cast_int(i) cast(int, (i)) 117 | #define cast_uchar(i) cast(unsigned char, (i)) 118 | 119 | 120 | /* cast a signed lua_Integer to lua_Unsigned */ 121 | #if !defined(l_castS2U) 122 | #define l_castS2U(i) ((lua_Unsigned)(i)) 123 | #endif 124 | 125 | /* 126 | ** cast a lua_Unsigned to a signed lua_Integer; this cast is 127 | ** not strict ISO C, but two-complement architectures should 128 | ** work fine. 129 | */ 130 | #if !defined(l_castU2S) 131 | #define l_castU2S(i) ((lua_Integer)(i)) 132 | #endif 133 | 134 | 135 | /* 136 | ** non-return type 137 | */ 138 | #if defined(__GNUC__) 139 | #define l_noret void __attribute__((noreturn)) 140 | #elif defined(_MSC_VER) && _MSC_VER >= 1200 141 | #define l_noret void __declspec(noreturn) 142 | #else 143 | #define l_noret void 144 | #endif 145 | 146 | 147 | 148 | /* 149 | ** maximum depth for nested C calls and syntactical nested non-terminals 150 | ** in a program. (Value must fit in an unsigned short int.) 151 | */ 152 | #if !defined(LUAI_MAXCCALLS) 153 | #define LUAI_MAXCCALLS 200 154 | #endif 155 | 156 | 157 | 158 | /* 159 | ** type for virtual-machine instructions; 160 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 161 | */ 162 | #if LUAI_BITSINT >= 32 163 | typedef unsigned int Instruction; 164 | #else 165 | typedef unsigned long Instruction; 166 | #endif 167 | 168 | 169 | 170 | /* 171 | ** Maximum length for short strings, that is, strings that are 172 | ** internalized. (Cannot be smaller than reserved words or tags for 173 | ** metamethods, as these strings must be internalized; 174 | ** #("function") = 8, #("__newindex") = 10.) 175 | */ 176 | #if !defined(LUAI_MAXSHORTLEN) 177 | #define LUAI_MAXSHORTLEN 40 178 | #endif 179 | 180 | 181 | /* 182 | ** Initial size for the string table (must be power of 2). 183 | ** The Lua core alone registers ~50 strings (reserved words + 184 | ** metaevent keys + a few others). Libraries would typically add 185 | ** a few dozens more. 186 | */ 187 | #if !defined(MINSTRTABSIZE) 188 | #define MINSTRTABSIZE 128 189 | #endif 190 | 191 | 192 | /* 193 | ** Size of cache for strings in the API. 'N' is the number of 194 | ** sets (better be a prime) and "M" is the size of each set (M == 1 195 | ** makes a direct cache.) 196 | */ 197 | #if !defined(STRCACHE_N) 198 | #define STRCACHE_N 53 199 | #define STRCACHE_M 2 200 | #endif 201 | 202 | 203 | /* minimum size for string buffer */ 204 | #if !defined(LUA_MINBUFFER) 205 | #define LUA_MINBUFFER 32 206 | #endif 207 | 208 | 209 | /* 210 | ** macros that are executed whenever program enters the Lua core 211 | ** ('lua_lock') and leaves the core ('lua_unlock') 212 | */ 213 | #if !defined(lua_lock) 214 | #define lua_lock(L) ((void) 0) 215 | #define lua_unlock(L) ((void) 0) 216 | #endif 217 | 218 | /* 219 | ** macro executed during Lua functions at points where the 220 | ** function can yield. 221 | */ 222 | #if !defined(luai_threadyield) 223 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 224 | #endif 225 | 226 | 227 | /* 228 | ** these macros allow user-specific actions on threads when you defined 229 | ** LUAI_EXTRASPACE and need to do something extra when a thread is 230 | ** created/deleted/resumed/yielded. 231 | */ 232 | #if !defined(luai_userstateopen) 233 | #define luai_userstateopen(L) ((void)L) 234 | #endif 235 | 236 | #if !defined(luai_userstateclose) 237 | #define luai_userstateclose(L) ((void)L) 238 | #endif 239 | 240 | #if !defined(luai_userstatethread) 241 | #define luai_userstatethread(L,L1) ((void)L) 242 | #endif 243 | 244 | #if !defined(luai_userstatefree) 245 | #define luai_userstatefree(L,L1) ((void)L) 246 | #endif 247 | 248 | #if !defined(luai_userstateresume) 249 | #define luai_userstateresume(L,n) ((void)L) 250 | #endif 251 | 252 | #if !defined(luai_userstateyield) 253 | #define luai_userstateyield(L,n) ((void)L) 254 | #endif 255 | 256 | 257 | 258 | /* 259 | ** The luai_num* macros define the primitive operations over numbers. 260 | */ 261 | 262 | /* floor division (defined as 'floor(a/b)') */ 263 | #if !defined(luai_numidiv) 264 | #define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b))) 265 | #endif 266 | 267 | /* float division */ 268 | #if !defined(luai_numdiv) 269 | #define luai_numdiv(L,a,b) ((a)/(b)) 270 | #endif 271 | 272 | /* 273 | ** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when 274 | ** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of 275 | ** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b) 276 | ** ~= floor(a/b)'. That happens when the division has a non-integer 277 | ** negative result, which is equivalent to the test below. 278 | */ 279 | #if !defined(luai_nummod) 280 | #define luai_nummod(L,a,b,m) \ 281 | { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); } 282 | #endif 283 | 284 | /* exponentiation */ 285 | #if !defined(luai_numpow) 286 | #define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b)) 287 | #endif 288 | 289 | /* the others are quite standard operations */ 290 | #if !defined(luai_numadd) 291 | #define luai_numadd(L,a,b) ((a)+(b)) 292 | #define luai_numsub(L,a,b) ((a)-(b)) 293 | #define luai_nummul(L,a,b) ((a)*(b)) 294 | #define luai_numunm(L,a) (-(a)) 295 | #define luai_numeq(a,b) ((a)==(b)) 296 | #define luai_numlt(a,b) ((a)<(b)) 297 | #define luai_numle(a,b) ((a)<=(b)) 298 | #define luai_numisnan(a) (!luai_numeq((a), (a))) 299 | #endif 300 | 301 | 302 | 303 | 304 | 305 | /* 306 | ** macro to control inclusion of some hard tests on stack reallocation 307 | */ 308 | #if !defined(HARDSTACKTESTS) 309 | #define condmovestack(L,pre,pos) ((void)0) 310 | #else 311 | /* realloc stack keeping its size */ 312 | #define condmovestack(L,pre,pos) \ 313 | { int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_); pos; } 314 | #endif 315 | 316 | #if !defined(HARDMEMTESTS) 317 | #define condchangemem(L,pre,pos) ((void)0) 318 | #else 319 | #define condchangemem(L,pre,pos) \ 320 | { if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } } 321 | #endif 322 | 323 | #endif 324 | -------------------------------------------------------------------------------- /3rd/lua/src/lauxlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lauxlib.h,v 1.131.1.1 2017/04/19 17:20:42 roberto Exp $ 3 | ** Auxiliary functions for building Lua libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lauxlib_h 9 | #define lauxlib_h 10 | 11 | 12 | #include 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | 18 | 19 | /* extra error code for 'luaL_loadfilex' */ 20 | #define LUA_ERRFILE (LUA_ERRERR+1) 21 | 22 | 23 | /* key, in the registry, for table of loaded modules */ 24 | #define LUA_LOADED_TABLE "_LOADED" 25 | 26 | 27 | /* key, in the registry, for table of preloaded loaders */ 28 | #define LUA_PRELOAD_TABLE "_PRELOAD" 29 | 30 | 31 | typedef struct luaL_Reg { 32 | const char *name; 33 | lua_CFunction func; 34 | } luaL_Reg; 35 | 36 | 37 | #define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number)) 38 | 39 | LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz); 40 | #define luaL_checkversion(L) \ 41 | luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES) 42 | 43 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 44 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 45 | LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); 46 | LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg); 47 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, 48 | size_t *l); 49 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, 50 | const char *def, size_t *l); 51 | LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg); 52 | LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def); 53 | 54 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg); 55 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg, 56 | lua_Integer def); 57 | 58 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 59 | LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t); 60 | LUALIB_API void (luaL_checkany) (lua_State *L, int arg); 61 | 62 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 63 | LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); 64 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); 65 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 66 | 67 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); 68 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); 69 | 70 | LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def, 71 | const char *const lst[]); 72 | 73 | LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); 74 | LUALIB_API int (luaL_execresult) (lua_State *L, int stat); 75 | 76 | /* predefined references */ 77 | #define LUA_NOREF (-2) 78 | #define LUA_REFNIL (-1) 79 | 80 | LUALIB_API int (luaL_ref) (lua_State *L, int t); 81 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 82 | 83 | LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, 84 | const char *mode); 85 | 86 | #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) 87 | 88 | LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, 89 | const char *name, const char *mode); 90 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 91 | 92 | LUALIB_API lua_State *(luaL_newstate) (void); 93 | 94 | LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); 95 | 96 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, 97 | const char *r); 98 | 99 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); 100 | 101 | LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname); 102 | 103 | LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1, 104 | const char *msg, int level); 105 | 106 | LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, 107 | lua_CFunction openf, int glb); 108 | 109 | /* 110 | ** =============================================================== 111 | ** some useful macros 112 | ** =============================================================== 113 | */ 114 | 115 | 116 | #define luaL_newlibtable(L,l) \ 117 | lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) 118 | 119 | #define luaL_newlib(L,l) \ 120 | (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) 121 | 122 | #define luaL_argcheck(L, cond,arg,extramsg) \ 123 | ((void)((cond) || luaL_argerror(L, (arg), (extramsg)))) 124 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 125 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 126 | 127 | #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) 128 | 129 | #define luaL_dofile(L, fn) \ 130 | (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 131 | 132 | #define luaL_dostring(L, s) \ 133 | (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 134 | 135 | #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 136 | 137 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 138 | 139 | #define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) 140 | 141 | 142 | /* 143 | ** {====================================================== 144 | ** Generic Buffer manipulation 145 | ** ======================================================= 146 | */ 147 | 148 | typedef struct luaL_Buffer { 149 | char *b; /* buffer address */ 150 | size_t size; /* buffer size */ 151 | size_t n; /* number of characters in buffer */ 152 | lua_State *L; 153 | char initb[LUAL_BUFFERSIZE]; /* initial buffer */ 154 | } luaL_Buffer; 155 | 156 | 157 | #define luaL_addchar(B,c) \ 158 | ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \ 159 | ((B)->b[(B)->n++] = (c))) 160 | 161 | #define luaL_addsize(B,s) ((B)->n += (s)) 162 | 163 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); 164 | LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz); 165 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); 166 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); 167 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); 168 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); 169 | LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz); 170 | LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); 171 | 172 | #define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE) 173 | 174 | /* }====================================================== */ 175 | 176 | 177 | 178 | /* 179 | ** {====================================================== 180 | ** File handles for IO library 181 | ** ======================================================= 182 | */ 183 | 184 | /* 185 | ** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and 186 | ** initial structure 'luaL_Stream' (it may contain other fields 187 | ** after that initial structure). 188 | */ 189 | 190 | #define LUA_FILEHANDLE "FILE*" 191 | 192 | 193 | typedef struct luaL_Stream { 194 | FILE *f; /* stream (NULL for incompletely created streams) */ 195 | lua_CFunction closef; /* to close stream (NULL for closed streams) */ 196 | } luaL_Stream; 197 | 198 | /* }====================================================== */ 199 | 200 | 201 | 202 | /* compatibility with old module system */ 203 | #if defined(LUA_COMPAT_MODULE) 204 | 205 | LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname, 206 | int sizehint); 207 | LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, 208 | const luaL_Reg *l, int nup); 209 | 210 | #define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0)) 211 | 212 | #endif 213 | 214 | 215 | /* 216 | ** {================================================================== 217 | ** "Abstraction Layer" for basic report of messages and errors 218 | ** =================================================================== 219 | */ 220 | 221 | /* print a string */ 222 | #if !defined(lua_writestring) 223 | #define lua_writestring(L, s,l) fwrite((s), sizeof(char), (l), stdout) 224 | #endif 225 | 226 | /* print a newline and flush the output */ 227 | #if !defined(lua_writeline) 228 | #define lua_writeline(L) (lua_writestring(L, "\n", 1), fflush(stdout)) 229 | #endif 230 | 231 | /* print an error message */ 232 | #if !defined(lua_writestringerror) 233 | #define lua_writestringerror(L, s,p) \ 234 | (fprintf(stderr, (s), (p)), fflush(stderr)) 235 | #endif 236 | 237 | /* }================================================================== */ 238 | 239 | 240 | /* 241 | ** {============================================================ 242 | ** Compatibility with deprecated conversions 243 | ** ============================================================= 244 | */ 245 | #if defined(LUA_COMPAT_APIINTCASTS) 246 | 247 | #define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a)) 248 | #define luaL_optunsigned(L,a,d) \ 249 | ((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d))) 250 | 251 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) 252 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) 253 | 254 | #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) 255 | #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) 256 | 257 | #endif 258 | /* }============================================================ */ 259 | 260 | 261 | 262 | #endif 263 | 264 | 265 | -------------------------------------------------------------------------------- /3rd/lua/src/lstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstate.h,v 2.133.1.1 2017/04/19 17:39:34 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 | ** Moreover, there is another set of lists that control gray objects. 31 | ** These lists are linked by fields 'gclist'. (All objects that 32 | ** can become gray have such a field. The field is not the same 33 | ** in all objects, but it always has this name.) Any gray object 34 | ** must belong to one of these lists, and all objects in these lists 35 | ** must be gray: 36 | ** 37 | ** 'gray': regular gray objects, still waiting to be visited. 38 | ** 'grayagain': objects that must be revisited at the atomic phase. 39 | ** That includes 40 | ** - black objects got in a write barrier; 41 | ** - all kinds of weak tables during propagation phase; 42 | ** - all threads. 43 | ** 'weak': tables with weak values to be cleared; 44 | ** 'ephemeron': ephemeron tables with white->white entries; 45 | ** 'allweak': tables with weak keys and/or weak values to be cleared. 46 | ** The last three lists are used only during the atomic phase. 47 | 48 | */ 49 | 50 | 51 | struct lua_longjmp; /* defined in ldo.c */ 52 | 53 | 54 | /* 55 | ** Atomic type (relative to signals) to better ensure that 'lua_sethook' 56 | ** is thread safe 57 | */ 58 | #if !defined(l_signalT) 59 | #include 60 | #define l_signalT sig_atomic_t 61 | #endif 62 | 63 | 64 | /* extra stack space to handle TM calls and some other extras */ 65 | #define EXTRA_STACK 5 66 | 67 | 68 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) 69 | 70 | 71 | /* kinds of Garbage Collection */ 72 | #define KGC_NORMAL 0 73 | #define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */ 74 | 75 | 76 | typedef struct stringtable { 77 | TString **hash; 78 | int nuse; /* number of elements */ 79 | int size; 80 | } stringtable; 81 | 82 | 83 | /* 84 | ** Information about a call. 85 | ** When a thread yields, 'func' is adjusted to pretend that the 86 | ** top function has only the yielded values in its stack; in that 87 | ** case, the actual 'func' value is saved in field 'extra'. 88 | ** When a function calls another with a continuation, 'extra' keeps 89 | ** the function index so that, in case of errors, the continuation 90 | ** function can be called with the correct top. 91 | */ 92 | typedef struct CallInfo { 93 | StkId func; /* function index in the stack */ 94 | StkId top; /* top for this function */ 95 | struct CallInfo *previous, *next; /* dynamic call link */ 96 | union { 97 | struct { /* only for Lua functions */ 98 | StkId base; /* base for this function */ 99 | const Instruction *savedpc; 100 | } l; 101 | struct { /* only for C functions */ 102 | lua_KFunction k; /* continuation in case of yields */ 103 | ptrdiff_t old_errfunc; 104 | lua_KContext ctx; /* context info. in case of yields */ 105 | } c; 106 | } u; 107 | ptrdiff_t extra; 108 | short nresults; /* expected number of results from this function */ 109 | unsigned short callstatus; 110 | } CallInfo; 111 | 112 | 113 | /* 114 | ** Bits in CallInfo status 115 | */ 116 | #define CIST_OAH (1<<0) /* original value of 'allowhook' */ 117 | #define CIST_LUA (1<<1) /* call is running a Lua function */ 118 | #define CIST_HOOKED (1<<2) /* call is running a debug hook */ 119 | #define CIST_FRESH (1<<3) /* call is running on a fresh invocation 120 | of luaV_execute */ 121 | #define CIST_YPCALL (1<<4) /* call is a yieldable protected call */ 122 | #define CIST_TAIL (1<<5) /* call was tail called */ 123 | #define CIST_HOOKYIELD (1<<6) /* last hook called yielded */ 124 | #define CIST_LEQ (1<<7) /* using __lt for __le */ 125 | #define CIST_FIN (1<<8) /* call is running a finalizer */ 126 | 127 | #define isLua(ci) ((ci)->callstatus & CIST_LUA) 128 | 129 | /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */ 130 | #define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v)) 131 | #define getoah(st) ((st) & CIST_OAH) 132 | 133 | 134 | /* 135 | ** 'global state', shared by all threads of this state 136 | */ 137 | typedef struct global_State { 138 | lua_Alloc frealloc; /* function to reallocate memory */ 139 | void *ud; /* auxiliary data to 'frealloc' */ 140 | l_mem totalbytes; /* number of bytes currently allocated - GCdebt */ 141 | l_mem GCdebt; /* bytes allocated not yet compensated by the collector */ 142 | lu_mem GCmemtrav; /* memory traversed by the GC */ 143 | lu_mem GCestimate; /* an estimate of the non-garbage memory in use */ 144 | stringtable strt; /* hash table for strings */ 145 | TValue l_registry; 146 | unsigned int seed; /* randomized seed for hashes */ 147 | lu_byte currentwhite; 148 | lu_byte gcstate; /* state of garbage collector */ 149 | lu_byte gckind; /* kind of GC running */ 150 | lu_byte gcrunning; /* true if GC is running */ 151 | GCObject *allgc; /* list of all collectable objects */ 152 | GCObject **sweepgc; /* current position of sweep in list */ 153 | GCObject *finobj; /* list of collectable objects with finalizers */ 154 | GCObject *gray; /* list of gray objects */ 155 | GCObject *grayagain; /* list of objects to be traversed atomically */ 156 | GCObject *weak; /* list of tables with weak values */ 157 | GCObject *ephemeron; /* list of ephemeron tables (weak keys) */ 158 | GCObject *allweak; /* list of all-weak tables */ 159 | GCObject *tobefnz; /* list of userdata to be GC */ 160 | GCObject *fixedgc; /* list of objects not to be collected */ 161 | struct lua_State *twups; /* list of threads with open upvalues */ 162 | unsigned int gcfinnum; /* number of finalizers to call in each GC step */ 163 | int gcpause; /* size of pause between successive GCs */ 164 | int gcstepmul; /* GC 'granularity' */ 165 | lua_CFunction panic; /* to be called in unprotected errors */ 166 | struct lua_State *mainthread; 167 | const lua_Number *version; /* pointer to version number */ 168 | TString *memerrmsg; /* memory-error message */ 169 | TString *tmname[TM_N]; /* array with tag-method names */ 170 | struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ 171 | TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */ 172 | } global_State; 173 | 174 | 175 | /* 176 | ** 'per thread' state 177 | */ 178 | struct lua_State { 179 | CommonHeader; 180 | unsigned short nci; /* number of items in 'ci' list */ 181 | lu_byte status; 182 | StkId top; /* first free slot in the stack */ 183 | global_State *l_G; 184 | CallInfo *ci; /* call info for current function */ 185 | const Instruction *oldpc; /* last pc traced */ 186 | StkId stack_last; /* last free slot in the stack */ 187 | StkId stack; /* stack base */ 188 | UpVal *openupval; /* list of open upvalues in this stack */ 189 | GCObject *gclist; 190 | struct lua_State *twups; /* list of threads with open upvalues */ 191 | struct lua_longjmp *errorJmp; /* current error recover point */ 192 | CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ 193 | volatile lua_Hook hook; 194 | ptrdiff_t errfunc; /* current error handling function (stack index) */ 195 | int stacksize; 196 | int basehookcount; 197 | int hookcount; 198 | unsigned short nny; /* number of non-yieldable calls in stack */ 199 | unsigned short nCcalls; /* number of nested C calls */ 200 | l_signalT hookmask; 201 | lu_byte allowhook; 202 | }; 203 | 204 | 205 | #define G(L) (L->l_G) 206 | 207 | 208 | /* 209 | ** Union of all collectable objects (only for conversions) 210 | */ 211 | union GCUnion { 212 | GCObject gc; /* common header */ 213 | struct TString ts; 214 | struct Udata u; 215 | union Closure cl; 216 | struct Table h; 217 | struct Proto p; 218 | struct lua_State th; /* thread */ 219 | }; 220 | 221 | 222 | #define cast_u(o) cast(union GCUnion *, (o)) 223 | 224 | /* macros to convert a GCObject into a specific value */ 225 | #define gco2ts(o) \ 226 | check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts)) 227 | #define gco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u)) 228 | #define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l)) 229 | #define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c)) 230 | #define gco2cl(o) \ 231 | check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl)) 232 | #define gco2t(o) check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h)) 233 | #define gco2p(o) check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p)) 234 | #define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th)) 235 | 236 | 237 | /* macro to convert a Lua object into a GCObject */ 238 | #define obj2gco(v) \ 239 | check_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc))) 240 | 241 | 242 | /* actual number of total bytes allocated */ 243 | #define gettotalbytes(g) cast(lu_mem, (g)->totalbytes + (g)->GCdebt) 244 | 245 | LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); 246 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 247 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); 248 | LUAI_FUNC void luaE_freeCI (lua_State *L); 249 | LUAI_FUNC void luaE_shrinkCI (lua_State *L); 250 | 251 | 252 | #endif 253 | 254 | --------------------------------------------------------------------------------