├── .gitattributes ├── .gitignore ├── AboutFrontend.cpp ├── AboutFrontend.hpp ├── AboutFrontend.ui ├── AboutPatreon.cpp ├── AboutPatreon.hpp ├── AboutPatreon.ui ├── Console.cpp ├── Console.hpp ├── Console.ui ├── DOCUMENT.md ├── LICENSE ├── LuaBackend.cpp ├── LuaBackend.hpp ├── LuaFrontend.pro ├── LuaThread.cpp ├── LuaThread.hpp ├── Main.cpp ├── MainWindow.cpp ├── MainWindow.hpp ├── MainWindow.ui ├── README.md ├── Resources.qrc ├── WaitDialog.cpp ├── WaitDialog.hpp ├── WaitDialog.ui ├── Windows.rc ├── configs ├── gameConfig.toml └── prefConfig.toml ├── include ├── DCInstance.hpp ├── MemoryLib.hpp ├── Operator32Lib.hpp ├── crcpp │ └── CRC32.h ├── discord │ ├── discord_register.h │ └── discord_rpc.h ├── lua │ ├── lapi.h │ ├── lauxlib.h │ ├── lcode.h │ ├── lctype.h │ ├── ldebug.h │ ├── ldo.h │ ├── lfunc.h │ ├── lgc.h │ ├── ljumptab.h │ ├── llex.h │ ├── llimits.h │ ├── lmem.h │ ├── lobject.h │ ├── lopcodes.h │ ├── lopnames.h │ ├── lparser.h │ ├── lprefix.h │ ├── lstate.h │ ├── lstring.h │ ├── ltable.h │ ├── ltm.h │ ├── lua.h │ ├── lua.hpp │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.h │ ├── lvm.h │ └── lzio.h ├── sol2 │ ├── config.hpp │ ├── forward.hpp │ └── sol.hpp └── toml11 │ ├── toml.hpp │ └── toml │ ├── color.hpp │ ├── combinator.hpp │ ├── comments.hpp │ ├── datetime.hpp │ ├── exception.hpp │ ├── from.hpp │ ├── get.hpp │ ├── into.hpp │ ├── lexer.hpp │ ├── literal.hpp │ ├── macros.hpp │ ├── parser.hpp │ ├── region.hpp │ ├── result.hpp │ ├── serializer.hpp │ ├── source_location.hpp │ ├── storage.hpp │ ├── string.hpp │ ├── traits.hpp │ ├── types.hpp │ ├── utility.hpp │ └── value.hpp ├── languages ├── en_US.ts └── tr_TR.ts ├── libraries ├── discord-rpc.lib └── lua.lib ├── resources ├── error.png ├── good.png ├── iconMain.ico ├── iconMain.png ├── iconPatreon.png └── warning.png └── version.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | libraries/discord-rpc.dll 3 | libraries/Lua.dll 4 | LuaFrontend.pro.user 5 | -------------------------------------------------------------------------------- /AboutFrontend.cpp: -------------------------------------------------------------------------------- 1 | #include "AboutFrontend.hpp" 2 | #include "ui_AboutFrontend.h" 3 | 4 | AboutFrontend::AboutFrontend(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::AboutFrontend) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | AboutFrontend::~AboutFrontend() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /AboutFrontend.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ABOUTFRONTEND_HPP 2 | #define ABOUTFRONTEND_HPP 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class AboutFrontend; 8 | } 9 | 10 | class AboutFrontend : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit AboutFrontend(QWidget *parent = nullptr); 16 | ~AboutFrontend(); 17 | 18 | private: 19 | Ui::AboutFrontend *ui; 20 | }; 21 | 22 | #endif // ABOUTFRONTEND_HPP 23 | -------------------------------------------------------------------------------- /AboutFrontend.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AboutFrontend 4 | 5 | 6 | Qt::WindowModal 7 | 8 | 9 | 10 | 0 11 | 0 12 | 633 13 | 188 14 | 15 | 16 | 17 | About LuaFrontend 18 | 19 | 20 | 21 | :/resources/iconMain.ico:/resources/iconMain.ico 22 | 23 | 24 | 25 | 26 | 14 27 | 8 28 | 171 29 | 171 30 | 31 | 32 | 33 | 34 | 35 | 36 | :/resources/iconMain.png 37 | 38 | 39 | true 40 | 41 | 42 | 43 | 44 | 45 | 200 46 | 3 47 | 291 48 | 41 49 | 50 | 51 | 52 | 53 | 14 54 | true 55 | 56 | 57 | 58 | LuaFrontend v1.15 59 | 60 | 61 | 62 | 63 | 64 | 200 65 | 60 66 | 411 67 | 21 68 | 69 | 70 | 71 | 72 | 10 73 | false 74 | 75 | 76 | 77 | LuaFrontend powered by Qt 6.2.2 (MSVC 2019, x64) 78 | 79 | 80 | 81 | 82 | 83 | 200 84 | 33 85 | 311 86 | 21 87 | 88 | 89 | 90 | 91 | 10 92 | false 93 | 94 | 95 | 96 | Compatible with LuaEngine v5.10. 97 | 98 | 99 | 100 | 101 | 102 | 200 103 | 105 104 | 411 105 | 21 106 | 107 | 108 | 109 | 110 | 9 111 | false 112 | 113 | 114 | 115 | Copyright 2020-2022 / TopazTK - Certain rights reserved. 116 | 117 | 118 | 119 | 120 | 121 | 200 122 | 125 123 | 411 124 | 21 125 | 126 | 127 | 128 | 129 | 9 130 | false 131 | 132 | 133 | 134 | Copyright 2008-2022 / Qt Company Ltd. All rights reserved. 135 | 136 | 137 | 138 | 139 | 140 | 200 141 | 153 142 | 421 143 | 21 144 | 145 | 146 | 147 | 148 | 9 149 | false 150 | 151 | 152 | 153 | 3rd Party libraries included. See the Github Repository for info. 154 | 155 | 156 | 157 | 158 | 159 | 200 160 | 78 161 | 411 162 | 21 163 | 164 | 165 | 166 | 167 | 10 168 | false 169 | 170 | 171 | 172 | LuaEngine powered by Lua 5.4.3 (MSVC 2019, x64) 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /AboutPatreon.cpp: -------------------------------------------------------------------------------- 1 | #include "AboutPatreon.hpp" 2 | #include "ui_AboutPatreon.h" 3 | 4 | AboutPatreon::AboutPatreon(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::AboutPatreon) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | AboutPatreon::~AboutPatreon() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /AboutPatreon.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ABOUTPATREON_HPP 2 | #define ABOUTPATREON_HPP 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class AboutPatreon; 8 | } 9 | 10 | class AboutPatreon : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit AboutPatreon(QWidget *parent = nullptr); 16 | ~AboutPatreon(); 17 | 18 | private: 19 | Ui::AboutPatreon *ui; 20 | }; 21 | 22 | #endif // ABOUTPATREON_HPP 23 | -------------------------------------------------------------------------------- /AboutPatreon.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AboutPatreon 4 | 5 | 6 | Qt::WindowModal 7 | 8 | 9 | 10 | 0 11 | 0 12 | 633 13 | 188 14 | 15 | 16 | 17 | Consider... 18 | 19 | 20 | 21 | :/resources/iconMain.ico:/resources/iconMain.ico 22 | 23 | 24 | 25 | 26 | 14 27 | 8 28 | 171 29 | 171 30 | 31 | 32 | 33 | 34 | 35 | 36 | :/resources/iconPatreon.png 37 | 38 | 39 | true 40 | 41 | 42 | 43 | 44 | 45 | 200 46 | 3 47 | 291 48 | 41 49 | 50 | 51 | 52 | 53 | 14 54 | true 55 | 56 | 57 | 58 | Consider Supporting TopazTK! 59 | 60 | 61 | 62 | 63 | 64 | 200 65 | 45 66 | 411 67 | 101 68 | 69 | 70 | 71 | 72 | 9 73 | false 74 | 75 | 76 | 77 | <html><head/><body><p>TopazTK is a lone developer, trying his best to make programs like LuaFrontend, and mods like Re:Fixed possible. Unfortunately, however, he is not financially stable enough to pour a lot of time to these projects. By supporting TopazTK on Patreon, you can make it possible for him to work on these things for longer, allowing him to do his passion job! There are also some benefits to this so please, do consider.</p></body></html> 78 | 79 | 80 | true 81 | 82 | 83 | 84 | 85 | 86 | 200 87 | 153 88 | 421 89 | 21 90 | 91 | 92 | 93 | 94 | 9 95 | false 96 | 97 | 98 | 99 | <html><head/><body><p>Any support is appreciated: <a href="https://patreon.com/topaztk"><span style=" text-decoration: underline; color:#007af4;">https://patreon.com/topaztk</span></a></p></body></html> 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /Console.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | Console::Console(QWidget *parent) : QDialog(parent), ui(new Ui::Console) 5 | { 6 | ui->setupUi(this); 7 | 8 | ui->output->setStyleSheet("font: 9pt \"Consolas\";"); 9 | 10 | ui->output->append("========================================"); 11 | ui->output->append("== LuaFrontend v1.15S - Powered by QT =="); 12 | ui->output->append("======= Copyright 2021 - TopazTK ======="); 13 | ui->output->append("========================================"); 14 | ui->output->append("==== Compatible with LuaEngine v5.1 ===="); 15 | ui->output->append("========================================"); 16 | ui->output->append(""); 17 | 18 | connect(this, SIGNAL(rejected()), parent, SLOT(consoleToggle())); 19 | } 20 | 21 | Console::~Console() 22 | { 23 | delete ui; 24 | } 25 | 26 | void Console::printMessage(QString inputTxt, int type) 27 | { 28 | QString _colors[] = { "CADETBLUE", "GREEN", "ORANGE", "RED" }; 29 | QString _titles[] = { "MESSAGE", "SUCCESS", "WARNING", "ERROR" }; 30 | 31 | QString _prefix = "%2: "; 32 | _prefix = _prefix.arg(_colors[type], _titles[type]); 33 | 34 | inputTxt = inputTxt.replace("\n", "
"); 35 | ui->output->append(_prefix + inputTxt); 36 | } 37 | -------------------------------------------------------------------------------- /Console.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CONSOLE_H 2 | #define CONSOLE_H 3 | 4 | #include 5 | 6 | namespace Ui { class Console; } 7 | 8 | class Console : public QDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | void printMessage(QString, int type = 0); 14 | 15 | explicit Console(QWidget *parent = nullptr); 16 | ~Console(); 17 | 18 | private: 19 | Ui::Console *ui; 20 | }; 21 | 22 | #endif // CONSOLE_H 23 | -------------------------------------------------------------------------------- /Console.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Console 4 | 5 | 6 | 7 | 0 8 | 0 9 | 438 10 | 354 11 | 12 | 13 | 14 | LuaEngine Console [v5.0 | STABLE] 15 | 16 | 17 | 18 | :/resources/iconMain.ico:/resources/iconMain.ico 19 | 20 | 21 | 22 | 0 23 | 24 | 25 | 5 26 | 27 | 28 | 5 29 | 30 | 31 | 5 32 | 33 | 34 | 5 35 | 36 | 37 | 38 | 39 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 40 | <html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css"> 41 | p, li { white-space: pre-wrap; } 42 | </style></head><body style=" font-family:'Segoe UI'; font-size:9pt; font-weight:400; font-style:normal;"> 43 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8.25pt;"><br /></p></body></html> 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /DOCUMENT.md: -------------------------------------------------------------------------------- 1 | ## LuaEngine Cheatsheet v5.10 2 | 3 | --- 4 | 5 | ## Global Variables 6 | 7 | - ``GAME_ID`` => Returns the current game's CRC32 checksum as an integer. This checksum is generated from the process name at this moment. 8 | - ``LUA_NAME`` => The name of your Lua script, used by functions such as ConsolePrint. It is the filename of your Lua by default. 9 | - ``SCRIPT_PATH`` => Returns the path which Lua scripts are loaded from as a string. Ex: ``"C:\Users\Topaz\Desktop\LuaBackend\scripts"`` 10 | - ``CHEATS_PATH`` => Always returns ``"NOT_AVAILABLE"`` 11 | - ``ENGINE_VERSION`` => Returns the LuaBackend's engine version as a float. Ex: ``5`` 12 | - ``ENGINE_TYPE`` => Always returns ``"BACKEND"`` 13 | 14 | ## Memory Functions 15 | 16 | ### Read\[XXXX\](Address, Absolute = false) / ReadString(Address, Length, Absolute = false) 17 | 18 | Reads a certain value from **Address**. Returns the read value. If reading a String, length must also be declared. 19 | The "**XXXX**" is a placeholder for the value type. 20 | 21 | If **Absolute** is true, the address is taken as written and base address is not added into it. 22 | 23 | List of types available: Byte, Short, Int, Long, Float, String, Boolean 24 | 25 | Example: 26 | ```lua 27 | local _tempInt = ReadInt(0xDEADB00) -- Read an integer from address BaseAddress+0xDEADB00 28 | local _tempByte = ReadByte(0xB007555) -- Read a byte from address BaseAddress+0xB007555 29 | ``` 30 | 31 | ### Write\[XXXX\](Address, Value, Abolsute = false) 32 | 33 | Writes **Value** to **Address** calculated relative to the base address. 34 | The "**\[XXXX\]**" is a placeholder for the value type. 35 | 36 | If **Absolute** is true, the address is taken as written and base address is not added into it. 37 | 38 | List of types available: Byte, Short, Int, Long, Float, String, Boolean 39 | 40 | Example: 41 | ```lua 42 | WriteShort(0xDEADB00, 0xFFFF) -- Write 0xFFFF to BaseAddress+0xDEADB00 43 | WriteBoolean(0xB007555, true) -- Write true to BaseAddress+0xB007555 44 | ``` 45 | 46 | 47 | ### ReadArray(Address, Length, Absolute = false) 48 | 49 | Reads **Length** amount of bytes from memory, starting at **Address**. Returns the read bytes as an array. 50 | If **Absolute** is true, the address is taken as written and base address is not added into it. 51 | 52 | Example: 53 | ```lua 54 | local _tempArray = ReadArray(0xBEEFDED, 0x10) -- Reads 16 bytes starting at BaseAddress+0xBEEFDED 55 | ``` 56 | 57 | ### WriteArray(Address, Array, Absolute = false) 58 | 59 | Writes **Array** to the memory, starting at **Address**. The array must be made of bytes (8-bit integers). 60 | If **Absolute** is true, the address is taken as written and base address is not added into it. 61 | 62 | Example: 63 | ```lua 64 | local _tempArray = { 0xFE, 0xA5, 0x70 } 65 | WriteArray(0x6660420, _tempArray) -- Writes _tempArray to memory, starting at BaseAddress+0x6660420 66 | ``` 67 | 68 | ### GetPointer(Address, Offset, Absolute = false) 69 | 70 | Calculates a pointer with the given values. 71 | Basically, reads the value at **Address** and adds **Offset** to it. Returns the resulting value. 72 | 73 | If **Absolute** is true, the address is taken as written and base address is not added into it. 74 | 75 | Example: 76 | ```lua 77 | local _tempPointer = GetPointer(0xBEEFDAD, 0x15) -- Reads the value at BaseAddress+0xBEEFDAD and adds 0x15 to it. 78 | ``` 79 | 80 | ## General I/O Functions 81 | 82 | ### GetHertz() 83 | 84 | Gets the frequency of which LuaBackend scripts execute. 85 | 86 | ### SetHertz(Frequency) 87 | 88 | Sets the Backend execution cycle to **Frequency**. The accepted values are **60**, **120**, and **240**. 89 | 90 | ### ULShift32(Base, Shift) 91 | 92 | Shifts **Base** left by **Shift** abont of bytes. Only exists for 32-bit applications. 93 | 94 | Example: 95 | ```lua 96 | ULShift32(4294967295, 8) -- Shifts 4294967295 left by 8 bytes without an overflow to 64-bits. 97 | ``` 98 | 99 | ### ConsolePrint(Text, Type = NULL) 100 | 101 | Prints **Text** to the console, in the format given below. 102 | Unless **Type** is declared, nothing will prefix the message. 103 | 104 | **Type** can be the following: 105 | - 0 = MESSAGE 106 | - 1 = SUCCESS 107 | - 2 = WARNING 108 | - 3 = ERROR 109 | 110 | Format: 111 | ``` 112 | [LUA_NAME] TYPE: Text 113 | ``` 114 | 115 | Example: 116 | ```lua 117 | LUA_NAME = "SomeDudeScript" 118 | ConsolePrint("GET UP ON THE HYDRA'S BACK!") -- Prints the following: [SomeDudeScript] GET UP ON THE HYDRA'S BACK! 119 | ConsolePrint("NICE VIEW FROM UP HERE!", 0) -- Prints the following: [SomeDudeScript] MESSAGE: NICE VIEW FROM UP HERE! 120 | ``` 121 | 122 | ## Discord RPC Functions 123 | 124 | ### InitializeRPC(ApplicationID) 125 | 126 | Initializes and hooks a Discord Application with **ApplicationID**, for Rich Presence control. 127 | 128 | Example: 129 | ```lua 130 | InitializeRPC("833511404274974740") -- Initiaizes Discord Application "833511404274974740". 131 | ``` 132 | 133 | ### UpdateDetails(Text) 134 | 135 | Updates the details of the rich presence application initialized with InitializeRPC to say **Text**. 136 | 137 | Example: 138 | ```lua 139 | UpdateDetails("Hello World!") -- Updates the details section of the RPC to say "Hello World!". 140 | ``` 141 | 142 | ### UpdateState(Text) 143 | 144 | Updates the state of the rich presence application initialized with InitializeRPC to say **Text**. 145 | 146 | Example: 147 | ```lua 148 | UpdateState("Hello World!") -- Updates the state section of the RPC to say "Hello World!". 149 | ``` 150 | 151 | ### UpdateLImage(Key, Text) 152 | 153 | Updates the large image of the rich presence to be the image with **Key**. And it's text is updates to say **Text**. 154 | 155 | Example: 156 | ```lua 157 | UpdateLImage("image", "This is Image!") -- Updates the large image to "image" and it's text to "This is Image!" 158 | ``` 159 | 160 | ### UpdateSImage(Key, Text) 161 | 162 | Updates the small image of the rich presence to be the image with **Key**. And it's text is updates to say **Text**. 163 | 164 | Example: 165 | ```lua 166 | UpdateSImage("imagetwo", "This too, is Image!") -- Updates the small image to "imagetwo" and it's text to "This too, is Image!" 167 | ``` 168 | 169 | ### WriteExec(Address, Value) 170 | 171 | Writes the given byte array **Value** to **Address** relative to the current EXE's address, NOT the provided base address. 172 | This function is non-existent on PCSX2-EX. 173 | 174 | Example: 175 | ```lua 176 | WriteExec(0x00FBAAD, 0x15) -- Writes 0x15 to EXE_NAME.exe+0x00FBAAD. 177 | 178 | ``` 179 | 180 | #### * Any functions present in this document signify compatibility with the latest version. Any function absent in this document is no longer supported and should be considered obsolete. 181 | -------------------------------------------------------------------------------- /LuaBackend.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | LuaBackend::LuaBackend() { } 4 | 5 | LuaBackend::LuaBackend(const char* ScrPath, uint64_t BaseInput, uint64_t ExecInput, Console* TargetConsole) 6 | { 7 | frameLimit = 1000 / 60; 8 | loadedScripts = vector(); 9 | scrPath = ScrPath; 10 | 11 | _outputConsole = TargetConsole; 12 | 13 | LoadScripts(ScrPath, BaseInput, ExecInput); 14 | } 15 | 16 | void LuaBackend::LoadScripts(const char* ScrPath, uint64_t BaseInput, uint64_t ExecInput) 17 | { 18 | loadedScripts.clear(); 19 | auto _iterator = QDirIterator(ScrPath, QDirIterator::Subdirectories); 20 | 21 | while (_iterator.hasNext()) 22 | { 23 | auto _path = _iterator.next(); 24 | 25 | if (_path.contains(".lua") && !_path.contains("io_packages") && !_path.contains("io_load")) 26 | { 27 | LuaScript* _script = new LuaScript(); 28 | 29 | _script->scriptPath = _path; 30 | 31 | _script->luaState.open_libraries 32 | ( 33 | lib::base, 34 | lib::package, 35 | lib::coroutine, 36 | lib::string, 37 | lib::os, 38 | lib::math, 39 | lib::table, 40 | lib::io, 41 | lib::bit32, 42 | lib::utf8 43 | ); 44 | 45 | _script->luaState.set_exception_handler(&ExceptionHandle); 46 | 47 | SetFunctions(&_script->luaState); 48 | 49 | string _luaPath = ScrPath; 50 | _luaPath.append("\\io_packages\\?.lua"); 51 | 52 | string _dllPath = ScrPath; 53 | _dllPath.append("\\io_packages\\?.dll"); 54 | 55 | _script->luaState["package"]["path"] = _luaPath; 56 | _script->luaState["package"]["cpath"] = _dllPath; 57 | 58 | string _loadPath = ScrPath; 59 | _loadPath.append("\\io_load"); 60 | 61 | _script->luaState["LOAD_PATH"] = _loadPath; 62 | _script->luaState["SCRIPT_PATH"] = ScrPath; 63 | _script->luaState["CHEATS_PATH"] = "NOT_AVAILABLE"; 64 | 65 | string _pathFull = MemoryLib::PName; 66 | auto _pathExe = _pathFull.substr(_pathFull.find_last_of("\\") + 1); 67 | 68 | _script->luaState["ENGINE_VERSION"] = 5.2; 69 | _script->luaState["ENGINE_TYPE"] = "BACKEND"; 70 | _script->luaState["GAME_ID"] = CRC::Calculate(_pathExe.c_str(), _pathExe.length(), CRC::CRC_32()); 71 | _script->luaState["BASE_ADDR"] = BaseInput; 72 | _script->luaState["EXEC_ADDR"] = ExecInput; 73 | 74 | _script->parseResult = _script->luaState.script_file(_path.toStdString(), &sol::script_pass_on_error); 75 | 76 | _script->initFunction = _script->luaState["_OnInit"]; 77 | _script->frameFunction = _script->luaState["_OnFrame"]; 78 | 79 | string _luaName = _path.split('/').last().toStdString(); 80 | _script->luaState["LUA_NAME"] = _luaName.substr(0, _luaName.size() - 4); 81 | 82 | loadedScripts.push_back(_script); 83 | } 84 | } 85 | } 86 | 87 | void LuaBackend::SetFunctions(LuaState* _state) 88 | { 89 | // Reader Functions 90 | 91 | _state->set_function("ReadByte", 92 | sol::overload 93 | ( 94 | [](uint64_t _addr) { return MemoryLib::ReadByte(_addr); }, 95 | [](uint64_t _addr, bool _absolute) { return MemoryLib::ReadByte(_addr, _absolute); } 96 | )); 97 | 98 | _state->set_function("ReadShort", 99 | sol::overload 100 | ( 101 | [](uint64_t _addr) { return MemoryLib::ReadShort(_addr); }, 102 | [](uint64_t _addr, bool _absolute) { return MemoryLib::ReadShort(_addr, _absolute); } 103 | )); 104 | 105 | _state->set_function("ReadInt", 106 | sol::overload 107 | ( 108 | [](uint64_t _addr) { return MemoryLib::ReadInt(_addr); }, 109 | [](uint64_t _addr, bool _absolute) { return MemoryLib::ReadInt(_addr, _absolute); } 110 | )); 111 | 112 | _state->set_function("ReadLong", 113 | sol::overload 114 | ( 115 | [](uint64_t _addr) { return MemoryLib::ReadLong(_addr); }, 116 | [](uint64_t _addr, bool _absolute) { return MemoryLib::ReadLong(_addr, _absolute); } 117 | )); 118 | 119 | _state->set_function("ReadFloat", 120 | sol::overload 121 | ( 122 | [](uint64_t _addr) { return MemoryLib::ReadFloat(_addr); }, 123 | [](uint64_t _addr, bool _absolute) { return MemoryLib::ReadFloat(_addr, _absolute); } 124 | )); 125 | 126 | _state->set_function("ReadBoolean", 127 | sol::overload 128 | ( 129 | [](uint64_t _addr) { return MemoryLib::ReadBool(_addr); }, 130 | [](uint64_t _addr, bool _absolute) { return MemoryLib::ReadBool(_addr, _absolute); } 131 | )); 132 | 133 | _state->set_function("ReadArray", 134 | sol::overload 135 | ( 136 | [](uint64_t _addr, int _len) { return MemoryLib::ReadBytes(_addr, _len); }, 137 | [](uint64_t _addr, int _len, bool _absolute) { return MemoryLib::ReadBytes(_addr, _len, _absolute); } 138 | )); 139 | 140 | _state->set_function("ReadString", 141 | sol::overload 142 | ( 143 | [](uint64_t _addr, int _len) { return MemoryLib::ReadString(_addr, _len); }, 144 | [](uint64_t _addr, int _len, bool _absolute) { return MemoryLib::ReadString(_addr, _len, _absolute); } 145 | )); 146 | 147 | // Writer Functions 148 | 149 | _state->set_function("WriteByte", 150 | sol::overload 151 | ( 152 | [](uint64_t _addr, uint8_t _val) { MemoryLib::WriteByte(_addr, _val); }, 153 | [](uint64_t _addr, uint8_t _val, bool _absolute) { MemoryLib::WriteByte(_addr, _val, _absolute); } 154 | )); 155 | 156 | _state->set_function("WriteShort", 157 | sol::overload 158 | ( 159 | [](uint64_t _addr, uint16_t _val) { MemoryLib::WriteShort(_addr, _val); }, 160 | [](uint64_t _addr, uint16_t _val, bool _absolute) { MemoryLib::WriteShort(_addr, _val, _absolute); } 161 | )); 162 | 163 | _state->set_function("WriteInt", 164 | sol::overload 165 | ( 166 | [](uint64_t _addr, uint32_t _val) { MemoryLib::WriteInt(_addr, _val); }, 167 | [](uint64_t _addr, uint32_t _val, bool _absolute) { MemoryLib::WriteInt(_addr, _val, _absolute); } 168 | )); 169 | 170 | _state->set_function("WriteLong", 171 | sol::overload 172 | ( 173 | [](uint64_t _addr, uint64_t _val) { MemoryLib::WriteLong(_addr, _val); }, 174 | [](uint64_t _addr, uint64_t _val, bool _absolute) { MemoryLib::WriteLong(_addr, _val, _absolute); } 175 | )); 176 | 177 | _state->set_function("WriteFloat", 178 | sol::overload 179 | ( 180 | [](uint64_t _addr, float _val) { MemoryLib::WriteFloat(_addr, _val); }, 181 | [](uint64_t _addr, float _val, bool _absolute) { MemoryLib::WriteFloat(_addr, _val, _absolute); } 182 | )); 183 | 184 | _state->set_function("WriteBoolean", 185 | sol::overload 186 | ( 187 | [](uint64_t _addr, bool _val) { MemoryLib::WriteBool(_addr, _val); }, 188 | [](uint64_t _addr, bool _val, bool _absolute) { MemoryLib::WriteBool(_addr, _val, _absolute); } 189 | )); 190 | 191 | _state->set_function("WriteArray", 192 | sol::overload 193 | ( 194 | [](uint64_t _addr, vector _val) { MemoryLib::WriteBytes(_addr, _val); }, 195 | [](uint64_t _addr, vector _val, bool _absolute) { MemoryLib::WriteBytes(_addr, _val, _absolute); } 196 | 197 | )); 198 | 199 | _state->set_function("WriteString", 200 | sol::overload 201 | ( 202 | [](uint64_t _addr, string _val) { MemoryLib::WriteString(_addr, _val); }, 203 | [](uint64_t _addr, string _val, bool _absolute) { MemoryLib::WriteString(_addr, _val, _absolute); } 204 | )); 205 | 206 | _state->set_function("WriteExec", MemoryLib::WriteExec); 207 | 208 | // Misc. Functions 209 | 210 | _state->set_function("ConsolePrint", 211 | sol::overload( 212 | [this](LuaObject Text) 213 | { 214 | auto _text = QString::fromStdString(Text.as()); 215 | _outputConsole->printMessage(_text, 0); 216 | }, 217 | 218 | [this](LuaObject Text, int MessageType) 219 | { 220 | auto _text = QString::fromStdString(Text.as()); 221 | _outputConsole->printMessage(_text, MessageType); 222 | } 223 | ) 224 | ); 225 | 226 | _state->set_function("GetHertz", [this]() { return floor(1000 / frameLimit); }); 227 | _state->set_function("SetHertz", [this](int _input) { frameLimit = floor(1000 / _input); }); 228 | 229 | _state->set_function("ULShift32", Operator32Lib::UnsignedShift32); 230 | 231 | // Discord Functions 232 | 233 | _state->set_function("InitializeRPC", DCInstance::InitializeRPC); 234 | _state->set_function("UpdateDetails", DCInstance::UpdateDetails); 235 | _state->set_function("UpdateState", DCInstance::UpdateState); 236 | _state->set_function("UpdateLImage", DCInstance::UpdateLImage); 237 | _state->set_function("UpdateSImage", DCInstance::UpdateSImage); 238 | } 239 | -------------------------------------------------------------------------------- /LuaBackend.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABACKEND 2 | #define LUABACKEND 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | using namespace sol; 17 | using namespace std; 18 | 19 | using LuaError = sol::error; 20 | using LuaState = sol::state; 21 | using LuaObject = sol::object; 22 | using LuaFunction = sol::safe_function; 23 | using LuaResult = sol::protected_function_result; 24 | 25 | class LuaBackend 26 | { 27 | public: 28 | struct LuaScript 29 | { 30 | LuaState luaState; 31 | LuaResult parseResult; 32 | LuaFunction initFunction; 33 | LuaFunction frameFunction; 34 | 35 | QString scriptPath; 36 | }; 37 | 38 | float frameLimit; 39 | string scrPath; 40 | 41 | std::vector loadedScripts; 42 | 43 | static int ExceptionHandle(lua_State* luaState, sol::optional thrownException, sol::string_view) 44 | { 45 | const std::exception _ex = *thrownException; 46 | return sol::stack::push(luaState, _ex.what()); 47 | } 48 | 49 | void SetFunctions(LuaState*); 50 | void LoadScripts(const char*, uint64_t, uint64_t); 51 | 52 | LuaBackend(); 53 | LuaBackend(const char*, uint64_t, uint64_t, Console*); 54 | 55 | private: 56 | Console* _outputConsole; 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /LuaFrontend.pro: -------------------------------------------------------------------------------- 1 | QT += core gui widgets network 2 | 3 | CONFIG += c++17 4 | 5 | LIBS += -L$$PWD/libraries/ -llua -ldiscord-rpc 6 | PRE_TARGETDEPS += $$PWD/libraries/discord-rpc.lib 7 | 8 | RC_ICONS = resources/iconMain.ico 9 | RC_FILE = Windows.rc 10 | 11 | TRANSLATIONS = languages/tr_TR.ts languages/en_US.ts 12 | 13 | 14 | SOURCES += \ 15 | AboutFrontend.cpp \ 16 | AboutPatreon.cpp \ 17 | LuaThread.cpp \ 18 | Main.cpp \ 19 | Console.cpp \ 20 | LuaBackend.cpp \ 21 | MainWindow.cpp \ 22 | WaitDialog.cpp \ 23 | 24 | HEADERS += \ 25 | AboutFrontend.hpp \ 26 | AboutPatreon.hpp \ 27 | Console.hpp \ 28 | LuaThread.hpp \ 29 | WaitDialog.hpp \ 30 | LuaBackend.hpp \ 31 | MainWindow.hpp \ 32 | version.h 33 | 34 | FORMS += \ 35 | AboutFrontend.ui \ 36 | AboutPatreon.ui \ 37 | Console.ui \ 38 | MainWindow.ui \ 39 | WaitDialog.ui 40 | 41 | INCLUDEPATH += \ 42 | $$PWD/include/ \ 43 | $$PWD/include/lua \ 44 | $$PWD/include/sol2 \ 45 | $$PWD/include/crcpp \ 46 | $$PWD/include/toml11 \ 47 | $$PWD/include/discord 48 | 49 | DEPENDPATH += \ 50 | $$PWD/include/lua \ 51 | $$PWD/include/discord 52 | 53 | RESOURCES += \ 54 | Resources.qrc 55 | 56 | DISTFILES += \ 57 | Windows.rc 58 | -------------------------------------------------------------------------------- /LuaThread.cpp: -------------------------------------------------------------------------------- 1 | #include "LuaThread.hpp" 2 | 3 | LuaThread::LuaThread(Console* consoleInput) 4 | { 5 | _thread = new QThread(this); 6 | _runTimer = new QTimer(this); 7 | 8 | _console = consoleInput; 9 | } 10 | 11 | void LuaThread::start() 12 | { 13 | this->moveToThread(_thread); 14 | 15 | _runTimer->moveToThread(_thread); 16 | 17 | connect(_thread, SIGNAL(started()), this, SLOT(startEvent())); 18 | connect(_runTimer, SIGNAL(timeout()), this, SLOT(runEvent())); 19 | 20 | _thread->start(); 21 | } 22 | 23 | void LuaThread::stop() 24 | { 25 | _runTimer->stop(); 26 | _thread->exit(); 27 | } 28 | 29 | void LuaThread::startEvent() 30 | { 31 | _runTimer->start(runInterval); 32 | } 33 | 34 | void LuaThread::runEvent() 35 | { 36 | if (exeScript->frameFunction) 37 | { 38 | auto _result = exeScript->frameFunction(); 39 | 40 | if (!_result.valid()) 41 | { 42 | sol::error _err = _result; 43 | 44 | auto _errStr = QString(_err.what()); 45 | _console->printMessage(_errStr + "
", 3); 46 | 47 | _runTimer->stop(); 48 | _thread->exit(); 49 | } 50 | } 51 | 52 | if (_runTimer->interval() != runInterval) 53 | _runTimer->setInterval(runInterval); 54 | } 55 | -------------------------------------------------------------------------------- /LuaThread.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUATHREAD_H 2 | #define LUATHREAD_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | class LuaThread : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | int runInterval; 15 | LuaBackend::LuaScript* exeScript; 16 | 17 | LuaThread(Console*); 18 | 19 | void start(); 20 | void stop(); 21 | 22 | private: 23 | Console* _console; 24 | 25 | QThread* _thread; 26 | QTimer* _runTimer; 27 | 28 | private slots: 29 | void startEvent(); 30 | void runEvent(); 31 | }; 32 | 33 | #endif // LUATHREAD_H 34 | -------------------------------------------------------------------------------- /Main.cpp: -------------------------------------------------------------------------------- 1 | #include "MainWindow.hpp" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication App(argc, argv); 8 | App.setStyle("Fusion"); 9 | 10 | MainWindow w; 11 | w.show(); 12 | 13 | return App.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /MainWindow.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | QT_BEGIN_NAMESPACE 24 | namespace Ui { class MainWindow; } 25 | QT_END_NAMESPACE 26 | 27 | class MainWindow : public QMainWindow 28 | { 29 | struct QGameInfo 30 | { 31 | QString gameName; 32 | QString exeName; 33 | QString scriptPath; 34 | uint64_t baseAddress; 35 | uint64_t offset; 36 | bool isBigEndian; 37 | }; 38 | 39 | Q_OBJECT 40 | 41 | public: 42 | QTimer* latchTimer; 43 | 44 | LuaBackend* backend; 45 | LuaBackend* backendFake; 46 | 47 | MainWindow(QWidget *parent = nullptr); 48 | ~MainWindow(); 49 | 50 | public slots: 51 | void consoleToggle(); 52 | 53 | private slots: 54 | void runEvent(); 55 | void stopEvent(); 56 | void autoToggle(); 57 | void latchEvent(); 58 | void startEvent(); 59 | void darkToggle(); 60 | void reloadEvent(); 61 | void connectEvent(); 62 | void threadToggle(); 63 | void gameClickEvent(int); 64 | void scriptClickEvent(QTreeWidgetItem*, int); 65 | 66 | void scriptContextEvent(QPoint); 67 | 68 | void newScriptEvent(); 69 | void editScriptEvent(); 70 | void deleteScriptEvent(); 71 | void refreshScriptEvent(); 72 | void folderOpenEvent(); 73 | void languageEvent(); 74 | 75 | void showAbout(); 76 | void showPatreon(); 77 | 78 | 79 | private: 80 | toml::value _prefTable; 81 | toml::value _gameToml; 82 | 83 | QPalette _darkPal; 84 | QPalette _lightPal; 85 | 86 | bool _autoBool; 87 | bool _threadBool; 88 | bool _consoleBool; 89 | bool _darkPalBool; 90 | 91 | QString _language; 92 | 93 | Console* _console; 94 | WaitDialog* _waitWindow; 95 | AboutFrontend* _aboutDiag; 96 | AboutPatreon* _patreonDiag; 97 | 98 | QTimer* _runTimer; 99 | QList _threadList; 100 | 101 | QString _basePath; 102 | QGameInfo _currGame; 103 | 104 | int parseGame(); 105 | int parseScript(); 106 | 107 | void serializePref(); 108 | 109 | QTranslator _translator; 110 | 111 | Ui::MainWindow *ui; 112 | 113 | }; 114 | 115 | #endif // MAINWINDOW_H 116 | -------------------------------------------------------------------------------- /MainWindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 555 10 | 365 11 | 12 | 13 | 14 | 15 | 555 16 | 365 17 | 18 | 19 | 20 | LuaFrontend [v1.15 | STABLE] 21 | 22 | 23 | 24 | :/resources/iconMain.ico:/resources/iconMain.ico 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 5 33 | 34 | 35 | 0 36 | 37 | 38 | 0 39 | 40 | 41 | 0 42 | 43 | 44 | 0 45 | 46 | 47 | 48 | 49 | 50 | 2 51 | 0 52 | 53 | 54 | 55 | Games: 56 | 57 | 58 | 59 | 0 60 | 61 | 62 | 0 63 | 64 | 65 | 0 66 | 67 | 68 | 0 69 | 70 | 71 | 0 72 | 73 | 74 | 75 | 76 | Qt::CustomContextMenu 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 6 88 | 0 89 | 90 | 91 | 92 | Scripts: 93 | 94 | 95 | 96 | 0 97 | 98 | 99 | 0 100 | 101 | 102 | 0 103 | 104 | 105 | 0 106 | 107 | 108 | 0 109 | 110 | 111 | 112 | 113 | Qt::CustomContextMenu 114 | 115 | 116 | 16 117 | 118 | 119 | 0 120 | 121 | 122 | 3 123 | 124 | 125 | false 126 | 127 | 128 | 35 129 | 130 | 131 | 132 | 1 133 | 134 | 135 | 136 | 137 | 2 138 | 139 | 140 | 141 | 142 | 3 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 0 159 | 0 160 | 555 161 | 21 162 | 163 | 164 | 165 | 166 | Engine 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | Edit 179 | 180 | 181 | 182 | Languages 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | false 196 | 197 | 198 | Show Console... 199 | 200 | 201 | 202 | 203 | Enable Auto-Reload 204 | 205 | 206 | 207 | 208 | Start Engine 209 | 210 | 211 | 212 | 213 | false 214 | 215 | 216 | Reload Engine 217 | 218 | 219 | 220 | 221 | false 222 | 223 | 224 | Stop Engine 225 | 226 | 227 | 228 | 229 | Switch to Dark Mode 230 | 231 | 232 | 233 | 234 | Enable Multi-Threading 235 | 236 | 237 | 238 | 239 | false 240 | 241 | 242 | false 243 | 244 | 245 | English 246 | 247 | 248 | 249 | 250 | false 251 | 252 | 253 | Turkish 254 | 255 | 256 | 257 | 258 | 259 | 260 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LuaFrontend 2 | 3 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/f203de1330334726a97188ec7aa16654)](https://www.codacy.com/gh/TopazTK/LuaFrontend/dashboard?utm_source=github.com&utm_medium=referral&utm_content=TopazTK/LuaFrontend&utm_campaign=Badge_Grade) 4 | 5 | LuaFrontend is a standalone script interpreter for PC games. It attaches itself to the PC application and executes Lua scripts. 6 | It is fully compatible with LuaEngine. 7 | 8 | ## How do I use LuaEngine mod that I have downloaded with LuaFrontend? 9 | 10 | To use a LuaEngine script, all you have to do is to right click the scripts section of the game you want, and click "**Open Script Folder**", 11 | then drop the script in question to the opened folder. That's it! 12 | 13 | However, LuaEngine also has I/O capability. So if a mod you have downloaded also has "**io_load**" or "**io_packages**" directories included, 14 | you would need to drop those folders to that folder as well. 15 | 16 | ## How do I use libraries made for Lua with LuaEngine? 17 | 18 | The libraries you would need to use must be 5.4.3 compliant. In addition, if the libraries need to be compiled, they must be compiled 19 | for x86_64 and with Lua 5.4.3 with the MSVC 2019 compiler. 20 | 21 | Put the libraries on the "**io_packages**" folder in the script folder of your game. To reference them, you can then use the ``require`` command. 22 | Exampe being, if I want to use ``socket.http`` from LuaSocket, which I put in ``scripts/io_packages/LuaSocket/``, I would need to do: 23 | 24 | ```lua 25 | local http = require("LuaSocket/socket.http") 26 | ``` 27 | 28 | That's it! 29 | 30 | ## How do I use LuaFrontend to create a LuaEngine mod myself? 31 | 32 | Right clock the scripts section of the game you want to make a script for and click "**New Script**". 33 | The script will be created and opened automatically. You should see something like this: 34 | 35 | ```lua 36 | LUAGUI_NAME = "" 37 | LUAGUI_AUTH = "" 38 | LUAGUI_DESC = "" 39 | 40 | function _OnInit() 41 | -- Code here executes on script load. 42 | end 43 | 44 | function _OnFrame() 45 | -- Code here executes on every frame. 46 | end 47 | ``` 48 | 49 | The "LUAGUI" globals are for LuaFrontend. They signify the Title, Author and Description sections respectively. 50 | They are optional globals and not required for operation. 51 | 52 | The script in question should have at least one of these functions to work. The "**\_OnInit**" function is executed when the script is first loaded, 53 | and the "**\_OnFrame**" function is executed every frame. So put the things you want to happen every frame into the "**\_OnFrame**" function. 54 | 55 | That is the minimum you would need to have a functioning script. The rest is on you. The scripts in LuaEngine function just as if they were regular Lua scripts. 56 | Because... they kind of are! 57 | 58 | In **DOCUMENT.md**, you can find the cheatsheet to all LuaEngine specific functions. 59 | 60 | ## How do I add games to LuaFrontend 61 | 62 | Simply open the "**configs/gameConfig.toml**" file and edit it accordingly. You can copy-paste an already-existing game as a template. 63 | The ability to add games from the GUI will come soon-ish. 64 | 65 | ## A script errors out. How can I see what's wrong 66 | 67 | Hover over the script with your mouse to see warnings. 68 | If prompted by the tooltip, double click the script to show a more detailed error. 69 | 70 | ## Important Notes to using LuaEngine 71 | 72 | - All values are unsigned. 73 | - There is no limit for the amount of scripts loaded at this moment. 74 | 75 | ## Third Party Libraries 76 | 77 | https://qt.io/ (Qt 6.2.2) 78 | http://www.lua.org/ (Lua 5.4.3) 79 | https://github.com/ThePhD/sol2 80 | https://github.com/d-bahr/CRCpp 81 | https://github.com/ToruNiina/toml11 82 | https://github.com/discord/discord-rpc 83 | -------------------------------------------------------------------------------- /Resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | resources/error.png 4 | resources/good.png 5 | resources/iconMain.png 6 | resources/warning.png 7 | resources/iconPatreon.png 8 | 9 | 10 | -------------------------------------------------------------------------------- /WaitDialog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | MainWindow* _rootParent; 7 | 8 | WaitDialog::WaitDialog(QWidget *parent) : QDialog(parent), ui(new Ui::WaitDialog) 9 | { 10 | ui->setupUi(this); 11 | 12 | _rootParent = (MainWindow*)parent; 13 | 14 | connect(this, SIGNAL(rejected()), this, SLOT(rejectEvent())); 15 | connect(ui->abortButton, SIGNAL(pressed()), this, SLOT(rejectEvent())); 16 | 17 | setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); 18 | } 19 | 20 | WaitDialog::~WaitDialog() 21 | { 22 | delete ui; 23 | } 24 | 25 | void WaitDialog::rejectEvent() 26 | { 27 | _rootParent->latchTimer->stop(); 28 | this->close(); 29 | } 30 | -------------------------------------------------------------------------------- /WaitDialog.hpp: -------------------------------------------------------------------------------- 1 | #ifndef WAITDIALOG_HPP 2 | #define WAITDIALOG_HPP 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class WaitDialog; 8 | } 9 | 10 | class WaitDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit WaitDialog(QWidget *parent = nullptr); 16 | ~WaitDialog(); 17 | 18 | private: 19 | Ui::WaitDialog *ui; 20 | 21 | private slots: 22 | void rejectEvent(); 23 | }; 24 | 25 | #endif // WAITDIALOG_HPP 26 | -------------------------------------------------------------------------------- /WaitDialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | WaitDialog 4 | 5 | 6 | Qt::WindowModal 7 | 8 | 9 | 10 | 0 11 | 0 12 | 231 13 | 94 14 | 15 | 16 | 17 | Qt::NoContextMenu 18 | 19 | 20 | Please Wait... 21 | 22 | 23 | 24 | :/resources/iconMain.ico:/resources/iconMain.ico 25 | 26 | 27 | 28 | 29 | 30 | Please Wait... Trying to attach to process... 31 | 32 | 33 | 34 | 35 | 36 | 37 | 0 38 | 39 | 40 | 0 41 | 42 | 43 | 44 | 45 | 46 | 47 | Abort 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /Windows.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "resources/iconMain.ico" 2 | 3 | #include 4 | #include "version.h" 5 | 6 | VS_VERSION_INFO VERSIONINFO 7 | FILEVERSION VER_FILEVERSION 8 | PRODUCTVERSION VER_PRODUCTVERSION 9 | BEGIN 10 | BLOCK "StringFileInfo" 11 | BEGIN 12 | BLOCK "040904E4" 13 | BEGIN 14 | VALUE "CompanyName", VER_COMPANYNAME_STR 15 | VALUE "FileDescription", VER_FILEDESCRIPTION_STR 16 | VALUE "FileVersion", VER_FILEVERSION_STR 17 | VALUE "InternalName", VER_INTERNALNAME_STR 18 | VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR 19 | VALUE "LegalTrademarks1", VER_LEGALTRADEMARKS1_STR 20 | VALUE "LegalTrademarks2", VER_LEGALTRADEMARKS2_STR 21 | VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR 22 | VALUE "ProductName", VER_PRODUCTNAME_STR 23 | VALUE "ProductVersion", VER_PRODUCTVERSION_STR 24 | END 25 | END 26 | 27 | BLOCK "VarFileInfo" 28 | BEGIN 29 | VALUE "Translation", 0x409, 1252 30 | END 31 | END 32 | -------------------------------------------------------------------------------- /configs/gameConfig.toml: -------------------------------------------------------------------------------- 1 | [GameEntry00] 2 | Title = "Kingdom Hearts [GL]" 3 | Path = "/scripts/kh1gl/" 4 | Address = "0" 5 | Offset = "3A0606" 6 | BigEndian = false 7 | Executable = "KINGDOM HEARTS FINAL MIX.exe" 8 | 9 | [GameEntry01] 10 | Title = "Kingdom Hearts II [GL]" 11 | Path = "/scripts/kh2gl/" 12 | Address = "0" 13 | Offset = "56450E" 14 | BigEndian = false 15 | Executable = "KINGDOM HEARTS II FINAL MIX.exe" 16 | 17 | [GameEntry02] 18 | Title = "Kingdom Hearts II [JP]" 19 | Path = "/scripts/kh2jp/" 20 | Address = "0" 21 | Offset = "56350E" 22 | BigEndian = false 23 | Executable = "KINGDOM HEARTS II FINAL MIX.exe" 24 | 25 | [GameEntry03] 26 | Title = "RPCS3" 27 | Path = "/scripts/rpcs3/" 28 | Address = "300010000" 29 | Offset = "0" 30 | BigEndian = true 31 | Executable = "RPCS3.exe" 32 | 33 | [GameEntry04] 34 | Title = "Kingdom Hearts Birth by Sleep [GL]" 35 | Path = "/scripts/khbbs/" 36 | Address = "0" 37 | Offset = "60E334" 38 | BigEndian = false 39 | Executable = "KINGDOM HEARTS Birth by Sleep FINAL MIX.exe" 40 | 41 | [GameEntry05] 42 | Title = "Kingdom Hearts Re:Chain of Memories [GL]" 43 | Path = "/scripts/khcom/" 44 | Address = "0" 45 | Offset = "4E4660" 46 | BigEndian = false 47 | Executable = "KINGDOM HEARTS Re_Chain of Memories.exe" 48 | -------------------------------------------------------------------------------- /configs/prefConfig.toml: -------------------------------------------------------------------------------- 1 | [Preferences] 2 | autoBool = false 3 | threadBool = false 4 | consoleBool = false 5 | darkPalBool = false 6 | language = "en_US" 7 | -------------------------------------------------------------------------------- /include/DCInstance.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | class DCInstance { 11 | public: 12 | static inline DiscordRichPresence Presence; 13 | 14 | static void InitializeRPC(const char* applicationID) 15 | { 16 | Discord_Initialize(applicationID, NULL, 1, NULL); 17 | 18 | memset(&DCInstance::Presence, 0, sizeof(DCInstance::Presence)); 19 | 20 | auto _currTime = chrono::system_clock::now().time_since_epoch(); 21 | auto _secondCast = chrono::duration_cast(_currTime); 22 | 23 | DCInstance::Presence.startTimestamp = _secondCast.count(); 24 | Discord_UpdatePresence(&DCInstance::Presence); 25 | } 26 | 27 | static void UpdateDetails(const char* input) 28 | { 29 | DCInstance::Presence.details = input; 30 | Discord_UpdatePresence(&DCInstance::Presence); 31 | } 32 | 33 | static void UpdateState(const char* input) 34 | { 35 | DCInstance::Presence.state = input; 36 | Discord_UpdatePresence(&DCInstance::Presence); 37 | } 38 | 39 | static void UpdateLImage(const char* key, const char* text) 40 | { 41 | DCInstance::Presence.largeImageKey = key; 42 | DCInstance::Presence.largeImageText = text; 43 | Discord_UpdatePresence(&DCInstance::Presence); 44 | } 45 | 46 | static void UpdateSImage(const char* key, const char* text) 47 | { 48 | DCInstance::Presence.smallImageKey = key; 49 | DCInstance::Presence.smallImageText = text; 50 | Discord_UpdatePresence(&DCInstance::Presence); 51 | } 52 | }; -------------------------------------------------------------------------------- /include/MemoryLib.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MEMORYLIB 2 | #define MEMORYLIB 3 | 4 | #if defined(_WIN32) || defined(_WIN64) 5 | #include 6 | #include 7 | #include "TlHelp32.h" 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | class MemoryLib 17 | { 18 | private: 19 | 20 | #if defined(_WIN32) || defined(_WIN64) 21 | static inline STARTUPINFOA _sInfo; 22 | static inline PROCESS_INFORMATION _pInfo; 23 | #endif 24 | 25 | public: 26 | 27 | static inline uint64_t ExecAddress; 28 | static inline uint64_t BaseAddress; 29 | static inline bool BigEndian = false; 30 | 31 | #if defined(_WIN32) || defined(_WIN64) 32 | static inline DWORD PIdentifier = 0; 33 | static inline HANDLE PHandle = NULL; 34 | static inline char PName[MAX_PATH]; 35 | 36 | static HMODULE FindBaseAddr(HANDLE InputHandle, string InputName) 37 | { 38 | HMODULE hMods[1024]; 39 | DWORD cbNeeded; 40 | unsigned int i; 41 | 42 | if (EnumProcessModules(InputHandle, hMods, sizeof(hMods), &cbNeeded)) 43 | { 44 | for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) 45 | { 46 | TCHAR szModName[MAX_PATH]; 47 | if (GetModuleFileNameEx(InputHandle, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))) 48 | { 49 | wstring wstrModName = szModName; 50 | wstring wstrModContain = wstring(InputName.begin(), InputName.end()); 51 | 52 | if (wstrModName.find(wstrModContain) != string::npos) 53 | return hMods[i]; 54 | } 55 | } 56 | } 57 | 58 | return nullptr; 59 | } 60 | 61 | static DWORD FindProcessId(const std::wstring& processName) 62 | { 63 | PROCESSENTRY32 processInfo; 64 | processInfo.dwSize = sizeof(processInfo); 65 | 66 | HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 67 | if (processesSnapshot == INVALID_HANDLE_VALUE) 68 | return 0; 69 | 70 | Process32First(processesSnapshot, &processInfo); 71 | if (!processName.compare(processInfo.szExeFile)) 72 | { 73 | CloseHandle(processesSnapshot); 74 | return processInfo.th32ProcessID; 75 | } 76 | 77 | while (Process32Next(processesSnapshot, &processInfo)) 78 | { 79 | if (!processName.compare(processInfo.szExeFile)) 80 | { 81 | CloseHandle(processesSnapshot); 82 | return processInfo.th32ProcessID; 83 | } 84 | } 85 | 86 | CloseHandle(processesSnapshot); 87 | return 0; 88 | } 89 | static int ExecuteProcess(string InputName, uint64_t InputAddress, bool InputEndian) 90 | { 91 | ZeroMemory(&_sInfo, sizeof(_sInfo)); _sInfo.cb = sizeof(_sInfo); 92 | ZeroMemory(&_pInfo, sizeof(_pInfo)); 93 | 94 | if (CreateProcessA(InputName.c_str(), NULL, NULL, NULL, TRUE, 0, NULL, NULL, &_sInfo, &_pInfo) == 0) 95 | return -1; 96 | 97 | BaseAddress = InputAddress; 98 | BigEndian = InputEndian; 99 | 100 | return 0; 101 | }; 102 | static bool LatchProcess(string InputName, uint64_t InputAddress, bool InputEndian) 103 | { 104 | ZeroMemory(&_sInfo, sizeof(_sInfo)); _sInfo.cb = sizeof(_sInfo); 105 | ZeroMemory(&_pInfo, sizeof(_pInfo)); 106 | 107 | PIdentifier = FindProcessId(wstring(InputName.begin(), InputName.end())); 108 | PHandle = OpenProcess(PROCESS_ALL_ACCESS, false, PIdentifier); 109 | 110 | GetProcessImageFileNameA(MemoryLib::PHandle, PName, MAX_PATH); 111 | BaseAddress = InputAddress; 112 | 113 | ExecAddress = (uint64_t)FindBaseAddr(PHandle, PName); 114 | BigEndian = InputEndian; 115 | 116 | if (PHandle == NULL) 117 | return false; 118 | 119 | return true; 120 | }; 121 | static void ExternProcess(DWORD InputID, HANDLE InputH, uint64_t InputAddress) 122 | { 123 | PIdentifier = InputID; 124 | PHandle = InputH; 125 | 126 | GetProcessImageFileNameA(MemoryLib::PHandle, PName, MAX_PATH); 127 | 128 | BaseAddress = InputAddress; 129 | ExecAddress = (uint64_t)FindBaseAddr(PHandle, PName); 130 | }; 131 | #endif 132 | 133 | static void SetBaseAddr(uint64_t InputAddress) 134 | { 135 | BaseAddress = InputAddress; 136 | } 137 | 138 | // Reader Functions 139 | 140 | static uint8_t ReadByte(uint64_t _addr, bool _absolute = false) { return ReadBytes(_addr, 1, _absolute)[0]; } 141 | static vector ReadBytes(uint64_t _addr, int _len, bool _absolute = false) 142 | { 143 | vector _buffer; 144 | _buffer.resize(_len); 145 | 146 | ReadProcessMemory(PHandle, _absolute ? (void*)(_addr) : (void*)(_addr + BaseAddress), _buffer.data(), _len, 0); 147 | return _buffer; 148 | } 149 | static uint16_t ReadShort(uint64_t _addr, bool _absolute = false) 150 | { 151 | auto _buffer = ReadBytes(_addr, 2, _absolute); 152 | 153 | if (BigEndian) 154 | return (_buffer[0] << 8) | _buffer[1]; 155 | else 156 | return (_buffer[1] << 8) | _buffer[0]; 157 | } 158 | static uint32_t ReadInt(uint64_t _addr, bool _absolute = false) 159 | { 160 | auto _buffer = ReadBytes(_addr, 4, _absolute); 161 | 162 | if (BigEndian) 163 | return (_buffer[0] << 24) | (_buffer[1] << 16) | (_buffer[2] << 8) | (_buffer[3]); 164 | else 165 | return (_buffer[3] << 24) | (_buffer[2] << 16) | (_buffer[1] << 8) | (_buffer[0]); 166 | } 167 | static uint64_t ReadLong(uint64_t _addr, bool _absolute = false) 168 | { 169 | auto _buffer = ReadBytes(_addr, 8, _absolute); 170 | 171 | if (BigEndian) 172 | return ((uint64_t)_buffer[0] << 56) | ((uint64_t)_buffer[1] << 48) | ((uint64_t)_buffer[2] << 40) | ((uint64_t)_buffer[3] << 32) | ((uint64_t)_buffer[4] << 24) | ((uint64_t)_buffer[5] << 16) | ((uint64_t)_buffer[6] << 8) | ((uint64_t)_buffer[7]); 173 | 174 | else 175 | return ((uint64_t)_buffer[7] << 56) | ((uint64_t)_buffer[6] << 48) | ((uint64_t)_buffer[5] << 40) | ((uint64_t)_buffer[4] << 32) | ((uint64_t)_buffer[3] << 24) | ((uint64_t)_buffer[2] << 16) | ((uint64_t)_buffer[1] << 8) | ((uint64_t)_buffer[0]); 176 | } 177 | static float ReadFloat(uint64_t _addr, bool _absolute = false) 178 | { 179 | auto _value = ReadInt(_addr, _absolute); 180 | auto _return = *reinterpret_cast(&_value); 181 | return _return; 182 | } 183 | static bool ReadBool(uint64_t _addr, bool _absolute = false) 184 | { 185 | auto _value = ReadByte(_addr, _absolute); 186 | return _value == 0 ? false : true; 187 | } 188 | static string ReadString(uint64_t _addr, int _len, bool _absolute = false) 189 | { 190 | auto _value = ReadBytes(_addr, _len, _absolute); 191 | string _output(_value.begin(), _value.end()); 192 | return _output; 193 | } 194 | 195 | // Writer Functions 196 | 197 | static void WriteByte(uint64_t _addr, uint8_t _val, bool _absolute = false) 198 | { 199 | if (WriteProcessMemory(PHandle, _absolute ? (void*)(_addr) : (void*)(_addr + BaseAddress), &_val, 1, 0) == 0) 200 | { 201 | DWORD _protectOld = 0; 202 | VirtualProtectEx(PHandle, _absolute ? (void*)(_addr) : (void*)(_addr + BaseAddress), 256, PAGE_READWRITE, &_protectOld); 203 | WriteProcessMemory(PHandle, _absolute ? (void*)(_addr) : (void*)(_addr + BaseAddress), &_val, 1, 0); 204 | } 205 | } 206 | static void WriteBytes(uint64_t _addr, vector _val, bool _absolute = false) 207 | { 208 | if (WriteProcessMemory(PHandle, _absolute ? (void*)(_addr) : (void*)(_addr + BaseAddress), _val.data(), _val.size(), 0) == 0) 209 | { 210 | DWORD _protectOld = 0; 211 | VirtualProtectEx(PHandle, _absolute ? (void*)(_addr) : (void*)(_addr + BaseAddress), 256, PAGE_READWRITE, &_protectOld); 212 | WriteProcessMemory(PHandle, _absolute ? (void*)(_addr) : (void*)(_addr + BaseAddress), _val.data(), _val.size(), 0); 213 | } 214 | } 215 | static void WriteShort(uint64_t _addr, uint16_t _val, bool _absolute = false) 216 | { 217 | vector _write(2); 218 | 219 | for (uint64_t i = 0; i < 2; i++) 220 | { 221 | if (BigEndian) 222 | _write[1 - i] = (_val >> (i * 8)) & 0xFF; 223 | 224 | else 225 | _write[i] = (_val >> (i * 8)) & 0xFF; 226 | } 227 | 228 | WriteBytes(_addr, _write, _absolute); 229 | _write.clear(); 230 | } 231 | static void WriteInt(uint64_t _addr, uint32_t _val, bool _absolute = false) 232 | { 233 | vector _write(4); 234 | 235 | for (uint64_t i = 0; i < 4; i++) 236 | { 237 | if (BigEndian) 238 | _write[3 - i] = (_val >> (i * 8)) & 0xFF; 239 | 240 | else 241 | _write[i] = (_val >> (i * 8)) & 0xFF; 242 | } 243 | 244 | WriteBytes(_addr, _write, _absolute); 245 | _write.clear(); 246 | } 247 | static void WriteLong(uint64_t _addr, uint64_t _val, bool _absolute = false) 248 | { 249 | vector _write(8); 250 | 251 | for (uint64_t i = 0; i < 8; i++) 252 | { 253 | if (BigEndian) 254 | _write[1 - i] = (_val >> (i * 8)) & 0xFF; 255 | 256 | else 257 | _write[i] = (_val >> (i * 8)) & 0xFF; 258 | } 259 | 260 | WriteBytes(_addr, _write, _absolute); 261 | _write.clear(); 262 | } 263 | static void WriteFloat(uint64_t _addr, float _val, bool _absolute = false) 264 | { 265 | auto _value = *reinterpret_cast(&_val); 266 | WriteInt(_addr, _value, _absolute); 267 | } 268 | static void WriteBool(uint64_t _addr, bool _val, bool _absolute = false) { _val == true ? WriteByte(_addr, 1, _absolute) : WriteByte(_addr, 0, _absolute); } 269 | static void WriteString(uint64_t _addr, string _val, bool _absolute = false) 270 | { 271 | vector _value(_val.begin(), _val.end()); 272 | WriteBytes(_addr, _value, _absolute); 273 | } 274 | 275 | // Misc. Functions 276 | 277 | static void WriteExec(uint64_t _addr, vector _val) 278 | { 279 | WriteProcessMemory(PHandle, (void*)(_addr + ExecAddress), _val.data(), _val.size(), 0); 280 | } 281 | 282 | }; 283 | #endif 284 | -------------------------------------------------------------------------------- /include/Operator32Lib.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OP32LIB 2 | #define OP32LIB 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "TlHelp32.h" 9 | 10 | using namespace std; 11 | 12 | class Operator32Lib 13 | { 14 | public: 15 | static uint32_t UnsignedShift32(uint32_t base, uint32_t shift) 16 | { 17 | string _inBinary = bitset<32>(base).to_string(); 18 | string _outBinary = "00000000000000000000000000000000"; 19 | 20 | for (uint32_t i = 0; i < 32 - shift; i++) 21 | _outBinary[i] = _inBinary[i + shift]; 22 | 23 | uint32_t _out = bitset<32>(_outBinary).to_ulong(); 24 | return _out; 25 | } 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /include/discord/discord_register.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(DISCORD_DYNAMIC_LIB) 4 | #if defined(_WIN32) 5 | #if defined(DISCORD_BUILDING_SDK) 6 | #define DISCORD_EXPORT __declspec(dllexport) 7 | #else 8 | #define DISCORD_EXPORT __declspec(dllimport) 9 | #endif 10 | #else 11 | #define DISCORD_EXPORT __attribute__((visibility("default"))) 12 | #endif 13 | #else 14 | #define DISCORD_EXPORT 15 | #endif 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command); 22 | DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /include/discord/discord_rpc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | // clang-format off 5 | 6 | #if defined(DISCORD_DYNAMIC_LIB) 7 | # if defined(_WIN32) 8 | # if defined(DISCORD_BUILDING_SDK) 9 | # define DISCORD_EXPORT __declspec(dllexport) 10 | # else 11 | # define DISCORD_EXPORT __declspec(dllimport) 12 | # endif 13 | # else 14 | # define DISCORD_EXPORT __attribute__((visibility("default"))) 15 | # endif 16 | #else 17 | # define DISCORD_EXPORT 18 | #endif 19 | 20 | // clang-format on 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef struct DiscordRichPresence { 27 | const char* state; /* max 128 bytes */ 28 | const char* details; /* max 128 bytes */ 29 | int64_t startTimestamp; 30 | int64_t endTimestamp; 31 | const char* largeImageKey; /* max 32 bytes */ 32 | const char* largeImageText; /* max 128 bytes */ 33 | const char* smallImageKey; /* max 32 bytes */ 34 | const char* smallImageText; /* max 128 bytes */ 35 | const char* partyId; /* max 128 bytes */ 36 | int partySize; 37 | int partyMax; 38 | const char* matchSecret; /* max 128 bytes */ 39 | const char* joinSecret; /* max 128 bytes */ 40 | const char* spectateSecret; /* max 128 bytes */ 41 | int8_t instance; 42 | } DiscordRichPresence; 43 | 44 | typedef struct DiscordUser { 45 | const char* userId; 46 | const char* username; 47 | const char* discriminator; 48 | const char* avatar; 49 | } DiscordUser; 50 | 51 | typedef struct DiscordEventHandlers { 52 | void (*ready)(const DiscordUser* request); 53 | void (*disconnected)(int errorCode, const char* message); 54 | void (*errored)(int errorCode, const char* message); 55 | void (*joinGame)(const char* joinSecret); 56 | void (*spectateGame)(const char* spectateSecret); 57 | void (*joinRequest)(const DiscordUser* request); 58 | } DiscordEventHandlers; 59 | 60 | #define DISCORD_REPLY_NO 0 61 | #define DISCORD_REPLY_YES 1 62 | #define DISCORD_REPLY_IGNORE 2 63 | 64 | DISCORD_EXPORT void Discord_Initialize(const char* applicationId, 65 | DiscordEventHandlers* handlers, 66 | int autoRegister, 67 | const char* optionalSteamId); 68 | DISCORD_EXPORT void Discord_Shutdown(void); 69 | 70 | /* checks for incoming messages, dispatches callbacks */ 71 | DISCORD_EXPORT void Discord_RunCallbacks(void); 72 | 73 | /* If you disable the lib starting its own io thread, you'll need to call this from your own */ 74 | #ifdef DISCORD_DISABLE_IO_THREAD 75 | DISCORD_EXPORT void Discord_UpdateConnection(void); 76 | #endif 77 | 78 | DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence); 79 | DISCORD_EXPORT void Discord_ClearPresence(void); 80 | 81 | DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply); 82 | 83 | DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers); 84 | 85 | #ifdef __cplusplus 86 | } /* extern "C" */ 87 | #endif 88 | -------------------------------------------------------------------------------- /include/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 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 | 15 | /* Increments 'L->top', checking for stack overflows */ 16 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 17 | "stack overflow");} 18 | 19 | 20 | /* 21 | ** If a call returns too many multiple returns, the callee may not have 22 | ** stack space to accommodate all results. In this case, this macro 23 | ** increases its stack space ('L->ci->top'). 24 | */ 25 | #define adjustresults(L,nres) \ 26 | { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 27 | 28 | 29 | /* Ensure the stack has at least 'n' elements */ 30 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 31 | "not enough elements in the stack") 32 | 33 | 34 | /* 35 | ** To reduce the overhead of returning from C functions, the presence of 36 | ** to-be-closed variables in these functions is coded in the CallInfo's 37 | ** field 'nresults', in a way that functions with no to-be-closed variables 38 | ** with zero, one, or "all" wanted results have no overhead. Functions 39 | ** with other number of wanted results, as well as functions with 40 | ** variables to be closed, have an extra check. 41 | */ 42 | 43 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 44 | 45 | /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */ 46 | #define codeNresults(n) (-(n) - 3) 47 | #define decodeNresults(n) (-(n) - 3) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/lua/lauxlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lauxlib.h $ 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 "luaconf.h" 16 | #include "lua.h" 17 | 18 | 19 | /* global table */ 20 | #define LUA_GNAME "_G" 21 | 22 | 23 | typedef struct luaL_Buffer luaL_Buffer; 24 | 25 | 26 | /* extra error code for 'luaL_loadfilex' */ 27 | #define LUA_ERRFILE (LUA_ERRERR+1) 28 | 29 | 30 | /* key, in the registry, for table of loaded modules */ 31 | #define LUA_LOADED_TABLE "_LOADED" 32 | 33 | 34 | /* key, in the registry, for table of preloaded loaders */ 35 | #define LUA_PRELOAD_TABLE "_PRELOAD" 36 | 37 | 38 | typedef struct luaL_Reg { 39 | const char *name; 40 | lua_CFunction func; 41 | } luaL_Reg; 42 | 43 | 44 | #define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number)) 45 | 46 | LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz); 47 | #define luaL_checkversion(L) \ 48 | luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES) 49 | 50 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 51 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 52 | LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); 53 | LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg); 54 | LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname); 55 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, 56 | size_t *l); 57 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, 58 | const char *def, size_t *l); 59 | LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg); 60 | LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def); 61 | 62 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg); 63 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg, 64 | lua_Integer def); 65 | 66 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 67 | LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t); 68 | LUALIB_API void (luaL_checkany) (lua_State *L, int arg); 69 | 70 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 71 | LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); 72 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); 73 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 74 | 75 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); 76 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); 77 | 78 | LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def, 79 | const char *const lst[]); 80 | 81 | LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); 82 | LUALIB_API int (luaL_execresult) (lua_State *L, int stat); 83 | 84 | 85 | /* predefined references */ 86 | #define LUA_NOREF (-2) 87 | #define LUA_REFNIL (-1) 88 | 89 | LUALIB_API int (luaL_ref) (lua_State *L, int t); 90 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 91 | 92 | LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, 93 | const char *mode); 94 | 95 | #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) 96 | 97 | LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, 98 | const char *name, const char *mode); 99 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 100 | 101 | LUALIB_API lua_State *(luaL_newstate) (void); 102 | 103 | LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); 104 | 105 | LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s, 106 | const char *p, const char *r); 107 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, 108 | const char *p, const char *r); 109 | 110 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); 111 | 112 | LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname); 113 | 114 | LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1, 115 | const char *msg, int level); 116 | 117 | LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, 118 | lua_CFunction openf, int glb); 119 | 120 | /* 121 | ** =============================================================== 122 | ** some useful macros 123 | ** =============================================================== 124 | */ 125 | 126 | 127 | #define luaL_newlibtable(L,l) \ 128 | lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) 129 | 130 | #define luaL_newlib(L,l) \ 131 | (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) 132 | 133 | #define luaL_argcheck(L, cond,arg,extramsg) \ 134 | ((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg)))) 135 | 136 | #define luaL_argexpected(L,cond,arg,tname) \ 137 | ((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname)))) 138 | 139 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 140 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 141 | 142 | #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) 143 | 144 | #define luaL_dofile(L, fn) \ 145 | (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 146 | 147 | #define luaL_dostring(L, s) \ 148 | (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 149 | 150 | #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 151 | 152 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 153 | 154 | #define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) 155 | 156 | 157 | /* push the value used to represent failure/error */ 158 | #define luaL_pushfail(L) lua_pushnil(L) 159 | 160 | 161 | /* 162 | ** Internal assertions for in-house debugging 163 | */ 164 | #if !defined(lua_assert) 165 | 166 | #if defined LUAI_ASSERT 167 | #include 168 | #define lua_assert(c) assert(c) 169 | #else 170 | #define lua_assert(c) ((void)0) 171 | #endif 172 | 173 | #endif 174 | 175 | 176 | 177 | /* 178 | ** {====================================================== 179 | ** Generic Buffer manipulation 180 | ** ======================================================= 181 | */ 182 | 183 | struct luaL_Buffer { 184 | char *b; /* buffer address */ 185 | size_t size; /* buffer size */ 186 | size_t n; /* number of characters in buffer */ 187 | lua_State *L; 188 | union { 189 | LUAI_MAXALIGN; /* ensure maximum alignment for buffer */ 190 | char b[LUAL_BUFFERSIZE]; /* initial buffer */ 191 | } init; 192 | }; 193 | 194 | 195 | #define luaL_bufflen(bf) ((bf)->n) 196 | #define luaL_buffaddr(bf) ((bf)->b) 197 | 198 | 199 | #define luaL_addchar(B,c) \ 200 | ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \ 201 | ((B)->b[(B)->n++] = (c))) 202 | 203 | #define luaL_addsize(B,s) ((B)->n += (s)) 204 | 205 | #define luaL_buffsub(B,s) ((B)->n -= (s)) 206 | 207 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); 208 | LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz); 209 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); 210 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); 211 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); 212 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); 213 | LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz); 214 | LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); 215 | 216 | #define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE) 217 | 218 | /* }====================================================== */ 219 | 220 | 221 | 222 | /* 223 | ** {====================================================== 224 | ** File handles for IO library 225 | ** ======================================================= 226 | */ 227 | 228 | /* 229 | ** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and 230 | ** initial structure 'luaL_Stream' (it may contain other fields 231 | ** after that initial structure). 232 | */ 233 | 234 | #define LUA_FILEHANDLE "FILE*" 235 | 236 | 237 | typedef struct luaL_Stream { 238 | FILE *f; /* stream (NULL for incompletely created streams) */ 239 | lua_CFunction closef; /* to close stream (NULL for closed streams) */ 240 | } luaL_Stream; 241 | 242 | /* }====================================================== */ 243 | 244 | /* 245 | ** {================================================================== 246 | ** "Abstraction Layer" for basic report of messages and errors 247 | ** =================================================================== 248 | */ 249 | 250 | /* print a string */ 251 | #if !defined(lua_writestring) 252 | #define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout) 253 | #endif 254 | 255 | /* print a newline and flush the output */ 256 | #if !defined(lua_writeline) 257 | #define lua_writeline() (lua_writestring("\n", 1), fflush(stdout)) 258 | #endif 259 | 260 | /* print an error message */ 261 | #if !defined(lua_writestringerror) 262 | #define lua_writestringerror(s,p) \ 263 | (fprintf(stderr, (s), (p)), fflush(stderr)) 264 | #endif 265 | 266 | /* }================================================================== */ 267 | 268 | 269 | /* 270 | ** {============================================================ 271 | ** Compatibility with deprecated conversions 272 | ** ============================================================= 273 | */ 274 | #if defined(LUA_COMPAT_APIINTCASTS) 275 | 276 | #define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a)) 277 | #define luaL_optunsigned(L,a,d) \ 278 | ((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d))) 279 | 280 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) 281 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) 282 | 283 | #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) 284 | #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) 285 | 286 | #endif 287 | /* }============================================================ */ 288 | 289 | 290 | 291 | #endif 292 | 293 | 294 | -------------------------------------------------------------------------------- /include/lua/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h $ 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 | /* arithmetic operators */ 28 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, 29 | OPR_DIV, OPR_IDIV, 30 | /* bitwise operators */ 31 | OPR_BAND, OPR_BOR, OPR_BXOR, 32 | OPR_SHL, OPR_SHR, 33 | /* string operator */ 34 | OPR_CONCAT, 35 | /* comparison operators */ 36 | OPR_EQ, OPR_LT, OPR_LE, 37 | OPR_NE, OPR_GT, OPR_GE, 38 | /* logical operators */ 39 | OPR_AND, OPR_OR, 40 | OPR_NOBINOPR 41 | } BinOpr; 42 | 43 | 44 | /* true if operation is foldable (that is, it is arithmetic or bitwise) */ 45 | #define foldbinop(op) ((op) <= OPR_SHR) 46 | 47 | 48 | #define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0) 49 | 50 | 51 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 52 | 53 | 54 | /* get (pointer to) instruction of given 'expdesc' */ 55 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) 56 | 57 | 58 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 59 | 60 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 61 | 62 | LUAI_FUNC int luaK_code (FuncState *fs, Instruction i); 63 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 64 | LUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx); 65 | LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A, 66 | int B, int C, int k); 67 | LUAI_FUNC int luaK_isKint (expdesc *e); 68 | LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v); 69 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 70 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 71 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 72 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 73 | LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n); 74 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 75 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 76 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 77 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 78 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 79 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 80 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 81 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 82 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 83 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 84 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 85 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 86 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 87 | LUAI_FUNC int luaK_jump (FuncState *fs); 88 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 89 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 90 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 91 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 92 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 93 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 94 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 95 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 96 | expdesc *v2, int line); 97 | LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc, 98 | int ra, int asize, int hsize); 99 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 100 | LUAI_FUNC void luaK_finish (FuncState *fs); 101 | LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg); 102 | 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /include/lua/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h $ 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 | /* 66 | ** In ASCII, this 'ltolower' is correct for alphabetic characters and 67 | ** for '.'. That is enough for Lua needs. ('check_exp' ensures that 68 | ** the character either is an upper-case letter or is unchanged by 69 | ** the transformation, which holds for lower-case letters and '.'.) 70 | */ 71 | #define ltolower(c) \ 72 | check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \ 73 | (c) | ('A' ^ 'a')) 74 | 75 | 76 | /* one entry for each character and for -1 (EOZ) */ 77 | LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];) 78 | 79 | 80 | #else /* }{ */ 81 | 82 | /* 83 | ** use standard C ctypes 84 | */ 85 | 86 | #include 87 | 88 | 89 | #define lislalpha(c) (isalpha(c) || (c) == '_') 90 | #define lislalnum(c) (isalnum(c) || (c) == '_') 91 | #define lisdigit(c) (isdigit(c)) 92 | #define lisspace(c) (isspace(c)) 93 | #define lisprint(c) (isprint(c)) 94 | #define lisxdigit(c) (isxdigit(c)) 95 | 96 | #define ltolower(c) (tolower(c)) 97 | 98 | #endif /* } */ 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /include/lua/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h $ 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 | 17 | /* Active Lua function (given call info) */ 18 | #define ci_func(ci) (clLvalue(s2v((ci)->func))) 19 | 20 | 21 | #define resethookcount(L) (L->hookcount = L->basehookcount) 22 | 23 | /* 24 | ** mark for entries in 'lineinfo' array that has absolute information in 25 | ** 'abslineinfo' array 26 | */ 27 | #define ABSLINEINFO (-0x80) 28 | 29 | 30 | /* 31 | ** MAXimum number of successive Instructions WiTHout ABSolute line 32 | ** information. (A power of two allows fast divisions.) 33 | */ 34 | #if !defined(MAXIWTHABS) 35 | #define MAXIWTHABS 128 36 | #endif 37 | 38 | 39 | LUAI_FUNC int luaG_getfuncline (const Proto *f, int pc); 40 | LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, 41 | StkId *pos); 42 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 43 | const char *opname); 44 | LUAI_FUNC l_noret luaG_callerror (lua_State *L, const TValue *o); 45 | LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o, 46 | const char *what); 47 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 48 | const TValue *p2); 49 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 50 | const TValue *p2, 51 | const char *msg); 52 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 53 | const TValue *p2); 54 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 55 | const TValue *p2); 56 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 57 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 58 | TString *src, int line); 59 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 60 | LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc); 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/lua/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h $ 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 | ** It also allows the running of one GC step when the stack is 21 | ** reallocated. 22 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 23 | ** at every check. 24 | */ 25 | #define luaD_checkstackaux(L,n,pre,pos) \ 26 | if (l_unlikely(L->stack_last - L->top <= (n))) \ 27 | { pre; luaD_growstack(L, n, 1); pos; } \ 28 | else { condmovestack(L,pre,pos); } 29 | 30 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 31 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 32 | 33 | 34 | 35 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 36 | #define restorestack(L,n) ((StkId)((char *)L->stack + (n))) 37 | 38 | 39 | /* macro to check stack size, preserving 'p' */ 40 | #define checkstackGCp(L,n,p) \ 41 | luaD_checkstackaux(L, n, \ 42 | ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \ 43 | luaC_checkGC(L), /* stack grow uses memory */ \ 44 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */ 45 | 46 | 47 | /* macro to check stack size and GC */ 48 | #define checkstackGC(L,fsize) \ 49 | luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0) 50 | 51 | 52 | /* type of protected functions, to be ran by 'runprotected' */ 53 | typedef void (*Pfunc) (lua_State *L, void *ud); 54 | 55 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 56 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 57 | const char *mode); 58 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line, 59 | int fTransfer, int nTransfer); 60 | LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci); 61 | LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n); 62 | LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults); 63 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 64 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 65 | LUAI_FUNC void luaD_tryfuncTM (lua_State *L, StkId func); 66 | LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status); 67 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 68 | ptrdiff_t oldtop, ptrdiff_t ef); 69 | LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres); 70 | LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror); 71 | LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror); 72 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 73 | LUAI_FUNC void luaD_inctop (lua_State *L); 74 | 75 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 76 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 77 | 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /include/lua/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h $ 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(offsetof(CClosure, upvalue)) + \ 15 | cast_int(sizeof(TValue)) * (n)) 16 | 17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \ 18 | cast_int(sizeof(TValue *)) * (n)) 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 | #define upisopen(up) ((up)->v != &(up)->u.value) 33 | 34 | 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v)) 36 | 37 | 38 | /* 39 | ** maximum number of misses before giving up the cache of closures 40 | ** in prototypes 41 | */ 42 | #define MAXMISS 10 43 | 44 | 45 | 46 | /* special status to close upvalues preserving the top of the stack */ 47 | #define CLOSEKTOP (-1) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals); 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_newtbcupval (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 57 | LUAI_FUNC void luaF_close (lua_State *L, StkId level, int status, int yy); 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 59 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 60 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 61 | int pc); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/lua/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h $ 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 means 16 | ** the object is not marked; gray, which means the object is marked, but 17 | ** its references may be not marked; and black, which means that the 18 | ** object and all its references are marked. The main invariant of the 19 | ** garbage collector, while marking objects, is that a black object can 20 | ** never point to a white one. Moreover, any gray object must be in a 21 | ** "gray list" (gray, grayagain, weak, allweak, ephemeron) so that it 22 | ** can be visited again before finishing the collection cycle. (Open 23 | ** upvalues are an exception to this rule.) These lists have no meaning 24 | ** when the invariant is not being enforced (e.g., sweep phase). 25 | */ 26 | 27 | 28 | /* 29 | ** Possible states of the Garbage Collector 30 | */ 31 | #define GCSpropagate 0 32 | #define GCSenteratomic 1 33 | #define GCSatomic 2 34 | #define GCSswpallgc 3 35 | #define GCSswpfinobj 4 36 | #define GCSswptobefnz 5 37 | #define GCSswpend 6 38 | #define GCScallfin 7 39 | #define GCSpause 8 40 | 41 | 42 | #define issweepphase(g) \ 43 | (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend) 44 | 45 | 46 | /* 47 | ** macro to tell when main invariant (white objects cannot point to black 48 | ** ones) must be kept. During a collection, the sweep 49 | ** phase may break the invariant, as objects turned white may point to 50 | ** still-black objects. The invariant is restored when sweep ends and 51 | ** all objects are white again. 52 | */ 53 | 54 | #define keepinvariant(g) ((g)->gcstate <= GCSatomic) 55 | 56 | 57 | /* 58 | ** some useful bit tricks 59 | */ 60 | #define resetbits(x,m) ((x) &= cast_byte(~(m))) 61 | #define setbits(x,m) ((x) |= (m)) 62 | #define testbits(x,m) ((x) & (m)) 63 | #define bitmask(b) (1<<(b)) 64 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 65 | #define l_setbit(x,b) setbits(x, bitmask(b)) 66 | #define resetbit(x,b) resetbits(x, bitmask(b)) 67 | #define testbit(x,b) testbits(x, bitmask(b)) 68 | 69 | 70 | /* 71 | ** Layout for bit use in 'marked' field. First three bits are 72 | ** used for object "age" in generational mode. Last bit is used 73 | ** by tests. 74 | */ 75 | #define WHITE0BIT 3 /* object is white (type 0) */ 76 | #define WHITE1BIT 4 /* object is white (type 1) */ 77 | #define BLACKBIT 5 /* object is black */ 78 | #define FINALIZEDBIT 6 /* object has been marked for finalization */ 79 | 80 | #define TESTBIT 7 81 | 82 | 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) & (ow)) 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->marked) 97 | 98 | #define changewhite(x) ((x)->marked ^= WHITEBITS) 99 | #define nw2black(x) \ 100 | check_exp(!iswhite(x), l_setbit((x)->marked, BLACKBIT)) 101 | 102 | #define luaC_white(g) cast_byte((g)->currentwhite & WHITEBITS) 103 | 104 | 105 | /* object age in generational mode */ 106 | #define G_NEW 0 /* created in current cycle */ 107 | #define G_SURVIVAL 1 /* created in previous cycle */ 108 | #define G_OLD0 2 /* marked old by frw. barrier in this cycle */ 109 | #define G_OLD1 3 /* first full cycle as old */ 110 | #define G_OLD 4 /* really old object (not to be visited) */ 111 | #define G_TOUCHED1 5 /* old object touched this cycle */ 112 | #define G_TOUCHED2 6 /* old object touched in previous cycle */ 113 | 114 | #define AGEBITS 7 /* all age bits (111) */ 115 | 116 | #define getage(o) ((o)->marked & AGEBITS) 117 | #define setage(o,a) ((o)->marked = cast_byte(((o)->marked & (~AGEBITS)) | a)) 118 | #define isold(o) (getage(o) > G_SURVIVAL) 119 | 120 | #define changeage(o,f,t) \ 121 | check_exp(getage(o) == (f), (o)->marked ^= ((f)^(t))) 122 | 123 | 124 | /* Default Values for GC parameters */ 125 | #define LUAI_GENMAJORMUL 100 126 | #define LUAI_GENMINORMUL 20 127 | 128 | /* wait memory to double before starting new cycle */ 129 | #define LUAI_GCPAUSE 200 130 | 131 | /* 132 | ** some gc parameters are stored divided by 4 to allow a maximum value 133 | ** up to 1023 in a 'lu_byte'. 134 | */ 135 | #define getgcparam(p) ((p) * 4) 136 | #define setgcparam(p,v) ((p) = (v) / 4) 137 | 138 | #define LUAI_GCMUL 100 139 | 140 | /* how much to allocate before next GC step (log2) */ 141 | #define LUAI_GCSTEPSIZE 13 /* 8 KB */ 142 | 143 | 144 | /* 145 | ** Check whether the declared GC mode is generational. While in 146 | ** generational mode, the collector can go temporarily to incremental 147 | ** mode to improve performance. This is signaled by 'g->lastatomic != 0'. 148 | */ 149 | #define isdecGCmodegen(g) (g->gckind == KGC_GEN || g->lastatomic != 0) 150 | 151 | /* 152 | ** Does one step of collection when debt becomes positive. 'pre'/'pos' 153 | ** allows some adjustments to be done only when needed. macro 154 | ** 'condchangemem' is used only for heavy tests (forcing a full 155 | ** GC cycle on every opportunity) 156 | */ 157 | #define luaC_condGC(L,pre,pos) \ 158 | { if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \ 159 | condchangemem(L,pre,pos); } 160 | 161 | /* more often than not, 'pre'/'pos' are empty */ 162 | #define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0) 163 | 164 | 165 | #define luaC_barrier(L,p,v) ( \ 166 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 167 | luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0)) 168 | 169 | #define luaC_barrierback(L,p,v) ( \ 170 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 171 | luaC_barrierback_(L,p) : cast_void(0)) 172 | 173 | #define luaC_objbarrier(L,p,o) ( \ 174 | (isblack(p) && iswhite(o)) ? \ 175 | luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0)) 176 | 177 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 178 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); 179 | LUAI_FUNC void luaC_step (lua_State *L); 180 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 181 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 182 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 183 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 184 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); 185 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 186 | LUAI_FUNC void luaC_changemode (lua_State *L, int newmode); 187 | 188 | 189 | #endif 190 | -------------------------------------------------------------------------------- /include/lua/ljumptab.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ljumptab.h $ 3 | ** Jump Table for the Lua interpreter 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #undef vmdispatch 9 | #undef vmcase 10 | #undef vmbreak 11 | 12 | #define vmdispatch(x) goto *disptab[x]; 13 | 14 | #define vmcase(l) L_##l: 15 | 16 | #define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i)); 17 | 18 | 19 | static const void *const disptab[NUM_OPCODES] = { 20 | 21 | #if 0 22 | ** you can update the following list with this command: 23 | ** 24 | ** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h 25 | ** 26 | #endif 27 | 28 | &&L_OP_MOVE, 29 | &&L_OP_LOADI, 30 | &&L_OP_LOADF, 31 | &&L_OP_LOADK, 32 | &&L_OP_LOADKX, 33 | &&L_OP_LOADFALSE, 34 | &&L_OP_LFALSESKIP, 35 | &&L_OP_LOADTRUE, 36 | &&L_OP_LOADNIL, 37 | &&L_OP_GETUPVAL, 38 | &&L_OP_SETUPVAL, 39 | &&L_OP_GETTABUP, 40 | &&L_OP_GETTABLE, 41 | &&L_OP_GETI, 42 | &&L_OP_GETFIELD, 43 | &&L_OP_SETTABUP, 44 | &&L_OP_SETTABLE, 45 | &&L_OP_SETI, 46 | &&L_OP_SETFIELD, 47 | &&L_OP_NEWTABLE, 48 | &&L_OP_SELF, 49 | &&L_OP_ADDI, 50 | &&L_OP_ADDK, 51 | &&L_OP_SUBK, 52 | &&L_OP_MULK, 53 | &&L_OP_MODK, 54 | &&L_OP_POWK, 55 | &&L_OP_DIVK, 56 | &&L_OP_IDIVK, 57 | &&L_OP_BANDK, 58 | &&L_OP_BORK, 59 | &&L_OP_BXORK, 60 | &&L_OP_SHRI, 61 | &&L_OP_SHLI, 62 | &&L_OP_ADD, 63 | &&L_OP_SUB, 64 | &&L_OP_MUL, 65 | &&L_OP_MOD, 66 | &&L_OP_POW, 67 | &&L_OP_DIV, 68 | &&L_OP_IDIV, 69 | &&L_OP_BAND, 70 | &&L_OP_BOR, 71 | &&L_OP_BXOR, 72 | &&L_OP_SHL, 73 | &&L_OP_SHR, 74 | &&L_OP_MMBIN, 75 | &&L_OP_MMBINI, 76 | &&L_OP_MMBINK, 77 | &&L_OP_UNM, 78 | &&L_OP_BNOT, 79 | &&L_OP_NOT, 80 | &&L_OP_LEN, 81 | &&L_OP_CONCAT, 82 | &&L_OP_CLOSE, 83 | &&L_OP_TBC, 84 | &&L_OP_JMP, 85 | &&L_OP_EQ, 86 | &&L_OP_LT, 87 | &&L_OP_LE, 88 | &&L_OP_EQK, 89 | &&L_OP_EQI, 90 | &&L_OP_LTI, 91 | &&L_OP_LEI, 92 | &&L_OP_GTI, 93 | &&L_OP_GEI, 94 | &&L_OP_TEST, 95 | &&L_OP_TESTSET, 96 | &&L_OP_CALL, 97 | &&L_OP_TAILCALL, 98 | &&L_OP_RETURN, 99 | &&L_OP_RETURN0, 100 | &&L_OP_RETURN1, 101 | &&L_OP_FORLOOP, 102 | &&L_OP_FORPREP, 103 | &&L_OP_TFORPREP, 104 | &&L_OP_TFORCALL, 105 | &&L_OP_TFORLOOP, 106 | &&L_OP_SETLIST, 107 | &&L_OP_CLOSURE, 108 | &&L_OP_VARARG, 109 | &&L_OP_VARARGPREP, 110 | &&L_OP_EXTRAARG 111 | 112 | }; 113 | -------------------------------------------------------------------------------- /include/lua/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include 11 | 12 | #include "lobject.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Single-char tokens (terminal symbols) are represented by their own 18 | ** numeric code. Other tokens start at the following value. 19 | */ 20 | #define FIRST_RESERVED (UCHAR_MAX + 1) 21 | 22 | 23 | #if !defined(LUA_ENV) 24 | #define LUA_ENV "_ENV" 25 | #endif 26 | 27 | 28 | /* 29 | * WARNING: if you change the order of this enumeration, 30 | * grep "ORDER RESERVED" 31 | */ 32 | enum RESERVED { 33 | /* terminal symbols denoted by reserved words */ 34 | TK_AND = FIRST_RESERVED, TK_BREAK, 35 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 36 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 37 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 38 | /* other terminal symbols */ 39 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 40 | TK_SHL, TK_SHR, 41 | TK_DBCOLON, TK_EOS, 42 | TK_FLT, TK_INT, TK_NAME, TK_STRING 43 | }; 44 | 45 | /* number of reserved words */ 46 | #define NUM_RESERVED (cast_int(TK_WHILE-FIRST_RESERVED + 1)) 47 | 48 | 49 | typedef union { 50 | lua_Number r; 51 | lua_Integer i; 52 | TString *ts; 53 | } SemInfo; /* semantics information */ 54 | 55 | 56 | typedef struct Token { 57 | int token; 58 | SemInfo seminfo; 59 | } Token; 60 | 61 | 62 | /* state of the lexer plus state of the parser when shared by all 63 | functions */ 64 | typedef struct LexState { 65 | int current; /* current character (charint) */ 66 | int linenumber; /* input line counter */ 67 | int lastline; /* line of last token 'consumed' */ 68 | Token t; /* current token */ 69 | Token lookahead; /* look ahead token */ 70 | struct FuncState *fs; /* current function (parser) */ 71 | struct lua_State *L; 72 | ZIO *z; /* input stream */ 73 | Mbuffer *buff; /* buffer for tokens */ 74 | Table *h; /* to avoid collection/reuse strings */ 75 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 76 | TString *source; /* current source name */ 77 | TString *envn; /* environment variable name */ 78 | } LexState; 79 | 80 | 81 | LUAI_FUNC void luaX_init (lua_State *L); 82 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 83 | TString *source, int firstchar); 84 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 85 | LUAI_FUNC void luaX_next (LexState *ls); 86 | LUAI_FUNC int luaX_lookahead (LexState *ls); 87 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 88 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 89 | 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /include/lua/llimits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llimits.h $ 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 | /* 19 | ** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count 20 | ** the total memory used by Lua (in bytes). Usually, 'size_t' and 21 | ** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines. 22 | */ 23 | #if defined(LUAI_MEM) /* { external definitions? */ 24 | typedef LUAI_UMEM lu_mem; 25 | typedef LUAI_MEM l_mem; 26 | #elif LUAI_IS32INT /* }{ */ 27 | typedef size_t lu_mem; 28 | typedef ptrdiff_t l_mem; 29 | #else /* 16-bit ints */ /* }{ */ 30 | typedef unsigned long lu_mem; 31 | typedef long l_mem; 32 | #endif /* } */ 33 | 34 | 35 | /* chars used as small naturals (so that 'char' is reserved for characters) */ 36 | typedef unsigned char lu_byte; 37 | typedef signed char ls_byte; 38 | 39 | 40 | /* maximum value for size_t */ 41 | #define MAX_SIZET ((size_t)(~(size_t)0)) 42 | 43 | /* maximum size visible for Lua (must be representable in a lua_Integer) */ 44 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ 45 | : (size_t)(LUA_MAXINTEGER)) 46 | 47 | 48 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)) 49 | 50 | #define MAX_LMEM ((l_mem)(MAX_LUMEM >> 1)) 51 | 52 | 53 | #define MAX_INT INT_MAX /* maximum value of an int */ 54 | 55 | 56 | /* 57 | ** floor of the log2 of the maximum signed value for integral type 't'. 58 | ** (That is, maximum 'n' such that '2^n' fits in the given signed type.) 59 | */ 60 | #define log2maxs(t) (sizeof(t) * 8 - 2) 61 | 62 | 63 | /* 64 | ** test whether an unsigned value is a power of 2 (or zero) 65 | */ 66 | #define ispow2(x) (((x) & ((x) - 1)) == 0) 67 | 68 | 69 | /* number of chars of a literal string without the ending \0 */ 70 | #define LL(x) (sizeof(x)/sizeof(char) - 1) 71 | 72 | 73 | /* 74 | ** conversion of pointer to unsigned integer: 75 | ** this is for hashing only; there is no problem if the integer 76 | ** cannot hold the whole pointer value 77 | */ 78 | #define point2uint(p) ((unsigned int)((size_t)(p) & UINT_MAX)) 79 | 80 | 81 | 82 | /* types of 'usual argument conversions' for lua_Number and lua_Integer */ 83 | typedef LUAI_UACNUMBER l_uacNumber; 84 | typedef LUAI_UACINT l_uacInt; 85 | 86 | 87 | /* 88 | ** Internal assertions for in-house debugging 89 | */ 90 | #if defined LUAI_ASSERT 91 | #undef NDEBUG 92 | #include 93 | #define lua_assert(c) assert(c) 94 | #endif 95 | 96 | #if defined(lua_assert) 97 | #define check_exp(c,e) (lua_assert(c), (e)) 98 | /* to avoid problems with conditions too long */ 99 | #define lua_longassert(c) ((c) ? (void)0 : lua_assert(0)) 100 | #else 101 | #define lua_assert(c) ((void)0) 102 | #define check_exp(c,e) (e) 103 | #define lua_longassert(c) ((void)0) 104 | #endif 105 | 106 | /* 107 | ** assertion for checking API calls 108 | */ 109 | #if !defined(luai_apicheck) 110 | #define luai_apicheck(l,e) ((void)l, lua_assert(e)) 111 | #endif 112 | 113 | #define api_check(l,e,msg) luai_apicheck(l,(e) && msg) 114 | 115 | 116 | /* macro to avoid warnings about unused variables */ 117 | #if !defined(UNUSED) 118 | #define UNUSED(x) ((void)(x)) 119 | #endif 120 | 121 | 122 | /* type casts (a macro highlights casts in the code) */ 123 | #define cast(t, exp) ((t)(exp)) 124 | 125 | #define cast_void(i) cast(void, (i)) 126 | #define cast_voidp(i) cast(void *, (i)) 127 | #define cast_num(i) cast(lua_Number, (i)) 128 | #define cast_int(i) cast(int, (i)) 129 | #define cast_uint(i) cast(unsigned int, (i)) 130 | #define cast_byte(i) cast(lu_byte, (i)) 131 | #define cast_uchar(i) cast(unsigned char, (i)) 132 | #define cast_char(i) cast(char, (i)) 133 | #define cast_charp(i) cast(char *, (i)) 134 | #define cast_sizet(i) cast(size_t, (i)) 135 | 136 | 137 | /* cast a signed lua_Integer to lua_Unsigned */ 138 | #if !defined(l_castS2U) 139 | #define l_castS2U(i) ((lua_Unsigned)(i)) 140 | #endif 141 | 142 | /* 143 | ** cast a lua_Unsigned to a signed lua_Integer; this cast is 144 | ** not strict ISO C, but two-complement architectures should 145 | ** work fine. 146 | */ 147 | #if !defined(l_castU2S) 148 | #define l_castU2S(i) ((lua_Integer)(i)) 149 | #endif 150 | 151 | 152 | /* 153 | ** non-return type 154 | */ 155 | #if !defined(l_noret) 156 | 157 | #if defined(__GNUC__) 158 | #define l_noret void __attribute__((noreturn)) 159 | #elif defined(_MSC_VER) && _MSC_VER >= 1200 160 | #define l_noret void __declspec(noreturn) 161 | #else 162 | #define l_noret void 163 | #endif 164 | 165 | #endif 166 | 167 | 168 | /* 169 | ** type for virtual-machine instructions; 170 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 171 | */ 172 | #if LUAI_IS32INT 173 | typedef unsigned int l_uint32; 174 | #else 175 | typedef unsigned long l_uint32; 176 | #endif 177 | 178 | typedef l_uint32 Instruction; 179 | 180 | 181 | 182 | /* 183 | ** Maximum length for short strings, that is, strings that are 184 | ** internalized. (Cannot be smaller than reserved words or tags for 185 | ** metamethods, as these strings must be internalized; 186 | ** #("function") = 8, #("__newindex") = 10.) 187 | */ 188 | #if !defined(LUAI_MAXSHORTLEN) 189 | #define LUAI_MAXSHORTLEN 40 190 | #endif 191 | 192 | 193 | /* 194 | ** Initial size for the string table (must be power of 2). 195 | ** The Lua core alone registers ~50 strings (reserved words + 196 | ** metaevent keys + a few others). Libraries would typically add 197 | ** a few dozens more. 198 | */ 199 | #if !defined(MINSTRTABSIZE) 200 | #define MINSTRTABSIZE 128 201 | #endif 202 | 203 | 204 | /* 205 | ** Size of cache for strings in the API. 'N' is the number of 206 | ** sets (better be a prime) and "M" is the size of each set (M == 1 207 | ** makes a direct cache.) 208 | */ 209 | #if !defined(STRCACHE_N) 210 | #define STRCACHE_N 53 211 | #define STRCACHE_M 2 212 | #endif 213 | 214 | 215 | /* minimum size for string buffer */ 216 | #if !defined(LUA_MINBUFFER) 217 | #define LUA_MINBUFFER 32 218 | #endif 219 | 220 | 221 | /* 222 | ** Maximum depth for nested C calls, syntactical nested non-terminals, 223 | ** and other features implemented through recursion in C. (Value must 224 | ** fit in a 16-bit unsigned integer. It must also be compatible with 225 | ** the size of the C stack.) 226 | */ 227 | #if !defined(LUAI_MAXCCALLS) 228 | #define LUAI_MAXCCALLS 200 229 | #endif 230 | 231 | 232 | /* 233 | ** macros that are executed whenever program enters the Lua core 234 | ** ('lua_lock') and leaves the core ('lua_unlock') 235 | */ 236 | #if !defined(lua_lock) 237 | #define lua_lock(L) ((void) 0) 238 | #define lua_unlock(L) ((void) 0) 239 | #endif 240 | 241 | /* 242 | ** macro executed during Lua functions at points where the 243 | ** function can yield. 244 | */ 245 | #if !defined(luai_threadyield) 246 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 247 | #endif 248 | 249 | 250 | /* 251 | ** these macros allow user-specific actions when a thread is 252 | ** created/deleted/resumed/yielded. 253 | */ 254 | #if !defined(luai_userstateopen) 255 | #define luai_userstateopen(L) ((void)L) 256 | #endif 257 | 258 | #if !defined(luai_userstateclose) 259 | #define luai_userstateclose(L) ((void)L) 260 | #endif 261 | 262 | #if !defined(luai_userstatethread) 263 | #define luai_userstatethread(L,L1) ((void)L) 264 | #endif 265 | 266 | #if !defined(luai_userstatefree) 267 | #define luai_userstatefree(L,L1) ((void)L) 268 | #endif 269 | 270 | #if !defined(luai_userstateresume) 271 | #define luai_userstateresume(L,n) ((void)L) 272 | #endif 273 | 274 | #if !defined(luai_userstateyield) 275 | #define luai_userstateyield(L,n) ((void)L) 276 | #endif 277 | 278 | 279 | 280 | /* 281 | ** The luai_num* macros define the primitive operations over numbers. 282 | */ 283 | 284 | /* floor division (defined as 'floor(a/b)') */ 285 | #if !defined(luai_numidiv) 286 | #define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b))) 287 | #endif 288 | 289 | /* float division */ 290 | #if !defined(luai_numdiv) 291 | #define luai_numdiv(L,a,b) ((a)/(b)) 292 | #endif 293 | 294 | /* 295 | ** modulo: defined as 'a - floor(a/b)*b'; the direct computation 296 | ** using this definition has several problems with rounding errors, 297 | ** so it is better to use 'fmod'. 'fmod' gives the result of 298 | ** 'a - trunc(a/b)*b', and therefore must be corrected when 299 | ** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a 300 | ** non-integer negative result: non-integer result is equivalent to 301 | ** a non-zero remainder 'm'; negative result is equivalent to 'a' and 302 | ** 'b' with different signs, or 'm' and 'b' with different signs 303 | ** (as the result 'm' of 'fmod' has the same sign of 'a'). 304 | */ 305 | #if !defined(luai_nummod) 306 | #define luai_nummod(L,a,b,m) \ 307 | { (void)L; (m) = l_mathop(fmod)(a,b); \ 308 | if (((m) > 0) ? (b) < 0 : ((m) < 0 && (b) > 0)) (m) += (b); } 309 | #endif 310 | 311 | /* exponentiation */ 312 | #if !defined(luai_numpow) 313 | #define luai_numpow(L,a,b) \ 314 | ((void)L, (b == 2) ? (a)*(a) : l_mathop(pow)(a,b)) 315 | #endif 316 | 317 | /* the others are quite standard operations */ 318 | #if !defined(luai_numadd) 319 | #define luai_numadd(L,a,b) ((a)+(b)) 320 | #define luai_numsub(L,a,b) ((a)-(b)) 321 | #define luai_nummul(L,a,b) ((a)*(b)) 322 | #define luai_numunm(L,a) (-(a)) 323 | #define luai_numeq(a,b) ((a)==(b)) 324 | #define luai_numlt(a,b) ((a)<(b)) 325 | #define luai_numle(a,b) ((a)<=(b)) 326 | #define luai_numgt(a,b) ((a)>(b)) 327 | #define luai_numge(a,b) ((a)>=(b)) 328 | #define luai_numisnan(a) (!luai_numeq((a), (a))) 329 | #endif 330 | 331 | 332 | 333 | 334 | 335 | /* 336 | ** macro to control inclusion of some hard tests on stack reallocation 337 | */ 338 | #if !defined(HARDSTACKTESTS) 339 | #define condmovestack(L,pre,pos) ((void)0) 340 | #else 341 | /* realloc stack keeping its size */ 342 | #define condmovestack(L,pre,pos) \ 343 | { int sz_ = stacksize(L); pre; luaD_reallocstack((L), sz_, 0); pos; } 344 | #endif 345 | 346 | #if !defined(HARDMEMTESTS) 347 | #define condchangemem(L,pre,pos) ((void)0) 348 | #else 349 | #define condchangemem(L,pre,pos) \ 350 | { if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } } 351 | #endif 352 | 353 | #endif 354 | -------------------------------------------------------------------------------- /include/lua/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h $ 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 | #define luaM_error(L) luaD_throw(L, LUA_ERRMEM) 18 | 19 | 20 | /* 21 | ** This macro tests whether it is safe to multiply 'n' by the size of 22 | ** type 't' without overflows. Because 'e' is always constant, it avoids 23 | ** the runtime division MAX_SIZET/(e). 24 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 25 | ** comparison avoids a runtime comparison when overflow cannot occur. 26 | ** The compiler should be able to optimize the real test by itself, but 27 | ** when it does it, it may give a warning about "comparison is always 28 | ** false due to limited range of data type"; the +1 tricks the compiler, 29 | ** avoiding this warning but also this optimization.) 30 | */ 31 | #define luaM_testsize(n,e) \ 32 | (sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e)) 33 | 34 | #define luaM_checksize(L,n,e) \ 35 | (luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0)) 36 | 37 | 38 | /* 39 | ** Computes the minimum between 'n' and 'MAX_SIZET/sizeof(t)', so that 40 | ** the result is not larger than 'n' and cannot overflow a 'size_t' 41 | ** when multiplied by the size of type 't'. (Assumes that 'n' is an 42 | ** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.) 43 | */ 44 | #define luaM_limitN(n,t) \ 45 | ((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \ 46 | cast_uint((MAX_SIZET/sizeof(t)))) 47 | 48 | 49 | /* 50 | ** Arrays of chars do not need any test 51 | */ 52 | #define luaM_reallocvchar(L,b,on,n) \ 53 | cast_charp(luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 54 | 55 | #define luaM_freemem(L, b, s) luaM_free_(L, (b), (s)) 56 | #define luaM_free(L, b) luaM_free_(L, (b), sizeof(*(b))) 57 | #define luaM_freearray(L, b, n) luaM_free_(L, (b), (n)*sizeof(*(b))) 58 | 59 | #define luaM_new(L,t) cast(t*, luaM_malloc_(L, sizeof(t), 0)) 60 | #define luaM_newvector(L,n,t) cast(t*, luaM_malloc_(L, (n)*sizeof(t), 0)) 61 | #define luaM_newvectorchecked(L,n,t) \ 62 | (luaM_checksize(L,n,sizeof(t)), luaM_newvector(L,n,t)) 63 | 64 | #define luaM_newobject(L,tag,s) luaM_malloc_(L, (s), tag) 65 | 66 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 67 | ((v)=cast(t *, luaM_growaux_(L,v,nelems,&(size),sizeof(t), \ 68 | luaM_limitN(limit,t),e))) 69 | 70 | #define luaM_reallocvector(L, v,oldn,n,t) \ 71 | (cast(t *, luaM_realloc_(L, v, cast_sizet(oldn) * sizeof(t), \ 72 | cast_sizet(n) * sizeof(t)))) 73 | 74 | #define luaM_shrinkvector(L,v,size,fs,t) \ 75 | ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t)))) 76 | 77 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 78 | 79 | /* not to be called directly */ 80 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 81 | size_t size); 82 | LUAI_FUNC void *luaM_saferealloc_ (lua_State *L, void *block, size_t oldsize, 83 | size_t size); 84 | LUAI_FUNC void luaM_free_ (lua_State *L, void *block, size_t osize); 85 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int nelems, 86 | int *size, int size_elem, int limit, 87 | const char *what); 88 | LUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem, 89 | int final_n, int size_elem); 90 | LUAI_FUNC void *luaM_malloc_ (lua_State *L, size_t size, int tag); 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /include/lua/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | #include 11 | 12 | 13 | /* ORDER OP */ 14 | 15 | static const char *const opnames[] = { 16 | "MOVE", 17 | "LOADI", 18 | "LOADF", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADFALSE", 22 | "LFALSESKIP", 23 | "LOADTRUE", 24 | "LOADNIL", 25 | "GETUPVAL", 26 | "SETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "GETI", 30 | "GETFIELD", 31 | "SETTABUP", 32 | "SETTABLE", 33 | "SETI", 34 | "SETFIELD", 35 | "NEWTABLE", 36 | "SELF", 37 | "ADDI", 38 | "ADDK", 39 | "SUBK", 40 | "MULK", 41 | "MODK", 42 | "POWK", 43 | "DIVK", 44 | "IDIVK", 45 | "BANDK", 46 | "BORK", 47 | "BXORK", 48 | "SHRI", 49 | "SHLI", 50 | "ADD", 51 | "SUB", 52 | "MUL", 53 | "MOD", 54 | "POW", 55 | "DIV", 56 | "IDIV", 57 | "BAND", 58 | "BOR", 59 | "BXOR", 60 | "SHL", 61 | "SHR", 62 | "MMBIN", 63 | "MMBINI", 64 | "MMBINK", 65 | "UNM", 66 | "BNOT", 67 | "NOT", 68 | "LEN", 69 | "CONCAT", 70 | "CLOSE", 71 | "TBC", 72 | "JMP", 73 | "EQ", 74 | "LT", 75 | "LE", 76 | "EQK", 77 | "EQI", 78 | "LTI", 79 | "LEI", 80 | "GTI", 81 | "GEI", 82 | "TEST", 83 | "TESTSET", 84 | "CALL", 85 | "TAILCALL", 86 | "RETURN", 87 | "RETURN0", 88 | "RETURN1", 89 | "FORLOOP", 90 | "FORPREP", 91 | "TFORPREP", 92 | "TFORCALL", 93 | "TFORLOOP", 94 | "SETLIST", 95 | "CLOSURE", 96 | "VARARG", 97 | "VARARGPREP", 98 | "EXTRAARG", 99 | NULL 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /include/lua/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h $ 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 of 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; ival = numerical integer value */ 34 | VKSTR, /* string constant; strval = TString address; 35 | (string is fixed by the lexer) */ 36 | VNONRELOC, /* expression has its value in a fixed register; 37 | info = result register */ 38 | VLOCAL, /* local variable; var.ridx = register index; 39 | var.vidx = relative index in 'actvar.arr' */ 40 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ 41 | VCONST, /* compile-time variable; 42 | info = absolute index in 'actvar.arr' */ 43 | VINDEXED, /* indexed variable; 44 | ind.t = table register; 45 | ind.idx = key's R index */ 46 | VINDEXUP, /* indexed upvalue; 47 | ind.t = table upvalue; 48 | ind.idx = key's K index */ 49 | VINDEXI, /* indexed variable with constant integer; 50 | ind.t = table register; 51 | ind.idx = key's value */ 52 | VINDEXSTR, /* indexed variable with literal string; 53 | ind.t = table register; 54 | ind.idx = key's K index */ 55 | VJMP, /* expression is a test/comparison; 56 | info = pc of corresponding jump instruction */ 57 | VRELOC, /* expression can put result in any register; 58 | info = instruction pc */ 59 | VCALL, /* expression is a function call; info = instruction pc */ 60 | VVARARG /* vararg expression; info = instruction pc */ 61 | } expkind; 62 | 63 | 64 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR) 65 | #define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR) 66 | 67 | 68 | typedef struct expdesc { 69 | expkind k; 70 | union { 71 | lua_Integer ival; /* for VKINT */ 72 | lua_Number nval; /* for VKFLT */ 73 | TString *strval; /* for VKSTR */ 74 | int info; /* for generic use */ 75 | struct { /* for indexed variables */ 76 | short idx; /* index (R or "long" K) */ 77 | lu_byte t; /* table (register or upvalue) */ 78 | } ind; 79 | struct { /* for local variables */ 80 | lu_byte ridx; /* register holding the variable */ 81 | unsigned short vidx; /* compiler index (in 'actvar.arr') */ 82 | } var; 83 | } u; 84 | int t; /* patch list of 'exit when true' */ 85 | int f; /* patch list of 'exit when false' */ 86 | } expdesc; 87 | 88 | 89 | /* kinds of variables */ 90 | #define VDKREG 0 /* regular */ 91 | #define RDKCONST 1 /* constant */ 92 | #define RDKTOCLOSE 2 /* to-be-closed */ 93 | #define RDKCTC 3 /* compile-time constant */ 94 | 95 | /* description of an active local variable */ 96 | typedef union Vardesc { 97 | struct { 98 | TValuefields; /* constant value (if it is a compile-time constant) */ 99 | lu_byte kind; 100 | lu_byte ridx; /* register holding the variable */ 101 | short pidx; /* index of the variable in the Proto's 'locvars' array */ 102 | TString *name; /* variable name */ 103 | } vd; 104 | TValue k; /* constant value (if any) */ 105 | } Vardesc; 106 | 107 | 108 | 109 | /* description of pending goto statements and label statements */ 110 | typedef struct Labeldesc { 111 | TString *name; /* label identifier */ 112 | int pc; /* position in code */ 113 | int line; /* line where it appeared */ 114 | lu_byte nactvar; /* number of active variables in that position */ 115 | lu_byte close; /* goto that escapes upvalues */ 116 | } Labeldesc; 117 | 118 | 119 | /* list of labels or gotos */ 120 | typedef struct Labellist { 121 | Labeldesc *arr; /* array */ 122 | int n; /* number of entries in use */ 123 | int size; /* array size */ 124 | } Labellist; 125 | 126 | 127 | /* dynamic structures used by the parser */ 128 | typedef struct Dyndata { 129 | struct { /* list of all active local variables */ 130 | Vardesc *arr; 131 | int n; 132 | int size; 133 | } actvar; 134 | Labellist gt; /* list of pending gotos */ 135 | Labellist label; /* list of active labels */ 136 | } Dyndata; 137 | 138 | 139 | /* control of blocks */ 140 | struct BlockCnt; /* defined in lparser.c */ 141 | 142 | 143 | /* state needed to generate code for a given function */ 144 | typedef struct FuncState { 145 | Proto *f; /* current function header */ 146 | struct FuncState *prev; /* enclosing function */ 147 | struct LexState *ls; /* lexical state */ 148 | struct BlockCnt *bl; /* chain of current blocks */ 149 | int pc; /* next position to code (equivalent to 'ncode') */ 150 | int lasttarget; /* 'label' of last 'jump label' */ 151 | int previousline; /* last line that was saved in 'lineinfo' */ 152 | int nk; /* number of elements in 'k' */ 153 | int np; /* number of elements in 'p' */ 154 | int nabslineinfo; /* number of elements in 'abslineinfo' */ 155 | int firstlocal; /* index of first local var (in Dyndata array) */ 156 | int firstlabel; /* index of first label (in 'dyd->label->arr') */ 157 | short ndebugvars; /* number of elements in 'f->locvars' */ 158 | lu_byte nactvar; /* number of active local variables */ 159 | lu_byte nups; /* number of upvalues */ 160 | lu_byte freereg; /* first free register */ 161 | lu_byte iwthabs; /* instructions issued since last absolute line info */ 162 | lu_byte needclose; /* function needs to close upvalues when returning */ 163 | } FuncState; 164 | 165 | 166 | LUAI_FUNC int luaY_nvarstack (FuncState *fs); 167 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 168 | Dyndata *dyd, const char *name, int firstchar); 169 | 170 | 171 | #endif 172 | -------------------------------------------------------------------------------- /include/lua/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 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 | -------------------------------------------------------------------------------- /include/lua/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h $ 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 | /* 16 | ** Memory-allocation error message must be preallocated (it cannot 17 | ** be created after memory is exhausted) 18 | */ 19 | #define MEMERRMSG "not enough memory" 20 | 21 | 22 | /* 23 | ** Size of a TString: Size of the header plus space for the string 24 | ** itself (including final '\0'). 25 | */ 26 | #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) 27 | 28 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 29 | (sizeof(s)/sizeof(char))-1)) 30 | 31 | 32 | /* 33 | ** test whether a string is a reserved word 34 | */ 35 | #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0) 36 | 37 | 38 | /* 39 | ** equality for short strings, which are always internalized 40 | */ 41 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 42 | 43 | 44 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 45 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 46 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 47 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 48 | LUAI_FUNC void luaS_clearcache (global_State *g); 49 | LUAI_FUNC void luaS_init (lua_State *L); 50 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 51 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 52 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 53 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 54 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /include/lua/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h $ 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)->u.next) 16 | 17 | 18 | /* 19 | ** Clear all bits of fast-access metamethods, which means that the table 20 | ** may have any of these metamethods. (First access that fails after the 21 | ** clearing will set the bit again.) 22 | */ 23 | #define invalidateTMcache(t) ((t)->flags &= ~maskflags) 24 | 25 | 26 | /* true when 't' is using 'dummynode' as its hash part */ 27 | #define isdummy(t) ((t)->lastfree == NULL) 28 | 29 | 30 | /* allocated size for hash nodes */ 31 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 32 | 33 | 34 | /* returns the Node, given the value of a table entry */ 35 | #define nodefromval(v) cast(Node *, (v)) 36 | 37 | 38 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 39 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 40 | TValue *value); 41 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 42 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 43 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 44 | LUAI_FUNC void luaH_newkey (lua_State *L, Table *t, const TValue *key, 45 | TValue *value); 46 | LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, 47 | TValue *value); 48 | LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, 49 | const TValue *slot, TValue *value); 50 | LUAI_FUNC Table *luaH_new (lua_State *L); 51 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 52 | unsigned int nhsize); 53 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 54 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 55 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 56 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 57 | LUAI_FUNC unsigned int luaH_realasize (const 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 | -------------------------------------------------------------------------------- /include/lua/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h $ 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_CLOSE, 44 | TM_N /* number of elements in the enum */ 45 | } TMS; 46 | 47 | 48 | /* 49 | ** Mask with 1 in all fast-access methods. A 1 in any of these bits 50 | ** in the flag of a (meta)table means the metatable does not have the 51 | ** corresponding metamethod field. (Bit 7 of the flag is used for 52 | ** 'isrealasize'.) 53 | */ 54 | #define maskflags (~(~0u << (TM_EQ + 1))) 55 | 56 | 57 | /* 58 | ** Test whether there is no tagmethod. 59 | ** (Because tagmethods use raw accesses, the result may be an "empty" nil.) 60 | */ 61 | #define notm(tm) ttisnil(tm) 62 | 63 | 64 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 65 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 66 | 67 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 68 | 69 | #define ttypename(x) luaT_typenames_[(x) + 1] 70 | 71 | LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];) 72 | 73 | 74 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 75 | 76 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 77 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 78 | TMS event); 79 | LUAI_FUNC void luaT_init (lua_State *L); 80 | 81 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 82 | const TValue *p2, const TValue *p3); 83 | LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f, 84 | const TValue *p1, const TValue *p2, StkId p3); 85 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 86 | StkId res, TMS event); 87 | LUAI_FUNC void luaT_tryconcatTM (lua_State *L); 88 | LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1, 89 | const TValue *p2, int inv, StkId res, TMS event); 90 | LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2, 91 | int inv, StkId res, TMS event); 92 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 93 | const TValue *p2, TMS event); 94 | LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, 95 | int inv, int isfloat, TMS event); 96 | 97 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, 98 | struct CallInfo *ci, const Proto *p); 99 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, 100 | StkId where, int wanted); 101 | 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /include/lua/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 | -------------------------------------------------------------------------------- /include/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 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_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/lua/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 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 | /* 22 | ** Encode major-minor version in one byte, one nibble for each 23 | */ 24 | #define MYINT(s) (s[0]-'0') /* assume one-digit numerals */ 25 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 26 | 27 | #define LUAC_FORMAT 0 /* this is the official format */ 28 | 29 | /* load one chunk; from lundump.c */ 30 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 31 | 32 | /* dump one chunk; from ldump.c */ 33 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 34 | void* data, int strip); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/lua/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h $ 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 F2Ieq 37 | #endif 38 | 39 | 40 | /* 41 | ** Rounding modes for float->integer coercion 42 | */ 43 | typedef enum { 44 | F2Ieq, /* no rounding; accepts only integral values */ 45 | F2Ifloor, /* takes the floor of the number */ 46 | F2Iceil /* takes the ceil of the number */ 47 | } F2Imod; 48 | 49 | 50 | /* convert an object to a float (including string coercion) */ 51 | #define tonumber(o,n) \ 52 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 53 | 54 | 55 | /* convert an object to a float (without string coercion) */ 56 | #define tonumberns(o,n) \ 57 | (ttisfloat(o) ? ((n) = fltvalue(o), 1) : \ 58 | (ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0)) 59 | 60 | 61 | /* convert an object to an integer (including string coercion) */ 62 | #define tointeger(o,i) \ 63 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \ 64 | : luaV_tointeger(o,i,LUA_FLOORN2I)) 65 | 66 | 67 | /* convert an object to an integer (without string coercion) */ 68 | #define tointegerns(o,i) \ 69 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \ 70 | : luaV_tointegerns(o,i,LUA_FLOORN2I)) 71 | 72 | 73 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 74 | 75 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 76 | 77 | 78 | /* 79 | ** fast track for 'gettable': if 't' is a table and 't[k]' is present, 80 | ** return 1 with 'slot' pointing to 't[k]' (position of final result). 81 | ** Otherwise, return 0 (meaning it will have to check metamethod) 82 | ** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL 83 | ** (otherwise). 'f' is the raw get function to use. 84 | */ 85 | #define luaV_fastget(L,t,k,slot,f) \ 86 | (!ttistable(t) \ 87 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 88 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ 89 | !isempty(slot))) /* result not empty? */ 90 | 91 | 92 | /* 93 | ** Special case of 'luaV_fastget' for integers, inlining the fast case 94 | ** of 'luaH_getint'. 95 | */ 96 | #define luaV_fastgeti(L,t,k,slot) \ 97 | (!ttistable(t) \ 98 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 99 | : (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \ 100 | ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \ 101 | !isempty(slot))) /* result not empty? */ 102 | 103 | 104 | /* 105 | ** Finish a fast set operation (when fast get succeeds). In that case, 106 | ** 'slot' points to the place to put the value. 107 | */ 108 | #define luaV_finishfastset(L,t,slot,v) \ 109 | { setobj2t(L, cast(TValue *,slot), v); \ 110 | luaC_barrierback(L, gcvalue(t), v); } 111 | 112 | 113 | 114 | 115 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 116 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 117 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 118 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 119 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode); 120 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, 121 | F2Imod mode); 122 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); 123 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 124 | StkId val, const TValue *slot); 125 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 126 | TValue *val, const TValue *slot); 127 | LUAI_FUNC void luaV_finishOp (lua_State *L); 128 | LUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci); 129 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 130 | LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y); 131 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 132 | LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y); 133 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 134 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /include/lua/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 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 | -------------------------------------------------------------------------------- /include/sol2/config.hpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // 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, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // This file was generated with a script. 23 | // Generated 2020-10-03 21:34:25.034794 UTC 24 | // This header was generated with sol v3.2.1 (revision 48eea7b5) 25 | // https://github.com/ThePhD/sol2 26 | 27 | #ifndef SOL_SINGLE_CONFIG_HPP 28 | #define SOL_SINGLE_CONFIG_HPP 29 | 30 | // beginning of sol/config.hpp 31 | 32 | /* Base, empty configuration file! 33 | 34 | To override, place a file in your include paths of the form: 35 | 36 | . (your include path here) 37 | | sol (directory, or equivalent) 38 | | config.hpp (your config.hpp file) 39 | 40 | So that when sol2 includes the file 41 | 42 | #include 43 | 44 | it gives you the configuration values you desire. Configuration values can be 45 | seen in the safety.rst of the doc/src, or at 46 | https://sol2.readthedocs.io/en/latest/safety.html ! You can also pass them through 47 | the build system, or the command line options of your compiler. 48 | 49 | */ 50 | 51 | // end of sol/config.hpp 52 | 53 | #endif // SOL_SINGLE_CONFIG_HPP -------------------------------------------------------------------------------- /include/toml11/toml.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Toru Niina 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | #ifndef TOML_FOR_MODERN_CPP 26 | #define TOML_FOR_MODERN_CPP 27 | 28 | #ifndef __cplusplus 29 | # error "__cplusplus is not defined" 30 | #endif 31 | 32 | #if __cplusplus < 201103L && _MSC_VER < 1900 33 | # error "toml11 requires C++11 or later." 34 | #endif 35 | 36 | #define TOML11_VERSION_MAJOR 3 37 | #define TOML11_VERSION_MINOR 7 38 | #define TOML11_VERSION_PATCH 0 39 | 40 | #include "toml/parser.hpp" 41 | #include "toml/literal.hpp" 42 | #include "toml/serializer.hpp" 43 | #include "toml/get.hpp" 44 | #include "toml/macros.hpp" 45 | 46 | #endif// TOML_FOR_MODERN_CPP 47 | -------------------------------------------------------------------------------- /include/toml11/toml/color.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TOML11_COLOR_HPP 2 | #define TOML11_COLOR_HPP 3 | #include 4 | #include 5 | 6 | #ifdef TOML11_COLORIZE_ERROR_MESSAGE 7 | #define TOML11_ERROR_MESSAGE_COLORIZED true 8 | #else 9 | #define TOML11_ERROR_MESSAGE_COLORIZED false 10 | #endif 11 | 12 | namespace toml 13 | { 14 | 15 | // put ANSI escape sequence to ostream 16 | namespace color_ansi 17 | { 18 | namespace detail 19 | { 20 | inline int colorize_index() 21 | { 22 | static const int index = std::ios_base::xalloc(); 23 | return index; 24 | } 25 | } // detail 26 | 27 | inline std::ostream& colorize(std::ostream& os) 28 | { 29 | // by default, it is zero. 30 | os.iword(detail::colorize_index()) = 1; 31 | return os; 32 | } 33 | inline std::ostream& nocolorize(std::ostream& os) 34 | { 35 | os.iword(detail::colorize_index()) = 0; 36 | return os; 37 | } 38 | inline std::ostream& reset (std::ostream& os) 39 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[00m";} return os;} 40 | inline std::ostream& bold (std::ostream& os) 41 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[01m";} return os;} 42 | inline std::ostream& grey (std::ostream& os) 43 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[30m";} return os;} 44 | inline std::ostream& red (std::ostream& os) 45 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[31m";} return os;} 46 | inline std::ostream& green (std::ostream& os) 47 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[32m";} return os;} 48 | inline std::ostream& yellow (std::ostream& os) 49 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[33m";} return os;} 50 | inline std::ostream& blue (std::ostream& os) 51 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[34m";} return os;} 52 | inline std::ostream& magenta(std::ostream& os) 53 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[35m";} return os;} 54 | inline std::ostream& cyan (std::ostream& os) 55 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[36m";} return os;} 56 | inline std::ostream& white (std::ostream& os) 57 | {if(os.iword(detail::colorize_index()) == 1) {os << "\033[37m";} return os;} 58 | } // color_ansi 59 | 60 | // ANSI escape sequence is the only and default colorization method currently 61 | namespace color = color_ansi; 62 | 63 | } // toml 64 | #endif// TOML11_COLOR_HPP 65 | -------------------------------------------------------------------------------- /include/toml11/toml/combinator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2017. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_COMBINATOR_HPP 4 | #define TOML11_COMBINATOR_HPP 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "region.hpp" 16 | #include "result.hpp" 17 | #include "traits.hpp" 18 | #include "utility.hpp" 19 | 20 | // they scans characters and returns region if it matches to the condition. 21 | // when they fail, it does not change the location. 22 | // in lexer.hpp, these are used. 23 | 24 | namespace toml 25 | { 26 | namespace detail 27 | { 28 | 29 | // to output character as an error message. 30 | inline std::string show_char(const char c) 31 | { 32 | // It supress an error that occurs only in Debug mode of MSVC++ on Windows. 33 | // I'm not completely sure but they check the value of char to be in the 34 | // range [0, 256) and some of the COMPLETELY VALID utf-8 character sometimes 35 | // has negative value (if char has sign). So here it re-interprets c as 36 | // unsigned char through pointer. In general, converting pointer to a 37 | // pointer that has different type cause UB, but `(signed|unsigned)?char` 38 | // are one of the exceptions. Converting pointer only to char and std::byte 39 | // (c++17) are valid. 40 | if(std::isgraph(*reinterpret_cast(std::addressof(c)))) 41 | { 42 | return std::string(1, c); 43 | } 44 | else 45 | { 46 | std::array buf; 47 | buf.fill('\0'); 48 | const auto r = std::snprintf( 49 | buf.data(), buf.size(), "0x%02x", static_cast(c) & 0xFF); 50 | (void) r; // Unused variable warning 51 | assert(r == static_cast(buf.size()) - 1); 52 | return std::string(buf.data()); 53 | } 54 | } 55 | 56 | template 57 | struct character 58 | { 59 | static constexpr char target = C; 60 | 61 | static result 62 | invoke(location& loc) 63 | { 64 | if(loc.iter() == loc.end()) {return none();} 65 | const auto first = loc.iter(); 66 | 67 | const char c = *(loc.iter()); 68 | if(c != target) 69 | { 70 | return none(); 71 | } 72 | loc.advance(); // update location 73 | 74 | return ok(region(loc, first, loc.iter())); 75 | } 76 | }; 77 | template 78 | constexpr char character::target; 79 | 80 | // closed interval [Low, Up]. both Low and Up are included. 81 | template 82 | struct in_range 83 | { 84 | // assuming ascii part of UTF-8... 85 | static_assert(Low <= Up, "lower bound should be less than upper bound."); 86 | 87 | static constexpr char upper = Up; 88 | static constexpr char lower = Low; 89 | 90 | static result 91 | invoke(location& loc) 92 | { 93 | if(loc.iter() == loc.end()) {return none();} 94 | const auto first = loc.iter(); 95 | 96 | const char c = *(loc.iter()); 97 | if(c < lower || upper < c) 98 | { 99 | return none(); 100 | } 101 | 102 | loc.advance(); 103 | return ok(region(loc, first, loc.iter())); 104 | } 105 | }; 106 | template constexpr char in_range::upper; 107 | template constexpr char in_range::lower; 108 | 109 | // keep iterator if `Combinator` matches. otherwise, increment `iter` by 1 char. 110 | // for detecting invalid characters, like control sequences in toml string. 111 | template 112 | struct exclude 113 | { 114 | static result 115 | invoke(location& loc) 116 | { 117 | if(loc.iter() == loc.end()) {return none();} 118 | auto first = loc.iter(); 119 | 120 | auto rslt = Combinator::invoke(loc); 121 | if(rslt.is_ok()) 122 | { 123 | loc.reset(first); 124 | return none(); 125 | } 126 | loc.reset(std::next(first)); // XXX maybe loc.advance() is okay but... 127 | return ok(region(loc, first, loc.iter())); 128 | } 129 | }; 130 | 131 | // increment `iter`, if matches. otherwise, just return empty string. 132 | template 133 | struct maybe 134 | { 135 | static result 136 | invoke(location& loc) 137 | { 138 | const auto rslt = Combinator::invoke(loc); 139 | if(rslt.is_ok()) 140 | { 141 | return rslt; 142 | } 143 | return ok(region(loc)); 144 | } 145 | }; 146 | 147 | template 148 | struct sequence; 149 | 150 | template 151 | struct sequence 152 | { 153 | static result 154 | invoke(location& loc) 155 | { 156 | const auto first = loc.iter(); 157 | const auto rslt = Head::invoke(loc); 158 | if(rslt.is_err()) 159 | { 160 | loc.reset(first); 161 | return none(); 162 | } 163 | return sequence::invoke(loc, std::move(rslt.unwrap()), first); 164 | } 165 | 166 | // called from the above function only, recursively. 167 | template 168 | static result 169 | invoke(location& loc, region reg, Iterator first) 170 | { 171 | const auto rslt = Head::invoke(loc); 172 | if(rslt.is_err()) 173 | { 174 | loc.reset(first); 175 | return none(); 176 | } 177 | reg += rslt.unwrap(); // concat regions 178 | return sequence::invoke(loc, std::move(reg), first); 179 | } 180 | }; 181 | 182 | template 183 | struct sequence 184 | { 185 | // would be called from sequence::invoke only. 186 | template 187 | static result 188 | invoke(location& loc, region reg, Iterator first) 189 | { 190 | const auto rslt = Head::invoke(loc); 191 | if(rslt.is_err()) 192 | { 193 | loc.reset(first); 194 | return none(); 195 | } 196 | reg += rslt.unwrap(); // concat regions 197 | return ok(reg); 198 | } 199 | }; 200 | 201 | template 202 | struct either; 203 | 204 | template 205 | struct either 206 | { 207 | static result 208 | invoke(location& loc) 209 | { 210 | const auto rslt = Head::invoke(loc); 211 | if(rslt.is_ok()) {return rslt;} 212 | return either::invoke(loc); 213 | } 214 | }; 215 | template 216 | struct either 217 | { 218 | static result 219 | invoke(location& loc) 220 | { 221 | return Head::invoke(loc); 222 | } 223 | }; 224 | 225 | template 226 | struct repeat; 227 | 228 | template struct exactly{}; 229 | template struct at_least{}; 230 | struct unlimited{}; 231 | 232 | template 233 | struct repeat> 234 | { 235 | static result 236 | invoke(location& loc) 237 | { 238 | region retval(loc); 239 | const auto first = loc.iter(); 240 | for(std::size_t i=0; i 255 | struct repeat> 256 | { 257 | static result 258 | invoke(location& loc) 259 | { 260 | region retval(loc); 261 | 262 | const auto first = loc.iter(); 263 | for(std::size_t i=0; i 286 | struct repeat 287 | { 288 | static result 289 | invoke(location& loc) 290 | { 291 | region retval(loc); 292 | while(true) 293 | { 294 | auto rslt = T::invoke(loc); 295 | if(rslt.is_err()) 296 | { 297 | return ok(std::move(retval)); 298 | } 299 | retval += rslt.unwrap(); 300 | } 301 | } 302 | }; 303 | 304 | } // detail 305 | } // toml 306 | #endif// TOML11_COMBINATOR_HPP 307 | -------------------------------------------------------------------------------- /include/toml11/toml/exception.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2017. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_EXCEPTION_HPP 4 | #define TOML11_EXCEPTION_HPP 5 | #include 6 | #include 7 | 8 | #include "source_location.hpp" 9 | 10 | namespace toml 11 | { 12 | 13 | struct exception : public std::exception 14 | { 15 | public: 16 | explicit exception(const source_location& loc): loc_(loc) {} 17 | virtual ~exception() noexcept override = default; 18 | virtual const char* what() const noexcept override {return "";} 19 | virtual source_location const& location() const noexcept {return loc_;} 20 | 21 | protected: 22 | source_location loc_; 23 | }; 24 | 25 | struct syntax_error : public toml::exception 26 | { 27 | public: 28 | explicit syntax_error(const std::string& what_arg, const source_location& loc) 29 | : exception(loc), what_(what_arg) 30 | {} 31 | virtual ~syntax_error() noexcept override = default; 32 | virtual const char* what() const noexcept override {return what_.c_str();} 33 | 34 | protected: 35 | std::string what_; 36 | }; 37 | 38 | struct type_error : public toml::exception 39 | { 40 | public: 41 | explicit type_error(const std::string& what_arg, const source_location& loc) 42 | : exception(loc), what_(what_arg) 43 | {} 44 | virtual ~type_error() noexcept override = default; 45 | virtual const char* what() const noexcept override {return what_.c_str();} 46 | 47 | protected: 48 | std::string what_; 49 | }; 50 | 51 | struct internal_error : public toml::exception 52 | { 53 | public: 54 | explicit internal_error(const std::string& what_arg, const source_location& loc) 55 | : exception(loc), what_(what_arg) 56 | {} 57 | virtual ~internal_error() noexcept override = default; 58 | virtual const char* what() const noexcept override {return what_.c_str();} 59 | 60 | protected: 61 | std::string what_; 62 | }; 63 | 64 | } // toml 65 | #endif // TOML_EXCEPTION 66 | -------------------------------------------------------------------------------- /include/toml11/toml/from.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2019. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_FROM_HPP 4 | #define TOML11_FROM_HPP 5 | 6 | namespace toml 7 | { 8 | 9 | template 10 | struct from; 11 | // { 12 | // static T from_toml(const toml::value& v) 13 | // { 14 | // // User-defined conversions ... 15 | // } 16 | // }; 17 | 18 | } // toml 19 | #endif // TOML11_FROM_HPP 20 | -------------------------------------------------------------------------------- /include/toml11/toml/into.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2019. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_INTO_HPP 4 | #define TOML11_INTO_HPP 5 | 6 | namespace toml 7 | { 8 | 9 | template 10 | struct into; 11 | // { 12 | // static toml::value into_toml(const T& user_defined_type) 13 | // { 14 | // // User-defined conversions ... 15 | // } 16 | // }; 17 | 18 | } // toml 19 | #endif // TOML11_INTO_HPP 20 | -------------------------------------------------------------------------------- /include/toml11/toml/literal.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2019. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_LITERAL_HPP 4 | #define TOML11_LITERAL_HPP 5 | #include "parser.hpp" 6 | 7 | namespace toml 8 | { 9 | inline namespace literals 10 | { 11 | inline namespace toml_literals 12 | { 13 | 14 | // implementation 15 | inline ::toml::basic_value 16 | literal_internal_impl(::toml::detail::location loc) 17 | { 18 | using value_type = ::toml::basic_value< 19 | TOML11_DEFAULT_COMMENT_STRATEGY, std::unordered_map, std::vector>; 20 | // if there are some comments or empty lines, skip them. 21 | using skip_line = ::toml::detail::repeat, 23 | ::toml::detail::maybe<::toml::detail::lex_comment>, 24 | ::toml::detail::lex_newline 25 | >, ::toml::detail::at_least<1>>; 26 | skip_line::invoke(loc); 27 | 28 | // if there are some whitespaces before a value, skip them. 29 | using skip_ws = ::toml::detail::repeat< 30 | ::toml::detail::lex_ws, ::toml::detail::at_least<1>>; 31 | skip_ws::invoke(loc); 32 | 33 | // to distinguish arrays and tables, first check it is a table or not. 34 | // 35 | // "[1,2,3]"_toml; // this is an array 36 | // "[table]"_toml; // a table that has an empty table named "table" inside. 37 | // "[[1,2,3]]"_toml; // this is an array of arrays 38 | // "[[table]]"_toml; // this is a table that has an array of tables inside. 39 | // 40 | // "[[1]]"_toml; // this can be both... (currently it becomes a table) 41 | // "1 = [{}]"_toml; // this is a table that has an array of table named 1. 42 | // "[[1,]]"_toml; // this is an array of arrays. 43 | // "[[1],]"_toml; // this also. 44 | 45 | const auto the_front = loc.iter(); 46 | 47 | const bool is_table_key = ::toml::detail::lex_std_table::invoke(loc); 48 | loc.reset(the_front); 49 | 50 | const bool is_aots_key = ::toml::detail::lex_array_table::invoke(loc); 51 | loc.reset(the_front); 52 | 53 | // If it is neither a table-key or a array-of-table-key, it may be a value. 54 | if(!is_table_key && !is_aots_key) 55 | { 56 | if(auto data = ::toml::detail::parse_value(loc)) 57 | { 58 | return data.unwrap(); 59 | } 60 | } 61 | 62 | // Note that still it can be a table, because the literal might be something 63 | // like the following. 64 | // ```cpp 65 | // R"( // c++11 raw string literals 66 | // key = "value" 67 | // int = 42 68 | // )"_toml; 69 | // ``` 70 | // It is a valid toml file. 71 | // It should be parsed as if we parse a file with this content. 72 | 73 | if(auto data = ::toml::detail::parse_toml_file(loc)) 74 | { 75 | return data.unwrap(); 76 | } 77 | else // none of them. 78 | { 79 | throw ::toml::syntax_error(data.unwrap_err(), source_location(loc)); 80 | } 81 | 82 | } 83 | 84 | inline ::toml::basic_value 85 | operator"" _toml(const char* str, std::size_t len) 86 | { 87 | ::toml::detail::location loc( 88 | std::string("TOML literal encoded in a C++ code"), 89 | std::vector(str, str + len)); 90 | return literal_internal_impl(std::move(loc)); 91 | } 92 | 93 | // value of __cplusplus in C++2a/20 mode is not fixed yet along compilers. 94 | // So here we use the feature test macro for `char8_t` itself. 95 | #if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L 96 | // value of u8"" literal has been changed from char to char8_t and char8_t is 97 | // NOT compatible to char 98 | inline ::toml::basic_value 99 | operator"" _toml(const char8_t* str, std::size_t len) 100 | { 101 | ::toml::detail::location loc( 102 | std::string("TOML literal encoded in a C++ code"), 103 | std::vector(reinterpret_cast(str), 104 | reinterpret_cast(str) + len)); 105 | return literal_internal_impl(std::move(loc)); 106 | } 107 | #endif 108 | 109 | } // toml_literals 110 | } // literals 111 | } // toml 112 | #endif//TOML11_LITERAL_HPP 113 | -------------------------------------------------------------------------------- /include/toml11/toml/macros.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TOML11_MACROS_HPP 2 | #define TOML11_MACROS_HPP 3 | 4 | #define TOML11_STRINGIZE_AUX(x) #x 5 | #define TOML11_STRINGIZE(x) TOML11_STRINGIZE_AUX(x) 6 | 7 | #define TOML11_CONCATENATE_AUX(x, y) x##y 8 | #define TOML11_CONCATENATE(x, y) TOML11_CONCATENATE_AUX(x, y) 9 | 10 | // ============================================================================ 11 | // TOML11_DEFINE_CONVERSION_NON_INTRUSIVE 12 | 13 | #ifndef TOML11_WITHOUT_DEFINE_NON_INTRUSIVE 14 | 15 | // ---------------------------------------------------------------------------- 16 | // TOML11_ARGS_SIZE 17 | 18 | #define TOML11_INDEX_RSEQ() \ 19 | 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, \ 20 | 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 21 | #define TOML11_ARGS_SIZE_IMPL(\ 22 | ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, ARG9, ARG10, \ 23 | ARG11, ARG12, ARG13, ARG14, ARG15, ARG16, ARG17, ARG18, ARG19, ARG20, \ 24 | ARG21, ARG22, ARG23, ARG24, ARG25, ARG26, ARG27, ARG28, ARG29, ARG30, \ 25 | ARG31, ARG32, N, ...) N 26 | #define TOML11_ARGS_SIZE_AUX(...) TOML11_ARGS_SIZE_IMPL(__VA_ARGS__) 27 | #define TOML11_ARGS_SIZE(...) TOML11_ARGS_SIZE_AUX(__VA_ARGS__, TOML11_INDEX_RSEQ()) 28 | 29 | // ---------------------------------------------------------------------------- 30 | // TOML11_FOR_EACH_VA_ARGS 31 | 32 | #define TOML11_FOR_EACH_VA_ARGS_AUX_1( FUNCTOR, ARG1 ) FUNCTOR(ARG1) 33 | #define TOML11_FOR_EACH_VA_ARGS_AUX_2( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_1( FUNCTOR, __VA_ARGS__) 34 | #define TOML11_FOR_EACH_VA_ARGS_AUX_3( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_2( FUNCTOR, __VA_ARGS__) 35 | #define TOML11_FOR_EACH_VA_ARGS_AUX_4( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_3( FUNCTOR, __VA_ARGS__) 36 | #define TOML11_FOR_EACH_VA_ARGS_AUX_5( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_4( FUNCTOR, __VA_ARGS__) 37 | #define TOML11_FOR_EACH_VA_ARGS_AUX_6( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_5( FUNCTOR, __VA_ARGS__) 38 | #define TOML11_FOR_EACH_VA_ARGS_AUX_7( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_6( FUNCTOR, __VA_ARGS__) 39 | #define TOML11_FOR_EACH_VA_ARGS_AUX_8( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_7( FUNCTOR, __VA_ARGS__) 40 | #define TOML11_FOR_EACH_VA_ARGS_AUX_9( FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_8( FUNCTOR, __VA_ARGS__) 41 | #define TOML11_FOR_EACH_VA_ARGS_AUX_10(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_9( FUNCTOR, __VA_ARGS__) 42 | #define TOML11_FOR_EACH_VA_ARGS_AUX_11(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_10(FUNCTOR, __VA_ARGS__) 43 | #define TOML11_FOR_EACH_VA_ARGS_AUX_12(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_11(FUNCTOR, __VA_ARGS__) 44 | #define TOML11_FOR_EACH_VA_ARGS_AUX_13(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_12(FUNCTOR, __VA_ARGS__) 45 | #define TOML11_FOR_EACH_VA_ARGS_AUX_14(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_13(FUNCTOR, __VA_ARGS__) 46 | #define TOML11_FOR_EACH_VA_ARGS_AUX_15(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_14(FUNCTOR, __VA_ARGS__) 47 | #define TOML11_FOR_EACH_VA_ARGS_AUX_16(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_15(FUNCTOR, __VA_ARGS__) 48 | #define TOML11_FOR_EACH_VA_ARGS_AUX_17(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_16(FUNCTOR, __VA_ARGS__) 49 | #define TOML11_FOR_EACH_VA_ARGS_AUX_18(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_17(FUNCTOR, __VA_ARGS__) 50 | #define TOML11_FOR_EACH_VA_ARGS_AUX_19(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_18(FUNCTOR, __VA_ARGS__) 51 | #define TOML11_FOR_EACH_VA_ARGS_AUX_20(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_19(FUNCTOR, __VA_ARGS__) 52 | #define TOML11_FOR_EACH_VA_ARGS_AUX_21(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_20(FUNCTOR, __VA_ARGS__) 53 | #define TOML11_FOR_EACH_VA_ARGS_AUX_22(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_21(FUNCTOR, __VA_ARGS__) 54 | #define TOML11_FOR_EACH_VA_ARGS_AUX_23(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_22(FUNCTOR, __VA_ARGS__) 55 | #define TOML11_FOR_EACH_VA_ARGS_AUX_24(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_23(FUNCTOR, __VA_ARGS__) 56 | #define TOML11_FOR_EACH_VA_ARGS_AUX_25(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_24(FUNCTOR, __VA_ARGS__) 57 | #define TOML11_FOR_EACH_VA_ARGS_AUX_26(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_25(FUNCTOR, __VA_ARGS__) 58 | #define TOML11_FOR_EACH_VA_ARGS_AUX_27(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_26(FUNCTOR, __VA_ARGS__) 59 | #define TOML11_FOR_EACH_VA_ARGS_AUX_28(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_27(FUNCTOR, __VA_ARGS__) 60 | #define TOML11_FOR_EACH_VA_ARGS_AUX_29(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_28(FUNCTOR, __VA_ARGS__) 61 | #define TOML11_FOR_EACH_VA_ARGS_AUX_30(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_29(FUNCTOR, __VA_ARGS__) 62 | #define TOML11_FOR_EACH_VA_ARGS_AUX_31(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_30(FUNCTOR, __VA_ARGS__) 63 | #define TOML11_FOR_EACH_VA_ARGS_AUX_32(FUNCTOR, ARG1, ...) FUNCTOR(ARG1) TOML11_FOR_EACH_VA_ARGS_AUX_31(FUNCTOR, __VA_ARGS__) 64 | 65 | #define TOML11_FOR_EACH_VA_ARGS(FUNCTOR, ...)\ 66 | TOML11_CONCATENATE(TOML11_FOR_EACH_VA_ARGS_AUX_, TOML11_ARGS_SIZE(__VA_ARGS__))(FUNCTOR, __VA_ARGS__) 67 | 68 | // ---------------------------------------------------------------------------- 69 | // TOML11_DEFINE_CONVERSION_NON_INTRUSIVE 70 | 71 | // use it in the following way. 72 | // ```cpp 73 | // namespace foo 74 | // { 75 | // struct Foo 76 | // { 77 | // std::string s; 78 | // double d; 79 | // int i; 80 | // }; 81 | // } // foo 82 | // 83 | // TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(foo::Foo, s, d, i) 84 | // ``` 85 | // And then you can use `toml::find(file, "foo");` 86 | // 87 | #define TOML11_FIND_MEMBER_VARIABLE_FROM_VALUE(VAR_NAME)\ 88 | obj.VAR_NAME = toml::find(v, TOML11_STRINGIZE(VAR_NAME)); 89 | 90 | #define TOML11_ASSIGN_MEMBER_VARIABLE_TO_VALUE(VAR_NAME)\ 91 | v[TOML11_STRINGIZE(VAR_NAME)] = obj.VAR_NAME; 92 | 93 | #define TOML11_DEFINE_CONVERSION_NON_INTRUSIVE(NAME, ...)\ 94 | namespace toml { \ 95 | template<> \ 96 | struct from \ 97 | { \ 98 | template class T, \ 99 | template class A> \ 100 | static NAME from_toml(const basic_value& v) \ 101 | { \ 102 | NAME obj; \ 103 | TOML11_FOR_EACH_VA_ARGS(TOML11_FIND_MEMBER_VARIABLE_FROM_VALUE, __VA_ARGS__) \ 104 | return obj; \ 105 | } \ 106 | }; \ 107 | template<> \ 108 | struct into \ 109 | { \ 110 | static value into_toml(const NAME& obj) \ 111 | { \ 112 | ::toml::value v = ::toml::table{}; \ 113 | TOML11_FOR_EACH_VA_ARGS(TOML11_ASSIGN_MEMBER_VARIABLE_TO_VALUE, __VA_ARGS__) \ 114 | return v; \ 115 | } \ 116 | }; \ 117 | } /* toml */ 118 | 119 | #endif// TOML11_WITHOUT_DEFINE_NON_INTRUSIVE 120 | 121 | #endif// TOML11_MACROS_HPP 122 | -------------------------------------------------------------------------------- /include/toml11/toml/source_location.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2019. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_SOURCE_LOCATION_HPP 4 | #define TOML11_SOURCE_LOCATION_HPP 5 | #include 6 | #include 7 | 8 | #include "region.hpp" 9 | 10 | namespace toml 11 | { 12 | 13 | // A struct to contain location in a toml file. 14 | // The interface imitates std::experimental::source_location, 15 | // but not completely the same. 16 | // 17 | // It would be constructed by toml::value. It can be used to generate 18 | // user-defined error messages. 19 | // 20 | // - std::uint_least32_t line() const noexcept 21 | // - returns the line number where the region is on. 22 | // - std::uint_least32_t column() const noexcept 23 | // - returns the column number where the region starts. 24 | // - std::uint_least32_t region() const noexcept 25 | // - returns the size of the region. 26 | // 27 | // +-- line() +-- region of interest (region() == 9) 28 | // v .---+---. 29 | // 12 | value = "foo bar" 30 | // ^ 31 | // +-- column() 32 | // 33 | // - std::string const& file_name() const noexcept; 34 | // - name of the file. 35 | // - std::string const& line_str() const noexcept; 36 | // - the whole line that contains the region of interest. 37 | // 38 | struct source_location 39 | { 40 | public: 41 | 42 | source_location() 43 | : line_num_(1), column_num_(1), region_size_(1), 44 | file_name_("unknown file"), line_str_("") 45 | {} 46 | 47 | explicit source_location(const detail::region_base* reg) 48 | : line_num_(1), column_num_(1), region_size_(1), 49 | file_name_("unknown file"), line_str_("") 50 | { 51 | if(reg) 52 | { 53 | if(reg->line_num() != detail::region_base().line_num()) 54 | { 55 | line_num_ = static_cast( 56 | std::stoul(reg->line_num())); 57 | } 58 | column_num_ = static_cast(reg->before() + 1); 59 | region_size_ = static_cast(reg->size()); 60 | file_name_ = reg->name(); 61 | line_str_ = reg->line(); 62 | } 63 | } 64 | 65 | explicit source_location(const detail::region& reg) 66 | : line_num_(static_cast(std::stoul(reg.line_num()))), 67 | column_num_(static_cast(reg.before() + 1)), 68 | region_size_(static_cast(reg.size())), 69 | file_name_(reg.name()), 70 | line_str_ (reg.line()) 71 | {} 72 | explicit source_location(const detail::location& loc) 73 | : line_num_(static_cast(std::stoul(loc.line_num()))), 74 | column_num_(static_cast(loc.before() + 1)), 75 | region_size_(static_cast(loc.size())), 76 | file_name_(loc.name()), 77 | line_str_ (loc.line()) 78 | {} 79 | 80 | ~source_location() = default; 81 | source_location(source_location const&) = default; 82 | source_location(source_location &&) = default; 83 | source_location& operator=(source_location const&) = default; 84 | source_location& operator=(source_location &&) = default; 85 | 86 | std::uint_least32_t line() const noexcept {return line_num_;} 87 | std::uint_least32_t column() const noexcept {return column_num_;} 88 | std::uint_least32_t region() const noexcept {return region_size_;} 89 | 90 | std::string const& file_name() const noexcept {return file_name_;} 91 | std::string const& line_str() const noexcept {return line_str_;} 92 | 93 | private: 94 | 95 | std::uint_least32_t line_num_; 96 | std::uint_least32_t column_num_; 97 | std::uint_least32_t region_size_; 98 | std::string file_name_; 99 | std::string line_str_; 100 | }; 101 | 102 | namespace detail 103 | { 104 | 105 | // internal error message generation. 106 | inline std::string format_underline(const std::string& message, 107 | const std::vector>& loc_com, 108 | const std::vector& helps = {}, 109 | const bool colorize = TOML11_ERROR_MESSAGE_COLORIZED) 110 | { 111 | std::size_t line_num_width = 0; 112 | for(const auto& lc : loc_com) 113 | { 114 | std::uint_least32_t line = lc.first.line(); 115 | std::size_t digit = 0; 116 | while(line != 0) 117 | { 118 | line /= 10; 119 | digit += 1; 120 | } 121 | line_num_width = (std::max)(line_num_width, digit); 122 | } 123 | // 1 is the minimum width 124 | line_num_width = std::max(line_num_width, 1); 125 | 126 | std::ostringstream retval; 127 | 128 | if(colorize) 129 | { 130 | retval << color::colorize; // turn on ANSI color 131 | } 132 | 133 | // XXX 134 | // Here, before `colorize` support, it does not output `[error]` prefix 135 | // automatically. So some user may output it manually and this change may 136 | // duplicate the prefix. To avoid it, check the first 7 characters and 137 | // if it is "[error]", it removes that part from the message shown. 138 | if(message.size() > 7 && message.substr(0, 7) == "[error]") 139 | { 140 | retval << color::bold << color::red << "[error]" << color::reset 141 | << color::bold << message.substr(7) << color::reset << '\n'; 142 | } 143 | else 144 | { 145 | retval << color::bold << color::red << "[error] " << color::reset 146 | << color::bold << message << color::reset << '\n'; 147 | } 148 | 149 | const auto format_one_location = [line_num_width] 150 | (std::ostringstream& oss, 151 | const source_location& loc, const std::string& comment) -> void 152 | { 153 | oss << ' ' << color::bold << color::blue 154 | << std::setw(static_cast(line_num_width)) 155 | << std::right << loc.line() << " | " << color::reset 156 | << loc.line_str() << '\n'; 157 | 158 | oss << make_string(line_num_width + 1, ' ') 159 | << color::bold << color::blue << " | " << color::reset 160 | << make_string(loc.column()-1 /*1-origin*/, ' '); 161 | 162 | if(loc.region() == 1) 163 | { 164 | // invalid 165 | // ^------ 166 | oss << color::bold << color::red << "^---" << color::reset; 167 | } 168 | else 169 | { 170 | // invalid 171 | // ~~~~~~~ 172 | const auto underline_len = (std::min)( 173 | static_cast(loc.region()), loc.line_str().size()); 174 | oss << color::bold << color::red 175 | << make_string(underline_len, '~') << color::reset; 176 | } 177 | oss << ' '; 178 | oss << comment; 179 | return; 180 | }; 181 | 182 | assert(!loc_com.empty()); 183 | 184 | // --> example.toml 185 | // | 186 | retval << color::bold << color::blue << " --> " << color::reset 187 | << loc_com.front().first.file_name() << '\n'; 188 | retval << make_string(line_num_width + 1, ' ') 189 | << color::bold << color::blue << " |\n" << color::reset; 190 | // 1 | key value 191 | // | ^--- missing = 192 | format_one_location(retval, loc_com.front().first, loc_com.front().second); 193 | 194 | // process the rest of the locations 195 | for(std::size_t i=1; i filename.toml" again 207 | { 208 | retval << color::bold << color::blue << " --> " << color::reset 209 | << curr.first.file_name() << '\n'; 210 | retval << make_string(line_num_width + 1, ' ') 211 | << color::bold << color::blue << " |\n" << color::reset; 212 | } 213 | 214 | format_one_location(retval, curr.first, curr.second); 215 | } 216 | 217 | if(!helps.empty()) 218 | { 219 | retval << '\n'; 220 | retval << make_string(line_num_width + 1, ' '); 221 | retval << color::bold << color::blue << " |" << color::reset; 222 | for(const auto& help : helps) 223 | { 224 | retval << color::bold << "\nHint: " << color::reset; 225 | retval << help; 226 | } 227 | } 228 | return retval.str(); 229 | } 230 | 231 | } // detail 232 | } // toml 233 | #endif// TOML11_SOURCE_LOCATION_HPP 234 | -------------------------------------------------------------------------------- /include/toml11/toml/storage.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2017. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_STORAGE_HPP 4 | #define TOML11_STORAGE_HPP 5 | #include "utility.hpp" 6 | 7 | namespace toml 8 | { 9 | namespace detail 10 | { 11 | 12 | // this contains pointer and deep-copy the content if copied. 13 | // to avoid recursive pointer. 14 | template 15 | struct storage 16 | { 17 | using value_type = T; 18 | 19 | explicit storage(value_type const& v): ptr(toml::make_unique(v)) {} 20 | explicit storage(value_type&& v): ptr(toml::make_unique(std::move(v))) {} 21 | ~storage() = default; 22 | storage(const storage& rhs): ptr(toml::make_unique(*rhs.ptr)) {} 23 | storage& operator=(const storage& rhs) 24 | { 25 | this->ptr = toml::make_unique(*rhs.ptr); 26 | return *this; 27 | } 28 | storage(storage&&) = default; 29 | storage& operator=(storage&&) = default; 30 | 31 | bool is_ok() const noexcept {return static_cast(ptr);} 32 | 33 | value_type& value() & noexcept {return *ptr;} 34 | value_type const& value() const& noexcept {return *ptr;} 35 | value_type&& value() && noexcept {return std::move(*ptr);} 36 | 37 | private: 38 | std::unique_ptr ptr; 39 | }; 40 | 41 | } // detail 42 | } // toml 43 | #endif// TOML11_STORAGE_HPP 44 | -------------------------------------------------------------------------------- /include/toml11/toml/string.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2017. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_STRING_HPP 4 | #define TOML11_STRING_HPP 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #if __cplusplus >= 201703L 11 | #if __has_include() 12 | #include 13 | #endif 14 | #endif 15 | 16 | namespace toml 17 | { 18 | 19 | enum class string_t : std::uint8_t 20 | { 21 | basic = 0, 22 | literal = 1, 23 | }; 24 | 25 | struct string 26 | { 27 | string() = default; 28 | ~string() = default; 29 | string(const string& s) = default; 30 | string(string&& s) = default; 31 | string& operator=(const string& s) = default; 32 | string& operator=(string&& s) = default; 33 | 34 | string(const std::string& s): kind(string_t::basic), str(s){} 35 | string(const std::string& s, string_t k): kind(k), str(s){} 36 | string(const char* s): kind(string_t::basic), str(s){} 37 | string(const char* s, string_t k): kind(k), str(s){} 38 | 39 | string(std::string&& s): kind(string_t::basic), str(std::move(s)){} 40 | string(std::string&& s, string_t k): kind(k), str(std::move(s)){} 41 | 42 | string& operator=(const std::string& s) 43 | {kind = string_t::basic; str = s; return *this;} 44 | string& operator=(std::string&& s) 45 | {kind = string_t::basic; str = std::move(s); return *this;} 46 | 47 | operator std::string& () & noexcept {return str;} 48 | operator std::string const& () const& noexcept {return str;} 49 | operator std::string&& () && noexcept {return std::move(str);} 50 | 51 | string& operator+=(const char* rhs) {str += rhs; return *this;} 52 | string& operator+=(const char rhs) {str += rhs; return *this;} 53 | string& operator+=(const std::string& rhs) {str += rhs; return *this;} 54 | string& operator+=(const string& rhs) {str += rhs.str; return *this;} 55 | 56 | #if __cplusplus >= 201703L 57 | explicit string(std::string_view s): kind(string_t::basic), str(s){} 58 | string(std::string_view s, string_t k): kind(k), str(s){} 59 | 60 | string& operator=(std::string_view s) 61 | {kind = string_t::basic; str = s; return *this;} 62 | 63 | explicit operator std::string_view() const noexcept 64 | {return std::string_view(str);} 65 | 66 | string& operator+=(const std::string_view& rhs) {str += rhs; return *this;} 67 | #endif 68 | 69 | string_t kind; 70 | std::string str; 71 | }; 72 | 73 | inline bool operator==(const string& lhs, const string& rhs) 74 | { 75 | return lhs.kind == rhs.kind && lhs.str == rhs.str; 76 | } 77 | inline bool operator!=(const string& lhs, const string& rhs) 78 | { 79 | return !(lhs == rhs); 80 | } 81 | inline bool operator<(const string& lhs, const string& rhs) 82 | { 83 | return (lhs.kind == rhs.kind) ? (lhs.str < rhs.str) : (lhs.kind < rhs.kind); 84 | } 85 | inline bool operator>(const string& lhs, const string& rhs) 86 | { 87 | return rhs < lhs; 88 | } 89 | inline bool operator<=(const string& lhs, const string& rhs) 90 | { 91 | return !(rhs < lhs); 92 | } 93 | inline bool operator>=(const string& lhs, const string& rhs) 94 | { 95 | return !(lhs < rhs); 96 | } 97 | 98 | inline bool 99 | operator==(const string& lhs, const std::string& rhs) {return lhs.str == rhs;} 100 | inline bool 101 | operator!=(const string& lhs, const std::string& rhs) {return lhs.str != rhs;} 102 | inline bool 103 | operator< (const string& lhs, const std::string& rhs) {return lhs.str < rhs;} 104 | inline bool 105 | operator> (const string& lhs, const std::string& rhs) {return lhs.str > rhs;} 106 | inline bool 107 | operator<=(const string& lhs, const std::string& rhs) {return lhs.str <= rhs;} 108 | inline bool 109 | operator>=(const string& lhs, const std::string& rhs) {return lhs.str >= rhs;} 110 | 111 | inline bool 112 | operator==(const std::string& lhs, const string& rhs) {return lhs == rhs.str;} 113 | inline bool 114 | operator!=(const std::string& lhs, const string& rhs) {return lhs != rhs.str;} 115 | inline bool 116 | operator< (const std::string& lhs, const string& rhs) {return lhs < rhs.str;} 117 | inline bool 118 | operator> (const std::string& lhs, const string& rhs) {return lhs > rhs.str;} 119 | inline bool 120 | operator<=(const std::string& lhs, const string& rhs) {return lhs <= rhs.str;} 121 | inline bool 122 | operator>=(const std::string& lhs, const string& rhs) {return lhs >= rhs.str;} 123 | 124 | inline bool 125 | operator==(const string& lhs, const char* rhs) {return lhs.str == std::string(rhs);} 126 | inline bool 127 | operator!=(const string& lhs, const char* rhs) {return lhs.str != std::string(rhs);} 128 | inline bool 129 | operator< (const string& lhs, const char* rhs) {return lhs.str < std::string(rhs);} 130 | inline bool 131 | operator> (const string& lhs, const char* rhs) {return lhs.str > std::string(rhs);} 132 | inline bool 133 | operator<=(const string& lhs, const char* rhs) {return lhs.str <= std::string(rhs);} 134 | inline bool 135 | operator>=(const string& lhs, const char* rhs) {return lhs.str >= std::string(rhs);} 136 | 137 | inline bool 138 | operator==(const char* lhs, const string& rhs) {return std::string(lhs) == rhs.str;} 139 | inline bool 140 | operator!=(const char* lhs, const string& rhs) {return std::string(lhs) != rhs.str;} 141 | inline bool 142 | operator< (const char* lhs, const string& rhs) {return std::string(lhs) < rhs.str;} 143 | inline bool 144 | operator> (const char* lhs, const string& rhs) {return std::string(lhs) > rhs.str;} 145 | inline bool 146 | operator<=(const char* lhs, const string& rhs) {return std::string(lhs) <= rhs.str;} 147 | inline bool 148 | operator>=(const char* lhs, const string& rhs) {return std::string(lhs) >= rhs.str;} 149 | 150 | template 151 | std::basic_ostream& 152 | operator<<(std::basic_ostream& os, const string& s) 153 | { 154 | if(s.kind == string_t::basic) 155 | { 156 | if(std::find(s.str.cbegin(), s.str.cend(), '\n') != s.str.cend()) 157 | { 158 | // it contains newline. make it multiline string. 159 | os << "\"\"\"\n"; 160 | for(auto i=s.str.cbegin(), e=s.str.cend(); i!=e; ++i) 161 | { 162 | switch(*i) 163 | { 164 | case '\\': {os << "\\\\"; break;} 165 | case '\"': {os << "\\\""; break;} 166 | case '\b': {os << "\\b"; break;} 167 | case '\t': {os << "\\t"; break;} 168 | case '\f': {os << "\\f"; break;} 169 | case '\n': {os << '\n'; break;} 170 | case '\r': 171 | { 172 | // since it is a multiline string, 173 | // CRLF is not needed to be escaped. 174 | if(std::next(i) != e && *std::next(i) == '\n') 175 | { 176 | os << "\r\n"; 177 | ++i; 178 | } 179 | else 180 | { 181 | os << "\\r"; 182 | } 183 | break; 184 | } 185 | default: {os << *i; break;} 186 | } 187 | } 188 | os << "\\\n\"\"\""; 189 | return os; 190 | } 191 | // no newline. make it inline. 192 | os << "\""; 193 | for(const auto c : s.str) 194 | { 195 | switch(c) 196 | { 197 | case '\\': {os << "\\\\"; break;} 198 | case '\"': {os << "\\\""; break;} 199 | case '\b': {os << "\\b"; break;} 200 | case '\t': {os << "\\t"; break;} 201 | case '\f': {os << "\\f"; break;} 202 | case '\n': {os << "\\n"; break;} 203 | case '\r': {os << "\\r"; break;} 204 | default : {os << c; break;} 205 | } 206 | } 207 | os << "\""; 208 | return os; 209 | } 210 | // the string `s` is literal-string. 211 | if(std::find(s.str.cbegin(), s.str.cend(), '\n') != s.str.cend() || 212 | std::find(s.str.cbegin(), s.str.cend(), '\'') != s.str.cend() ) 213 | { 214 | // contains newline or single quote. make it multiline. 215 | os << "'''\n" << s.str << "'''"; 216 | return os; 217 | } 218 | // normal literal string 219 | os << '\'' << s.str << '\''; 220 | return os; 221 | } 222 | 223 | } // toml 224 | #endif// TOML11_STRING_H 225 | -------------------------------------------------------------------------------- /include/toml11/toml/types.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2017. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_TYPES_HPP 4 | #define TOML11_TYPES_HPP 5 | #include 6 | #include 7 | 8 | #include "comments.hpp" 9 | #include "datetime.hpp" 10 | #include "string.hpp" 11 | #include "traits.hpp" 12 | 13 | namespace toml 14 | { 15 | 16 | template class Table, // map-like class 18 | template class Array> // vector-like class 19 | class basic_value; 20 | 21 | using character = char; 22 | using key = std::string; 23 | 24 | #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ <= 4 25 | # pragma GCC diagnostic push 26 | # pragma GCC diagnostic ignored "-Wshadow" 27 | #endif 28 | 29 | using boolean = bool; 30 | using integer = std::int64_t; 31 | using floating = double; // "float" is a keyward, cannot use it here. 32 | // the following stuffs are structs defined here, so aliases are not needed. 33 | // - string 34 | // - offset_datetime 35 | // - offset_datetime 36 | // - local_datetime 37 | // - local_date 38 | // - local_time 39 | 40 | #if defined(__GNUC__) && !defined(__clang__) 41 | # pragma GCC diagnostic pop 42 | #endif 43 | 44 | // default toml::value and default array/table. these are defined after defining 45 | // basic_value itself. 46 | // using value = basic_value; 47 | // using array = typename value::array_type; 48 | // using table = typename value::table_type; 49 | 50 | // to avoid warnings about `value_t::integer` is "shadowing" toml::integer in 51 | // GCC -Wshadow=global. 52 | #if defined(__GNUC__) && !defined(__clang__) 53 | # pragma GCC diagnostic push 54 | # if 7 <= __GNUC__ 55 | # pragma GCC diagnostic ignored "-Wshadow=global" 56 | # else // gcc-6 or older 57 | # pragma GCC diagnostic ignored "-Wshadow" 58 | # endif 59 | #endif 60 | enum class value_t : std::uint8_t 61 | { 62 | empty = 0, 63 | boolean = 1, 64 | integer = 2, 65 | floating = 3, 66 | string = 4, 67 | offset_datetime = 5, 68 | local_datetime = 6, 69 | local_date = 7, 70 | local_time = 8, 71 | array = 9, 72 | table = 10, 73 | }; 74 | #if defined(__GNUC__) && !defined(__clang__) 75 | # pragma GCC diagnostic pop 76 | #endif 77 | 78 | template 79 | inline std::basic_ostream& 80 | operator<<(std::basic_ostream& os, value_t t) 81 | { 82 | switch(t) 83 | { 84 | case value_t::boolean : os << "boolean"; return os; 85 | case value_t::integer : os << "integer"; return os; 86 | case value_t::floating : os << "floating"; return os; 87 | case value_t::string : os << "string"; return os; 88 | case value_t::offset_datetime : os << "offset_datetime"; return os; 89 | case value_t::local_datetime : os << "local_datetime"; return os; 90 | case value_t::local_date : os << "local_date"; return os; 91 | case value_t::local_time : os << "local_time"; return os; 92 | case value_t::array : os << "array"; return os; 93 | case value_t::table : os << "table"; return os; 94 | case value_t::empty : os << "empty"; return os; 95 | default : os << "unknown"; return os; 96 | } 97 | } 98 | 99 | template, 101 | typename alloc = std::allocator> 102 | inline std::basic_string stringize(value_t t) 103 | { 104 | std::basic_ostringstream oss; 105 | oss << t; 106 | return oss.str(); 107 | } 108 | 109 | namespace detail 110 | { 111 | 112 | // helper to define a type that represents a value_t value. 113 | template 114 | using value_t_constant = std::integral_constant; 115 | 116 | // meta-function that convertes from value_t to the exact toml type that corresponds to. 117 | // It takes toml::basic_value type because array and table types depend on it. 118 | template struct enum_to_type {using type = void ;}; 119 | template struct enum_to_type{using type = void ;}; 120 | template struct enum_to_type{using type = boolean ;}; 121 | template struct enum_to_type{using type = integer ;}; 122 | template struct enum_to_type{using type = floating ;}; 123 | template struct enum_to_type{using type = string ;}; 124 | template struct enum_to_type{using type = offset_datetime ;}; 125 | template struct enum_to_type{using type = local_datetime ;}; 126 | template struct enum_to_type{using type = local_date ;}; 127 | template struct enum_to_type{using type = local_time ;}; 128 | template struct enum_to_type{using type = typename Value::array_type;}; 129 | template struct enum_to_type{using type = typename Value::table_type;}; 130 | 131 | // meta-function that converts from an exact toml type to the enum that corresponds to. 132 | template 133 | struct type_to_enum : std::conditional< 134 | std::is_same::value, // if T == array_type, 135 | value_t_constant, // then value_t::array 136 | typename std::conditional< // else... 137 | std::is_same::value, // if T == table_type 138 | value_t_constant, // then value_t::table 139 | value_t_constant // else value_t::empty 140 | >::type 141 | >::type {}; 142 | template struct type_to_enum: value_t_constant {}; 143 | template struct type_to_enum: value_t_constant {}; 144 | template struct type_to_enum: value_t_constant {}; 145 | template struct type_to_enum: value_t_constant {}; 146 | template struct type_to_enum: value_t_constant {}; 147 | template struct type_to_enum: value_t_constant {}; 148 | template struct type_to_enum: value_t_constant {}; 149 | template struct type_to_enum: value_t_constant {}; 150 | 151 | // meta-function that checks the type T is the same as one of the toml::* types. 152 | template 153 | struct is_exact_toml_type : disjunction< 154 | std::is_same, 155 | std::is_same, 156 | std::is_same, 157 | std::is_same, 158 | std::is_same, 159 | std::is_same, 160 | std::is_same, 161 | std::is_same, 162 | std::is_same, 163 | std::is_same 164 | >{}; 165 | template struct is_exact_toml_type : is_exact_toml_type{}; 166 | template struct is_exact_toml_type : is_exact_toml_type{}; 167 | template struct is_exact_toml_type : is_exact_toml_type{}; 168 | template struct is_exact_toml_type: is_exact_toml_type{}; 169 | 170 | } // detail 171 | } // toml 172 | 173 | #endif// TOML11_TYPES_H 174 | -------------------------------------------------------------------------------- /include/toml11/toml/utility.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Toru Niina 2017. 2 | // Distributed under the MIT License. 3 | #ifndef TOML11_UTILITY_HPP 4 | #define TOML11_UTILITY_HPP 5 | #include 6 | #include 7 | #include 8 | 9 | #include "traits.hpp" 10 | 11 | #if __cplusplus >= 201402L 12 | # define TOML11_MARK_AS_DEPRECATED(msg) [[deprecated(msg)]] 13 | #elif defined(__GNUC__) 14 | # define TOML11_MARK_AS_DEPRECATED(msg) __attribute__((deprecated(msg))) 15 | #elif defined(_MSC_VER) 16 | # define TOML11_MARK_AS_DEPRECATED(msg) __declspec(deprecated(msg)) 17 | #else 18 | # define TOML11_MARK_AS_DEPRECATED 19 | #endif 20 | 21 | namespace toml 22 | { 23 | 24 | #if __cplusplus >= 201402L 25 | 26 | using std::make_unique; 27 | 28 | #else 29 | 30 | template 31 | inline std::unique_ptr make_unique(Ts&& ... args) 32 | { 33 | return std::unique_ptr(new T(std::forward(args)...)); 34 | } 35 | 36 | #endif // __cplusplus >= 2014 37 | 38 | namespace detail 39 | { 40 | template 41 | void try_reserve_impl(Container& container, std::size_t N, std::true_type) 42 | { 43 | container.reserve(N); 44 | return; 45 | } 46 | template 47 | void try_reserve_impl(Container&, std::size_t, std::false_type) noexcept 48 | { 49 | return; 50 | } 51 | } // detail 52 | 53 | template 54 | void try_reserve(Container& container, std::size_t N) 55 | { 56 | if(N <= container.size()) {return;} 57 | detail::try_reserve_impl(container, N, detail::has_reserve_method{}); 58 | return; 59 | } 60 | 61 | namespace detail 62 | { 63 | inline std::string concat_to_string_impl(std::ostringstream& oss) 64 | { 65 | return oss.str(); 66 | } 67 | template 68 | std::string concat_to_string_impl(std::ostringstream& oss, T&& head, Ts&& ... tail) 69 | { 70 | oss << std::forward(head); 71 | return concat_to_string_impl(oss, std::forward(tail) ... ); 72 | } 73 | } // detail 74 | 75 | template 76 | std::string concat_to_string(Ts&& ... args) 77 | { 78 | std::ostringstream oss; 79 | oss << std::boolalpha << std::fixed; 80 | return detail::concat_to_string_impl(oss, std::forward(args) ...); 81 | } 82 | 83 | template 84 | T from_string(const std::string& str, T opt) 85 | { 86 | T v(opt); 87 | std::istringstream iss(str); 88 | iss >> v; 89 | return v; 90 | } 91 | 92 | namespace detail 93 | { 94 | #if __cplusplus >= 201402L 95 | template 96 | decltype(auto) last_one(T&& tail) noexcept 97 | { 98 | return std::forward(tail); 99 | } 100 | 101 | template 102 | decltype(auto) last_one(T&& /*head*/, Ts&& ... tail) noexcept 103 | { 104 | return last_one(std::forward(tail)...); 105 | } 106 | #else // C++11 107 | // The following code 108 | // ```cpp 109 | // 1 | template 110 | // 2 | auto last_one(T&& /*head*/, Ts&& ... tail) 111 | // 3 | -> decltype(last_one(std::forward(tail)...)) 112 | // 4 | { 113 | // 5 | return last_one(std::forward(tail)...); 114 | // 6 | } 115 | // ``` 116 | // does not work because the function `last_one(...)` is not yet defined at 117 | // line #3, so `decltype()` cannot deduce the type returned from `last_one`. 118 | // So we need to determine return type in a different way, like a meta func. 119 | 120 | template 121 | struct last_one_in_pack 122 | { 123 | using type = typename last_one_in_pack::type; 124 | }; 125 | template 126 | struct last_one_in_pack 127 | { 128 | using type = T; 129 | }; 130 | template 131 | using last_one_in_pack_t = typename last_one_in_pack::type; 132 | 133 | template 134 | T&& last_one(T&& tail) noexcept 135 | { 136 | return std::forward(tail); 137 | } 138 | template 139 | enable_if_t<(sizeof...(Ts) > 0), last_one_in_pack_t> 140 | last_one(T&& /*head*/, Ts&& ... tail) 141 | { 142 | return last_one(std::forward(tail)...); 143 | } 144 | 145 | #endif 146 | } // detail 147 | 148 | }// toml 149 | #endif // TOML11_UTILITY 150 | -------------------------------------------------------------------------------- /libraries/discord-rpc.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TopazTK/LuaFrontend/f211042ac3247a78bf32c1081f0cdb9bd1746b03/libraries/discord-rpc.lib -------------------------------------------------------------------------------- /libraries/lua.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TopazTK/LuaFrontend/f211042ac3247a78bf32c1081f0cdb9bd1746b03/libraries/lua.lib -------------------------------------------------------------------------------- /resources/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TopazTK/LuaFrontend/f211042ac3247a78bf32c1081f0cdb9bd1746b03/resources/error.png -------------------------------------------------------------------------------- /resources/good.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TopazTK/LuaFrontend/f211042ac3247a78bf32c1081f0cdb9bd1746b03/resources/good.png -------------------------------------------------------------------------------- /resources/iconMain.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TopazTK/LuaFrontend/f211042ac3247a78bf32c1081f0cdb9bd1746b03/resources/iconMain.ico -------------------------------------------------------------------------------- /resources/iconMain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TopazTK/LuaFrontend/f211042ac3247a78bf32c1081f0cdb9bd1746b03/resources/iconMain.png -------------------------------------------------------------------------------- /resources/iconPatreon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TopazTK/LuaFrontend/f211042ac3247a78bf32c1081f0cdb9bd1746b03/resources/iconPatreon.png -------------------------------------------------------------------------------- /resources/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TopazTK/LuaFrontend/f211042ac3247a78bf32c1081f0cdb9bd1746b03/resources/warning.png -------------------------------------------------------------------------------- /version.h: -------------------------------------------------------------------------------- 1 | #ifndef VERSION_H 2 | #define VERSION_H 3 | 4 | #define VER_FILEVERSION 1,0,0,0 5 | #define VER_FILEVERSION_STR "1.1.0.0\0" 6 | 7 | #define VER_PRODUCTVERSION 1,0,0,0 8 | #define VER_PRODUCTVERSION_STR "v1.10S\0" 9 | 10 | #define VER_COMPANYNAME_STR "TopazTK" 11 | #define VER_FILEDESCRIPTION_STR "LuaFrontend" 12 | #define VER_INTERNALNAME_STR "LuaFrontend" 13 | #define VER_LEGALCOPYRIGHT_STR "Copyright 2020-2021 | TopazTK" 14 | #define VER_LEGALTRADEMARKS1_STR "Certain Rights Reserved" 15 | #define VER_LEGALTRADEMARKS2_STR VER_LEGALTRADEMARKS1_STR 16 | #define VER_ORIGINALFILENAME_STR "LuaFrontend.exe" 17 | #define VER_PRODUCTNAME_STR "LuaFrontend" 18 | 19 | #define VER_COMPANYDOMAIN_STR "github.com/Topaz-Reality/LuaFrontend" 20 | 21 | #endif 22 | --------------------------------------------------------------------------------