├── .editorconfig
├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── azure-pipelines.yaml
├── module
├── Common.h
├── JobManager.h
├── Luna.h
├── LunaRedisClient.cpp
├── LunaRedisClient.h
├── LunaRedisClientHelper.h
├── Main.cpp
├── Module.cpp
├── Module.h
├── RedisClient.cpp
├── RedisClient.h
├── Utils.h
├── extra
│ ├── CLuaArgument.cpp
│ ├── CLuaArgument.h
│ ├── CLuaArguments.cpp
│ └── CLuaArguments.h
├── include
│ ├── ILuaModuleManager.h
│ ├── lauxlib.h
│ ├── lua.h
│ ├── luaconf.h
│ └── lualib.h
├── lib
│ ├── lua5.1.lib
│ └── lua5.1_64.lib
├── luaimports
│ ├── luaimports.linux.cpp
│ └── luaimports.linux.h
└── premake5.lua
├── premake5.lua
├── test
├── Main.cpp
├── lib
│ ├── cpp_redis.lib
│ ├── cpp_redis_64.lib
│ ├── tacopie.lib
│ └── tacopie_64.lib
└── premake5.lua
└── utils
├── premake5
├── premake5-macos
└── premake5.exe
/.editorconfig:
--------------------------------------------------------------------------------
1 | # top-most EditorConfig file
2 | root = true
3 |
4 | # Unix-style newlines with a newline ending every file
5 | [*]
6 | insert_final_newline = true
7 |
8 | [*.yml]
9 | indent_style = space
10 | indent_size = 2
11 |
12 | [{*.cpp,*.c,*.h,*.hpp}]
13 | indent_style = tab
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Build
2 | Bin
3 | obj
4 | mta-server
5 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "cpp_redis"]
2 | path = cpp_redis
3 | url = https://github.com/eXo-OpenSource/cpp_redis.git
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JWT Server Module for MTA:SA
2 | [](https://dev.azure.com/eXo-OpenSource/ml_redis/_build/latest?definitionId=1&branchName=master)
3 |
4 | ## Developing
5 | 1. Download and install the EditorConfig plugin for Visual Studio: [https://github.com/editorconfig/editorconfig-visualstudio#readme](https://github.com/editorconfig/editorconfig-visualstudio#readme)
6 | 2. Launch `premake.bat`
7 | 3. Open `Build/Redis.sln`
8 | 4. Update configuration `x64` to use compiler option `/bigobj` (See more: [VS /bigobj](https://docs.microsoft.com/en-us/cpp/build/reference/bigobj-increase-number-of-sections-in-dot-obj-file?view=vs-2019#to-set-this-compiler-option-in-the-visual-studio-development-environment))
9 |
10 | ### Debugging
11 | 1. Create a directory junktion to MTA-Server directory in the root of the repo
12 | * `mklink /J mta-server "PATH_TO_INSTALL_DIR\MTA San Andreas 1.5\server"`
13 | 2. Create a symlink to the build output dll in the modules directory
14 | * `cd PATH_TO_INSTALL_DIR\MTA San Andreas 1.5\server\x64\modules` for x64
15 | * `cd PATH_TO_INSTALL_DIR\MTA San Andreas 1.5\server\mods\deathmatch\modules` for Win32
16 | * `mklink ml_redis.dll "PATH_TO_REPO\Bin\Debug\ml_redis.dll"`
17 | 3. Press `F5` in Visual Studio and the MTA-Server should start
18 |
19 | ## Installing
20 | 1. Put the resulting `Bin/ml_redis.dll/.so` into your MTA:SA server `modules` folder.
21 | 2. Add `` (or `.so` for Linux) to your `mtaserver.conf`.
22 | 3. Start the server
23 |
24 |
25 | ## API
26 | ## Globals
27 | *Todo*
28 |
29 | ## Functions
30 | *Todo*
31 |
32 | ## Download
33 | via https://github.com/Contextualist/glare
34 | * [Linux x64](https://glare.now.sh/eXo-OpenSource/ml_redis/ml_redis.so)
35 | * [Windows x64](https://glare.now.sh/eXo-OpenSource/ml_redis/ml_redis_x64.dll)
36 | * [Windows x86](https://glare.now.sh/eXo-OpenSource/ml_redis/ml_redis_win32.dll)
37 |
38 | ## Contributors
39 | * Stefan K.
40 |
--------------------------------------------------------------------------------
/azure-pipelines.yaml:
--------------------------------------------------------------------------------
1 | stages:
2 | - stage: Build
3 | jobs:
4 | - job: Linux
5 | pool:
6 | vmImage: 'ubuntu-16.04'
7 | steps:
8 | - checkout: self
9 | submodules: 'recursive'
10 | - script: chmod +x utils/premake5 && utils/premake5 gmake
11 | displayName: 'Generate Makefile'
12 | - script: cd Build && make -j 3 CXX=g++-7 CC=gcc-7 config=release_x64
13 | displayName: 'Build project'
14 | - script: mv $(Build.SourcesDirectory)/Bin/Release/libml_redis.so $(Build.SourcesDirectory)/Bin/Release/ml_redis.so
15 | - publish: '$(Build.SourcesDirectory)/Bin/Release/ml_redis.so'
16 | artifact: 'ml_redis_linux'
17 | - job: Windows
18 | pool:
19 | vmImage: 'windows-2019'
20 | strategy:
21 | maxParallel: 2
22 | matrix:
23 | Win32:
24 | platform: 'win32'
25 | x64:
26 | platform: 'x64'
27 | variables:
28 | solution: 'Build/Redis.sln'
29 | buildConfiguration: 'Release'
30 | steps:
31 | - checkout: self
32 | submodules: 'recursive'
33 | - script: utils\premake5 vs2019
34 | displayName: 'Create Visual Studio 2019 Solution'
35 | - task: VSBuild@1
36 | inputs:
37 | solution: '$(solution)'
38 | configuration: '$(buildConfiguration)'
39 | platform: '$(platform)'
40 | - script: move /Y $(Build.SourcesDirectory)\Bin\Release\ml_redis.dll $(Build.SourcesDirectory)\Bin\Release\ml_redis_$(platform).dll
41 | - publish: '$(Build.SourcesDirectory)\Bin\Release\ml_redis_$(platform).dll'
42 | artifact: 'ml_redis_$(platform)'
43 |
--------------------------------------------------------------------------------
/module/Common.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/module/Common.h
--------------------------------------------------------------------------------
/module/JobManager.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | template
10 | class JobManager
11 | {
12 | public:
13 | using Task = std::function;
14 | using TaskCompleteCallback = std::function;
15 |
16 | JobManager(std::size_t numWorkers) : _numWorkers(numWorkers)
17 | {
18 | }
19 |
20 | void Start()
21 | {
22 | _running = true;
23 |
24 | for (std::size_t i = 0; i < _numWorkers; ++i)
25 | {
26 | _workers.emplace_back(&JobManager::RunWorker, this);
27 | }
28 | }
29 |
30 | void Stop()
31 | {
32 | _running = false;
33 |
34 | // Wait for threads to end
35 | for (auto& worker : _workers)
36 | {
37 | if (worker.joinable())
38 | worker.join();
39 | }
40 | }
41 |
42 | void PushTask(Task task, TaskCompleteCallback completeCallback)
43 | {
44 | std::lock_guard lock{ _mutex };
45 |
46 | _tasks.push({ task, completeCallback });
47 | }
48 |
49 | void RunWorker()
50 | {
51 | while (_running)
52 | {
53 | // Wait if there's no task for us
54 | _mutex.lock();
55 | if (_tasks.empty())
56 | {
57 | _mutex.unlock();
58 | std::this_thread::sleep_for(std::chrono::milliseconds(100));
59 | continue;
60 | }
61 |
62 | // Get next task
63 | auto [task, completed_callback] = _tasks.front();
64 | _tasks.pop();
65 | _mutex.unlock();
66 |
67 | // Run task
68 | TaskResult result = task();
69 |
70 | // Put result into completed tasks list
71 | std::lock_guard lock{ _mutex };
72 | _completedTasks.push_back({ result, completed_callback });
73 | }
74 | }
75 |
76 | void SpreadResults()
77 | {
78 | std::lock_guard lock{ _mutex };
79 | if (_completedTasks.empty())
80 | return;
81 |
82 | for (auto& [result, callback] : _completedTasks)
83 | {
84 | callback(result);
85 | }
86 |
87 | _completedTasks.clear();
88 | }
89 |
90 | private:
91 | std::vector _workers;
92 | std::size_t _numWorkers;
93 | bool _running = false;
94 |
95 | std::queue> _tasks;
96 | std::list> _completedTasks;
97 |
98 | std::recursive_mutex _mutex;
99 | };
100 |
--------------------------------------------------------------------------------
/module/Luna.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "lua.h"
3 | #include "lauxlib.h"
4 |
5 | // http://lua-users.org/wiki/SimplerCppBinding
6 | template class Luna {
7 | typedef struct { T *pT; } userdataType;
8 | public:
9 | typedef int (T::*mfp)(lua_State *L);
10 | typedef struct { const char *name; mfp mfunc; } RegType;
11 |
12 | static void Register(lua_State *L) {
13 | lua_newtable(L);
14 | int methods = lua_gettop(L);
15 |
16 | luaL_newmetatable(L, T::className);
17 | int metatable = lua_gettop(L);
18 |
19 | // store method table in globals so that
20 | // scripts can add functions written in Lua.
21 | lua_pushstring(L, T::className);
22 | lua_pushvalue(L, methods);
23 | lua_settable(L, LUA_GLOBALSINDEX);
24 |
25 | lua_pushliteral(L, "__metatable");
26 | lua_pushvalue(L, methods);
27 | lua_settable(L, metatable); // hide metatable from Lua getmetatable()
28 |
29 | lua_pushliteral(L, "__index");
30 | lua_pushvalue(L, methods);
31 | lua_settable(L, metatable);
32 |
33 | lua_pushliteral(L, "__tostring");
34 | lua_pushcfunction(L, tostring_T);
35 | lua_settable(L, metatable);
36 |
37 | lua_pushliteral(L, "__gc");
38 | lua_pushcfunction(L, gc_T);
39 | lua_settable(L, metatable);
40 |
41 | lua_newtable(L); // mt for method table
42 | int mt = lua_gettop(L);
43 | lua_pushliteral(L, "__call");
44 | lua_pushcfunction(L, new_T);
45 | lua_pushliteral(L, "new");
46 | lua_pushvalue(L, -2); // dup new_T function
47 | lua_settable(L, methods); // add new_T to method table
48 | lua_settable(L, mt); // mt.__call = new_T
49 | lua_setmetatable(L, methods);
50 |
51 | // fill method table with methods from class T
52 | for (RegType *l = T::methods; l->name; l++) {
53 | /* edited by Snaily: shouldn't it be const RegType *l ... ? */
54 | lua_pushstring(L, l->name);
55 | lua_pushlightuserdata(L, (void*)l);
56 | lua_pushcclosure(L, thunk, 1);
57 | lua_settable(L, methods);
58 | }
59 |
60 | lua_pop(L, 2); // drop metatable and method table
61 | }
62 |
63 | // get userdata from Lua stack and return pointer to T object
64 | static T *check(lua_State *L, int narg) {
65 | userdataType *ud = static_cast(luaL_checkudata(L, narg, T::className));
66 | if(!ud) luaL_typerror(L, narg, T::className);
67 | return ud->pT; // pointer to T object
68 | }
69 |
70 | private:
71 | Luna(); // hide default constructor
72 |
73 | // member function dispatcher
74 | static int thunk(lua_State *L) {
75 | // stack has userdata, followed by method args
76 | T *obj = check(L, 1); // get 'self', or if you prefer, 'this'
77 | lua_remove(L, 1); // remove self so member function args start at index 1
78 | // get member function from upvalue
79 | RegType *l = static_cast(lua_touserdata(L, lua_upvalueindex(1)));
80 | return (obj->*(l->mfunc))(L); // call member function
81 | }
82 |
83 | // create a new T object and
84 | // push onto the Lua stack a userdata containing a pointer to T object
85 | static int new_T(lua_State *L) {
86 | lua_remove(L, 1); // use classname:new(), instead of classname.new()
87 | T *obj = new T(L); // call constructor for T objects
88 | userdataType *ud =
89 | static_cast(lua_newuserdata(L, sizeof(userdataType)));
90 | ud->pT = obj; // store pointer to object in userdata
91 | luaL_getmetatable(L, T::className); // lookup metatable in Lua registry
92 | lua_setmetatable(L, -2);
93 | return 1; // userdata containing pointer to T object
94 | }
95 |
96 | // garbage collection metamethod
97 | static int gc_T(lua_State *L) {
98 | userdataType *ud = static_cast(lua_touserdata(L, 1));
99 | T *obj = ud->pT;
100 | delete obj; // call destructor for T objects
101 | return 0;
102 | }
103 |
104 | static int tostring_T (lua_State *L) {
105 | char buff[32];
106 | userdataType *ud = static_cast(lua_touserdata(L, 1));
107 | T *obj = ud->pT;
108 | #ifdef WINDOWS
109 | sprintf_s(buff, "%p", obj);
110 | #else
111 | sprintf(buff, "&p", obj);
112 | #endif
113 | lua_pushfstring(L, "%s (%s)", T::className, buff);
114 | return 1;
115 | }
116 | };
117 |
--------------------------------------------------------------------------------
/module/LunaRedisClient.cpp:
--------------------------------------------------------------------------------
1 | #include "LunaRedisClient.h"
2 | #include "Utils.h"
3 |
4 | #ifndef _WIN32
5 | #include
6 | #endif
7 |
8 | // ReSharper disable CppMemberFunctionMayBeConst
9 | LunaRedisClient::LunaRedisClient(lua_State* lua_vm)
10 | {
11 | _client = std::make_shared();
12 | g_Module->AddRedisClient(_client);
13 | }
14 |
15 | LunaRedisClient::~LunaRedisClient()
16 | {
17 | g_Module->RemoveRedisClient(_client);
18 | }
19 |
20 | void LunaRedisClient::verify_self(lua_State* lua_vm) const
21 | {
22 | if (!g_Module->HasRedisClient(_client))
23 | luaL_argerror(lua_vm, 1, "invalid client has been passed");
24 | }
25 |
26 | int LunaRedisClient::connect(lua_State* lua_vm)
27 | {
28 | // Read arguments
29 | const auto host = luaL_checkstring(lua_vm, 1);
30 | const auto port = luaL_checknumber(lua_vm, 2);
31 |
32 | // verify client
33 | verify_self(lua_vm);
34 |
35 | try
36 | {
37 | _client->connect(host, port);
38 | lua_pushboolean(lua_vm, true);
39 | } catch (std::exception& e)
40 | {
41 | luaL_error(lua_vm, "Failed to connect to redis server. [%s]\n", e.what());
42 | }
43 |
44 | return 1;
45 | }
46 |
47 | int LunaRedisClient::disconnect(lua_State* lua_vm)
48 | {
49 | // verify client
50 | verify_self(lua_vm);
51 |
52 | try {
53 | _client->disconnect();
54 | lua_pushboolean(lua_vm, true);
55 | } catch(std::exception& e)
56 | {
57 | luaL_error(lua_vm, e.what());
58 | }
59 |
60 | return 1;
61 | }
62 |
63 | int LunaRedisClient::authenticate(lua_State* lua_vm)
64 | {
65 | // Save function ref
66 | const auto func_ref = utils::lua_getfuncref(lua_vm, 1);
67 |
68 | // Read arguments
69 | const auto password = luaL_checkstring(lua_vm, 2);
70 |
71 | // verify client
72 | verify_self(lua_vm);
73 |
74 | try
75 | {
76 | _client->authenticate(password, [lua_vm = lua_getmainstate(lua_vm), func_ref](cpp_redis::reply& reply)
77 | {
78 | // Validate LuaVM (use ResourceStart/-Stop to manage valid lua states)
79 | if (!g_Module->HasLuaVM(lua_vm))
80 | return;
81 |
82 | // Push stored reference to callback function to the stack
83 | lua_rawgeti(lua_vm, LUA_REGISTRYINDEX, func_ref);
84 |
85 | // Push the result
86 | if(!reply.is_error())
87 | {
88 | lua_pushboolean(lua_vm, true);
89 | } else
90 | {
91 | pModuleManager->ErrorPrintf("%s\n", reply.error().c_str());
92 | lua_pushboolean(lua_vm, false);
93 | }
94 |
95 | // Finally, call the function
96 | const auto err = lua_pcall(lua_vm, 1, 0, 0);
97 | if (err != 0)
98 | pModuleManager->ErrorPrintf("%s\n", lua_tostring(lua_vm, -1));
99 | }, nullptr);
100 | } catch (std::exception& e)
101 | {
102 | luaL_error(lua_vm, e.what());
103 | }
104 |
105 | return 1;
106 | }
107 |
108 | int LunaRedisClient::set(lua_State* lua_vm)
109 | {
110 | // Save function ref
111 | const auto func_ref = utils::lua_getfuncref(lua_vm, 1);
112 |
113 | // Read arguments
114 | const auto key = luaL_checkstring(lua_vm, 2);
115 | const auto value = luaL_checkstring(lua_vm, 3);
116 |
117 | // verify client
118 | verify_self(lua_vm);
119 |
120 | g_Module->GetJobManager().PushTask([client = _client, key, value]() -> const std::optional
121 | {
122 | try {
123 | return client->set(key, value);
124 | } catch(std::exception& e)
125 | {
126 | pModuleManager->ErrorPrintf("%s\n", e.what());
127 | return {};
128 | }
129 | }, [lua_vm = lua_getmainstate(lua_vm), func_ref](const std::optional& result)
130 | {
131 | // Validate LuaVM (use ResourceStart/-Stop to manage valid lua states)
132 | if (!g_Module->HasLuaVM(lua_vm))
133 | return;
134 |
135 | // Push stored reference to callback function to the stack
136 | lua_rawgeti(lua_vm, LUA_REGISTRYINDEX, func_ref);
137 |
138 | // Push the result
139 | try
140 | {
141 | if (result.has_value())
142 | {
143 | const auto reply = std::any_cast(result.value());
144 | if (!reply.is_error())
145 | {
146 | lua_pushboolean(lua_vm, true);
147 | } else
148 | {
149 | std::cout << reply.error() << std::endl;
150 | lua_pushboolean(lua_vm, false);
151 | }
152 | } else {
153 | lua_pushboolean(lua_vm, false);
154 | }
155 | } catch(std::bad_any_cast&)
156 | {
157 | lua_pushboolean(lua_vm, false);
158 | }
159 |
160 | // Finally, call the function
161 | const auto err = lua_pcall(lua_vm, 1, 0, 0);
162 | if (err != 0)
163 | pModuleManager->ErrorPrintf("%s\n", lua_tostring(lua_vm, -1));
164 | });
165 |
166 | lua_pushboolean(lua_vm, true);
167 | return 1;
168 | }
169 |
170 | int LunaRedisClient::get(lua_State* lua_vm)
171 | {
172 | // Save function ref
173 | const auto func_ref = utils::lua_getfuncref(lua_vm, 1);
174 |
175 | // Read arguments
176 | const auto key = luaL_checkstring(lua_vm, 2);
177 |
178 | // verify client
179 | verify_self(lua_vm);
180 |
181 | g_Module->GetJobManager().PushTask([client = _client, key]() -> const std::optional
182 | {
183 | try {
184 | return client->get(key);
185 | } catch(std::exception& e)
186 | {
187 | pModuleManager->ErrorPrintf("%s\n", e.what());
188 | return {};
189 | }
190 | }, [lua_vm = lua_getmainstate(lua_vm), func_ref](const std::optional& result)
191 | {
192 | // Validate LuaVM (use ResourceStart/-Stop to manage valid lua states)
193 | if (!g_Module->HasLuaVM(lua_vm))
194 | return;
195 |
196 | // Push stored reference to callback function to the stack
197 | lua_rawgeti(lua_vm, LUA_REGISTRYINDEX, func_ref);
198 |
199 | // Push the result
200 | try
201 | {
202 | if (result.has_value())
203 | {
204 | const auto reply = std::any_cast(result.value());
205 | if (!reply.is_error())
206 | {
207 | lua_pushstring(lua_vm, reply.as_string().c_str());
208 | } else
209 | {
210 | std::cout << reply.error() << std::endl;
211 | lua_pushboolean(lua_vm, false);
212 | }
213 | } else {
214 | lua_pushboolean(lua_vm, false);
215 | }
216 | } catch(std::bad_any_cast&)
217 | {
218 | lua_pushboolean(lua_vm, false);
219 | }
220 |
221 | // Finally, call the function
222 | const auto err = lua_pcall(lua_vm, 1, 0, 0);
223 | if (err != 0)
224 | pModuleManager->ErrorPrintf("%s\n", lua_tostring(lua_vm, -1));
225 | });
226 |
227 | lua_pushboolean(lua_vm, true);
228 | return 1;
229 | }
230 |
231 | int LunaRedisClient::subscribe(lua_State* lua_vm)
232 | {
233 | // Save function ref
234 | const auto func_ref = utils::lua_getfuncref(lua_vm, 1);
235 |
236 | // Read arguments
237 | const auto channel = lua_tostring(lua_vm, 2);
238 |
239 | // verify client
240 | verify_self(lua_vm);
241 |
242 | // subscribe to the channel
243 | try {
244 | _client->subscribe(channel, [lua_vm = lua_getmainstate(lua_vm), func_ref](const std::string& channel, const std::string& message)
245 | {
246 | // Validate LuaVM (use ResourceStart/-Stop to manage valid lua states)
247 | if (!g_Module->HasLuaVM(lua_vm))
248 | return;
249 |
250 | // Push stored reference to callback function to the stack
251 | lua_rawgeti(lua_vm, LUA_REGISTRYINDEX, func_ref);
252 |
253 | // Push results from redis to the stack
254 | lua_pushstring(lua_vm, channel.c_str());
255 | lua_pushstring(lua_vm, message.c_str());
256 |
257 | // Finally, call the function
258 | const auto err = lua_pcall(lua_vm, 2, 0, 0);
259 | if (err != 0)
260 | pModuleManager->ErrorPrintf("%s\n", lua_tostring(lua_vm, -1));
261 | });
262 |
263 | lua_pushboolean(lua_vm, true);
264 | } catch(std::exception& e)
265 | {
266 | luaL_error(lua_vm, e.what());
267 | }
268 |
269 | return 1;
270 | }
271 |
272 | int LunaRedisClient::unsubscribe(lua_State* lua_vm)
273 | {
274 | // Read arugments
275 | const auto channel = luaL_checkstring(lua_vm, 1);
276 |
277 | // verify client
278 | verify_self(lua_vm);
279 |
280 | try
281 | {
282 | _client->unsubscribe(channel);
283 | lua_pushboolean(lua_vm, true);
284 | } catch(std::exception& e)
285 | {
286 | luaL_error(lua_vm, e.what());
287 | }
288 |
289 | return 1;
290 | }
291 |
292 | int LunaRedisClient::publish(lua_State* lua_vm)
293 | {
294 | // Save function ref
295 | const auto func_ref = utils::lua_getfuncref(lua_vm, 1);
296 |
297 | // Read arguments
298 | const auto channel = lua_tostring(lua_vm, 2);
299 | const auto message = lua_tostring(lua_vm, 3);
300 |
301 | // verify client
302 | verify_self(lua_vm);
303 |
304 | g_Module->GetJobManager().PushTask([client = _client, channel, message]() -> const std::optional
305 | {
306 | try {
307 | return client->publish(channel, message);
308 | } catch(std::exception& e)
309 | {
310 | pModuleManager->ErrorPrintf("%s\n", e.what());
311 | return {};
312 | }
313 | }, [lua_vm = lua_getmainstate(lua_vm), func_ref](const std::optional& result)
314 | {
315 | // Validate LuaVM (use ResourceStart/-Stop to manage valid lua states)
316 | if (!g_Module->HasLuaVM(lua_vm))
317 | return;
318 |
319 | // Push stored reference to callback function to the stack
320 | lua_rawgeti(lua_vm, LUA_REGISTRYINDEX, func_ref);
321 |
322 | // Push the result
323 | try
324 | {
325 | if (result.has_value())
326 | {
327 | const auto reply = std::any_cast(result.value());
328 | if (!reply.is_error())
329 | {
330 | lua_pushboolean(lua_vm, true);
331 | } else
332 | {
333 | std::cout << reply.error() << std::endl;
334 | lua_pushboolean(lua_vm, false);
335 | }
336 | } else {
337 | lua_pushboolean(lua_vm, false);
338 | }
339 | } catch(std::bad_any_cast&)
340 | {
341 | lua_pushboolean(lua_vm, false);
342 | }
343 |
344 | // Finally, call the function
345 | const auto err = lua_pcall(lua_vm, 1, 0, 0);
346 | if (err != 0)
347 | pModuleManager->ErrorPrintf("%s\n", lua_tostring(lua_vm, -1));
348 | });
349 |
350 | lua_pushboolean(lua_vm, true);
351 | return 1;
352 | }
353 | // ReSharper restore CppMemberFunctionMayBeConst
354 |
--------------------------------------------------------------------------------
/module/LunaRedisClient.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Module.h"
3 |
4 | class ILuaModuleManager10;
5 | struct lua_State;
6 |
7 | extern ILuaModuleManager10* pModuleManager;
8 |
9 | // http://lua-users.org/wiki/SimplerCppBinding
10 | class LunaRedisClient
11 | {
12 | public:
13 | static const char className[];
14 | static Luna::RegType methods[];
15 |
16 | LunaRedisClient(lua_State*);
17 | ~LunaRedisClient();
18 |
19 | void verify_self(lua_State* lua_vm) const;
20 |
21 | int connect(lua_State* lua_vm);
22 | int disconnect(lua_State* lua_vm);
23 | int authenticate(lua_State* lua_vm);
24 | int set(lua_State* lua_vm);
25 | int get(lua_State* lua_vm);
26 | int subscribe(lua_State* lua_vm);
27 | int unsubscribe(lua_State* lua_vm);
28 | int publish(lua_State* lua_vm);
29 |
30 | private:
31 | std::shared_ptr _client;
32 | };
33 |
--------------------------------------------------------------------------------
/module/LunaRedisClientHelper.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "LunaRedisClient.h"
3 | #include "Utils.h"
4 |
5 | const char LunaRedisClient::className[] = "RedisClient";
6 | Luna::RegType LunaRedisClient::methods[] = {
7 | // methods
8 | method(LunaRedisClient, connect),
9 | method(LunaRedisClient, disconnect),
10 | method(LunaRedisClient, authenticate),
11 | method(LunaRedisClient, get),
12 | method(LunaRedisClient, set),
13 | method(LunaRedisClient, subscribe),
14 | method(LunaRedisClient, unsubscribe),
15 | method(LunaRedisClient, publish),
16 |
17 | // Do not remove, required
18 | { nullptr, nullptr}
19 | };
20 |
21 | class LunaRedisClientHelper
22 | {
23 | public:
24 | static inline void Register(lua_State* lua_vm) { Luna::Register(lua_vm); }
25 | };
26 |
27 |
--------------------------------------------------------------------------------
/module/Main.cpp:
--------------------------------------------------------------------------------
1 | #include "Common.h"
2 | #include "include/ILuaModuleManager.h"
3 | #include "Module.h"
4 | #include "LunaRedisClient.h"
5 | #include "LunaRedisClientHelper.h"
6 |
7 | #ifndef WIN32
8 | #include "luaimports/luaimports.linux.h"
9 | #endif
10 |
11 | ILuaModuleManager10* pModuleManager = nullptr;
12 |
13 | // Initialization function (module entrypoint)
14 | MTAEXPORT bool InitModule(ILuaModuleManager10* pManager, char* szModuleName, char* szAuthor, float* fVersion)
15 | {
16 | #ifndef WIN32
17 | ImportLua();
18 | #endif
19 |
20 | pModuleManager = pManager;
21 |
22 | // Set the module info
23 | const auto module_name = "Redis client module";
24 | const auto author = "StiviK";
25 | std::memcpy(szModuleName, module_name, MAX_INFO_LENGTH);
26 | std::memcpy(szAuthor, author, MAX_INFO_LENGTH);
27 | *fVersion = 1.0f;
28 |
29 | // Load module
30 | g_Module = new Module(pManager);
31 | g_Module->Start();
32 |
33 | return true;
34 | }
35 |
36 | MTAEXPORT void RegisterFunctions(lua_State* lua_vm)
37 | {
38 | if (!pModuleManager || !lua_vm)
39 | return;
40 |
41 | // Add lua vm to states list (to check validity)
42 | g_Module->AddLuaVM(lua_vm);
43 |
44 | // Register luna class
45 | LunaRedisClientHelper::Register(lua_vm);
46 | }
47 |
48 | MTAEXPORT bool DoPulse()
49 | {
50 | g_Module->Process();
51 |
52 | return true;
53 | }
54 |
55 | MTAEXPORT bool ShutdownModule()
56 | {
57 | // Unload module
58 | delete g_Module;
59 |
60 | return true;
61 | }
62 |
63 | MTAEXPORT bool ResourceStopping(lua_State* luaVM)
64 | {
65 | // Invalidate lua vm by removing it from the valid list
66 | g_Module->RemoveLuaVM(luaVM);
67 |
68 | return true;
69 | }
70 |
71 | MTAEXPORT bool ResourceStopped(lua_State* luaVM)
72 | {
73 | return true;
74 | }
75 |
--------------------------------------------------------------------------------
/module/Module.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Module.h"
3 | Module* g_Module = nullptr;
4 |
5 | constexpr std::size_t kNumWorkers = 2;
6 |
7 | Module::Module(ILuaModuleManager* manager) : _moduleManager(manager), _jobManager(kNumWorkers)
8 | {
9 | }
10 |
11 | Module::~Module()
12 | {
13 | // Shutdown job manager threads
14 | _jobManager.Stop();
15 | }
16 |
17 | void Module::Start()
18 | {
19 | // Start job manager worker threads
20 | _jobManager.Start();
21 | }
22 |
23 | void Module::Process()
24 | {
25 | // Call complete callbacks on main thread
26 | _jobManager.SpreadResults();
27 | }
28 |
29 | void Module::register_table_function(lua_State* lua_vm, const char* function_name, lua_CFunction function)
30 | {
31 | lua_pushstring(lua_vm, function_name);
32 | lua_pushcfunction(lua_vm, function);
33 | lua_settable(lua_vm, -3);
34 | }
35 |
36 | void Module::register_class(lua_State* lua_vm, const char* metatable, const luaL_Reg* registry)
37 | {
38 | // https://www.lua.org/pil/28.2.html
39 | // Register metatable
40 | luaL_newmetatable(lua_vm, metatable);
41 | lua_pushstring(lua_vm, "__index");
42 | lua_pushvalue(lua_vm, -2);
43 | lua_settable(lua_vm, -3);
44 | luaL_openlib(lua_vm, nullptr, registry, 0);
45 |
46 | lua_setglobal(lua_vm, metatable);
47 | }
48 |
--------------------------------------------------------------------------------
/module/Module.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "ILuaModuleManager.h"
8 | #include "JobManager.h"
9 | #include "RedisClient.h"
10 | #include "Luna.h"
11 |
12 | struct lua_State;
13 | class ILuaModuleManager;
14 |
15 | class Module
16 | {
17 | public:
18 | Module(ILuaModuleManager* manager);
19 | ~Module();
20 |
21 | void Start();
22 | void Process();
23 |
24 | inline void AddLuaVM(lua_State* luaVM) { _luaStates.insert(luaVM); }
25 | inline void RemoveLuaVM(lua_State* luaVM) { _luaStates.erase(luaVM); }
26 | inline bool HasLuaVM(lua_State* luaVM) { return _luaStates.find(luaVM) != _luaStates.end(); }
27 |
28 | inline void AddRedisClient(const std::shared_ptr& client) { _redisClients.insert(client); }
29 | inline void RemoveRedisClient(const std::shared_ptr& client) { _redisClients.erase(client); }
30 | inline bool HasRedisClient(const std::shared_ptr& client) { return _redisClients.find(client) != _redisClients.end(); }
31 |
32 | inline JobManager>& GetJobManager() { return _jobManager; }
33 |
34 | static void register_table_function(lua_State* lua_vm, const char* function_name, lua_CFunction function);
35 | static void register_class(lua_State* lua_vm, const char* metatable, const luaL_Reg* registry);
36 |
37 | private:
38 | ILuaModuleManager* _moduleManager;
39 | JobManager> _jobManager;
40 | std::unordered_set _luaStates;
41 | std::unordered_set> _redisClients;
42 | };
43 |
44 | extern Module* g_Module;
45 |
--------------------------------------------------------------------------------
/module/RedisClient.cpp:
--------------------------------------------------------------------------------
1 | #include "RedisClient.h"
2 | #include "Module.h"
3 |
4 | redis_client::redis_client()
5 | {
6 | _client = std::make_unique();
7 | _subscriber = std::make_unique();
8 | }
9 |
10 | void redis_client::authenticate(const std::string& password, const cpp_redis::client::reply_callback_t& client_callback,
11 | const cpp_redis::client::reply_callback_t& subscriber_callback) const
12 | {
13 | _client->auth(password, client_callback);
14 | _subscriber->auth(password, subscriber_callback);
15 |
16 | _client->commit();
17 | _subscriber->commit();
18 | }
19 |
20 | cpp_redis::reply redis_client::set(const std::string& key, const std::string& value) const
21 | {
22 | auto result = _client->set(key, value);
23 | _client->commit();
24 |
25 | result.wait();
26 | return result.get();
27 | }
28 |
29 | void redis_client::set(const std::map& pairs, const std::function& callback) const
30 | {
31 | for(auto& [key, value] : pairs)
32 | {
33 | _client->set(key, value, [key, callback](cpp_redis::reply& reply)
34 | {
35 | callback(key, reply);
36 | });
37 | }
38 | _client->commit();
39 | }
40 |
41 | cpp_redis::reply redis_client::get(const std::string& key) const
42 | {
43 | auto result = _client->get(key);
44 | _client->commit();
45 |
46 | result.wait();
47 | return result.get();
48 | }
49 |
50 | void redis_client::get(const std::list& keys, const std::function& callback) const
51 | {
52 | for (auto& key : keys)
53 | {
54 | _client->get(key, [key, callback](cpp_redis::reply& reply)
55 | {
56 | callback(key, reply);
57 | });
58 | }
59 | _client->commit();
60 | }
61 |
62 | void redis_client::subscribe(const std::list& channels,
63 | const cpp_redis::subscriber::subscribe_callback_t& callback) const
64 | {
65 | for (auto& channel : channels)
66 | {
67 | _subscriber->subscribe(channel, callback);
68 | }
69 |
70 | _subscriber->commit();
71 | }
72 |
73 | void redis_client::unsubscribe(const std::list& channels) const
74 | {
75 | for (auto& channel : channels)
76 | {
77 | _subscriber->unsubscribe(channel);
78 | }
79 | _subscriber->commit();
80 | }
81 |
82 | cpp_redis::reply redis_client::publish(const std::string& channel, const std::string& message) const
83 | {
84 | auto result = _client->publish(channel, message);
85 | _client->commit();
86 |
87 | result.wait();
88 | return result.get();
89 | }
90 |
91 | void redis_client::publish(const std::map& pairs,
92 | const std::function& callback) const
93 | {
94 | for (auto& [channel, message] : pairs)
95 | {
96 | _client->publish(channel, message, [channel, callback](cpp_redis::reply& reply)
97 | {
98 | callback(channel, reply);
99 | });
100 | }
101 | _client->commit();
102 | }
103 |
--------------------------------------------------------------------------------
/module/RedisClient.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 |
6 | class redis_client
7 | {
8 | public:
9 | redis_client();
10 |
11 | [[nodiscard]] bool validate() const { return _client != nullptr && _subscriber != nullptr; }
12 |
13 | // redis commands
14 | void connect(const std::string& host, const int& port) const { _client->connect(host, port); _subscriber->connect(host, port); }
15 | void disconnect() const { _client->disconnect(); _subscriber->disconnect(); }
16 | [[nodiscard]] bool is_connected() const { return _client->is_connected() && _subscriber->is_connected(); }
17 | void authenticate(const std::string& password, const cpp_redis::client::reply_callback_t& client_callback, const cpp_redis::client::reply_callback_t& subscriber_callback) const;
18 |
19 | // Key, Value
20 | [[nodiscard]] cpp_redis::reply set(const std::string& key, const std::string& value) const;
21 | void set(const std::string& key, const std::string& value, const cpp_redis::client::reply_callback_t& callback) const { _client->set(key, value, callback); _client->commit(); }
22 | void set(const std::map& pairs, const std::function& callback) const;
23 |
24 | [[nodiscard]] cpp_redis::reply get(const std::string& key) const;
25 | void get(const std::string& key, const cpp_redis::client::reply_callback_t& callback) const { _client->get(key, callback); _client->commit(); };
26 | void get(const std::list& keys, const std::function& callback) const;
27 |
28 | // Channels
29 | void subscribe(const std::string& channel, const cpp_redis::subscriber::subscribe_callback_t& callback) const { _subscriber->subscribe(channel, callback); _subscriber->commit(); }
30 | void subscribe(const std::list& channels, const cpp_redis::subscriber::subscribe_callback_t& callback) const;
31 |
32 | void unsubscribe(const std::string& channel) const { _subscriber->unsubscribe(channel); _subscriber->commit(); }
33 | void unsubscribe(const std::list& channels) const;
34 |
35 | [[nodiscard]] cpp_redis::reply publish(const std::string& channel, const std::string& message) const;
36 | void publish(const std::string& channel, const std::string& message, cpp_redis::client::reply_callback_t& callback) const { _client->publish(channel, message, callback); _client->commit(); }
37 | void publish(const std::map& pairs, const std::function& callback) const;
38 |
39 | private:
40 | std::unique_ptr _client;
41 | std::unique_ptr _subscriber;
42 | };
43 |
--------------------------------------------------------------------------------
/module/Utils.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "lua.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | static const int index_value = -1;
9 | static const int index_key = -2;
10 |
11 | #define method(class, name) {#name, &class::name}
12 |
13 | class utils
14 | {
15 | public:
16 | template
17 | static _Type* lua_checkobject(lua_State* lua_vm, const char* metatable, const int index = 1)
18 | {
19 | // get and verify our heap ptr and dereference it
20 | return *static_cast<_Type**>(luaL_checkudata(lua_vm, index, metatable));
21 | }
22 |
23 | template
24 | static void lua_createobject(lua_State* lua_vm, _Type* heap_object, const char* metatable)
25 | {
26 | const auto udata = static_cast<_Type**>(lua_newuserdata(lua_vm, sizeof(_Type*))); // Allocate space for a ptr to our heap object ptr
27 | *udata = heap_object; // assign our heap object to the udata ptr
28 |
29 | luaL_getmetatable(lua_vm, metatable); // assign the metatable to our udata
30 | lua_setmetatable(lua_vm, -2);
31 | }
32 |
33 | template
34 | static void lua_deleteobject(lua_State* lua_vm, const char* metatable, const int index = 1)
35 | {
36 | const auto udata = static_cast<_Type**>(luaL_checkudata(lua_vm, index, metatable));
37 | delete udata;
38 | }
39 |
40 | static int lua_getfuncref(lua_State* lua_vm, const int index)
41 | {
42 | // Verify argument
43 | luaL_checktype(lua_vm, index, LUA_TFUNCTION);
44 |
45 | // Save reference of the Lua callback function
46 | // See: http://lua-users.org/lists/lua-l/2008-12/msg00193.html
47 | lua_pushvalue(lua_vm, index);
48 | return luaL_ref(lua_vm, LUA_REGISTRYINDEX);
49 | }
50 |
51 | static inline std::unordered_map parse_table(lua_State* lua_vm, const int index)
52 | {
53 | std::unordered_map result;
54 |
55 | for(lua_pushnil(lua_vm); lua_next(lua_vm, index) != 0; lua_pop(lua_vm, 1))
56 | {
57 | const auto type_key = lua_type(lua_vm, index_key);
58 | const auto type_value = lua_type(lua_vm, index_value);
59 | if (type_key != LUA_TSTRING && type_key != LUA_TNUMBER)
60 | {
61 | std::stringstream ss;
62 | ss << "got invalid table key, expected string or number got " << lua_typename(lua_vm, type_key);
63 | throw std::runtime_error(ss.str());
64 | }
65 |
66 | if (type_value != LUA_TSTRING && type_value != LUA_TNUMBER)
67 | {
68 | std::stringstream ss;
69 | ss << "got invalid table value, expected string or number got " << lua_typename(lua_vm, type_value);
70 | throw std::runtime_error(ss.str());
71 | }
72 |
73 | auto to_string = [lua_vm](const int index) -> const std::string
74 | {
75 | const auto type = lua_type(lua_vm, index);
76 | if (type == LUA_TSTRING)
77 | {
78 | return lua_tostring(lua_vm, index);
79 | }
80 |
81 | if (type == LUA_TNUMBER)
82 | {
83 | return std::to_string(lua_tointeger(lua_vm, index));
84 | }
85 | return {};
86 | };
87 |
88 | result[to_string(index_key)] = to_string(index_value);
89 | }
90 |
91 | return result;
92 | }
93 | };
94 |
95 |
--------------------------------------------------------------------------------
/module/extra/CLuaArgument.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/module/extra/CLuaArgument.cpp
--------------------------------------------------------------------------------
/module/extra/CLuaArgument.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/module/extra/CLuaArgument.h
--------------------------------------------------------------------------------
/module/extra/CLuaArguments.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/module/extra/CLuaArguments.cpp
--------------------------------------------------------------------------------
/module/extra/CLuaArguments.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/module/extra/CLuaArguments.h
--------------------------------------------------------------------------------
/module/include/ILuaModuleManager.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * PROJECT: Multi Theft Auto v1.0
4 | * LICENSE: See LICENSE in the top level directory
5 | * FILE: publicsdk/include/ILuaModuleManager.h
6 | * PURPOSE: Lua dynamic module interface
7 | *
8 | * Multi Theft Auto is available from http://www.multitheftauto.com/
9 | *
10 | *****************************************************************************/
11 |
12 | // INTERFACE for Lua dynamic modules
13 |
14 | #ifndef __ILUAMODULEMANAGER_H
15 | #define __ILUAMODULEMANAGER_H
16 |
17 | #define MAX_INFO_LENGTH 128
18 |
19 | extern "C"
20 | {
21 | #include "lua.h"
22 | #include "lualib.h"
23 | #include "lauxlib.h"
24 | }
25 | #include
26 |
27 | #ifndef __CChecksum_H
28 | class CChecksum
29 | {
30 | public:
31 | unsigned long ulCRC;
32 | unsigned char mD5 [16];
33 | };
34 | #endif
35 |
36 | /* Interface for modules until DP2.3 */
37 | class ILuaModuleManager
38 | {
39 | public:
40 | virtual void ErrorPrintf ( const char* szFormat, ... ) = 0;
41 | virtual void DebugPrintf ( lua_State * luaVM, const char* szFormat, ... ) = 0;
42 | virtual void Printf ( const char* szFormat, ... ) = 0;
43 |
44 | virtual bool RegisterFunction ( lua_State * luaVM, const char *szFunctionName, lua_CFunction Func ) = 0;
45 | virtual bool GetResourceName ( lua_State * luaVM, std::string &strName ) = 0;
46 | virtual CChecksum GetResourceMetaChecksum ( lua_State * luaVM ) = 0;
47 | virtual CChecksum GetResourceFileChecksum ( lua_State * luaVM, const char* szFile ) = 0;
48 | };
49 |
50 | /* Interface for modules until 1.0 */
51 | class ILuaModuleManager10 : public ILuaModuleManager
52 | {
53 | public:
54 | virtual unsigned long GetVersion ( ) = 0;
55 | virtual const char* GetVersionString ( ) = 0;
56 | virtual const char* GetVersionName ( ) = 0;
57 | virtual unsigned long GetNetcodeVersion ( ) = 0;
58 | virtual const char* GetOperatingSystemName ( ) = 0;
59 |
60 | virtual lua_State* GetResourceFromName ( const char* szResourceName ) = 0;
61 | virtual bool GetResourceName ( lua_State* luaVM, char* szName, size_t length ) = 0;
62 | virtual bool GetResourceFilePath ( lua_State* luaVM, const char* fileName, char* path, size_t length ) = 0;
63 | };
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/module/include/lauxlib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lauxlib.h,v 1.2 2007/08/14 19:23:35 toady Exp $
3 | ** Auxiliary functions for building Lua libraries
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #ifndef lauxlib_h
9 | #define lauxlib_h
10 |
11 |
12 | #include
13 | #include
14 |
15 | #include "lua.h"
16 |
17 |
18 | #if defined(LUA_COMPAT_GETN)
19 | LUALIB_API int (luaL_getn) (lua_State *L, int t);
20 | LUALIB_API void (luaL_setn) (lua_State *L, int t, int n);
21 | #else
22 | #define luaL_getn(L,i) ((int)lua_objlen(L, i))
23 | #define luaL_setn(L,i,j) ((void)0) /* no op! */
24 | #endif
25 |
26 | #if defined(LUA_COMPAT_OPENLIB)
27 | #define luaI_openlib luaL_openlib
28 | #endif
29 |
30 |
31 | /* extra error code for `luaL_load' */
32 | #define LUA_ERRFILE (LUA_ERRERR+1)
33 |
34 |
35 | typedef struct luaL_Reg {
36 | const char *name;
37 | lua_CFunction func;
38 | } luaL_Reg;
39 |
40 |
41 |
42 | LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname,
43 | const luaL_Reg *l, int nup);
44 | LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
45 | const luaL_Reg *l);
46 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
47 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
48 | LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
49 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
50 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
51 | size_t *l);
52 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
53 | const char *def, size_t *l);
54 | LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
55 | LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
56 |
57 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
58 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
59 | lua_Integer def);
60 |
61 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
62 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
63 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
64 |
65 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
66 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
67 |
68 | LUALIB_API void (luaL_where) (lua_State *L, int lvl);
69 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
70 |
71 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
72 | const char *const lst[]);
73 |
74 | LUALIB_API int (luaL_ref) (lua_State *L, int t);
75 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
76 |
77 | LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
78 | LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
79 | const char *name);
80 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
81 |
82 | LUALIB_API lua_State *(luaL_newstate) (void);
83 |
84 |
85 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
86 | const char *r);
87 |
88 | LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
89 | const char *fname, int szhint);
90 |
91 |
92 |
93 |
94 | /*
95 | ** ===============================================================
96 | ** some useful macros
97 | ** ===============================================================
98 | */
99 |
100 | #define luaL_argcheck(L, cond,numarg,extramsg) \
101 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
102 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
103 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
104 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
105 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
106 | #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
107 | #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
108 |
109 | #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
110 |
111 | #define luaL_dofile(L, fn) \
112 | (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
113 |
114 | #define luaL_dostring(L, s) \
115 | (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
116 |
117 | #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
118 |
119 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
120 |
121 | /*
122 | ** {======================================================
123 | ** Generic Buffer manipulation
124 | ** =======================================================
125 | */
126 |
127 |
128 |
129 | typedef struct luaL_Buffer {
130 | char *p; /* current position in buffer */
131 | int lvl; /* number of strings in the stack (level) */
132 | lua_State *L;
133 | char buffer[LUAL_BUFFERSIZE];
134 | } luaL_Buffer;
135 |
136 | #define luaL_addchar(B,c) \
137 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
138 | (*(B)->p++ = (char)(c)))
139 |
140 | /* compatibility only */
141 | #define luaL_putchar(B,c) luaL_addchar(B,c)
142 |
143 | #define luaL_addsize(B,n) ((B)->p += (n))
144 |
145 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
146 | LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);
147 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
148 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
149 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
150 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
151 |
152 |
153 | /* }====================================================== */
154 |
155 |
156 | /* compatibility with ref system */
157 |
158 | /* pre-defined references */
159 | #define LUA_NOREF (-2)
160 | #define LUA_REFNIL (-1)
161 |
162 | #define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
163 | (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
164 |
165 | #define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
166 |
167 | #define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
168 |
169 |
170 | #define luaL_reg luaL_Reg
171 |
172 | #endif
173 |
174 |
175 |
--------------------------------------------------------------------------------
/module/include/lua.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lua.h,v 1.218.1.7 2012/01/13 20:36:20 roberto Exp $
3 | ** Lua - An Extensible Extension Language
4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5 | ** See Copyright Notice at the end of this file
6 | */
7 |
8 |
9 | #ifndef lua_h
10 | #define lua_h
11 |
12 | #include
13 | #include
14 |
15 |
16 | #include "luaconf.h"
17 |
18 |
19 | #define LUA_VERSION "Lua 5.1"
20 | #define LUA_RELEASE "Lua 5.1.5"
21 | #define LUA_VERSION_NUM 501
22 | #define LUA_COPYRIGHT "Copyright (C) 1994-2012 Lua.org, PUC-Rio"
23 | #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
24 |
25 |
26 | /* mark for precompiled code (`Lua') */
27 | #define LUA_SIGNATURE "\033Lua"
28 |
29 | /* option for multiple returns in `lua_pcall' and `lua_call' */
30 | #define LUA_MULTRET (-1)
31 |
32 |
33 | /*
34 | ** pseudo-indices
35 | */
36 | #define LUA_REGISTRYINDEX (-10000)
37 | #define LUA_ENVIRONINDEX (-10001)
38 | #define LUA_GLOBALSINDEX (-10002)
39 | #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
40 |
41 |
42 | /* thread status; 0 is OK */
43 | #define LUA_YIELD 1
44 | #define LUA_ERRRUN 2
45 | #define LUA_ERRSYNTAX 3
46 | #define LUA_ERRMEM 4
47 | #define LUA_ERRERR 5
48 |
49 |
50 | typedef struct lua_State lua_State;
51 |
52 | typedef int (*lua_CFunction) (lua_State *L);
53 |
54 | /*
55 | ** MTA Specific stuff written by Oli for pre C Function call hooking
56 | */
57 | typedef int (*lua_PreCallHook) ( lua_CFunction f, lua_State* L );
58 | LUA_API void lua_registerPreCallHook ( lua_PreCallHook f );
59 | typedef void (*lua_PostCallHook) ( lua_CFunction f, lua_State* L );
60 | LUA_API void lua_registerPostCallHook ( lua_PostCallHook f );
61 |
62 | // MTA Specific
63 | typedef int (*lua_UndumpHook) ( const char* p, size_t n );
64 | LUA_API void lua_registerUndumpHook ( lua_UndumpHook f );
65 |
66 | /*
67 | ** functions that read/write blocks when loading/dumping Lua chunks
68 | */
69 | typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
70 |
71 | typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
72 |
73 |
74 | /*
75 | ** prototype for memory-allocation functions
76 | */
77 | typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
78 |
79 |
80 | /*
81 | ** basic types
82 | */
83 | #define LUA_TNONE (-1)
84 |
85 | #define LUA_TNIL 0
86 | #define LUA_TBOOLEAN 1
87 | #define LUA_TLIGHTUSERDATA 2
88 | #define LUA_TNUMBER 3
89 | #define LUA_TSTRING 4
90 | #define LUA_TTABLE 5
91 | #define LUA_TFUNCTION 6
92 | #define LUA_TUSERDATA 7
93 | #define LUA_TTHREAD 8
94 |
95 |
96 |
97 | /* minimum Lua stack available to a C function */
98 | #define LUA_MINSTACK 50 // MTA change. Was 20
99 |
100 |
101 | /*
102 | ** generic extra include file
103 | */
104 | #if defined(LUA_USER_H)
105 | #include LUA_USER_H
106 | #endif
107 |
108 |
109 | /* type of numbers in Lua */
110 | typedef LUA_NUMBER lua_Number;
111 |
112 |
113 | /* type for integer functions */
114 | typedef LUA_INTEGER lua_Integer;
115 |
116 |
117 |
118 | /*
119 | ** state manipulation
120 | */
121 | LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
122 | LUA_API void (lua_close) (lua_State *L);
123 | LUA_API lua_State *(lua_newthread) (lua_State *L);
124 |
125 | LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
126 |
127 | // MTA Specific functions.
128 | // ChrML: Added function to get the main state from a lua state that is a coroutine
129 | LUA_API lua_State* (lua_getmainstate) (lua_State* L);
130 |
131 | /*
132 | ** basic stack manipulation
133 | */
134 | LUA_API int (lua_gettop) (lua_State *L);
135 | LUA_API void (lua_settop) (lua_State *L, int idx);
136 | LUA_API void (lua_pushvalue) (lua_State *L, int idx);
137 | LUA_API void (lua_remove) (lua_State *L, int idx);
138 | LUA_API void (lua_insert) (lua_State *L, int idx);
139 | LUA_API void (lua_replace) (lua_State *L, int idx);
140 | LUA_API int (lua_checkstack) (lua_State *L, int sz);
141 | LUA_API int (lua_getstackgap) (lua_State *L); // MTA addition
142 |
143 | LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
144 |
145 |
146 | /*
147 | ** access functions (stack -> C)
148 | */
149 |
150 | LUA_API int (lua_isnumber) (lua_State *L, int idx);
151 | LUA_API int (lua_isstring) (lua_State *L, int idx);
152 | LUA_API int (lua_iscfunction) (lua_State *L, int idx);
153 | LUA_API int (lua_isuserdata) (lua_State *L, int idx);
154 | LUA_API int (lua_type) (lua_State *L, int idx);
155 | LUA_API const char *(lua_typename) (lua_State *L, int tp);
156 |
157 | LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2);
158 | LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
159 | LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2);
160 |
161 | LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
162 | LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
163 | LUA_API lua_Integer (lua_tointegerW) (lua_State *L, int idx); // MTA Specific
164 | LUA_API int (lua_toboolean) (lua_State *L, int idx);
165 | LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
166 | LUA_API size_t (lua_objlen) (lua_State *L, int idx);
167 | LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
168 | LUA_API void *(lua_touserdata) (lua_State *L, int idx);
169 | LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
170 | LUA_API const void *(lua_topointer) (lua_State *L, int idx);
171 |
172 |
173 | /*
174 | ** push functions (C -> stack)
175 | */
176 | LUA_API void (lua_pushnil) (lua_State *L);
177 | LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
178 | LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
179 | LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l);
180 | LUA_API void (lua_pushstring) (lua_State *L, const char *s);
181 | LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
182 | va_list argp);
183 | LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
184 | LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
185 | LUA_API void (lua_pushboolean) (lua_State *L, int b);
186 | LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
187 | LUA_API int (lua_pushthread) (lua_State *L);
188 |
189 |
190 | /*
191 | ** get functions (Lua -> stack)
192 | */
193 | LUA_API void (lua_gettable) (lua_State *L, int idx);
194 | LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
195 | LUA_API void (lua_rawget) (lua_State *L, int idx);
196 | LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
197 | LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
198 | LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
199 | LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
200 | LUA_API void (lua_getfenv) (lua_State *L, int idx);
201 |
202 |
203 | /*
204 | ** set functions (stack -> Lua)
205 | */
206 | LUA_API void (lua_settable) (lua_State *L, int idx);
207 | LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
208 | LUA_API void (lua_rawset) (lua_State *L, int idx);
209 | LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
210 | LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
211 | LUA_API int (lua_setfenv) (lua_State *L, int idx);
212 |
213 |
214 | /*
215 | ** `load' and `call' functions (load and run Lua code)
216 | */
217 | LUA_API void (lua_call) (lua_State *L, int nargs, int nresults);
218 | LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
219 | LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
220 | LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
221 | const char *chunkname);
222 |
223 | LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
224 |
225 |
226 | /*
227 | ** coroutine functions
228 | */
229 | LUA_API int (lua_yield) (lua_State *L, int nresults);
230 | LUA_API int (lua_resume) (lua_State *L, int narg);
231 | LUA_API int (lua_status) (lua_State *L);
232 |
233 | /*
234 | ** garbage-collection function and options
235 | */
236 |
237 | #define LUA_GCSTOP 0
238 | #define LUA_GCRESTART 1
239 | #define LUA_GCCOLLECT 2
240 | #define LUA_GCCOUNT 3
241 | #define LUA_GCCOUNTB 4
242 | #define LUA_GCSTEP 5
243 | #define LUA_GCSETPAUSE 6
244 | #define LUA_GCSETSTEPMUL 7
245 |
246 | LUA_API int (lua_gc) (lua_State *L, int what, int data);
247 |
248 |
249 | /*
250 | ** miscellaneous functions
251 | */
252 |
253 | LUA_API int (lua_error) (lua_State *L);
254 |
255 | LUA_API int (lua_next) (lua_State *L, int idx);
256 |
257 | LUA_API void (lua_concat) (lua_State *L, int n);
258 |
259 | LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
260 | LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
261 |
262 |
263 |
264 | /*
265 | ** ===============================================================
266 | ** some useful macros
267 | ** ===============================================================
268 | */
269 |
270 | #define lua_pop(L,n) lua_settop(L, -(n)-1)
271 |
272 | #define lua_newtable(L) lua_createtable(L, 0, 0)
273 |
274 | #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
275 |
276 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
277 |
278 | #define lua_strlen(L,i) lua_objlen(L, (i))
279 |
280 | #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
281 | #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
282 | #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
283 | #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
284 | #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
285 | #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
286 | #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
287 | #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
288 |
289 | #define lua_pushliteral(L, s) \
290 | lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
291 |
292 | #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
293 | #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
294 |
295 | #define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
296 |
297 |
298 |
299 | /*
300 | ** compatibility macros and functions
301 | */
302 |
303 | #define lua_open() luaL_newstate()
304 |
305 | #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX)
306 |
307 | #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
308 |
309 | #define lua_Chunkreader lua_Reader
310 | #define lua_Chunkwriter lua_Writer
311 |
312 |
313 | /* hack */
314 | LUA_API void lua_setlevel (lua_State *from, lua_State *to);
315 |
316 |
317 | /*
318 | ** {======================================================================
319 | ** Debug API
320 | ** =======================================================================
321 | */
322 |
323 |
324 | /*
325 | ** Event codes
326 | */
327 | #define LUA_HOOKCALL 0
328 | #define LUA_HOOKRET 1
329 | #define LUA_HOOKLINE 2
330 | #define LUA_HOOKCOUNT 3
331 | #define LUA_HOOKTAILRET 4
332 |
333 |
334 | /*
335 | ** Event masks
336 | */
337 | #define LUA_MASKCALL (1 << LUA_HOOKCALL)
338 | #define LUA_MASKRET (1 << LUA_HOOKRET)
339 | #define LUA_MASKLINE (1 << LUA_HOOKLINE)
340 | #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
341 |
342 | typedef struct lua_Debug lua_Debug; /* activation record */
343 |
344 |
345 | /* Functions to be called by the debuger in specific events */
346 | typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
347 |
348 |
349 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
350 | LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
351 | LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
352 | LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
353 | LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
354 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
355 |
356 | LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
357 | LUA_API lua_Hook lua_gethook (lua_State *L);
358 | LUA_API int lua_gethookmask (lua_State *L);
359 | LUA_API int lua_gethookcount (lua_State *L);
360 |
361 |
362 | struct lua_Debug {
363 | int event;
364 | const char *name; /* (n) */
365 | const char *namewhat; /* (n) `global', `local', `field', `method' */
366 | const char *what; /* (S) `Lua', `C', `main', `tail' */
367 | const char *source; /* (S) */
368 | int currentline; /* (l) */
369 | int nups; /* (u) number of upvalues */
370 | int linedefined; /* (S) */
371 | int lastlinedefined; /* (S) */
372 | char short_src[LUA_IDSIZE]; /* (S) */
373 | /* private part */
374 | int i_ci; /* active function */
375 | };
376 |
377 | /* }====================================================================== */
378 |
379 |
380 | /******************************************************************************
381 | * Copyright (C) 1994-2012 Lua.org, PUC-Rio. All rights reserved.
382 | *
383 | * Permission is hereby granted, free of charge, to any person obtaining
384 | * a copy of this software and associated documentation files (the
385 | * "Software"), to deal in the Software without restriction, including
386 | * without limitation the rights to use, copy, modify, merge, publish,
387 | * distribute, sublicense, and/or sell copies of the Software, and to
388 | * permit persons to whom the Software is furnished to do so, subject to
389 | * the following conditions:
390 | *
391 | * The above copyright notice and this permission notice shall be
392 | * included in all copies or substantial portions of the Software.
393 | *
394 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
395 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
396 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
397 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
398 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
399 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
400 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
401 | ******************************************************************************/
402 |
403 |
404 | #endif
405 |
--------------------------------------------------------------------------------
/module/include/luaconf.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $
3 | ** Configuration file for Lua
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #ifndef lconfig_h
9 | #define lconfig_h
10 |
11 | #include
12 | #include
13 |
14 |
15 | /*
16 | ** ==================================================================
17 | ** Search for "@@" to find all configurable definitions.
18 | ** ===================================================================
19 | */
20 |
21 |
22 | /*
23 | @@ LUA_ANSI controls the use of non-ansi features.
24 | ** CHANGE it (define it) if you want Lua to avoid the use of any
25 | ** non-ansi feature or library.
26 | */
27 | #if defined(__STRICT_ANSI__)
28 | #define LUA_ANSI
29 | #endif
30 |
31 |
32 | #if !defined(LUA_ANSI) && defined(_WIN32)
33 | #define LUA_WIN
34 | #endif
35 |
36 | #if defined(LUA_USE_LINUX)
37 | #define LUA_USE_POSIX
38 | #define LUA_USE_DLOPEN /* needs an extra library: -ldl */
39 | #define LUA_USE_READLINE /* needs some extra libraries */
40 | #endif
41 |
42 | #if defined(LUA_USE_MACOSX)
43 | #define LUA_USE_POSIX
44 | #define LUA_DL_DYLD /* does not need extra library */
45 | #endif
46 |
47 |
48 |
49 | /*
50 | @@ LUA_USE_POSIX includes all functionallity listed as X/Open System
51 | @* Interfaces Extension (XSI).
52 | ** CHANGE it (define it) if your system is XSI compatible.
53 | */
54 | #if defined(LUA_USE_POSIX)
55 | #define LUA_USE_MKSTEMP
56 | #define LUA_USE_ISATTY
57 | #define LUA_USE_POPEN
58 | #define LUA_USE_ULONGJMP
59 | #endif
60 |
61 |
62 | /*
63 | @@ LUA_PATH and LUA_CPATH are the names of the environment variables that
64 | @* Lua check to set its paths.
65 | @@ LUA_INIT is the name of the environment variable that Lua
66 | @* checks for initialization code.
67 | ** CHANGE them if you want different names.
68 | */
69 | #define LUA_PATH "LUA_PATH"
70 | #define LUA_CPATH "LUA_CPATH"
71 | #define LUA_INIT "LUA_INIT"
72 |
73 |
74 | /*
75 | @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
76 | @* Lua libraries.
77 | @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
78 | @* C libraries.
79 | ** CHANGE them if your machine has a non-conventional directory
80 | ** hierarchy or if you want to install your libraries in
81 | ** non-conventional directories.
82 | */
83 | #if defined(_WIN32)
84 | /*
85 | ** In Windows, any exclamation mark ('!') in the path is replaced by the
86 | ** path of the directory of the executable file of the current process.
87 | */
88 | #define LUA_LDIR "!\\lua\\"
89 | #define LUA_CDIR "!\\"
90 | #define LUA_PATH_DEFAULT \
91 | ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
92 | LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua"
93 | #define LUA_CPATH_DEFAULT \
94 | ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
95 |
96 | #else
97 | #define LUA_ROOT "/usr/local/"
98 | #define LUA_LDIR LUA_ROOT "share/lua/5.1/"
99 | #define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
100 | #define LUA_PATH_DEFAULT \
101 | "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
102 | LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
103 | #define LUA_CPATH_DEFAULT \
104 | "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
105 | #endif
106 |
107 |
108 | /*
109 | @@ LUA_DIRSEP is the directory separator (for submodules).
110 | ** CHANGE it if your machine does not use "/" as the directory separator
111 | ** and is not Windows. (On Windows Lua automatically uses "\".)
112 | */
113 | #if defined(_WIN32)
114 | #define LUA_DIRSEP "\\"
115 | #else
116 | #define LUA_DIRSEP "/"
117 | #endif
118 |
119 |
120 | /*
121 | @@ LUA_PATHSEP is the character that separates templates in a path.
122 | @@ LUA_PATH_MARK is the string that marks the substitution points in a
123 | @* template.
124 | @@ LUA_EXECDIR in a Windows path is replaced by the executable's
125 | @* directory.
126 | @@ LUA_IGMARK is a mark to ignore all before it when bulding the
127 | @* luaopen_ function name.
128 | ** CHANGE them if for some reason your system cannot use those
129 | ** characters. (E.g., if one of those characters is a common character
130 | ** in file/directory names.) Probably you do not need to change them.
131 | */
132 | #define LUA_PATHSEP ";"
133 | #define LUA_PATH_MARK "?"
134 | #define LUA_EXECDIR "!"
135 | #define LUA_IGMARK "-"
136 |
137 |
138 | /*
139 | @@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
140 | ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
141 | ** machines, ptrdiff_t gives a good choice between int or long.)
142 | */
143 | #define LUA_INTEGER ptrdiff_t
144 |
145 |
146 | /*
147 | @@ LUA_API is a mark for all core API functions.
148 | @@ LUALIB_API is a mark for all standard library functions.
149 | ** CHANGE them if you need to define those functions in some special way.
150 | ** For instance, if you want to create one Windows DLL with the core and
151 | ** the libraries, you may want to use the following definition (define
152 | ** LUA_BUILD_AS_DLL to get it).
153 | */
154 | #if defined(LUA_BUILD_AS_DLL)
155 |
156 | #if defined(LUA_CORE) || defined(LUA_LIB)
157 | #define LUA_API __declspec(dllexport)
158 | #else
159 | #define LUA_API __declspec(dllimport)
160 | #endif
161 |
162 | #else
163 |
164 | #define LUA_API extern
165 |
166 | #endif
167 |
168 | /* more often than not the libs go together with the core */
169 | #define LUALIB_API LUA_API
170 |
171 |
172 | /*
173 | @@ LUAI_FUNC is a mark for all extern functions that are not to be
174 | @* exported to outside modules.
175 | @@ LUAI_DATA is a mark for all extern (const) variables that are not to
176 | @* be exported to outside modules.
177 | ** CHANGE them if you need to mark them in some special way. Elf/gcc
178 | ** (versions 3.2 and later) mark them as "hidden" to optimize access
179 | ** when Lua is compiled as a shared library.
180 | */
181 | #if defined(luaall_c)
182 | #define LUAI_FUNC static
183 | #define LUAI_DATA /* empty */
184 |
185 | #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
186 | defined(__ELF__)
187 | #define LUAI_FUNC __attribute__((visibility("hidden"))) extern
188 | #define LUAI_DATA LUAI_FUNC
189 |
190 | #else
191 | #define LUAI_FUNC extern
192 | #define LUAI_DATA extern
193 | #endif
194 |
195 |
196 |
197 | /*
198 | @@ LUA_QL describes how error messages quote program elements.
199 | ** CHANGE it if you want a different appearance.
200 | */
201 | #define LUA_QL(x) "'" x "'"
202 | #define LUA_QS LUA_QL("%s")
203 |
204 |
205 | /*
206 | @@ LUA_IDSIZE gives the maximum size for the description of the source
207 | @* of a function in debug information.
208 | ** CHANGE it if you want a different size.
209 | */
210 | #define LUA_IDSIZE 60
211 |
212 |
213 | /*
214 | ** {==================================================================
215 | ** Stand-alone configuration
216 | ** ===================================================================
217 | */
218 |
219 | #if defined(lua_c) || defined(luaall_c)
220 |
221 | /*
222 | @@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
223 | @* is, whether we're running lua interactively).
224 | ** CHANGE it if you have a better definition for non-POSIX/non-Windows
225 | ** systems.
226 | */
227 | #if defined(LUA_USE_ISATTY)
228 | #include
229 | #define lua_stdin_is_tty() isatty(0)
230 | #elif defined(LUA_WIN)
231 | #include
232 | #include
233 | #define lua_stdin_is_tty() _isatty(_fileno(stdin))
234 | #else
235 | #define lua_stdin_is_tty() 1 /* assume stdin is a tty */
236 | #endif
237 |
238 |
239 | /*
240 | @@ LUA_PROMPT is the default prompt used by stand-alone Lua.
241 | @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
242 | ** CHANGE them if you want different prompts. (You can also change the
243 | ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
244 | */
245 | #define LUA_PROMPT "> "
246 | #define LUA_PROMPT2 ">> "
247 |
248 |
249 | /*
250 | @@ LUA_PROGNAME is the default name for the stand-alone Lua program.
251 | ** CHANGE it if your stand-alone interpreter has a different name and
252 | ** your system is not able to detect that name automatically.
253 | */
254 | #define LUA_PROGNAME "lua"
255 |
256 |
257 | /*
258 | @@ LUA_MAXINPUT is the maximum length for an input line in the
259 | @* stand-alone interpreter.
260 | ** CHANGE it if you need longer lines.
261 | */
262 | #define LUA_MAXINPUT 512
263 |
264 |
265 | /*
266 | @@ lua_readline defines how to show a prompt and then read a line from
267 | @* the standard input.
268 | @@ lua_saveline defines how to "save" a read line in a "history".
269 | @@ lua_freeline defines how to free a line read by lua_readline.
270 | ** CHANGE them if you want to improve this functionality (e.g., by using
271 | ** GNU readline and history facilities).
272 | */
273 | #if defined(LUA_USE_READLINE)
274 | #include
275 | #include
276 | #include
277 | #define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
278 | #define lua_saveline(L,idx) \
279 | if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
280 | add_history(lua_tostring(L, idx)); /* add it to history */
281 | #define lua_freeline(L,b) ((void)L, free(b))
282 | #else
283 | #define lua_readline(L,b,p) \
284 | ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
285 | fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
286 | #define lua_saveline(L,idx) { (void)L; (void)idx; }
287 | #define lua_freeline(L,b) { (void)L; (void)b; }
288 | #endif
289 |
290 | #endif
291 |
292 | /* }================================================================== */
293 |
294 |
295 | /*
296 | @@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
297 | @* as a percentage.
298 | ** CHANGE it if you want the GC to run faster or slower (higher values
299 | ** mean larger pauses which mean slower collection.) You can also change
300 | ** this value dynamically.
301 | */
302 | #define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */
303 |
304 |
305 | /*
306 | @@ LUAI_GCMUL defines the default speed of garbage collection relative to
307 | @* memory allocation as a percentage.
308 | ** CHANGE it if you want to change the granularity of the garbage
309 | ** collection. (Higher values mean coarser collections. 0 represents
310 | ** infinity, where each step performs a full collection.) You can also
311 | ** change this value dynamically.
312 | */
313 | #define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
314 |
315 |
316 |
317 | /*
318 | @@ LUA_COMPAT_GETN controls compatibility with old getn behavior.
319 | ** CHANGE it (define it) if you want exact compatibility with the
320 | ** behavior of setn/getn in Lua 5.0.
321 | */
322 | #undef LUA_COMPAT_GETN
323 |
324 | /*
325 | @@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.
326 | ** CHANGE it to undefined as soon as you do not need a global 'loadlib'
327 | ** function (the function is still available as 'package.loadlib').
328 | */
329 | #undef LUA_COMPAT_LOADLIB
330 |
331 | /*
332 | @@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
333 | ** CHANGE it to undefined as soon as your programs use only '...' to
334 | ** access vararg parameters (instead of the old 'arg' table).
335 | */
336 | #define LUA_COMPAT_VARARG
337 |
338 | /*
339 | @@ LUA_COMPAT_MOD controls compatibility with old math.mod function.
340 | ** CHANGE it to undefined as soon as your programs use 'math.fmod' or
341 | ** the new '%' operator instead of 'math.mod'.
342 | */
343 | #define LUA_COMPAT_MOD
344 |
345 | /*
346 | @@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
347 | @* facility.
348 | ** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
349 | ** off the advisory error when nesting [[...]].
350 | */
351 | #define LUA_COMPAT_LSTR 1
352 |
353 | /*
354 | @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
355 | ** CHANGE it to undefined as soon as you rename 'string.gfind' to
356 | ** 'string.gmatch'.
357 | */
358 | #define LUA_COMPAT_GFIND
359 |
360 | /*
361 | @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
362 | @* behavior.
363 | ** CHANGE it to undefined as soon as you replace to 'luaL_register'
364 | ** your uses of 'luaL_openlib'
365 | */
366 | #define LUA_COMPAT_OPENLIB
367 |
368 |
369 |
370 | /*
371 | @@ luai_apicheck is the assert macro used by the Lua-C API.
372 | ** CHANGE luai_apicheck if you want Lua to perform some checks in the
373 | ** parameters it gets from API calls. This may slow down the interpreter
374 | ** a bit, but may be quite useful when debugging C code that interfaces
375 | ** with Lua. A useful redefinition is to use assert.h.
376 | */
377 | #if defined(LUA_USE_APICHECK)
378 | /////////////////////////////////////////////////////////////////////////
379 | // MTA addition for testing if apicheck will function as expected, and generating more useful crash dumps
380 | #undef assert
381 | #define assert(_Expression) (void)( (!!(_Expression)) || ( *((int*)NULL) = 0) )
382 | LUA_API int luaX_is_apicheck_enabled();
383 | /////////////////////////////////////////////////////////////////////////
384 | #define luai_apicheck(L,o) { (void)L; assert(o); }
385 | #else
386 | #define luai_apicheck(L,o) { (void)L; }
387 | #endif
388 |
389 |
390 | /*
391 | @@ LUAI_BITSINT defines the number of bits in an int.
392 | ** CHANGE here if Lua cannot automatically detect the number of bits of
393 | ** your machine. Probably you do not need to change this.
394 | */
395 | /* avoid overflows in comparison */
396 | #if INT_MAX-20 < 32760
397 | #define LUAI_BITSINT 16
398 | #elif INT_MAX > 2147483640L
399 | /* int has at least 32 bits */
400 | #define LUAI_BITSINT 32
401 | #else
402 | #error "you must define LUA_BITSINT with number of bits in an integer"
403 | #endif
404 |
405 |
406 | /*
407 | @@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
408 | @@ LUAI_INT32 is an signed integer with at least 32 bits.
409 | @@ LUAI_UMEM is an unsigned integer big enough to count the total
410 | @* memory used by Lua.
411 | @@ LUAI_MEM is a signed integer big enough to count the total memory
412 | @* used by Lua.
413 | ** CHANGE here if for some weird reason the default definitions are not
414 | ** good enough for your machine. (The definitions in the 'else'
415 | ** part always works, but may waste space on machines with 64-bit
416 | ** longs.) Probably you do not need to change this.
417 | */
418 | #if LUAI_BITSINT >= 32
419 | #define LUAI_UINT32 unsigned int
420 | #define LUAI_INT32 int
421 | #define LUAI_MAXINT32 INT_MAX
422 | #define LUAI_UMEM size_t
423 | #define LUAI_MEM ptrdiff_t
424 | #else
425 | /* 16-bit ints */
426 | #define LUAI_UINT32 unsigned long
427 | #define LUAI_INT32 long
428 | #define LUAI_MAXINT32 LONG_MAX
429 | #define LUAI_UMEM unsigned long
430 | #define LUAI_MEM long
431 | #endif
432 |
433 |
434 | /*
435 | @@ LUAI_MAXCALLS limits the number of nested calls.
436 | ** CHANGE it if you need really deep recursive calls. This limit is
437 | ** arbitrary; its only purpose is to stop infinite recursion before
438 | ** exhausting memory.
439 | */
440 | #define LUAI_MAXCALLS 20000
441 |
442 |
443 | /*
444 | @@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
445 | @* can use.
446 | ** CHANGE it if you need lots of (Lua) stack space for your C
447 | ** functions. This limit is arbitrary; its only purpose is to stop C
448 | ** functions to consume unlimited stack space. (must be smaller than
449 | ** -LUA_REGISTRYINDEX)
450 | */
451 | #define LUAI_MAXCSTACK 8000
452 |
453 |
454 |
455 | /*
456 | ** {==================================================================
457 | ** CHANGE (to smaller values) the following definitions if your system
458 | ** has a small C stack. (Or you may want to change them to larger
459 | ** values if your system has a large C stack and these limits are
460 | ** too rigid for you.) Some of these constants control the size of
461 | ** stack-allocated arrays used by the compiler or the interpreter, while
462 | ** others limit the maximum number of recursive calls that the compiler
463 | ** or the interpreter can perform. Values too large may cause a C stack
464 | ** overflow for some forms of deep constructs.
465 | ** ===================================================================
466 | */
467 |
468 |
469 | /*
470 | @@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
471 | @* syntactical nested non-terminals in a program.
472 | */
473 | #define LUAI_MAXCCALLS 200
474 |
475 |
476 | /*
477 | @@ LUAI_MAXVARS is the maximum number of local variables per function
478 | @* (must be smaller than 250).
479 | */
480 | #define LUAI_MAXVARS 200
481 |
482 |
483 | /*
484 | @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
485 | @* (must be smaller than 250).
486 | */
487 | #define LUAI_MAXUPVALUES 60
488 |
489 |
490 | /*
491 | @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
492 | */
493 | #define LUAL_BUFFERSIZE BUFSIZ
494 |
495 | /* }================================================================== */
496 |
497 |
498 |
499 |
500 | /*
501 | ** {==================================================================
502 | @@ LUA_NUMBER is the type of numbers in Lua.
503 | ** CHANGE the following definitions only if you want to build Lua
504 | ** with a number type different from double. You may also need to
505 | ** change lua_number2int & lua_number2integer.
506 | ** ===================================================================
507 | */
508 |
509 | #define LUA_NUMBER_DOUBLE
510 | #define LUA_NUMBER double
511 |
512 | /*
513 | @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
514 | @* over a number.
515 | */
516 | #define LUAI_UACNUMBER double
517 |
518 |
519 | /*
520 | @@ LUA_NUMBER_SCAN is the format for reading numbers.
521 | @@ LUA_NUMBER_FMT is the format for writing numbers.
522 | @@ lua_number2str converts a number to a string.
523 | @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
524 | @@ lua_str2number converts a string to a number.
525 | */
526 | #define LUA_NUMBER_SCAN "%lf"
527 | #define LUA_NUMBER_FMT "%.14g"
528 | #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
529 | #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
530 | #define lua_str2number(s,p) strtod((s), (p))
531 |
532 |
533 | /*
534 | @@ The luai_num* macros define the primitive operations over numbers.
535 | */
536 | #if defined(LUA_CORE)
537 | #include
538 | #define luai_numadd(a,b) ((a)+(b))
539 | #define luai_numsub(a,b) ((a)-(b))
540 | #define luai_nummul(a,b) ((a)*(b))
541 | #define luai_numdiv(a,b) ((a)/(b))
542 | #define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
543 | #define luai_numpow(a,b) (pow(a,b))
544 | #define luai_numunm(a) (-(a))
545 | #define luai_numeq(a,b) ((a)==(b))
546 | #define luai_numlt(a,b) ((a)<(b))
547 | #define luai_numle(a,b) ((a)<=(b))
548 | #define luai_numisnan(a) (!luai_numeq((a), (a)))
549 | #endif
550 |
551 |
552 | /*
553 | @@ lua_number2int is a macro to convert lua_Number to int.
554 | @@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
555 | ** CHANGE them if you know a faster way to convert a lua_Number to
556 | ** int (with any rounding method and without throwing errors) in your
557 | ** system. In Pentium machines, a naive typecast from double to int
558 | ** in C is extremely slow, so any alternative is worth trying.
559 | */
560 |
561 | /* On a Pentium, resort to a trick */
562 | #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
563 | (defined(__i386) || defined (_M_IX86) || defined(__i386__))
564 |
565 | /* On a Microsoft compiler, use assembler */
566 | #if defined(_MSC_VER)
567 |
568 | #define lua_number2int(i,d) __asm fld d __asm fistp i
569 | #define lua_number2integer(i,n) lua_number2int(i, n)
570 |
571 | /* the next trick should work on any Pentium, but sometimes clashes
572 | with a DirectX idiosyncrasy */
573 | #else
574 |
575 | union luai_Cast { double l_d; long l_l; };
576 | #define lua_number2int(i,d) \
577 | { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
578 | #define lua_number2integer(i,n) lua_number2int(i, n)
579 |
580 | #endif
581 |
582 |
583 | /* this option always works, but may be slow */
584 | #else
585 | #define lua_number2int(i,d) ((i)=(int)(d))
586 | #define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
587 |
588 | #endif
589 |
590 | /* }================================================================== */
591 |
592 |
593 | /*
594 | @@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
595 | ** CHANGE it if your system requires alignments larger than double. (For
596 | ** instance, if your system supports long doubles and they must be
597 | ** aligned in 16-byte boundaries, then you should add long double in the
598 | ** union.) Probably you do not need to change this.
599 | */
600 | #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
601 |
602 |
603 | /*
604 | @@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
605 | ** CHANGE them if you prefer to use longjmp/setjmp even with C++
606 | ** or if want/don't to use _longjmp/_setjmp instead of regular
607 | ** longjmp/setjmp. By default, Lua handles errors with exceptions when
608 | ** compiling as C++ code, with _longjmp/_setjmp when asked to use them,
609 | ** and with longjmp/setjmp otherwise.
610 | */
611 | #if defined(__cplusplus)
612 | /* C++ exceptions */
613 | #define LUAI_THROW(L,c) throw(c)
614 | #define LUAI_TRY(L,c,a) try { a } catch(...) \
615 | { if ((c)->status == 0) (c)->status = -1; }
616 | #define luai_jmpbuf int /* dummy variable */
617 |
618 | #elif defined(LUA_USE_ULONGJMP)
619 | /* in Unix, try _longjmp/_setjmp (more efficient) */
620 | #define LUAI_THROW(L,c) _longjmp((c)->b, 1)
621 | #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
622 | #define luai_jmpbuf jmp_buf
623 |
624 | #else
625 | /* default handling with long jumps */
626 | #define LUAI_THROW(L,c) longjmp((c)->b, 1)
627 | #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
628 | #define luai_jmpbuf jmp_buf
629 |
630 | #endif
631 |
632 |
633 | /*
634 | @@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
635 | @* can do during pattern-matching.
636 | ** CHANGE it if you need more captures. This limit is arbitrary.
637 | */
638 | #define LUA_MAXCAPTURES 32
639 |
640 |
641 | /*
642 | @@ lua_tmpnam is the function that the OS library uses to create a
643 | @* temporary name.
644 | @@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
645 | ** CHANGE them if you have an alternative to tmpnam (which is considered
646 | ** insecure) or if you want the original tmpnam anyway. By default, Lua
647 | ** uses tmpnam except when POSIX is available, where it uses mkstemp.
648 | */
649 | #if defined(loslib_c) || defined(luaall_c)
650 |
651 | #if defined(LUA_USE_MKSTEMP)
652 | #include
653 | #define LUA_TMPNAMBUFSIZE 32
654 | #define lua_tmpnam(b,e) { \
655 | strcpy(b, "/tmp/lua_XXXXXX"); \
656 | e = mkstemp(b); \
657 | if (e != -1) close(e); \
658 | e = (e == -1); }
659 |
660 | #else
661 | #define LUA_TMPNAMBUFSIZE L_tmpnam
662 | #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
663 | #endif
664 |
665 | #endif
666 |
667 |
668 | /*
669 | @@ lua_popen spawns a new process connected to the current one through
670 | @* the file streams.
671 | ** CHANGE it if you have a way to implement it in your system.
672 | */
673 | #if defined(LUA_USE_POPEN)
674 |
675 | #define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
676 | #define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
677 |
678 | #elif defined(LUA_WIN)
679 |
680 | #define lua_popen(L,c,m) ((void)L, _popen(c,m))
681 | #define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
682 |
683 | #else
684 |
685 | #define lua_popen(L,c,m) ((void)((void)c, m), \
686 | luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
687 | #define lua_pclose(L,file) ((void)((void)L, file), 0)
688 |
689 | #endif
690 |
691 | /*
692 | @@ LUA_DL_* define which dynamic-library system Lua should use.
693 | ** CHANGE here if Lua has problems choosing the appropriate
694 | ** dynamic-library system for your platform (either Windows' DLL, Mac's
695 | ** dyld, or Unix's dlopen). If your system is some kind of Unix, there
696 | ** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
697 | ** it. To use dlopen you also need to adapt the src/Makefile (probably
698 | ** adding -ldl to the linker options), so Lua does not select it
699 | ** automatically. (When you change the makefile to add -ldl, you must
700 | ** also add -DLUA_USE_DLOPEN.)
701 | ** If you do not want any kind of dynamic library, undefine all these
702 | ** options.
703 | ** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
704 | */
705 | #if defined(LUA_USE_DLOPEN)
706 | #define LUA_DL_DLOPEN
707 | #endif
708 |
709 | #if defined(LUA_WIN)
710 | #define LUA_DL_DLL
711 | #endif
712 |
713 |
714 | /*
715 | @@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
716 | @* (the data goes just *before* the lua_State pointer).
717 | ** CHANGE (define) this if you really need that. This value must be
718 | ** a multiple of the maximum alignment required for your machine.
719 | */
720 | #define LUAI_EXTRASPACE 0
721 |
722 |
723 | /*
724 | @@ luai_userstate* allow user-specific actions on threads.
725 | ** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
726 | ** extra when a thread is created/deleted/resumed/yielded.
727 | */
728 | #define luai_userstateopen(L) ((void)L)
729 | #define luai_userstateclose(L) ((void)L)
730 | #define luai_userstatethread(L,L1) ((void)L)
731 | #define luai_userstatefree(L) ((void)L)
732 | #define luai_userstateresume(L,n) ((void)L)
733 | #define luai_userstateyield(L,n) ((void)L)
734 |
735 |
736 | /*
737 | @@ LUA_INTFRMLEN is the length modifier for integer conversions
738 | @* in 'string.format'.
739 | @@ LUA_INTFRM_T is the integer type correspoding to the previous length
740 | @* modifier.
741 | ** CHANGE them if your system supports long long or does not support long.
742 | */
743 |
744 | #if defined(LUA_USELONGLONG)
745 |
746 | #define LUA_INTFRMLEN "ll"
747 | #define LUA_INTFRM_T long long
748 |
749 | #else
750 |
751 | #define LUA_INTFRMLEN "l"
752 | #define LUA_INTFRM_T long
753 |
754 | #endif
755 |
756 |
757 |
758 | /* =================================================================== */
759 |
760 | /*
761 | ** Local configuration. You can use this space to add your redefinitions
762 | ** without modifying the main part of the file.
763 | */
764 |
765 |
766 |
767 | #endif
768 |
769 |
--------------------------------------------------------------------------------
/module/include/lualib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Lua standard libraries
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #ifndef lualib_h
9 | #define lualib_h
10 |
11 | #include "lua.h"
12 |
13 |
14 | /* Key to file-handle type */
15 | #define LUA_FILEHANDLE "FILE*"
16 |
17 |
18 | #define LUA_COLIBNAME "coroutine"
19 | LUALIB_API int (luaopen_base) (lua_State *L);
20 |
21 | #define LUA_TABLIBNAME "table"
22 | LUALIB_API int (luaopen_table) (lua_State *L);
23 |
24 | #define LUA_IOLIBNAME "io"
25 | LUALIB_API int (luaopen_io) (lua_State *L);
26 |
27 | #define LUA_OSLIBNAME "os"
28 | LUALIB_API int (luaopen_os) (lua_State *L);
29 |
30 | #define LUA_STRLIBNAME "string"
31 | LUALIB_API int (luaopen_string) (lua_State *L);
32 |
33 | #define LUA_MATHLIBNAME "math"
34 | LUALIB_API int (luaopen_math) (lua_State *L);
35 |
36 | #define LUA_DBLIBNAME "debug"
37 | LUALIB_API int (luaopen_debug) (lua_State *L);
38 |
39 | #define LUA_LOADLIBNAME "package"
40 | LUALIB_API int (luaopen_package) (lua_State *L);
41 |
42 |
43 | /* open all previous libraries */
44 | LUALIB_API void (luaL_openlibs) (lua_State *L);
45 |
46 | /* Additional luautf8 library */
47 | LUALIB_API int luaopen_utf8(lua_State *L);
48 |
49 | #ifndef lua_assert
50 | #define lua_assert(x) ((void)0)
51 | #endif
52 |
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/module/lib/lua5.1.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/module/lib/lua5.1.lib
--------------------------------------------------------------------------------
/module/lib/lua5.1_64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/module/lib/lua5.1_64.lib
--------------------------------------------------------------------------------
/module/luaimports/luaimports.linux.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2008, Alberto Alonso
3 | *
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without modification,
7 | * are permitted provided that the following conditions are met:
8 | *
9 | * * Redistributions of source code must retain the above copyright notice, this
10 | * list of conditions and the following disclaimer.
11 | * * Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or other
13 | * materials provided with the distribution.
14 | * * Neither the name of the mta-mysql nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior
16 | * written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #include
31 | #include
32 | #include "ILuaModuleManager.h"
33 | #include "lauxlib.h"
34 | #include "luaconf.h"
35 | #include "lua.h"
36 | #include "lualib.h"
37 |
38 | /* This file extracts the lua function addresses from the server core to avoid lua gc crashes */
39 |
40 | extern ILuaModuleManager* pModuleManager;
41 |
42 | /*
43 | ** state manipulation
44 | */
45 | static void* plua_newstate = 0;
46 | static void* plua_close = 0;
47 | static void* plua_newthread = 0;
48 | static void* plua_atpanic = 0;
49 |
50 | /*
51 | ** basic stack manipulation
52 | */
53 | static void* plua_gettop = 0;
54 | static void* plua_settop = 0;
55 | static void* plua_pushvalue = 0;
56 | static void* plua_remove = 0;
57 | static void* plua_insert = 0;
58 | static void* plua_replace = 0;
59 | static void* plua_checkstack = 0;
60 | static void* plua_xmove = 0;
61 |
62 | /*
63 | ** access functions (stack -> C)
64 | */
65 | static void* plua_isnumber = 0;
66 | static void* plua_isstring = 0;
67 | static void* plua_iscfunction = 0;
68 | static void* plua_isuserdata = 0;
69 | static void* plua_type = 0;
70 | static void* plua_typename = 0;
71 | static void* plua_equal = 0;
72 | static void* plua_rawequal = 0;
73 | static void* plua_lessthan = 0;
74 | static void* plua_tonumber = 0;
75 | static void* plua_tointeger = 0;
76 | static void* plua_toboolean = 0;
77 | static void* plua_tolstring = 0;
78 | static void* plua_objlen = 0;
79 | static void* plua_tocfunction = 0;
80 | static void* plua_touserdata = 0;
81 | static void* plua_tothread = 0;
82 | static void* plua_topointer = 0;
83 |
84 | /*
85 | ** push functions (C -> stack)
86 | */
87 | static void* plua_pushnil = 0;
88 | static void* plua_pushnumber = 0;
89 | static void* plua_pushinteger = 0;
90 | static void* plua_pushlstring = 0;
91 | static void* plua_pushstring = 0;
92 | static void* plua_pushvfstring = 0;
93 | static void* plua_pushfstring = 0;
94 | static void* plua_pushcclosure = 0;
95 | static void* plua_pushboolean = 0;
96 | static void* plua_pushlightuserdata = 0;
97 | static void* plua_pushthread = 0;
98 |
99 | /*
100 | ** get functions (Lua -> stack)
101 | */
102 | static void* plua_gettable = 0;
103 | static void* plua_getfield = 0;
104 | static void* plua_rawget = 0;
105 | static void* plua_rawgeti = 0;
106 | static void* plua_createtable = 0;
107 | static void* plua_newuserdata = 0;
108 | static void* plua_getmetatable = 0;
109 | static void* plua_getfenv = 0;
110 |
111 | /*
112 | ** set functions (stack -> Lua)
113 | */
114 | static void* plua_settable = 0;
115 | static void* plua_setfield = 0;
116 | static void* plua_rawset = 0;
117 | static void* plua_rawseti = 0;
118 | static void* plua_setmetatable = 0;
119 | static void* plua_setfenv = 0;
120 |
121 | /*
122 | ** `load' and `call' functions (load and run Lua code)
123 | */
124 | static void* plua_call = 0;
125 | static void* plua_pcall = 0;
126 | static void* plua_cpcall = 0;
127 | static void* plua_load = 0;
128 | static void* plua_dump = 0;
129 |
130 | /*
131 | ** coroutine functions
132 | */
133 | static void* plua_yield = 0;
134 | static void* plua_resume = 0;
135 | static void* plua_status = 0;
136 |
137 | /*
138 | ** garbage-collection function and options
139 | */
140 | static void* plua_gc = 0;
141 |
142 |
143 | /*
144 | ** miscellaneous functions
145 | */
146 | static void* plua_error = 0;
147 | static void* plua_next = 0;
148 | static void* plua_concat = 0;
149 | static void* plua_getallocf = 0;
150 | static void* plua_setallocf = 0;
151 |
152 | /* Functions to be called by the debuger in specific events */
153 | static void* plua_getstack = 0;
154 | static void* plua_getinfo = 0;
155 | static void* plua_getlocal = 0;
156 | static void* plua_setlocal = 0;
157 | static void* plua_getupvalue = 0;
158 | static void* plua_setupvalue = 0;
159 | static void* plua_sethook = 0;
160 | static void* plua_gethook = 0;
161 | static void* plua_gethookmask = 0;
162 | static void* plua_gethookcount = 0;
163 |
164 | /*
165 | ** Lua auxlib
166 | */
167 | #if defined(LUA_COMPAT_GETN)
168 | static void* pluaL_getn = 0;
169 | static void* pluaL_setn = 0;
170 | #endif
171 | static void* pluaL_register = 0;
172 | static void* pluaL_getmetafield = 0;
173 | static void* pluaL_callmeta = 0;
174 | static void* pluaL_typerror = 0;
175 | static void* pluaL_argerror = 0;
176 | static void* pluaL_checklstring = 0;
177 | static void* pluaL_optlstring = 0;
178 | static void* pluaL_checknumber = 0;
179 | static void* pluaL_optnumber = 0;
180 | static void* pluaL_checkinteger = 0;
181 | static void* pluaL_optinteger = 0;
182 | static void* pluaL_checkstack = 0;
183 | static void* pluaL_checktype = 0;
184 | static void* pluaL_checkany = 0;
185 | static void* pluaL_newmetatable = 0;
186 | static void* pluaL_checkudata = 0;
187 | static void* pluaL_where = 0;
188 | static void* pluaL_error = 0;
189 | static void* pluaL_checkoption = 0;
190 | static void* pluaL_ref = 0;
191 | static void* pluaL_unref = 0;
192 | static void* pluaL_loadfile = 0;
193 | static void* pluaL_loadbuffer = 0;
194 | static void* pluaL_loadstring = 0;
195 | static void* pluaL_newstate = 0;
196 | static void* pluaL_gsub = 0;
197 | static void* pluaL_findtable = 0;
198 | static void* pluaL_buffinit = 0;
199 | static void* pluaL_prepbuffer = 0;
200 | static void* pluaL_addlstring = 0;
201 | static void* pluaL_addstring = 0;
202 | static void* pluaL_addvalue = 0;
203 | static void* pluaL_pushresult = 0;
204 | static void* plua_getmainstate = 0;
205 |
206 |
207 | #define SAFE_IMPORT(x) \
208 | p ## x = dlsym(dl, #x); \
209 | if (p ## x == 0) \
210 | { \
211 | pModuleManager->Printf("Unable to import " #x ": %s\n", dlerror()); \
212 | return false; \
213 | }
214 |
215 | #ifdef __cplusplus
216 | extern "C"
217 | #endif
218 | bool ImportLua()
219 | {
220 | #ifdef __x86_64
221 | void* dl = dlopen("x64/deathmatch.so", RTLD_NOW | RTLD_NOLOAD);
222 | #else
223 | void* dl = dlopen("mods/deathmatch/deathmatch.so", RTLD_NOW | RTLD_NOLOAD);
224 | #endif
225 | if (!dl)
226 | {
227 | pModuleManager->ErrorPrintf("Unable to open deathmatch.so: %s\n", dlerror());
228 | return false;
229 | }
230 |
231 | /*
232 | ** state manipulation
233 | */
234 | SAFE_IMPORT(lua_newstate);
235 | SAFE_IMPORT(lua_close);
236 | SAFE_IMPORT(lua_newthread);
237 | SAFE_IMPORT(lua_atpanic);
238 |
239 | /*
240 | ** basic stack manipulation
241 | */
242 | SAFE_IMPORT(lua_gettop);
243 | SAFE_IMPORT(lua_settop);
244 | SAFE_IMPORT(lua_pushvalue);
245 | SAFE_IMPORT(lua_remove);
246 | SAFE_IMPORT(lua_insert);
247 | SAFE_IMPORT(lua_replace);
248 | SAFE_IMPORT(lua_checkstack);
249 | SAFE_IMPORT(lua_xmove);
250 |
251 | /*
252 | ** access functions (stack -> C)
253 | */
254 | SAFE_IMPORT(lua_isnumber);
255 | SAFE_IMPORT(lua_isstring);
256 | SAFE_IMPORT(lua_iscfunction);
257 | SAFE_IMPORT(lua_isuserdata);
258 | SAFE_IMPORT(lua_type);
259 | SAFE_IMPORT(lua_typename);
260 | SAFE_IMPORT(lua_equal);
261 | SAFE_IMPORT(lua_rawequal);
262 | SAFE_IMPORT(lua_lessthan);
263 | SAFE_IMPORT(lua_tonumber);
264 | SAFE_IMPORT(lua_tointeger);
265 | SAFE_IMPORT(lua_toboolean);
266 | SAFE_IMPORT(lua_tolstring);
267 | SAFE_IMPORT(lua_objlen);
268 | SAFE_IMPORT(lua_tocfunction);
269 | SAFE_IMPORT(lua_touserdata);
270 | SAFE_IMPORT(lua_tothread);
271 | SAFE_IMPORT(lua_topointer);
272 |
273 | /*
274 | ** push functions (C -> stack)
275 | */
276 | SAFE_IMPORT(lua_pushnil);
277 | SAFE_IMPORT(lua_pushnumber);
278 | SAFE_IMPORT(lua_pushinteger);
279 | SAFE_IMPORT(lua_pushlstring);
280 | SAFE_IMPORT(lua_pushstring);
281 | SAFE_IMPORT(lua_pushvfstring);
282 | SAFE_IMPORT(lua_pushfstring);
283 | SAFE_IMPORT(lua_pushcclosure);
284 | SAFE_IMPORT(lua_pushboolean);
285 | SAFE_IMPORT(lua_pushlightuserdata);
286 | SAFE_IMPORT(lua_pushthread);
287 |
288 | /*
289 | ** get functions (Lua -> stack)
290 | */
291 | SAFE_IMPORT(lua_gettable);
292 | SAFE_IMPORT(lua_getfield);
293 | SAFE_IMPORT(lua_rawget);
294 | SAFE_IMPORT(lua_rawgeti);
295 | SAFE_IMPORT(lua_createtable);
296 | SAFE_IMPORT(lua_newuserdata);
297 | SAFE_IMPORT(lua_getmetatable);
298 | SAFE_IMPORT(lua_getfenv);
299 |
300 | /*
301 | ** set functions (stack -> Lua)
302 | */
303 | SAFE_IMPORT(lua_settable);
304 | SAFE_IMPORT(lua_setfield);
305 | SAFE_IMPORT(lua_rawset);
306 | SAFE_IMPORT(lua_rawseti);
307 | SAFE_IMPORT(lua_setmetatable);
308 | SAFE_IMPORT(lua_setfenv);
309 |
310 | /*
311 | ** `load' and `call' functions (load and run Lua code)
312 | */
313 | SAFE_IMPORT(lua_call);
314 | SAFE_IMPORT(lua_pcall);
315 | SAFE_IMPORT(lua_cpcall);
316 | SAFE_IMPORT(lua_load);
317 | SAFE_IMPORT(lua_dump);
318 |
319 | /*
320 | ** coroutine functions
321 | */
322 | SAFE_IMPORT(lua_yield);
323 | SAFE_IMPORT(lua_resume);
324 | SAFE_IMPORT(lua_status);
325 |
326 | /*
327 | ** garbage-collection function and options
328 | */
329 | SAFE_IMPORT(lua_gc);
330 |
331 |
332 | /*
333 | ** miscellaneous functions
334 | */
335 | SAFE_IMPORT(lua_error);
336 | SAFE_IMPORT(lua_next);
337 | SAFE_IMPORT(lua_concat);
338 | SAFE_IMPORT(lua_getallocf);
339 | SAFE_IMPORT(lua_setallocf);
340 |
341 | /* Functions to be called by the debuger in specific events */
342 | SAFE_IMPORT(lua_getstack);
343 | SAFE_IMPORT(lua_getinfo);
344 | SAFE_IMPORT(lua_getlocal);
345 | SAFE_IMPORT(lua_setlocal);
346 | SAFE_IMPORT(lua_getupvalue);
347 | SAFE_IMPORT(lua_setupvalue);
348 | SAFE_IMPORT(lua_sethook);
349 | SAFE_IMPORT(lua_gethook);
350 | SAFE_IMPORT(lua_gethookmask);
351 | SAFE_IMPORT(lua_gethookcount);
352 |
353 | /*
354 | ** Lua auxlib
355 | */
356 | #if defined(LUA_COMPAT_GETN)
357 | SAFE_IMPORT(luaL_getn);
358 | SAFE_IMPORT(luaL_setn);
359 | #endif
360 | SAFE_IMPORT(luaL_register);
361 | SAFE_IMPORT(luaL_getmetafield);
362 | SAFE_IMPORT(luaL_callmeta);
363 | SAFE_IMPORT(luaL_typerror);
364 | SAFE_IMPORT(luaL_argerror);
365 | SAFE_IMPORT(luaL_checklstring);
366 | SAFE_IMPORT(luaL_optlstring);
367 | SAFE_IMPORT(luaL_checknumber);
368 | SAFE_IMPORT(luaL_optnumber);
369 | SAFE_IMPORT(luaL_checkinteger);
370 | SAFE_IMPORT(luaL_optinteger);
371 | SAFE_IMPORT(luaL_checkstack);
372 | SAFE_IMPORT(luaL_checktype);
373 | SAFE_IMPORT(luaL_checkany);
374 | SAFE_IMPORT(luaL_newmetatable);
375 | SAFE_IMPORT(luaL_checkudata);
376 | SAFE_IMPORT(luaL_where);
377 | SAFE_IMPORT(luaL_error);
378 | SAFE_IMPORT(luaL_checkoption);
379 | SAFE_IMPORT(luaL_ref);
380 | SAFE_IMPORT(luaL_unref);
381 | SAFE_IMPORT(luaL_loadfile);
382 | SAFE_IMPORT(luaL_loadbuffer);
383 | SAFE_IMPORT(luaL_loadstring);
384 | SAFE_IMPORT(luaL_newstate);
385 | SAFE_IMPORT(luaL_gsub);
386 | SAFE_IMPORT(luaL_findtable);
387 | SAFE_IMPORT(luaL_buffinit);
388 | SAFE_IMPORT(luaL_prepbuffer);
389 | SAFE_IMPORT(luaL_addlstring);
390 | SAFE_IMPORT(luaL_addstring);
391 | SAFE_IMPORT(luaL_addvalue);
392 | SAFE_IMPORT(luaL_pushresult);
393 |
394 | SAFE_IMPORT(lua_getmainstate);
395 |
396 | return true;
397 | }
398 | #undef SAFE_IMPORT
399 |
400 | /** typedefs **/
401 |
402 | /*
403 | ** state manipulation
404 | */
405 | typedef lua_State *(*lua_newstate_t)(lua_Alloc f, void *ud);
406 | typedef void (*lua_close_t)(lua_State *ls);
407 | typedef lua_State *(*lua_newthread_t)(lua_State *ls);
408 |
409 | typedef lua_CFunction (*lua_atpanic_t)(lua_State *ls, lua_CFunction panicf);
410 |
411 |
412 | /*
413 | ** basic stack manipulation
414 | */
415 | typedef int (*lua_gettop_t)(lua_State *ls);
416 | typedef void (*lua_settop_t)(lua_State *ls, int idx);
417 | typedef void (*lua_pushvalue_t)(lua_State *ls, int idx);
418 | typedef void (*lua_remove_t)(lua_State *ls, int idx);
419 | typedef void (*lua_insert_t)(lua_State *ls, int idx);
420 | typedef void (*lua_replace_t)(lua_State *ls, int idx);
421 | typedef int (*lua_checkstack_t)(lua_State *ls, int sz);
422 |
423 | typedef void (*lua_xmove_t)(lua_State *from, lua_State *to, int n);
424 |
425 | /*
426 | ** access functions (stack -> C)
427 | */
428 |
429 | typedef int (*lua_isnumber_t)(lua_State *ls, int idx);
430 | typedef int (*lua_isstring_t)(lua_State *ls, int idx);
431 | typedef int (*lua_iscfunction_t)(lua_State *ls, int idx);
432 | typedef int (*lua_isuserdata_t)(lua_State *ls, int idx);
433 | typedef int (*lua_type_t)(lua_State *ls, int idx);
434 | typedef const char *(*lua_typename_t)(lua_State *ls, int tp);
435 |
436 | typedef int (*lua_equal_t)(lua_State *ls, int idx1, int idx2);
437 | typedef int (*lua_rawequal_t)(lua_State *ls, int idx1, int idx2);
438 | typedef int (*lua_lessthan_t)(lua_State *ls, int idx1, int idx2);
439 |
440 | typedef lua_Number (*lua_tonumber_t)(lua_State *ls, int idx);
441 | typedef lua_Integer (*lua_tointeger_t)(lua_State *ls, int idx);
442 | typedef int (*lua_toboolean_t)(lua_State *ls, int idx);
443 | typedef const char *(*lua_tolstring_t)(lua_State *ls, int idx, size_t *len);
444 | typedef size_t (*lua_objlen_t)(lua_State *ls, int idx);
445 | typedef lua_CFunction (*lua_tocfunction_t)(lua_State *ls, int idx);
446 | typedef void *(*lua_touserdata_t)(lua_State *ls, int idx);
447 | typedef lua_State *(*lua_tothread_t)(lua_State *ls, int idx);
448 | typedef const void *(*lua_topointer_t)(lua_State *ls, int idx);
449 |
450 |
451 | /*
452 | ** push functions (C -> stack)
453 | */
454 | typedef void (*lua_pushnil_t)(lua_State *ls);
455 | typedef void (*lua_pushnumber_t)(lua_State *ls, lua_Number n);
456 | typedef void (*lua_pushinteger_t)(lua_State *ls, lua_Integer n);
457 | typedef void (*lua_pushlstring_t)(lua_State *ls, const char *s, size_t l);
458 | typedef void (*lua_pushstring_t)(lua_State *ls, const char *s);
459 | typedef const char *(*lua_pushvfstring_t) (lua_State *ls, const char *fmt, va_list argp);
460 | typedef const char *(*lua_pushfstring_t)(lua_State *ls, const char *fmt, ...);
461 | typedef void (*lua_pushcclosure_t)(lua_State *ls, lua_CFunction fn, int n);
462 | typedef void (*lua_pushboolean_t)(lua_State *ls, int b);
463 | typedef void (*lua_pushlightuserdata_t)(lua_State *ls, void *p);
464 | typedef int (*lua_pushthread_t)(lua_State *ls);
465 |
466 |
467 | /*
468 | ** get functions (Lua -> stack)
469 | */
470 | typedef void (*lua_gettable_t)(lua_State *ls, int idx);
471 | typedef void (*lua_getfield_t)(lua_State *ls, int idx, const char *k);
472 | typedef void (*lua_rawget_t)(lua_State *ls, int idx);
473 | typedef void (*lua_rawgeti_t)(lua_State *ls, int idx, int n);
474 | typedef void (*lua_createtable_t)(lua_State *ls, int narr, int nrec);
475 | typedef void *(*lua_newuserdata_t)(lua_State *ls, size_t sz);
476 | typedef int (*lua_getmetatable_t)(lua_State *ls, int objindex);
477 | typedef void (*lua_getfenv_t)(lua_State *ls, int idx);
478 |
479 | /*
480 | ** set functions (stack -> Lua)
481 | */
482 | typedef void (*lua_settable_t)(lua_State *ls, int idx);
483 | typedef void (*lua_setfield_t)(lua_State *ls, int idx, const char *k);
484 | typedef void (*lua_rawset_t)(lua_State *ls, int idx);
485 | typedef void (*lua_rawseti_t)(lua_State *ls, int idx, int n);
486 | typedef int (*lua_setmetatable_t)(lua_State *ls, int objindex);
487 | typedef int (*lua_setfenv_t)(lua_State *ls, int idx);
488 |
489 |
490 | /*
491 | ** `load' and `call' functions (load and run Lua code)
492 | */
493 | typedef void (*lua_call_t)(lua_State *ls, int nargs, int nresults);
494 | typedef int (*lua_pcall_t)(lua_State *ls, int nargs, int nresults, int errfunc);
495 | typedef int (*lua_cpcall_t)(lua_State *ls, lua_CFunction func, void *ud);
496 | typedef int (*lua_load_t) (lua_State *ls, lua_Reader reader, void *dt, const char *chunkname);
497 | typedef int (*lua_dump_t)(lua_State *ls, lua_Writer writer, void *data);
498 |
499 |
500 | /*
501 | ** coroutine functions
502 | */
503 | typedef int (*lua_yield_t)(lua_State *ls, int nresults);
504 | typedef int (*lua_resume_t)(lua_State *ls, int narg);
505 | typedef int (*lua_status_t)(lua_State *ls);
506 |
507 | /*
508 | ** garbage-collection function and options
509 | */
510 | typedef int (*lua_gc_t)(lua_State *ls, int what, int data);
511 |
512 | /*
513 | ** miscellaneous functions
514 | */
515 | typedef int (*lua_error_t)(lua_State *ls);
516 | typedef int (*lua_next_t)(lua_State *ls, int idx);
517 | typedef void (*lua_concat_t)(lua_State *ls, int n);
518 | typedef lua_Alloc (*lua_getallocf_t) (lua_State *ls, void **ud);
519 | typedef void (*lua_setallocf_t) (lua_State *ls, lua_Alloc f, void *ud);
520 |
521 | /* Functions to be called by the debuger in specific events */
522 | typedef int (*lua_getstack_t) (lua_State *ls, int level, lua_Debug *ar);
523 | typedef int (*lua_getinfo_t) (lua_State *ls, const char *what, lua_Debug *ar);
524 | typedef const char *(*lua_getlocal_t) (lua_State *ls, const lua_Debug *ar, int n);
525 | typedef const char *(*lua_setlocal_t) (lua_State *ls, const lua_Debug *ar, int n);
526 | typedef const char *(*lua_getupvalue_t) (lua_State *ls, int funcindex, int n);
527 | typedef const char *(*lua_setupvalue_t) (lua_State *ls, int funcindex, int n);
528 |
529 | typedef int (*lua_sethook_t) (lua_State *ls, lua_Hook func, int mask, int count);
530 | typedef lua_Hook (*lua_gethook_t) (lua_State *ls);
531 | typedef int (*lua_gethookmask_t) (lua_State *ls);
532 | typedef int (*lua_gethookcount_t) (lua_State *ls);
533 |
534 | /*
535 | ** Lua auxlib
536 | */
537 | #if defined(LUA_COMPAT_GETN)
538 | typedef int (*luaL_getn_t) (lua_State *ls, int t);
539 | typedef void (*luaL_setn_t) (lua_State *ls, int t, int n);
540 | #endif
541 | typedef void (*luaL_register_t)(lua_State *ls, const char *libname, const luaL_Reg *l);
542 | typedef int (*luaL_getmetafield_t)(lua_State *ls, int obj, const char *e);
543 | typedef int (*luaL_callmeta_t)(lua_State *ls, int obj, const char *e);
544 | typedef int (*luaL_typerror_t)(lua_State *ls, int narg, const char *tname);
545 | typedef int (*luaL_argerror_t)(lua_State *ls, int numarg, const char *extramsg);
546 | typedef const char *(*luaL_checklstring_t)(lua_State *ls, int numArg, size_t *l);
547 | typedef const char *(*luaL_optlstring_t)(lua_State *ls, int numArg, const char *def, size_t *l);
548 | typedef lua_Number (*luaL_checknumber_t)(lua_State *ls, int numArg);
549 | typedef lua_Number (*luaL_optnumber_t)(lua_State *ls, int nArg, lua_Number def);
550 |
551 | typedef lua_Integer (*luaL_checkinteger_t)(lua_State *ls, int numArg);
552 | typedef lua_Integer (*luaL_optinteger_t)(lua_State *ls, int nArg, lua_Integer def);
553 |
554 | typedef void (*luaL_checkstack_t)(lua_State *ls, int sz, const char *msg);
555 | typedef void (*luaL_checktype_t)(lua_State *ls, int narg, int t);
556 | typedef void (*luaL_checkany_t)(lua_State *ls, int narg);
557 |
558 | typedef int (*luaL_newmetatable_t)(lua_State *ls, const char *tname);
559 | typedef void *(*luaL_checkudata_t)(lua_State *ls, int ud, const char *tname);
560 |
561 | typedef void (*luaL_where_t)(lua_State *ls, int lvl);
562 | typedef int (*luaL_error_t)(lua_State *ls, const char *fmt, ...);
563 |
564 | typedef int (*luaL_checkoption_t)(lua_State *ls, int narg, const char *def, const char *const lst[]);
565 |
566 | typedef int (*luaL_ref_t)(lua_State *ls, int t);
567 | typedef void (*luaL_unref_t)(lua_State *ls, int t, int ref);
568 |
569 | typedef int (*luaL_loadfile_t)(lua_State *ls, const char *filename);
570 | typedef int (*luaL_loadbuffer_t)(lua_State *ls, const char *buff, size_t sz, const char *name);
571 | typedef int (*luaL_loadstring_t)(lua_State *ls, const char *s);
572 |
573 | typedef lua_State *(*luaL_newstate_t)(void);
574 |
575 | typedef const char *(*luaL_gsub_t)(lua_State *ls, const char *s, const char *p, const char *r);
576 |
577 | typedef const char *(*luaL_findtable_t)(lua_State *ls, int idx, const char *fname, int szhint);
578 | typedef void (*luaL_buffinit_t)(lua_State *ls, luaL_Buffer *B);
579 | typedef char *(*luaL_prepbuffer_t)(luaL_Buffer *B);
580 | typedef void (*luaL_addlstring_t)(luaL_Buffer *B, const char *s, size_t l);
581 | typedef void (*luaL_addstring_t)(luaL_Buffer *B, const char *s);
582 | typedef void (*luaL_addvalue_t)(luaL_Buffer *B);
583 | typedef void (*luaL_pushresult_t)(luaL_Buffer *B);
584 |
585 | typedef lua_State* (*lua_getmainstate_t)(lua_State* L);
586 |
587 |
588 | /** functions **/
589 |
590 | #ifdef __cplusplus
591 | extern "C" {
592 | #endif
593 |
594 | /*
595 | ** state manipulation
596 | */
597 | #define LRET(f, ...) return ((f ## _t)p ## f)(__VA_ARGS__)
598 | #define LCALL(f, ...) ((f ## _t)p ## f)(__VA_ARGS__)
599 | lua_State *(lua_newstate) (lua_Alloc f, void *ud)
600 | {
601 | LRET(lua_newstate, f, ud);
602 | }
603 |
604 | void (lua_close) (lua_State *ls)
605 | {
606 | LRET(lua_close, ls);
607 | }
608 |
609 | lua_State *(lua_newthread) (lua_State *ls)
610 | {
611 | LRET(lua_newthread, ls);
612 | }
613 |
614 |
615 | lua_CFunction (lua_atpanic) (lua_State *ls, lua_CFunction panicf)
616 | {
617 | LRET(lua_atpanic, ls, panicf);
618 | }
619 |
620 |
621 |
622 | /*
623 | ** basic stack manipulation
624 | */
625 | int (lua_gettop) (lua_State *ls)
626 | {
627 | LRET(lua_gettop, ls);
628 | }
629 |
630 | void (lua_settop) (lua_State *ls, int idx)
631 | {
632 | LCALL(lua_settop, ls, idx);
633 | }
634 |
635 | void (lua_pushvalue) (lua_State *ls, int idx)
636 | {
637 | LCALL(lua_pushvalue, ls, idx);
638 | }
639 |
640 | void (lua_remove) (lua_State *ls, int idx)
641 | {
642 | LCALL(lua_remove, ls, idx);
643 | }
644 |
645 | void (lua_insert) (lua_State *ls, int idx)
646 | {
647 | LCALL(lua_insert, ls, idx);
648 | }
649 |
650 | void (lua_replace) (lua_State *ls, int idx)
651 | {
652 | LCALL(lua_replace, ls, idx);
653 | }
654 |
655 | int (lua_checkstack) (lua_State *ls, int sz)
656 | {
657 | LRET(lua_checkstack, ls, sz);
658 | }
659 |
660 |
661 | void (lua_xmove) (lua_State *from, lua_State *to, int n)
662 | {
663 | LCALL(lua_xmove, from, to, n);
664 | }
665 |
666 |
667 | /*
668 | ** access functions (stack -> C)
669 | */
670 |
671 | int (lua_isnumber) (lua_State *ls, int idx)
672 | {
673 | LRET(lua_isnumber, ls, idx);
674 | }
675 |
676 | int (lua_isstring) (lua_State *ls, int idx)
677 | {
678 | LRET(lua_isstring, ls, idx);
679 | }
680 |
681 | int (lua_iscfunction) (lua_State *ls, int idx)
682 | {
683 | LRET(lua_iscfunction, ls, idx);
684 | }
685 |
686 | int (lua_isuserdata) (lua_State *ls, int idx)
687 | {
688 | LRET(lua_isuserdata, ls, idx);
689 | }
690 |
691 | int (lua_type) (lua_State *ls, int idx)
692 | {
693 | LRET(lua_type, ls, idx);
694 | }
695 |
696 | const char *(lua_typename) (lua_State *ls, int tp)
697 | {
698 | LRET(lua_typename, ls, tp);
699 | }
700 |
701 |
702 | int (lua_equal) (lua_State *ls, int idx1, int idx2)
703 | {
704 | LRET(lua_equal, ls, idx1, idx2);
705 | }
706 |
707 | int (lua_rawequal) (lua_State *ls, int idx1, int idx2)
708 | {
709 | LRET(lua_rawequal, ls, idx1, idx2);
710 | }
711 |
712 | int (lua_lessthan) (lua_State *ls, int idx1, int idx2)
713 | {
714 | LRET(lua_lessthan, ls, idx1, idx2);
715 | }
716 |
717 |
718 | lua_Number (lua_tonumber) (lua_State *ls, int idx)
719 | {
720 | LRET(lua_tonumber, ls, idx);
721 | }
722 |
723 | lua_Integer (lua_tointeger) (lua_State *ls, int idx)
724 | {
725 | LRET(lua_tointeger, ls, idx);
726 | }
727 |
728 | int (lua_toboolean) (lua_State *ls, int idx)
729 | {
730 | LRET(lua_toboolean, ls, idx);
731 | }
732 |
733 | const char *(lua_tolstring) (lua_State *ls, int idx, size_t *len)
734 | {
735 | LRET(lua_tolstring, ls, idx, len);
736 | }
737 |
738 | size_t (lua_objlen) (lua_State *ls, int idx)
739 | {
740 | LRET(lua_objlen, ls, idx);
741 | }
742 |
743 | lua_CFunction (lua_tocfunction) (lua_State *ls, int idx)
744 | {
745 | LRET(lua_tocfunction, ls, idx);
746 | }
747 |
748 | void *(lua_touserdata) (lua_State *ls, int idx)
749 | {
750 | LRET(lua_touserdata, ls, idx);
751 | }
752 |
753 | lua_State *(lua_tothread) (lua_State *ls, int idx)
754 | {
755 | LRET(lua_tothread, ls, idx);
756 | }
757 |
758 | const void *(lua_topointer) (lua_State *ls, int idx)
759 | {
760 | LRET(lua_topointer, ls, idx);
761 | }
762 |
763 |
764 |
765 | /*
766 | ** push functions (C -> stack)
767 | */
768 | void (lua_pushnil) (lua_State *ls)
769 | {
770 | LCALL(lua_pushnil, ls);
771 | }
772 |
773 | void (lua_pushnumber) (lua_State *ls, lua_Number n)
774 | {
775 | LCALL(lua_pushnumber, ls, n);
776 | }
777 |
778 | void (lua_pushinteger) (lua_State *ls, lua_Integer n)
779 | {
780 | LCALL(lua_pushinteger, ls, n);
781 | }
782 |
783 | void (lua_pushlstring) (lua_State *ls, const char *s, size_t l)
784 | {
785 | LCALL(lua_pushlstring, ls, s, l);
786 | }
787 |
788 | void (lua_pushstring) (lua_State *ls, const char *s)
789 | {
790 | LCALL(lua_pushstring, ls, s);
791 | }
792 |
793 | const char *(lua_pushvfstring) (lua_State *ls, const char *fmt, va_list argp)
794 | {
795 | LRET(lua_pushvfstring, ls, fmt, argp);
796 | }
797 |
798 | const char *(lua_pushfstring) (lua_State *ls, const char *fmt, ...)
799 | {
800 | char buffer[1024];
801 | va_list vl;
802 |
803 | va_start(vl, fmt);
804 | vsnprintf(buffer, 1024, fmt, vl);
805 | va_end(vl);
806 |
807 | LRET(lua_pushfstring, ls, buffer);
808 | }
809 |
810 | void (lua_pushcclosure) (lua_State *ls, lua_CFunction fn, int n)
811 | {
812 | LCALL(lua_pushcclosure, ls, fn, n);
813 | }
814 |
815 | void (lua_pushboolean) (lua_State *ls, int b)
816 | {
817 | LCALL(lua_pushboolean, ls, b);
818 | }
819 |
820 | void (lua_pushlightuserdata) (lua_State *ls, void *p)
821 | {
822 | LCALL(lua_pushlightuserdata, ls, p);
823 | }
824 |
825 | int (lua_pushthread) (lua_State *ls)
826 | {
827 | LRET(lua_pushthread, ls);
828 | }
829 |
830 |
831 |
832 | /*
833 | ** get functions (Lua -> stack)
834 | */
835 | void (lua_gettable) (lua_State *ls, int idx)
836 | {
837 | LCALL(lua_gettable, ls, idx);
838 | }
839 |
840 | void (lua_getfield) (lua_State *ls, int idx, const char *k)
841 | {
842 | LCALL(lua_getfield, ls, idx, k);
843 | }
844 |
845 | void (lua_rawget) (lua_State *ls, int idx)
846 | {
847 | LCALL(lua_rawget, ls, idx);
848 | }
849 |
850 | void (lua_rawgeti) (lua_State *ls, int idx, int n)
851 | {
852 | LCALL(lua_rawgeti, ls, idx, n);
853 | }
854 |
855 | void (lua_createtable) (lua_State *ls, int narr, int nrec)
856 | {
857 | LCALL(lua_createtable, ls, narr, nrec);
858 | }
859 |
860 | void *(lua_newuserdata) (lua_State *ls, size_t sz)
861 | {
862 | LRET(lua_newuserdata, ls, sz);
863 | }
864 |
865 | int (lua_getmetatable) (lua_State *ls, int objindex)
866 | {
867 | LRET(lua_getmetatable, ls, objindex);
868 | }
869 |
870 | void (lua_getfenv) (lua_State *ls, int idx)
871 | {
872 | LCALL(lua_getfenv, ls, idx);
873 | }
874 |
875 |
876 | /*
877 | ** set functions (stack -> Lua)
878 | */
879 | void (lua_settable) (lua_State *ls, int idx)
880 | {
881 | LCALL(lua_settable, ls, idx);
882 | }
883 |
884 | void (lua_setfield) (lua_State *ls, int idx, const char *k)
885 | {
886 | LCALL(lua_setfield, ls, idx, k);
887 | }
888 |
889 | void (lua_rawset) (lua_State *ls, int idx)
890 | {
891 | LCALL(lua_rawset, ls, idx);
892 | }
893 |
894 | void (lua_rawseti) (lua_State *ls, int idx, int n)
895 | {
896 | LCALL(lua_rawseti, ls, idx, n);
897 | }
898 |
899 | int (lua_setmetatable) (lua_State *ls, int objindex)
900 | {
901 | LRET(lua_setmetatable, ls, objindex);
902 | }
903 |
904 | int (lua_setfenv) (lua_State *ls, int idx)
905 | {
906 | LRET(lua_setfenv, ls, idx);
907 | }
908 |
909 |
910 |
911 | /*
912 | ** `load' and `call' functions (load and run Lua code)
913 | */
914 | void (lua_call) (lua_State *ls, int nargs, int nresults)
915 | {
916 | LCALL(lua_call, ls, nargs, nresults);
917 | }
918 |
919 | int (lua_pcall) (lua_State *ls, int nargs, int nresults, int errfunc)
920 | {
921 | LRET(lua_pcall, ls, nargs, nresults, errfunc);
922 | }
923 |
924 | int (lua_cpcall) (lua_State *ls, lua_CFunction func, void *ud)
925 | {
926 | LRET(lua_cpcall, ls, func, ud);
927 | }
928 |
929 | int (lua_load) (lua_State *ls, lua_Reader reader, void *dt, const char *chunkname)
930 | {
931 | LRET(lua_load, ls, reader, dt, chunkname);
932 | }
933 |
934 | int (lua_dump) (lua_State *ls, lua_Writer writer, void *data)
935 | {
936 | LRET(lua_dump, ls, writer, data);
937 | }
938 |
939 |
940 |
941 | /*
942 | ** coroutine functions
943 | */
944 | int (lua_yield) (lua_State *ls, int nresults)
945 | {
946 | LRET(lua_yield, ls, nresults);
947 | }
948 |
949 | int (lua_resume) (lua_State *ls, int narg)
950 | {
951 | LRET(lua_resume, ls, narg);
952 | }
953 |
954 | int (lua_status) (lua_State *ls)
955 | {
956 | LRET(lua_status, ls);
957 | }
958 |
959 |
960 | /*
961 | ** garbage-collection function and options
962 | */
963 | int (lua_gc) (lua_State *ls, int what, int data)
964 | {
965 | LRET(lua_gc, ls, what, data);
966 | }
967 |
968 |
969 | /*
970 | ** miscellaneous functions
971 | */
972 |
973 | int (lua_error) (lua_State *ls)
974 | {
975 | LRET(lua_error, ls);
976 | }
977 |
978 |
979 | int (lua_next) (lua_State *ls, int idx)
980 | {
981 | LRET(lua_next, ls, idx);
982 | }
983 |
984 |
985 | void (lua_concat) (lua_State *ls, int n)
986 | {
987 | LCALL(lua_concat, ls, n);
988 | }
989 |
990 |
991 | lua_Alloc (lua_getallocf) (lua_State *ls, void **ud)
992 | {
993 | LRET(lua_getallocf, ls, ud);
994 | }
995 |
996 | void lua_setallocf (lua_State *ls, lua_Alloc f, void *ud)
997 | {
998 | LCALL(lua_setallocf, ls, f, ud);
999 | }
1000 |
1001 |
1002 | /* Functions to be called by the debuger in specific events */
1003 | int lua_getstack (lua_State *ls, int level, lua_Debug *ar)
1004 | {
1005 | LRET(lua_getstack, ls, level, ar);
1006 | }
1007 |
1008 | int lua_getinfo (lua_State *ls, const char *what, lua_Debug *ar)
1009 | {
1010 | LRET(lua_getinfo, ls, what, ar);
1011 | }
1012 |
1013 | const char *lua_getlocal (lua_State *ls, const lua_Debug *ar, int n)
1014 | {
1015 | LRET(lua_getlocal, ls, ar, n);
1016 | }
1017 |
1018 | const char *lua_setlocal (lua_State *ls, const lua_Debug *ar, int n)
1019 | {
1020 | LRET(lua_setlocal, ls, ar, n);
1021 | }
1022 |
1023 | const char *lua_getupvalue (lua_State *ls, int funcindex, int n)
1024 | {
1025 | LRET(lua_getupvalue, ls, funcindex, n);
1026 | }
1027 |
1028 | const char *lua_setupvalue (lua_State *ls, int funcindex, int n)
1029 | {
1030 | LRET(lua_setupvalue, ls, funcindex, n);
1031 | }
1032 |
1033 |
1034 | int lua_sethook (lua_State *ls, lua_Hook func, int mask, int count)
1035 | {
1036 | LRET(lua_sethook, ls, func, mask, count);
1037 | }
1038 |
1039 | lua_Hook lua_gethook (lua_State *ls)
1040 | {
1041 | LRET(lua_gethook, ls);
1042 | }
1043 |
1044 | int lua_gethookmask (lua_State *ls)
1045 | {
1046 | LRET(lua_gethookmask, ls);
1047 | }
1048 |
1049 | int lua_gethookcount (lua_State *ls)
1050 | {
1051 | LRET(lua_gethookcount, ls);
1052 | }
1053 |
1054 |
1055 | /**
1056 | ** Lua auxlib
1057 | **/
1058 | #if defined(LUA_COMPAT_GETN)
1059 | int (luaL_getn) (lua_State *ls, int t)
1060 | {
1061 | LRET(luaL_getn, ls, t);
1062 | }
1063 |
1064 | void (luaL_setn) (lua_State *ls, int t, int n)
1065 | {
1066 | LRET(luaL_setn, ls, t, n);
1067 | }
1068 | #endif
1069 |
1070 | void (luaL_register) (lua_State *ls, const char *libname, const luaL_Reg *l)
1071 | {
1072 | LCALL(luaL_register, ls, libname, l);
1073 | }
1074 |
1075 | int (luaL_getmetafield) (lua_State *ls, int obj, const char *e)
1076 | {
1077 | LRET(luaL_getmetafield, ls, obj, e);
1078 | }
1079 |
1080 | int (luaL_callmeta) (lua_State *ls, int obj, const char *e)
1081 | {
1082 | LRET(luaL_callmeta, ls, obj, e);
1083 | }
1084 |
1085 | int (luaL_typerror) (lua_State *ls, int narg, const char *tname)
1086 | {
1087 | LRET(luaL_typerror, ls, narg, tname);
1088 | }
1089 |
1090 | int (luaL_argerror) (lua_State *ls, int numarg, const char *extramsg)
1091 | {
1092 | LRET(luaL_argerror, ls, numarg, extramsg);
1093 | }
1094 |
1095 | const char *(luaL_checklstring) (lua_State *ls, int numArg, size_t *l)
1096 | {
1097 | LRET(luaL_checklstring, ls, numArg, l);
1098 | }
1099 |
1100 | const char *(luaL_optlstring) (lua_State *ls, int numArg, const char *def, size_t *l)
1101 | {
1102 | LRET(luaL_optlstring, ls, numArg, def, l);
1103 | }
1104 |
1105 | lua_Number (luaL_checknumber) (lua_State *ls, int numArg)
1106 | {
1107 | LRET(luaL_checknumber, ls, numArg);
1108 | }
1109 |
1110 | lua_Number (luaL_optnumber) (lua_State *ls, int nArg, lua_Number def)
1111 | {
1112 | LRET(luaL_optnumber, ls, nArg, def);
1113 | }
1114 |
1115 |
1116 | lua_Integer (luaL_checkinteger) (lua_State *ls, int numArg)
1117 | {
1118 | LRET(luaL_checkinteger, ls, numArg);
1119 | }
1120 |
1121 | lua_Integer (luaL_optinteger) (lua_State *ls, int nArg, lua_Integer def)
1122 | {
1123 | LRET(luaL_optinteger, ls, nArg, def);
1124 | }
1125 |
1126 |
1127 | void (luaL_checkstack) (lua_State *ls, int sz, const char *msg)
1128 | {
1129 | LRET(luaL_checkstack, ls, sz, msg);
1130 | }
1131 |
1132 | void (luaL_checktype) (lua_State *ls, int narg, int t)
1133 | {
1134 | LCALL(luaL_checktype, ls, narg, t);
1135 | }
1136 |
1137 | void (luaL_checkany) (lua_State *ls, int narg)
1138 | {
1139 | LCALL(luaL_checkany, ls, narg);
1140 | }
1141 |
1142 |
1143 | int (luaL_newmetatable) (lua_State *ls, const char *tname)
1144 | {
1145 | LRET(luaL_newmetatable, ls, tname);
1146 | }
1147 |
1148 | void *(luaL_checkudata) (lua_State *ls, int ud, const char *tname)
1149 | {
1150 | LRET(luaL_checkudata, ls, ud, tname);
1151 | }
1152 |
1153 |
1154 | void (luaL_where) (lua_State *ls, int lvl)
1155 | {
1156 | LCALL(luaL_where, ls, lvl);
1157 | }
1158 |
1159 | int (luaL_error) (lua_State *ls, const char *fmt, ...)
1160 | {
1161 | char buffer[1024];
1162 | va_list vl;
1163 |
1164 | va_start(vl, fmt);
1165 | vsnprintf(buffer, 1024, fmt, vl);
1166 | va_end(vl);
1167 |
1168 | LRET(luaL_error, ls, buffer);
1169 | }
1170 |
1171 |
1172 | int (luaL_checkoption) (lua_State *ls, int narg, const char *def, const char *const lst[])
1173 | {
1174 | LRET(luaL_checkoption, ls, narg, def, lst);
1175 | }
1176 |
1177 |
1178 | int (luaL_ref) (lua_State *ls, int t)
1179 | {
1180 | LRET(luaL_ref, ls, t);
1181 | }
1182 |
1183 | void (luaL_unref) (lua_State *ls, int t, int ref)
1184 | {
1185 | LCALL(luaL_unref, ls, t, ref);
1186 | }
1187 |
1188 |
1189 | int (luaL_loadfile) (lua_State *ls, const char *filename)
1190 | {
1191 | LRET(luaL_loadfile, ls, filename);
1192 | }
1193 |
1194 | int (luaL_loadbuffer) (lua_State *ls, const char *buff, size_t sz, const char *name)
1195 | {
1196 | LRET(luaL_loadbuffer, ls, buff, sz, name);
1197 | }
1198 |
1199 | int (luaL_loadstring) (lua_State *ls, const char *s)
1200 | {
1201 | LRET(luaL_loadstring, ls, s);
1202 | }
1203 |
1204 |
1205 | lua_State *(luaL_newstate) (void)
1206 | {
1207 | LRET(luaL_newstate);
1208 | }
1209 |
1210 |
1211 |
1212 | const char *(luaL_gsub) (lua_State *ls, const char *s, const char *p, const char *r)
1213 | {
1214 | LRET(luaL_gsub, ls, s, p, r);
1215 | }
1216 |
1217 |
1218 | const char *(luaL_findtable) (lua_State *ls, int idx, const char *fname, int szhint)
1219 | {
1220 | LRET(luaL_findtable, ls, idx, fname, szhint);
1221 | }
1222 |
1223 |
1224 | void (luaL_buffinit) (lua_State *ls, luaL_Buffer *B)
1225 | {
1226 | LCALL(luaL_buffinit, ls, B);
1227 | }
1228 |
1229 | char *(luaL_prepbuffer) (luaL_Buffer *B)
1230 | {
1231 | LRET(luaL_prepbuffer, B);
1232 | }
1233 |
1234 | void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l)
1235 | {
1236 | LCALL(luaL_addlstring, B, s, l);
1237 | }
1238 |
1239 | void (luaL_addstring) (luaL_Buffer *B, const char *s)
1240 | {
1241 | LCALL(luaL_addstring, B, s);
1242 | }
1243 |
1244 | void (luaL_addvalue) (luaL_Buffer *B)
1245 | {
1246 | LCALL(luaL_addvalue, B);
1247 | }
1248 |
1249 | void (luaL_pushresult) (luaL_Buffer *B)
1250 | {
1251 | LCALL(luaL_pushresult, B);
1252 | }
1253 |
1254 | lua_State* (lua_getmainstate) (lua_State* L)
1255 | {
1256 | LRET(lua_getmainstate, L);
1257 | }
1258 |
1259 | #ifdef __cplusplus
1260 | }
1261 | #endif
1262 |
1263 | #undef LRET
1264 | #undef LCALL
1265 |
1266 |
--------------------------------------------------------------------------------
/module/luaimports/luaimports.linux.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2008, Alberto Alonso
3 | *
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without modification,
7 | * are permitted provided that the following conditions are met:
8 | *
9 | * * Redistributions of source code must retain the above copyright notice, this
10 | * list of conditions and the following disclaimer.
11 | * * Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or other
13 | * materials provided with the distribution.
14 | * * Neither the name of the mta-mysql nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior
16 | * written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
32 | #define ImportLua() true
33 | #else
34 | #ifdef __cplusplus
35 | extern "C"
36 | #endif
37 | bool ImportLua();
38 | #endif
39 |
--------------------------------------------------------------------------------
/module/premake5.lua:
--------------------------------------------------------------------------------
1 | project "module"
2 | language "C++"
3 | cppdialect "C++17"
4 | kind "SharedLib"
5 | targetname "ml_redis"
6 |
7 | includedirs { "include", "../cpp_redis/includes" }
8 | libdirs { "lib" }
9 |
10 | dependson { "cpp_redis" }
11 | links { "cpp_redis" }
12 |
13 | vpaths {
14 | ["Headers/*"] = "**.h",
15 | ["Sources/*"] = "**.cpp",
16 | ["*"] = "premake5.lua"
17 | }
18 |
19 | files {
20 | "premake5.lua",
21 | "**.cpp",
22 | "**.h"
23 | }
24 |
25 | filter { "system:windows" }
26 | debugdir "../mta-server"
27 |
28 | filter { "system:windows", "platforms:x86" }
29 | links { "lua5.1.lib" }
30 | debugcommand "../mta-server/MTA Server.exe"
31 |
32 | filter { "system:windows", "platforms:x64" }
33 | links { "lua5.1_64.lib" }
34 | debugcommand "../mta-server/MTA Server64.exe"
35 |
36 | -- filter "system:linux"
37 |
38 | filter "system:not linux"
39 | excludes { "luaimports/luaimports.linux.h", "luaimports/luaimports.linux.cpp" }
40 |
--------------------------------------------------------------------------------
/premake5.lua:
--------------------------------------------------------------------------------
1 | solution "Redis"
2 | configurations { "Debug", "Release" }
3 | location ( "Build" )
4 | startproject "module"
5 | targetdir "Bin/%{cfg.buildcfg}"
6 |
7 | platforms { "x86", "x64" }
8 | pic "On"
9 | symbols "On"
10 |
11 | includedirs { "vendor", "." }
12 |
13 | filter "system:windows"
14 | defines { "WINDOWS", "WIN32" }
15 |
16 | filter "configurations:Debug"
17 | defines { "DEBUG" }
18 |
19 | filter "configurations:Release"
20 | optimize "On"
21 |
22 | include "cpp_redis/tacopie/tacopie"
23 | include "cpp_redis/cpp_redis"
24 | include "module"
25 | --include "test"
26 |
--------------------------------------------------------------------------------
/test/Main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "cpp_redis/cpp_redis"
3 |
4 | int main(int argc, char* argv[])
5 | {
6 | try {
7 |
8 | #ifdef WINDOWS
9 | WSADATA wsa_data;
10 | const auto err = WSAStartup(MAKEWORD(2, 2), &wsa_data);
11 | if (err != 0) {
12 | /* Tell the user that we could not find a usable */
13 | /* Winsock DLL. */
14 | printf("WSAStartup failed with error: %d\n", err);
15 | return 1;
16 | }
17 | #endif
18 |
19 | cpp_redis::client client;
20 | client.connect();
21 |
22 | client.set("lol", "redis", [](cpp_redis::reply& reply)
23 | {
24 | std::cout << "Reply: " << reply << std::endl;
25 | });
26 | client.get("lol", [](cpp_redis::reply& reply) {
27 | std::cout << "Got from redis: " << reply << std::endl;
28 | });
29 | client.sync_commit();
30 | } catch(std::exception& e)
31 | {
32 | std::cout << e.what() << std::endl;
33 | }
34 |
35 | std::cin.get();
36 | return 0;
37 | }
38 |
--------------------------------------------------------------------------------
/test/lib/cpp_redis.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/test/lib/cpp_redis.lib
--------------------------------------------------------------------------------
/test/lib/cpp_redis_64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/test/lib/cpp_redis_64.lib
--------------------------------------------------------------------------------
/test/lib/tacopie.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/test/lib/tacopie.lib
--------------------------------------------------------------------------------
/test/lib/tacopie_64.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/test/lib/tacopie_64.lib
--------------------------------------------------------------------------------
/test/premake5.lua:
--------------------------------------------------------------------------------
1 | project "test"
2 | language "C++"
3 | cppdialect "C++17"
4 | kind "ConsoleApp"
5 |
6 | libdirs { "lib" }
7 |
8 | vpaths {
9 | ["Headers/*"] = "**.h",
10 | ["Sources/*"] = "**.cpp",
11 | ["*"] = "premake5.lua"
12 | }
13 |
14 | files {
15 | "premake5.lua",
16 | "**.cpp",
17 | "**.h",
18 | }
19 |
20 | filter { "system:windows", "platforms:x86" }
21 | links { "tacopie.lib" }
22 | links { "cpp_redis.lib" }
23 |
24 | filter { "system:windows", "platforms:x64" }
25 | links { "tacopie_64.lib" }
26 | links { "cpp_redis_64.lib" }
27 |
28 | filter "system:linux"
29 | links { "tacopie" }
30 | links { "cpp_redis" }
31 |
--------------------------------------------------------------------------------
/utils/premake5:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/utils/premake5
--------------------------------------------------------------------------------
/utils/premake5-macos:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/utils/premake5-macos
--------------------------------------------------------------------------------
/utils/premake5.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eXo-OpenSource/ml_redis/62e8fb2df671ffeac0711175e5bbd1389cdf1f20/utils/premake5.exe
--------------------------------------------------------------------------------