mirror of
https://github.com/Qsgs-Fans/FreeKill.git
synced 2024-11-15 19:22:25 +08:00
Add / Remove Player (#2)
* addplayer and removeplayer * add sqlite3 library and remove comment in library headers * setup database system
This commit is contained in:
parent
d2315c7533
commit
432a306de0
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ build/
|
|||
FreeKill
|
||||
FreeKill.exe
|
||||
freekill-wrap.cxx
|
||||
server/users.db
|
||||
|
|
|
@ -10,6 +10,7 @@ find_package(Qt5 REQUIRED COMPONENTS
|
|||
)
|
||||
|
||||
find_package(Lua)
|
||||
find_package(SQLite3)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
@ -18,6 +19,7 @@ set(REQUIRED_QT_VERSION "5.15.2")
|
|||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/)
|
||||
include_directories(include/lua)
|
||||
include_directories(include/sqlite3)
|
||||
include_directories(src)
|
||||
include_directories(src/client)
|
||||
include_directories(src/core)
|
||||
|
|
7
doc/dev/database.md
Normal file
7
doc/dev/database.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# FreeKill 的数据库(TODO)
|
||||
|
||||
> [dev](./index.md) > 数据库
|
||||
|
||||
___
|
||||
|
||||
FreeKill 使用 sqlite3 数据库。
|
|
@ -7,3 +7,5 @@ ___
|
|||
FreeKill采用Qt框架提供底层支持,在上层使用lua语言开发。在UI方面使用的是Qt Quick。
|
||||
|
||||
- [通信](./protocol.md)
|
||||
- [数据库](./database.md)
|
||||
- [UI](./ui.md)
|
||||
|
|
|
@ -33,4 +33,69 @@ $ ./FreeKill -s <port>
|
|||
|
||||
服务器以TCP方式监听。在默认情况下(比如单机启动),服务器的端口号是9527。
|
||||
|
||||
每当任何一个客户端连接上了之后,客户端进入大厅。
|
||||
每当任何一个客户端连接上了之后,游戏会先进行以下流程:
|
||||
|
||||
1. 检查IP是否被封禁。 // TODO: 数据库
|
||||
2. 检查客户端的延迟是否小于30秒。
|
||||
3. 在网络检测环节,若客户端网速达标的话,客户端应该会发回一个字符串。这个字符串保存着用户的用户名和密码,服务端检查这个字符串是否合法。
|
||||
4. 上述检查都通过后,重连(TODO)
|
||||
5. 不要重连的话,服务端便为新连接新建一个`ServerPlayer`对象,并将其添加到大厅中。
|
||||
|
||||
___
|
||||
|
||||
## 大厅和房间
|
||||
|
||||
大厅(Lobby)是一个比较特殊的房间。除了大厅之外,所有的房间都被作为游戏房间对待。
|
||||
|
||||
对于普通房间而言,有这几个特点:
|
||||
|
||||
1. 只要房间被添加玩家,那么那名玩家就自动从大厅移除。
|
||||
2. 当玩家离开房间时,玩家便会自动进入大厅。
|
||||
3. 当所有玩家都离开房间后,房间被销毁。
|
||||
|
||||
大厅的特点:
|
||||
|
||||
1. 只要有玩家进入,就刷新一次房间列表。
|
||||
|
||||
> 因为上述特点都是通过信号槽实现的,通过阅读代码不易发现,故记录之。
|
||||
|
||||
___
|
||||
|
||||
## 对掉线的处理
|
||||
|
||||
因为每个连接都对应着一个`new ClientSocket`和`new ServerPlayer`,所以对于掉线的处理要慎重,处理不当会导致内存泄漏以及各种奇怪的错误。
|
||||
|
||||
一般来说掉线有以下几种情况:
|
||||
|
||||
1. 刚刚登入,服务端还在检测时掉线。
|
||||
2. 在大厅里面掉线。
|
||||
3. 在未开始游戏的房间里面掉线。
|
||||
4. 在已开始游戏的房间里掉线。
|
||||
|
||||
首先对所有的这些情况,都应该把ClientSocket释放掉。这部分代码写在[server_socket.cpp](../../src/network/server_socket.cpp)里面。
|
||||
|
||||
对于2、3两种情况,都算是在游戏开始之前的房间中掉线。这种情况下直接从房间中删除这个玩家,并告诉其他玩家一声,然后从服务器玩家列表中也删除那名玩家。但对于情况3,因为从普通房间删除玩家的话,那名玩家会自动进入大厅,所以需要大厅再删除一次玩家。
|
||||
|
||||
对于情况4,因为游戏已经开始,所以不能直接删除玩家,需要把玩家的状态设为“离线”并继续游戏。在游戏结束后,若玩家仍未重连,则按情况2、3处理。
|
||||
|
||||
___
|
||||
|
||||
## 断线重连(TODO)
|
||||
|
||||
根据用户名找到掉线的那位玩家,将玩家的状态设置为“在线”,并将房间的状态都发送给他即可。
|
||||
|
||||
但是为了[UI不出错](./ui.md#mainStack),依然需要对重连的玩家走一遍进大厅的流程。
|
||||
|
||||
___
|
||||
|
||||
## 旁观(TODO)
|
||||
|
||||
因为房间不允许加入比玩家上限的玩家,可以考虑在房间里新建一个列表存储旁观中的玩家。但是这样或许会让某些处理(如掉线)变得复杂化。
|
||||
|
||||
也可以考虑旁观者在服务端中处于大厅中,自己的端中在旁观房间。但是这样的话无法在房间中发送聊天。
|
||||
|
||||
所以还是让旁观者在房间中吧。可以给ServerPlayer设置个属性保存正在旁观的房间的id。
|
||||
|
||||
旁观者的处理方式或许可以像观看录像那样,过滤所有的request事件。这样就确确实实只能看着了。
|
||||
|
||||
而不过滤request的旁观就可以理解为操控其他玩家了。hhh
|
||||
|
|
29
doc/dev/ui.md
Normal file
29
doc/dev/ui.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
# FreeKill 的UI
|
||||
|
||||
> [dev](./index.md) > UI
|
||||
|
||||
___
|
||||
|
||||
## 概述
|
||||
|
||||
FreeKill的UI系统使用Qt Quick开发。UI依赖[QmlBackend](../../src/ui/qmlbackend.h)调用需要的C++函数。关于这方面也可参考[main.cpp](../../src/main.cpp)。
|
||||
|
||||
> Note: 我感觉QmlBackend这种实现方式很尴尬。
|
||||
|
||||
整体UI采用StackView进行页面切换之类的。
|
||||
|
||||
___
|
||||
|
||||
## mainStack
|
||||
|
||||
mainStack定义于[main.qml](../../qml/main.qml)中。它以堆栈的形式保存着所有的页面,页面在栈中的顺序需要像这样排布:
|
||||
|
||||
- (栈底)登录界面,Init.qml
|
||||
- 大厅,Lobby.qml
|
||||
- 别的什么页面
|
||||
|
||||
___
|
||||
|
||||
## config
|
||||
|
||||
Config.qml存储一些客户端需要用到的设置或者即将发送的数据,(TODO)
|
|
@ -1,49 +1,40 @@
|
|||
/*
|
||||
** $Id: lapi.h $
|
||||
** Auxiliary functions from Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lapi.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lapi_h
|
||||
#define lapi_h
|
||||
#define lapi_h
|
||||
|
||||
|
||||
#include "llimits.h"
|
||||
#include "lstate.h"
|
||||
|
||||
|
||||
/* Increments 'L->top', checking for stack overflows */
|
||||
#define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
|
||||
"stack overflow");}
|
||||
|
||||
#define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
|
||||
"stack overflow");}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** If a call returns too many multiple returns, the callee may not have
|
||||
** stack space to accommodate all results. In this case, this macro
|
||||
** increases its stack space ('L->ci->top').
|
||||
*/
|
||||
#define adjustresults(L,nres) \
|
||||
{ if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
|
||||
|
||||
|
||||
/* Ensure the stack has at least 'n' elements */
|
||||
#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
|
||||
"not enough elements in the stack")
|
||||
|
||||
#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
|
||||
"not enough elements in the stack")
|
||||
# 43 "./lua/lapi.h"
|
||||
#define hastocloseCfunc(n) ((n) < LUA_MULTRET)
|
||||
|
||||
|
||||
/*
|
||||
** To reduce the overhead of returning from C functions, the presence of
|
||||
** to-be-closed variables in these functions is coded in the CallInfo's
|
||||
** field 'nresults', in a way that functions with no to-be-closed variables
|
||||
** with zero, one, or "all" wanted results have no overhead. Functions
|
||||
** with other number of wanted results, as well as functions with
|
||||
** variables to be closed, have an extra check.
|
||||
*/
|
||||
|
||||
#define hastocloseCfunc(n) ((n) < LUA_MULTRET)
|
||||
|
||||
/* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
|
||||
#define codeNresults(n) (-(n) - 3)
|
||||
#define decodeNresults(n) (-(n) - 3)
|
||||
#define codeNresults(n) (-(n) - 3)
|
||||
#define decodeNresults(n) (-(n) - 3)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*
|
||||
** $Id: lauxlib.h $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lauxlib.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lauxlib_h
|
||||
#define lauxlib_h
|
||||
#define lauxlib_h
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
@ -16,23 +17,23 @@
|
|||
#include "lua.h"
|
||||
|
||||
|
||||
/* global table */
|
||||
#define LUA_GNAME "_G"
|
||||
|
||||
#define LUA_GNAME "_G"
|
||||
|
||||
|
||||
typedef struct luaL_Buffer luaL_Buffer;
|
||||
|
||||
|
||||
/* extra error code for 'luaL_loadfilex' */
|
||||
#define LUA_ERRFILE (LUA_ERRERR+1)
|
||||
|
||||
#define LUA_ERRFILE (LUA_ERRERR+1)
|
||||
|
||||
|
||||
/* key, in the registry, for table of loaded modules */
|
||||
#define LUA_LOADED_TABLE "_LOADED"
|
||||
|
||||
#define LUA_LOADED_TABLE "_LOADED"
|
||||
|
||||
|
||||
/* key, in the registry, for table of preloaded loaders */
|
||||
#define LUA_PRELOAD_TABLE "_PRELOAD"
|
||||
|
||||
#define LUA_PRELOAD_TABLE "_PRELOAD"
|
||||
|
||||
|
||||
typedef struct luaL_Reg {
|
||||
|
@ -41,11 +42,11 @@ typedef struct luaL_Reg {
|
|||
} luaL_Reg;
|
||||
|
||||
|
||||
#define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number))
|
||||
#define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number))
|
||||
|
||||
LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);
|
||||
#define luaL_checkversion(L) \
|
||||
luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)
|
||||
#define luaL_checkversion(L) \
|
||||
luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)
|
||||
|
||||
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
|
||||
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
|
||||
|
@ -67,8 +68,8 @@ LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
|
|||
LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);
|
||||
LUALIB_API void (luaL_checkany) (lua_State *L, int arg);
|
||||
|
||||
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
|
||||
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
|
||||
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
|
||||
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
|
||||
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
|
||||
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
|
||||
|
||||
|
@ -82,9 +83,9 @@ LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
|
|||
LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
|
||||
|
||||
|
||||
/* predefined references */
|
||||
#define LUA_NOREF (-2)
|
||||
#define LUA_REFNIL (-1)
|
||||
|
||||
#define LUA_NOREF (-2)
|
||||
#define LUA_REFNIL (-1)
|
||||
|
||||
LUALIB_API int (luaL_ref) (lua_State *L, int t);
|
||||
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
|
||||
|
@ -92,7 +93,7 @@ LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
|
|||
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
|
||||
const char *mode);
|
||||
|
||||
#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
|
||||
#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
|
||||
|
||||
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
|
||||
const char *name, const char *mode);
|
||||
|
@ -116,101 +117,86 @@ LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
|
|||
|
||||
LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
|
||||
lua_CFunction openf, int glb);
|
||||
|
||||
/*
|
||||
** ===============================================================
|
||||
** some useful macros
|
||||
** ===============================================================
|
||||
*/
|
||||
|
||||
|
||||
#define luaL_newlibtable(L,l) \
|
||||
# 127 "./lua/lauxlib.h"
|
||||
#define luaL_newlibtable(L,l) \
|
||||
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
|
||||
|
||||
#define luaL_newlib(L,l) \
|
||||
#define luaL_newlib(L,l) \
|
||||
(luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
|
||||
|
||||
#define luaL_argcheck(L, cond,arg,extramsg) \
|
||||
((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg))))
|
||||
#define luaL_argcheck(L,cond,arg,extramsg) \
|
||||
((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg))))
|
||||
|
||||
#define luaL_argexpected(L,cond,arg,tname) \
|
||||
((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname))))
|
||||
#define luaL_argexpected(L,cond,arg,tname) \
|
||||
((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname))))
|
||||
|
||||
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
|
||||
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
|
||||
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
|
||||
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
|
||||
|
||||
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
|
||||
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
|
||||
|
||||
#define luaL_dofile(L, fn) \
|
||||
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
|
||||
#define luaL_dofile(L,fn) \
|
||||
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
|
||||
|
||||
#define luaL_dostring(L, s) \
|
||||
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
|
||||
#define luaL_dostring(L,s) \
|
||||
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
|
||||
|
||||
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
|
||||
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
|
||||
|
||||
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
|
||||
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
|
||||
|
||||
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
|
||||
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
|
||||
|
||||
|
||||
/*
|
||||
** Perform arithmetic operations on lua_Integer values with wrap-around
|
||||
** semantics, as the Lua core does.
|
||||
*/
|
||||
#define luaL_intop(op,v1,v2) \
|
||||
((lua_Integer)((lua_Unsigned)(v1) op (lua_Unsigned)(v2)))
|
||||
|
||||
|
||||
/* push the value used to represent failure/error */
|
||||
#define luaL_pushfail(L) lua_pushnil(L)
|
||||
|
||||
|
||||
/*
|
||||
** Internal assertions for in-house debugging
|
||||
*/
|
||||
#define luaL_intop(op,v1,v2) \
|
||||
((lua_Integer)((lua_Unsigned)(v1) op (lua_Unsigned)(v2)))
|
||||
|
||||
|
||||
|
||||
#define luaL_pushfail(L) lua_pushnil(L)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(lua_assert)
|
||||
|
||||
#if defined LUAI_ASSERT
|
||||
#include <assert.h>
|
||||
#define lua_assert(c) assert(c)
|
||||
#define lua_assert(c) assert(c)
|
||||
#else
|
||||
#define lua_assert(c) ((void)0)
|
||||
#define lua_assert(c) ((void)0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** Generic Buffer manipulation
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
# 191 "./lua/lauxlib.h"
|
||||
struct luaL_Buffer {
|
||||
char *b; /* buffer address */
|
||||
size_t size; /* buffer size */
|
||||
size_t n; /* number of characters in buffer */
|
||||
char *b;
|
||||
size_t size;
|
||||
size_t n;
|
||||
lua_State *L;
|
||||
union {
|
||||
LUAI_MAXALIGN; /* ensure maximum alignment for buffer */
|
||||
char b[LUAL_BUFFERSIZE]; /* initial buffer */
|
||||
LUAI_MAXALIGN;
|
||||
char b[LUAL_BUFFERSIZE];
|
||||
} init;
|
||||
};
|
||||
|
||||
|
||||
#define luaL_bufflen(bf) ((bf)->n)
|
||||
#define luaL_buffaddr(bf) ((bf)->b)
|
||||
#define luaL_bufflen(bf) ((bf)->n)
|
||||
#define luaL_buffaddr(bf) ((bf)->b)
|
||||
|
||||
|
||||
#define luaL_addchar(B,c) \
|
||||
((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
|
||||
((B)->b[(B)->n++] = (c)))
|
||||
|
||||
#define luaL_addsize(B,s) ((B)->n += (s))
|
||||
#define luaL_addsize(B,s) ((B)->n += (s))
|
||||
|
||||
#define luaL_buffsub(B,s) ((B)->n -= (s))
|
||||
#define luaL_buffsub(B,s) ((B)->n -= (s))
|
||||
|
||||
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
|
||||
LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
|
||||
|
@ -221,81 +207,46 @@ LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
|
|||
LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
|
||||
LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
|
||||
|
||||
#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** {======================================================
|
||||
** File handles for IO library
|
||||
** =======================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
|
||||
** initial structure 'luaL_Stream' (it may contain other fields
|
||||
** after that initial structure).
|
||||
*/
|
||||
|
||||
#define LUA_FILEHANDLE "FILE*"
|
||||
#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
|
||||
# 242 "./lua/lauxlib.h"
|
||||
#define LUA_FILEHANDLE "FILE*"
|
||||
|
||||
|
||||
typedef struct luaL_Stream {
|
||||
FILE *f; /* stream (NULL for incompletely created streams) */
|
||||
lua_CFunction closef; /* to close stream (NULL for closed streams) */
|
||||
FILE *f;
|
||||
lua_CFunction closef;
|
||||
} luaL_Stream;
|
||||
|
||||
/* }====================================================== */
|
||||
|
||||
/*
|
||||
** {==================================================================
|
||||
** "Abstraction Layer" for basic report of messages and errors
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
/* print a string */
|
||||
# 259 "./lua/lauxlib.h"
|
||||
#if !defined(lua_writestring)
|
||||
#define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
|
||||
#define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
|
||||
#endif
|
||||
|
||||
/* print a newline and flush the output */
|
||||
|
||||
#if !defined(lua_writeline)
|
||||
#define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
|
||||
#define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
|
||||
#endif
|
||||
|
||||
/* print an error message */
|
||||
|
||||
#if !defined(lua_writestringerror)
|
||||
#define lua_writestringerror(s,p) \
|
||||
(fprintf(stderr, (s), (p)), fflush(stderr))
|
||||
#endif
|
||||
|
||||
/* }================================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** {============================================================
|
||||
** Compatibility with deprecated conversions
|
||||
** =============================================================
|
||||
*/
|
||||
# 282 "./lua/lauxlib.h"
|
||||
#if defined(LUA_COMPAT_APIINTCASTS)
|
||||
|
||||
#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
|
||||
#define luaL_optunsigned(L,a,d) \
|
||||
((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
|
||||
|
||||
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
|
||||
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
|
||||
|
||||
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
|
||||
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
|
||||
|
||||
#endif
|
||||
/* }============================================================ */
|
||||
#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
|
||||
#define luaL_optunsigned(L,a,d) \
|
||||
((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
|
||||
|
||||
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
|
||||
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
|
||||
|
||||
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
|
||||
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
/*
|
||||
** $Id: lcode.h $
|
||||
** Code generator for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lcode.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lcode_h
|
||||
#define lcode_h
|
||||
#define lcode_h
|
||||
|
||||
#include "llex.h"
|
||||
#include "lobject.h"
|
||||
|
@ -13,51 +14,51 @@
|
|||
#include "lparser.h"
|
||||
|
||||
|
||||
/*
|
||||
** Marks the end of a patch list. It is an invalid value both as an absolute
|
||||
** address, and as a list link (would link an element to itself).
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#define NO_JUMP (-1)
|
||||
|
||||
|
||||
/*
|
||||
** grep "ORDER OPR" if you change these enums (ORDER OP)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef enum BinOpr {
|
||||
/* arithmetic operators */
|
||||
|
||||
OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,
|
||||
OPR_DIV, OPR_IDIV,
|
||||
/* bitwise operators */
|
||||
|
||||
OPR_BAND, OPR_BOR, OPR_BXOR,
|
||||
OPR_SHL, OPR_SHR,
|
||||
/* string operator */
|
||||
|
||||
OPR_CONCAT,
|
||||
/* comparison operators */
|
||||
|
||||
OPR_EQ, OPR_LT, OPR_LE,
|
||||
OPR_NE, OPR_GT, OPR_GE,
|
||||
/* logical operators */
|
||||
|
||||
OPR_AND, OPR_OR,
|
||||
OPR_NOBINOPR
|
||||
} BinOpr;
|
||||
|
||||
|
||||
/* true if operation is foldable (that is, it is arithmetic or bitwise) */
|
||||
#define foldbinop(op) ((op) <= OPR_SHR)
|
||||
|
||||
#define foldbinop(op) ((op) <= OPR_SHR)
|
||||
|
||||
|
||||
#define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0)
|
||||
#define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0)
|
||||
|
||||
|
||||
typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
|
||||
|
||||
|
||||
/* get (pointer to) instruction of given 'expdesc' */
|
||||
#define getinstruction(fs,e) ((fs)->f->code[(e)->u.info])
|
||||
|
||||
#define getinstruction(fs,e) ((fs)->f->code[(e)->u.info])
|
||||
|
||||
|
||||
#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
|
||||
#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
|
||||
|
||||
#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
|
||||
#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
|
||||
|
||||
LUAI_FUNC int luaK_code (FuncState *fs, Instruction i);
|
||||
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
|
||||
|
|
|
@ -1,101 +1,87 @@
|
|||
/*
|
||||
** $Id: lctype.h $
|
||||
** 'ctype' functions for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lctype.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lctype_h
|
||||
#define lctype_h
|
||||
#define lctype_h
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
|
||||
/*
|
||||
** WARNING: the functions defined here do not necessarily correspond
|
||||
** to the similar functions in the standard C ctype.h. They are
|
||||
** optimized for the specific needs of Lua.
|
||||
*/
|
||||
|
||||
# 19 "./lua/lctype.h"
|
||||
#if !defined(LUA_USE_CTYPE)
|
||||
|
||||
#if 'A' == 65 && '0' == 48
|
||||
/* ASCII case: can use its own tables; faster and fixed */
|
||||
#define LUA_USE_CTYPE 0
|
||||
|
||||
#define LUA_USE_CTYPE 0
|
||||
#else
|
||||
/* must use standard C ctype */
|
||||
#define LUA_USE_CTYPE 1
|
||||
|
||||
#define LUA_USE_CTYPE 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if !LUA_USE_CTYPE /* { */
|
||||
#if !LUA_USE_CTYPE
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "llimits.h"
|
||||
|
||||
|
||||
#define ALPHABIT 0
|
||||
#define DIGITBIT 1
|
||||
#define PRINTBIT 2
|
||||
#define SPACEBIT 3
|
||||
#define XDIGITBIT 4
|
||||
#define ALPHABIT 0
|
||||
#define DIGITBIT 1
|
||||
#define PRINTBIT 2
|
||||
#define SPACEBIT 3
|
||||
#define XDIGITBIT 4
|
||||
|
||||
|
||||
#define MASK(B) (1 << (B))
|
||||
#define MASK(B) (1 << (B))
|
||||
|
||||
|
||||
/*
|
||||
** add 1 to char to allow index -1 (EOZ)
|
||||
*/
|
||||
#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
|
||||
|
||||
/*
|
||||
** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
|
||||
*/
|
||||
#define lislalpha(c) testprop(c, MASK(ALPHABIT))
|
||||
#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
|
||||
#define lisdigit(c) testprop(c, MASK(DIGITBIT))
|
||||
#define lisspace(c) testprop(c, MASK(SPACEBIT))
|
||||
#define lisprint(c) testprop(c, MASK(PRINTBIT))
|
||||
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
|
||||
|
||||
|
||||
/*
|
||||
** In ASCII, this 'ltolower' is correct for alphabetic characters and
|
||||
** for '.'. That is enough for Lua needs. ('check_exp' ensures that
|
||||
** the character either is an upper-case letter or is unchanged by
|
||||
** the transformation, which holds for lower-case letters and '.'.)
|
||||
*/
|
||||
#define ltolower(c) \
|
||||
check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \
|
||||
|
||||
#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
|
||||
|
||||
|
||||
|
||||
|
||||
#define lislalpha(c) testprop(c, MASK(ALPHABIT))
|
||||
#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
|
||||
#define lisdigit(c) testprop(c, MASK(DIGITBIT))
|
||||
#define lisspace(c) testprop(c, MASK(SPACEBIT))
|
||||
#define lisprint(c) testprop(c, MASK(PRINTBIT))
|
||||
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
|
||||
# 71 "./lua/lctype.h"
|
||||
#define ltolower(c) \
|
||||
check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \
|
||||
(c) | ('A' ^ 'a'))
|
||||
|
||||
|
||||
/* one entry for each character and for -1 (EOZ) */
|
||||
|
||||
LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];)
|
||||
|
||||
|
||||
#else /* }{ */
|
||||
#else
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** use standard C ctypes
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
#define lislalpha(c) (isalpha(c) || (c) == '_')
|
||||
#define lislalnum(c) (isalnum(c) || (c) == '_')
|
||||
#define lisdigit(c) (isdigit(c))
|
||||
#define lisspace(c) (isspace(c))
|
||||
#define lisprint(c) (isprint(c))
|
||||
#define lisxdigit(c) (isxdigit(c))
|
||||
#define lislalpha(c) (isalpha(c) || (c) == '_')
|
||||
#define lislalnum(c) (isalnum(c) || (c) == '_')
|
||||
#define lisdigit(c) (isdigit(c))
|
||||
#define lisspace(c) (isspace(c))
|
||||
#define lisprint(c) (isprint(c))
|
||||
#define lisxdigit(c) (isxdigit(c))
|
||||
|
||||
#define ltolower(c) (tolower(c))
|
||||
|
||||
#endif /* } */
|
||||
#define ltolower(c) (tolower(c))
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,38 +1,39 @@
|
|||
/*
|
||||
** $Id: ldebug.h $
|
||||
** Auxiliary functions from Debug Interface module
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/ldebug.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef ldebug_h
|
||||
#define ldebug_h
|
||||
#define ldebug_h
|
||||
|
||||
|
||||
#include "lstate.h"
|
||||
|
||||
|
||||
#define pcRel(pc, p) (cast_int((pc) - (p)->code) - 1)
|
||||
#define pcRel(pc,p) (cast_int((pc) - (p)->code) - 1)
|
||||
|
||||
|
||||
|
||||
#define ci_func(ci) (clLvalue(s2v((ci)->func)))
|
||||
|
||||
|
||||
#define resethookcount(L) (L->hookcount = L->basehookcount)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ABSLINEINFO (-0x80)
|
||||
|
||||
|
||||
/* Active Lua function (given call info) */
|
||||
#define ci_func(ci) (clLvalue(s2v((ci)->func)))
|
||||
|
||||
|
||||
#define resethookcount(L) (L->hookcount = L->basehookcount)
|
||||
|
||||
/*
|
||||
** mark for entries in 'lineinfo' array that has absolute information in
|
||||
** 'abslineinfo' array
|
||||
*/
|
||||
#define ABSLINEINFO (-0x80)
|
||||
|
||||
|
||||
/*
|
||||
** MAXimum number of successive Instructions WiTHout ABSolute line
|
||||
** information. (A power of two allows fast divisions.)
|
||||
*/
|
||||
#if !defined(MAXIWTHABS)
|
||||
#define MAXIWTHABS 128
|
||||
#define MAXIWTHABS 128
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -1,55 +1,46 @@
|
|||
/*
|
||||
** $Id: ldo.h $
|
||||
** Stack and Call structure of Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/ldo.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef ldo_h
|
||||
#define ldo_h
|
||||
#define ldo_h
|
||||
|
||||
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
#include "lzio.h"
|
||||
|
||||
|
||||
/*
|
||||
** Macro to check stack size and grow stack if needed. Parameters
|
||||
** 'pre'/'pos' allow the macro to preserve a pointer into the
|
||||
** stack across reallocations, doing the work only when needed.
|
||||
** It also allows the running of one GC step when the stack is
|
||||
** reallocated.
|
||||
** 'condmovestack' is used in heavy tests to force a stack reallocation
|
||||
** at every check.
|
||||
*/
|
||||
#define luaD_checkstackaux(L,n,pre,pos) \
|
||||
if (l_unlikely(L->stack_last - L->top <= (n))) \
|
||||
{ pre; luaD_growstack(L, n, 1); pos; } \
|
||||
# 25 "./lua/ldo.h"
|
||||
#define luaD_checkstackaux(L,n,pre,pos) \
|
||||
if (l_unlikely(L->stack_last - L->top <= (n))) \
|
||||
{ pre; luaD_growstack(L, n, 1); pos; } \
|
||||
else { condmovestack(L,pre,pos); }
|
||||
|
||||
/* In general, 'pre'/'pos' are empty (nothing to save) */
|
||||
#define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0)
|
||||
|
||||
#define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0)
|
||||
|
||||
|
||||
|
||||
#define savestack(L,p) ((char *)(p) - (char *)L->stack)
|
||||
#define restorestack(L,n) ((StkId)((char *)L->stack + (n)))
|
||||
#define savestack(L,p) ((char *)(p) - (char *)L->stack)
|
||||
#define restorestack(L,n) ((StkId)((char *)L->stack + (n)))
|
||||
|
||||
|
||||
/* macro to check stack size, preserving 'p' */
|
||||
#define checkstackGCp(L,n,p) \
|
||||
|
||||
#define checkstackGCp(L,n,p) \
|
||||
luaD_checkstackaux(L, n, \
|
||||
ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
|
||||
luaC_checkGC(L), /* stack grow uses memory */ \
|
||||
p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
|
||||
ptrdiff_t t__ = savestack(L, p); \
|
||||
luaC_checkGC(L), \
|
||||
p = restorestack(L, t__))
|
||||
|
||||
|
||||
/* macro to check stack size and GC */
|
||||
#define checkstackGC(L,fsize) \
|
||||
luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
|
||||
|
||||
#define checkstackGC(L,fsize) \
|
||||
luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
|
||||
|
||||
|
||||
|
||||
/* type of protected functions, to be ran by 'runprotected' */
|
||||
typedef void (*Pfunc) (lua_State *L, void *ud);
|
||||
|
||||
LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
|
||||
|
@ -58,7 +49,7 @@ LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
|
|||
LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
|
||||
int fTransfer, int nTransfer);
|
||||
LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
|
||||
LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1, int delta);
|
||||
LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1, int delta);
|
||||
LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
|
||||
LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
|
||||
LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
|
||||
|
@ -76,4 +67,3 @@ LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
|
|||
LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,50 +1,51 @@
|
|||
/*
|
||||
** $Id: lfunc.h $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lfunc.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lfunc_h
|
||||
#define lfunc_h
|
||||
#define lfunc_h
|
||||
|
||||
|
||||
#include "lobject.h"
|
||||
|
||||
|
||||
#define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \
|
||||
#define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \
|
||||
cast_int(sizeof(TValue)) * (n))
|
||||
|
||||
#define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \
|
||||
#define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \
|
||||
cast_int(sizeof(TValue *)) * (n))
|
||||
|
||||
|
||||
/* test whether thread is in 'twups' list */
|
||||
#define isintwups(L) (L->twups != L)
|
||||
|
||||
|
||||
/*
|
||||
** maximum number of upvalues in a closure (both C and Lua). (Value
|
||||
** must fit in a VM register.)
|
||||
*/
|
||||
#define MAXUPVAL 255
|
||||
|
||||
|
||||
#define upisopen(up) ((up)->v != &(up)->u.value)
|
||||
|
||||
|
||||
#define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v))
|
||||
|
||||
|
||||
/*
|
||||
** maximum number of misses before giving up the cache of closures
|
||||
** in prototypes
|
||||
*/
|
||||
#define MAXMISS 10
|
||||
#define isintwups(L) (L->twups != L)
|
||||
|
||||
|
||||
|
||||
/* special status to close upvalues preserving the top of the stack */
|
||||
#define CLOSEKTOP (-1)
|
||||
|
||||
|
||||
|
||||
#define MAXUPVAL 255
|
||||
|
||||
|
||||
#define upisopen(up) ((up)->v != &(up)->u.value)
|
||||
|
||||
|
||||
#define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define MAXMISS 10
|
||||
|
||||
|
||||
|
||||
|
||||
#define CLOSEKTOP (-1)
|
||||
|
||||
|
||||
LUAI_FUNC Proto *luaF_newproto (lua_State *L);
|
||||
|
|
|
@ -1,188 +1,156 @@
|
|||
/*
|
||||
** $Id: lgc.h $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lgc.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lgc_h
|
||||
#define lgc_h
|
||||
#define lgc_h
|
||||
|
||||
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
|
||||
/*
|
||||
** Collectable objects may have one of three colors: white, which means
|
||||
** the object is not marked; gray, which means the object is marked, but
|
||||
** its references may be not marked; and black, which means that the
|
||||
** object and all its references are marked. The main invariant of the
|
||||
** garbage collector, while marking objects, is that a black object can
|
||||
** never point to a white one. Moreover, any gray object must be in a
|
||||
** "gray list" (gray, grayagain, weak, allweak, ephemeron) so that it
|
||||
** can be visited again before finishing the collection cycle. (Open
|
||||
** upvalues are an exception to this rule.) These lists have no meaning
|
||||
** when the invariant is not being enforced (e.g., sweep phase).
|
||||
*/
|
||||
# 31 "./lua/lgc.h"
|
||||
#define GCSpropagate 0
|
||||
#define GCSenteratomic 1
|
||||
#define GCSatomic 2
|
||||
#define GCSswpallgc 3
|
||||
#define GCSswpfinobj 4
|
||||
#define GCSswptobefnz 5
|
||||
#define GCSswpend 6
|
||||
#define GCScallfin 7
|
||||
#define GCSpause 8
|
||||
|
||||
|
||||
/*
|
||||
** Possible states of the Garbage Collector
|
||||
*/
|
||||
#define GCSpropagate 0
|
||||
#define GCSenteratomic 1
|
||||
#define GCSatomic 2
|
||||
#define GCSswpallgc 3
|
||||
#define GCSswpfinobj 4
|
||||
#define GCSswptobefnz 5
|
||||
#define GCSswpend 6
|
||||
#define GCScallfin 7
|
||||
#define GCSpause 8
|
||||
|
||||
|
||||
#define issweepphase(g) \
|
||||
(GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)
|
||||
|
||||
|
||||
/*
|
||||
** macro to tell when main invariant (white objects cannot point to black
|
||||
** ones) must be kept. During a collection, the sweep
|
||||
** phase may break the invariant, as objects turned white may point to
|
||||
** still-black objects. The invariant is restored when sweep ends and
|
||||
** all objects are white again.
|
||||
*/
|
||||
|
||||
#define keepinvariant(g) ((g)->gcstate <= GCSatomic)
|
||||
|
||||
|
||||
/*
|
||||
** some useful bit tricks
|
||||
*/
|
||||
#define resetbits(x,m) ((x) &= cast_byte(~(m)))
|
||||
#define setbits(x,m) ((x) |= (m))
|
||||
#define testbits(x,m) ((x) & (m))
|
||||
#define bitmask(b) (1<<(b))
|
||||
#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
|
||||
#define l_setbit(x,b) setbits(x, bitmask(b))
|
||||
#define resetbit(x,b) resetbits(x, bitmask(b))
|
||||
#define testbit(x,b) testbits(x, bitmask(b))
|
||||
|
||||
|
||||
/*
|
||||
** Layout for bit use in 'marked' field. First three bits are
|
||||
** used for object "age" in generational mode. Last bit is used
|
||||
** by tests.
|
||||
*/
|
||||
#define WHITE0BIT 3 /* object is white (type 0) */
|
||||
#define WHITE1BIT 4 /* object is white (type 1) */
|
||||
#define BLACKBIT 5 /* object is black */
|
||||
#define FINALIZEDBIT 6 /* object has been marked for finalization */
|
||||
|
||||
#define TESTBIT 7
|
||||
#define issweepphase(g) \
|
||||
(GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)
|
||||
# 54 "./lua/lgc.h"
|
||||
#define keepinvariant(g) ((g)->gcstate <= GCSatomic)
|
||||
|
||||
|
||||
|
||||
#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
|
||||
|
||||
|
||||
#define iswhite(x) testbits((x)->marked, WHITEBITS)
|
||||
#define isblack(x) testbit((x)->marked, BLACKBIT)
|
||||
#define isgray(x) /* neither white nor black */ \
|
||||
(!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))
|
||||
|
||||
#define tofinalize(x) testbit((x)->marked, FINALIZEDBIT)
|
||||
|
||||
#define otherwhite(g) ((g)->currentwhite ^ WHITEBITS)
|
||||
#define isdeadm(ow,m) ((m) & (ow))
|
||||
#define isdead(g,v) isdeadm(otherwhite(g), (v)->marked)
|
||||
|
||||
#define changewhite(x) ((x)->marked ^= WHITEBITS)
|
||||
#define nw2black(x) \
|
||||
check_exp(!iswhite(x), l_setbit((x)->marked, BLACKBIT))
|
||||
|
||||
#define luaC_white(g) cast_byte((g)->currentwhite & WHITEBITS)
|
||||
#define resetbits(x,m) ((x) &= cast_byte(~(m)))
|
||||
#define setbits(x,m) ((x) |= (m))
|
||||
#define testbits(x,m) ((x) & (m))
|
||||
#define bitmask(b) (1<<(b))
|
||||
#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
|
||||
#define l_setbit(x,b) setbits(x, bitmask(b))
|
||||
#define resetbit(x,b) resetbits(x, bitmask(b))
|
||||
#define testbit(x,b) testbits(x, bitmask(b))
|
||||
|
||||
|
||||
/* object age in generational mode */
|
||||
#define G_NEW 0 /* created in current cycle */
|
||||
#define G_SURVIVAL 1 /* created in previous cycle */
|
||||
#define G_OLD0 2 /* marked old by frw. barrier in this cycle */
|
||||
#define G_OLD1 3 /* first full cycle as old */
|
||||
#define G_OLD 4 /* really old object (not to be visited) */
|
||||
#define G_TOUCHED1 5 /* old object touched this cycle */
|
||||
#define G_TOUCHED2 6 /* old object touched in previous cycle */
|
||||
|
||||
#define AGEBITS 7 /* all age bits (111) */
|
||||
|
||||
#define getage(o) ((o)->marked & AGEBITS)
|
||||
#define setage(o,a) ((o)->marked = cast_byte(((o)->marked & (~AGEBITS)) | a))
|
||||
#define isold(o) (getage(o) > G_SURVIVAL)
|
||||
|
||||
#define changeage(o,f,t) \
|
||||
check_exp(getage(o) == (f), (o)->marked ^= ((f)^(t)))
|
||||
|
||||
|
||||
/* Default Values for GC parameters */
|
||||
#define LUAI_GENMAJORMUL 100
|
||||
#define LUAI_GENMINORMUL 20
|
||||
|
||||
/* wait memory to double before starting new cycle */
|
||||
#define LUAI_GCPAUSE 200
|
||||
|
||||
/*
|
||||
** some gc parameters are stored divided by 4 to allow a maximum value
|
||||
** up to 1023 in a 'lu_byte'.
|
||||
*/
|
||||
#define getgcparam(p) ((p) * 4)
|
||||
#define setgcparam(p,v) ((p) = (v) / 4)
|
||||
|
||||
#define LUAI_GCMUL 100
|
||||
|
||||
/* how much to allocate before next GC step (log2) */
|
||||
#define LUAI_GCSTEPSIZE 13 /* 8 KB */
|
||||
|
||||
|
||||
/*
|
||||
** Check whether the declared GC mode is generational. While in
|
||||
** generational mode, the collector can go temporarily to incremental
|
||||
** mode to improve performance. This is signaled by 'g->lastatomic != 0'.
|
||||
*/
|
||||
#define isdecGCmodegen(g) (g->gckind == KGC_GEN || g->lastatomic != 0)
|
||||
|
||||
#define WHITE0BIT 3
|
||||
#define WHITE1BIT 4
|
||||
#define BLACKBIT 5
|
||||
#define FINALIZEDBIT 6
|
||||
|
||||
#define TESTBIT 7
|
||||
|
||||
|
||||
/*
|
||||
** Control when GC is running:
|
||||
*/
|
||||
#define GCSTPUSR 1 /* bit true when GC stopped by user */
|
||||
#define GCSTPGC 2 /* bit true when GC stopped by itself */
|
||||
#define GCSTPCLS 4 /* bit true when closing Lua state */
|
||||
#define gcrunning(g) ((g)->gcstp == 0)
|
||||
|
||||
#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
|
||||
|
||||
|
||||
/*
|
||||
** Does one step of collection when debt becomes positive. 'pre'/'pos'
|
||||
** allows some adjustments to be done only when needed. macro
|
||||
** 'condchangemem' is used only for heavy tests (forcing a full
|
||||
** GC cycle on every opportunity)
|
||||
*/
|
||||
#define iswhite(x) testbits((x)->marked, WHITEBITS)
|
||||
#define isblack(x) testbit((x)->marked, BLACKBIT)
|
||||
#define isgray(x) \
|
||||
(!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT)))
|
||||
|
||||
#define tofinalize(x) testbit((x)->marked, FINALIZEDBIT)
|
||||
|
||||
#define otherwhite(g) ((g)->currentwhite ^ WHITEBITS)
|
||||
#define isdeadm(ow,m) ((m) & (ow))
|
||||
#define isdead(g,v) isdeadm(otherwhite(g), (v)->marked)
|
||||
|
||||
#define changewhite(x) ((x)->marked ^= WHITEBITS)
|
||||
#define nw2black(x) \
|
||||
check_exp(!iswhite(x), l_setbit((x)->marked, BLACKBIT))
|
||||
|
||||
#define luaC_white(g) cast_byte((g)->currentwhite & WHITEBITS)
|
||||
|
||||
|
||||
|
||||
#define G_NEW 0
|
||||
#define G_SURVIVAL 1
|
||||
#define G_OLD0 2
|
||||
#define G_OLD1 3
|
||||
#define G_OLD 4
|
||||
#define G_TOUCHED1 5
|
||||
#define G_TOUCHED2 6
|
||||
|
||||
#define AGEBITS 7
|
||||
|
||||
#define getage(o) ((o)->marked & AGEBITS)
|
||||
#define setage(o,a) ((o)->marked = cast_byte(((o)->marked & (~AGEBITS)) | a))
|
||||
#define isold(o) (getage(o) > G_SURVIVAL)
|
||||
|
||||
#define changeage(o,f,t) \
|
||||
check_exp(getage(o) == (f), (o)->marked ^= ((f)^(t)))
|
||||
|
||||
|
||||
|
||||
#define LUAI_GENMAJORMUL 100
|
||||
#define LUAI_GENMINORMUL 20
|
||||
|
||||
|
||||
#define LUAI_GCPAUSE 200
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define getgcparam(p) ((p) * 4)
|
||||
#define setgcparam(p,v) ((p) = (v) / 4)
|
||||
|
||||
#define LUAI_GCMUL 100
|
||||
|
||||
|
||||
#define LUAI_GCSTEPSIZE 13
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define isdecGCmodegen(g) (g->gckind == KGC_GEN || g->lastatomic != 0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define GCSTPUSR 1
|
||||
#define GCSTPGC 2
|
||||
#define GCSTPCLS 4
|
||||
#define gcrunning(g) ((g)->gcstp == 0)
|
||||
# 167 "./lua/lgc.h"
|
||||
#define luaC_condGC(L,pre,pos) \
|
||||
{ if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \
|
||||
condchangemem(L,pre,pos); }
|
||||
|
||||
/* more often than not, 'pre'/'pos' are empty */
|
||||
#define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0)
|
||||
{ if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \
|
||||
condchangemem(L,pre,pos); }
|
||||
|
||||
|
||||
#define luaC_barrier(L,p,v) ( \
|
||||
(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
|
||||
luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))
|
||||
#define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0)
|
||||
|
||||
#define luaC_barrierback(L,p,v) ( \
|
||||
(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
|
||||
luaC_barrierback_(L,p) : cast_void(0))
|
||||
|
||||
#define luaC_objbarrier(L,p,o) ( \
|
||||
(isblack(p) && iswhite(o)) ? \
|
||||
luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))
|
||||
#define luaC_barrier(L,p,v) ( \
|
||||
(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
|
||||
luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0))
|
||||
|
||||
#define luaC_barrierback(L,p,v) ( \
|
||||
(iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \
|
||||
luaC_barrierback_(L,p) : cast_void(0))
|
||||
|
||||
#define luaC_objbarrier(L,p,o) ( \
|
||||
(isblack(p) && iswhite(o)) ? \
|
||||
luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0))
|
||||
|
||||
LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);
|
||||
LUAI_FUNC void luaC_freeallobjects (lua_State *L);
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
/*
|
||||
** $Id: ljumptab.h $
|
||||
** Jump Table for the Lua interpreter
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/ljumptab.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#undef vmdispatch
|
||||
#undef vmcase
|
||||
#undef vmbreak
|
||||
|
||||
#define vmdispatch(x) goto *disptab[x];
|
||||
#define vmdispatch(x) goto *disptab[x];
|
||||
|
||||
#define vmcase(l) L_##l:
|
||||
#define vmcase(l) L_ ##l:
|
||||
|
||||
#define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i));
|
||||
#define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i));
|
||||
|
||||
|
||||
static const void *const disptab[NUM_OPCODES] = {
|
||||
|
@ -21,7 +22,7 @@ static const void *const disptab[NUM_OPCODES] = {
|
|||
#if 0
|
||||
** you can update the following list with this command:
|
||||
**
|
||||
** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h
|
||||
** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h
|
||||
**
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
/*
|
||||
** $Id: llex.h $
|
||||
** Lexical Analyzer
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/llex.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef llex_h
|
||||
#define llex_h
|
||||
#define llex_h
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
|
@ -13,44 +14,44 @@
|
|||
#include "lzio.h"
|
||||
|
||||
|
||||
/*
|
||||
** Single-char tokens (terminal symbols) are represented by their own
|
||||
** numeric code. Other tokens start at the following value.
|
||||
*/
|
||||
#define FIRST_RESERVED (UCHAR_MAX + 1)
|
||||
|
||||
|
||||
|
||||
|
||||
#define FIRST_RESERVED (UCHAR_MAX + 1)
|
||||
|
||||
|
||||
#if !defined(LUA_ENV)
|
||||
#define LUA_ENV "_ENV"
|
||||
#define LUA_ENV "_ENV"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* WARNING: if you change the order of this enumeration,
|
||||
* grep "ORDER RESERVED"
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
enum RESERVED {
|
||||
/* terminal symbols denoted by reserved words */
|
||||
|
||||
TK_AND = FIRST_RESERVED, TK_BREAK,
|
||||
TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
|
||||
TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
|
||||
TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
|
||||
/* other terminal symbols */
|
||||
|
||||
TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,
|
||||
TK_SHL, TK_SHR,
|
||||
TK_DBCOLON, TK_EOS,
|
||||
TK_FLT, TK_INT, TK_NAME, TK_STRING
|
||||
};
|
||||
|
||||
/* number of reserved words */
|
||||
#define NUM_RESERVED (cast_int(TK_WHILE-FIRST_RESERVED + 1))
|
||||
|
||||
#define NUM_RESERVED (cast_int(TK_WHILE-FIRST_RESERVED + 1))
|
||||
|
||||
|
||||
typedef union {
|
||||
lua_Number r;
|
||||
lua_Integer i;
|
||||
TString *ts;
|
||||
} SemInfo; /* semantics information */
|
||||
} SemInfo;
|
||||
|
||||
|
||||
typedef struct Token {
|
||||
|
@ -59,22 +60,22 @@ typedef struct Token {
|
|||
} Token;
|
||||
|
||||
|
||||
/* state of the lexer plus state of the parser when shared by all
|
||||
functions */
|
||||
|
||||
|
||||
typedef struct LexState {
|
||||
int current; /* current character (charint) */
|
||||
int linenumber; /* input line counter */
|
||||
int lastline; /* line of last token 'consumed' */
|
||||
Token t; /* current token */
|
||||
Token lookahead; /* look ahead token */
|
||||
struct FuncState *fs; /* current function (parser) */
|
||||
int current;
|
||||
int linenumber;
|
||||
int lastline;
|
||||
Token t;
|
||||
Token lookahead;
|
||||
struct FuncState *fs;
|
||||
struct lua_State *L;
|
||||
ZIO *z; /* input stream */
|
||||
Mbuffer *buff; /* buffer for tokens */
|
||||
Table *h; /* to avoid collection/reuse strings */
|
||||
struct Dyndata *dyd; /* dynamic structures used by the parser */
|
||||
TString *source; /* current source name */
|
||||
TString *envn; /* environment variable name */
|
||||
ZIO *z;
|
||||
Mbuffer *buff;
|
||||
Table *h;
|
||||
struct Dyndata *dyd;
|
||||
TString *source;
|
||||
TString *envn;
|
||||
} LexState;
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
/*
|
||||
** $Id: llimits.h $
|
||||
** Limits, basic types, and some other 'installation-dependent' definitions
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/llimits.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef llimits_h
|
||||
#define llimits_h
|
||||
#define llimits_h
|
||||
|
||||
|
||||
#include <limits.h>
|
||||
|
@ -15,174 +16,174 @@
|
|||
#include "lua.h"
|
||||
|
||||
|
||||
/*
|
||||
** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count
|
||||
** the total memory used by Lua (in bytes). Usually, 'size_t' and
|
||||
** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.
|
||||
*/
|
||||
#if defined(LUAI_MEM) /* { external definitions? */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(LUAI_MEM)
|
||||
typedef LUAI_UMEM lu_mem;
|
||||
typedef LUAI_MEM l_mem;
|
||||
#elif LUAI_IS32INT /* }{ */
|
||||
#elif LUAI_IS32INT
|
||||
typedef size_t lu_mem;
|
||||
typedef ptrdiff_t l_mem;
|
||||
#else /* 16-bit ints */ /* }{ */
|
||||
#else
|
||||
typedef unsigned long lu_mem;
|
||||
typedef long l_mem;
|
||||
#endif /* } */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* chars used as small naturals (so that 'char' is reserved for characters) */
|
||||
typedef unsigned char lu_byte;
|
||||
typedef signed char ls_byte;
|
||||
|
||||
|
||||
/* maximum value for size_t */
|
||||
#define MAX_SIZET ((size_t)(~(size_t)0))
|
||||
|
||||
/* maximum size visible for Lua (must be representable in a lua_Integer) */
|
||||
#define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \
|
||||
#define MAX_SIZET ((size_t)(~(size_t)0))
|
||||
|
||||
|
||||
#define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \
|
||||
: (size_t)(LUA_MAXINTEGER))
|
||||
|
||||
|
||||
#define MAX_LUMEM ((lu_mem)(~(lu_mem)0))
|
||||
#define MAX_LUMEM ((lu_mem)(~(lu_mem)0))
|
||||
|
||||
#define MAX_LMEM ((l_mem)(MAX_LUMEM >> 1))
|
||||
#define MAX_LMEM ((l_mem)(MAX_LUMEM >> 1))
|
||||
|
||||
|
||||
#define MAX_INT INT_MAX /* maximum value of an int */
|
||||
|
||||
|
||||
/*
|
||||
** floor of the log2 of the maximum signed value for integral type 't'.
|
||||
** (That is, maximum 'n' such that '2^n' fits in the given signed type.)
|
||||
*/
|
||||
#define log2maxs(t) (sizeof(t) * 8 - 2)
|
||||
|
||||
|
||||
/*
|
||||
** test whether an unsigned value is a power of 2 (or zero)
|
||||
*/
|
||||
#define ispow2(x) (((x) & ((x) - 1)) == 0)
|
||||
|
||||
|
||||
/* number of chars of a literal string without the ending \0 */
|
||||
#define LL(x) (sizeof(x)/sizeof(char) - 1)
|
||||
|
||||
|
||||
/*
|
||||
** conversion of pointer to unsigned integer:
|
||||
** this is for hashing only; there is no problem if the integer
|
||||
** cannot hold the whole pointer value
|
||||
*/
|
||||
#define point2uint(p) ((unsigned int)((size_t)(p) & UINT_MAX))
|
||||
#define MAX_INT INT_MAX
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define log2maxs(t) (sizeof(t) * 8 - 2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ispow2(x) (((x) & ((x) - 1)) == 0)
|
||||
|
||||
|
||||
|
||||
#define LL(x) (sizeof(x)/sizeof(char) - 1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define point2uint(p) ((unsigned int)((size_t)(p) & UINT_MAX))
|
||||
|
||||
|
||||
|
||||
|
||||
/* types of 'usual argument conversions' for lua_Number and lua_Integer */
|
||||
typedef LUAI_UACNUMBER l_uacNumber;
|
||||
typedef LUAI_UACINT l_uacInt;
|
||||
|
||||
|
||||
/*
|
||||
** Internal assertions for in-house debugging
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if defined LUAI_ASSERT
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#define lua_assert(c) assert(c)
|
||||
#define lua_assert(c) assert(c)
|
||||
#endif
|
||||
|
||||
#if defined(lua_assert)
|
||||
#define check_exp(c,e) (lua_assert(c), (e))
|
||||
/* to avoid problems with conditions too long */
|
||||
#define lua_longassert(c) ((c) ? (void)0 : lua_assert(0))
|
||||
#define check_exp(c,e) (lua_assert(c), (e))
|
||||
|
||||
#define lua_longassert(c) ((c) ? (void)0 : lua_assert(0))
|
||||
#else
|
||||
#define lua_assert(c) ((void)0)
|
||||
#define check_exp(c,e) (e)
|
||||
#define lua_longassert(c) ((void)0)
|
||||
#define lua_assert(c) ((void)0)
|
||||
#define check_exp(c,e) (e)
|
||||
#define lua_longassert(c) ((void)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** assertion for checking API calls
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if !defined(luai_apicheck)
|
||||
#define luai_apicheck(l,e) ((void)l, lua_assert(e))
|
||||
#define luai_apicheck(l,e) ((void)l, lua_assert(e))
|
||||
#endif
|
||||
|
||||
#define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
|
||||
#define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
|
||||
|
||||
|
||||
|
||||
/* macro to avoid warnings about unused variables */
|
||||
#if !defined(UNUSED)
|
||||
#define UNUSED(x) ((void)(x))
|
||||
#define UNUSED(x) ((void)(x))
|
||||
#endif
|
||||
|
||||
|
||||
/* type casts (a macro highlights casts in the code) */
|
||||
#define cast(t, exp) ((t)(exp))
|
||||
|
||||
#define cast_void(i) cast(void, (i))
|
||||
#define cast_voidp(i) cast(void *, (i))
|
||||
#define cast_num(i) cast(lua_Number, (i))
|
||||
#define cast_int(i) cast(int, (i))
|
||||
#define cast_uint(i) cast(unsigned int, (i))
|
||||
#define cast_byte(i) cast(lu_byte, (i))
|
||||
#define cast_uchar(i) cast(unsigned char, (i))
|
||||
#define cast_char(i) cast(char, (i))
|
||||
#define cast_charp(i) cast(char *, (i))
|
||||
#define cast_sizet(i) cast(size_t, (i))
|
||||
#define cast(t,exp) ((t)(exp))
|
||||
|
||||
#define cast_void(i) cast(void, (i))
|
||||
#define cast_voidp(i) cast(void *, (i))
|
||||
#define cast_num(i) cast(lua_Number, (i))
|
||||
#define cast_int(i) cast(int, (i))
|
||||
#define cast_uint(i) cast(unsigned int, (i))
|
||||
#define cast_byte(i) cast(lu_byte, (i))
|
||||
#define cast_uchar(i) cast(unsigned char, (i))
|
||||
#define cast_char(i) cast(char, (i))
|
||||
#define cast_charp(i) cast(char *, (i))
|
||||
#define cast_sizet(i) cast(size_t, (i))
|
||||
|
||||
|
||||
|
||||
/* cast a signed lua_Integer to lua_Unsigned */
|
||||
#if !defined(l_castS2U)
|
||||
#define l_castS2U(i) ((lua_Unsigned)(i))
|
||||
#define l_castS2U(i) ((lua_Unsigned)(i))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** cast a lua_Unsigned to a signed lua_Integer; this cast is
|
||||
** not strict ISO C, but two-complement architectures should
|
||||
** work fine.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(l_castU2S)
|
||||
#define l_castU2S(i) ((lua_Integer)(i))
|
||||
#define l_castU2S(i) ((lua_Integer)(i))
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** non-return type
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if !defined(l_noret)
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define l_noret void __attribute__((noreturn))
|
||||
#define l_noret void __attribute__((noreturn))
|
||||
#elif defined(_MSC_VER) && _MSC_VER >= 1200
|
||||
#define l_noret void __declspec(noreturn)
|
||||
#define l_noret void __declspec(noreturn)
|
||||
#else
|
||||
#define l_noret void
|
||||
#define l_noret void
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Inline functions
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if !defined(LUA_USE_C89)
|
||||
#define l_inline inline
|
||||
#define l_inline inline
|
||||
#elif defined(__GNUC__)
|
||||
#define l_inline __inline__
|
||||
#define l_inline __inline__
|
||||
#else
|
||||
#define l_inline /* empty */
|
||||
#define l_inline
|
||||
#endif
|
||||
|
||||
#define l_sinline static l_inline
|
||||
#define l_sinline static l_inline
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** type for virtual-machine instructions;
|
||||
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
|
||||
*/
|
||||
#if LUAI_IS32INT
|
||||
typedef unsigned int l_uint32;
|
||||
#else
|
||||
|
@ -190,178 +191,131 @@ typedef unsigned long l_uint32;
|
|||
#endif
|
||||
|
||||
typedef l_uint32 Instruction;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Maximum length for short strings, that is, strings that are
|
||||
** internalized. (Cannot be smaller than reserved words or tags for
|
||||
** metamethods, as these strings must be internalized;
|
||||
** #("function") = 8, #("__newindex") = 10.)
|
||||
*/
|
||||
# 202 "./lua/llimits.h"
|
||||
#if !defined(LUAI_MAXSHORTLEN)
|
||||
#define LUAI_MAXSHORTLEN 40
|
||||
#define LUAI_MAXSHORTLEN 40
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Initial size for the string table (must be power of 2).
|
||||
** The Lua core alone registers ~50 strings (reserved words +
|
||||
** metaevent keys + a few others). Libraries would typically add
|
||||
** a few dozens more.
|
||||
*/
|
||||
# 213 "./lua/llimits.h"
|
||||
#if !defined(MINSTRTABSIZE)
|
||||
#define MINSTRTABSIZE 128
|
||||
#define MINSTRTABSIZE 128
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Size of cache for strings in the API. 'N' is the number of
|
||||
** sets (better be a prime) and "M" is the size of each set (M == 1
|
||||
** makes a direct cache.)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(STRCACHE_N)
|
||||
#define STRCACHE_N 53
|
||||
#define STRCACHE_M 2
|
||||
#define STRCACHE_N 53
|
||||
#define STRCACHE_M 2
|
||||
#endif
|
||||
|
||||
|
||||
/* minimum size for string buffer */
|
||||
|
||||
#if !defined(LUA_MINBUFFER)
|
||||
#define LUA_MINBUFFER 32
|
||||
#define LUA_MINBUFFER 32
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Maximum depth for nested C calls, syntactical nested non-terminals,
|
||||
** and other features implemented through recursion in C. (Value must
|
||||
** fit in a 16-bit unsigned integer. It must also be compatible with
|
||||
** the size of the C stack.)
|
||||
*/
|
||||
# 241 "./lua/llimits.h"
|
||||
#if !defined(LUAI_MAXCCALLS)
|
||||
#define LUAI_MAXCCALLS 200
|
||||
#define LUAI_MAXCCALLS 200
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** macros that are executed whenever program enters the Lua core
|
||||
** ('lua_lock') and leaves the core ('lua_unlock')
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(lua_lock)
|
||||
#define lua_lock(L) ((void) 0)
|
||||
#define lua_unlock(L) ((void) 0)
|
||||
#define lua_lock(L) ((void) 0)
|
||||
#define lua_unlock(L) ((void) 0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** macro executed during Lua functions at points where the
|
||||
** function can yield.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(luai_threadyield)
|
||||
#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
|
||||
#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** these macros allow user-specific actions when a thread is
|
||||
** created/deleted/resumed/yielded.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(luai_userstateopen)
|
||||
#define luai_userstateopen(L) ((void)L)
|
||||
#define luai_userstateopen(L) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstateclose)
|
||||
#define luai_userstateclose(L) ((void)L)
|
||||
#define luai_userstateclose(L) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstatethread)
|
||||
#define luai_userstatethread(L,L1) ((void)L)
|
||||
#define luai_userstatethread(L,L1) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstatefree)
|
||||
#define luai_userstatefree(L,L1) ((void)L)
|
||||
#define luai_userstatefree(L,L1) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstateresume)
|
||||
#define luai_userstateresume(L,n) ((void)L)
|
||||
#define luai_userstateresume(L,n) ((void)L)
|
||||
#endif
|
||||
|
||||
#if !defined(luai_userstateyield)
|
||||
#define luai_userstateyield(L,n) ((void)L)
|
||||
#define luai_userstateyield(L,n) ((void)L)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** The luai_num* macros define the primitive operations over numbers.
|
||||
*/
|
||||
|
||||
/* floor division (defined as 'floor(a/b)') */
|
||||
# 299 "./lua/llimits.h"
|
||||
#if !defined(luai_numidiv)
|
||||
#define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b)))
|
||||
#define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b)))
|
||||
#endif
|
||||
|
||||
/* float division */
|
||||
|
||||
#if !defined(luai_numdiv)
|
||||
#define luai_numdiv(L,a,b) ((a)/(b))
|
||||
#define luai_numdiv(L,a,b) ((a)/(b))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** modulo: defined as 'a - floor(a/b)*b'; the direct computation
|
||||
** using this definition has several problems with rounding errors,
|
||||
** so it is better to use 'fmod'. 'fmod' gives the result of
|
||||
** 'a - trunc(a/b)*b', and therefore must be corrected when
|
||||
** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a
|
||||
** non-integer negative result: non-integer result is equivalent to
|
||||
** a non-zero remainder 'm'; negative result is equivalent to 'a' and
|
||||
** 'b' with different signs, or 'm' and 'b' with different signs
|
||||
** (as the result 'm' of 'fmod' has the same sign of 'a').
|
||||
*/
|
||||
# 319 "./lua/llimits.h"
|
||||
#if !defined(luai_nummod)
|
||||
#define luai_nummod(L,a,b,m) \
|
||||
#define luai_nummod(L,a,b,m) \
|
||||
{ (void)L; (m) = l_mathop(fmod)(a,b); \
|
||||
if (((m) > 0) ? (b) < 0 : ((m) < 0 && (b) > 0)) (m) += (b); }
|
||||
#endif
|
||||
|
||||
/* exponentiation */
|
||||
|
||||
#if !defined(luai_numpow)
|
||||
#define luai_numpow(L,a,b) \
|
||||
#define luai_numpow(L,a,b) \
|
||||
((void)L, (b == 2) ? (a)*(a) : l_mathop(pow)(a,b))
|
||||
#endif
|
||||
|
||||
/* the others are quite standard operations */
|
||||
|
||||
#if !defined(luai_numadd)
|
||||
#define luai_numadd(L,a,b) ((a)+(b))
|
||||
#define luai_numsub(L,a,b) ((a)-(b))
|
||||
#define luai_nummul(L,a,b) ((a)*(b))
|
||||
#define luai_numunm(L,a) (-(a))
|
||||
#define luai_numeq(a,b) ((a)==(b))
|
||||
#define luai_numlt(a,b) ((a)<(b))
|
||||
#define luai_numle(a,b) ((a)<=(b))
|
||||
#define luai_numgt(a,b) ((a)>(b))
|
||||
#define luai_numge(a,b) ((a)>=(b))
|
||||
#define luai_numisnan(a) (!luai_numeq((a), (a)))
|
||||
#define luai_numadd(L,a,b) ((a)+(b))
|
||||
#define luai_numsub(L,a,b) ((a)-(b))
|
||||
#define luai_nummul(L,a,b) ((a)*(b))
|
||||
#define luai_numunm(L,a) (-(a))
|
||||
#define luai_numeq(a,b) ((a)==(b))
|
||||
#define luai_numlt(a,b) ((a)<(b))
|
||||
#define luai_numle(a,b) ((a)<=(b))
|
||||
#define luai_numgt(a,b) ((a)>(b))
|
||||
#define luai_numge(a,b) ((a)>=(b))
|
||||
#define luai_numisnan(a) (!luai_numeq((a), (a)))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** macro to control inclusion of some hard tests on stack reallocation
|
||||
*/
|
||||
# 352 "./lua/llimits.h"
|
||||
#if !defined(HARDSTACKTESTS)
|
||||
#define condmovestack(L,pre,pos) ((void)0)
|
||||
#define condmovestack(L,pre,pos) ((void)0)
|
||||
#else
|
||||
/* realloc stack keeping its size */
|
||||
#define condmovestack(L,pre,pos) \
|
||||
|
||||
#define condmovestack(L,pre,pos) \
|
||||
{ int sz_ = stacksize(L); pre; luaD_reallocstack((L), sz_, 0); pos; }
|
||||
#endif
|
||||
|
||||
#if !defined(HARDMEMTESTS)
|
||||
#define condchangemem(L,pre,pos) ((void)0)
|
||||
#define condchangemem(L,pre,pos) ((void)0)
|
||||
#else
|
||||
#define condchangemem(L,pre,pos) \
|
||||
{ if (gcrunning(G(L))) { pre; luaC_fullgc(L, 0); pos; } }
|
||||
#define condchangemem(L,pre,pos) \
|
||||
{ if (gcrunning(G(L))) { pre; luaC_fullgc(L, 0); pos; } }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
/*
|
||||
** $Id: lmem.h $
|
||||
** Interface to Memory Manager
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lmem.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lmem_h
|
||||
#define lmem_h
|
||||
#define lmem_h
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
@ -14,60 +15,41 @@
|
|||
#include "lua.h"
|
||||
|
||||
|
||||
#define luaM_error(L) luaD_throw(L, LUA_ERRMEM)
|
||||
#define luaM_error(L) luaD_throw(L, LUA_ERRMEM)
|
||||
# 31 "./lua/lmem.h"
|
||||
#define luaM_testsize(n,e) \
|
||||
(sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e))
|
||||
|
||||
|
||||
/*
|
||||
** This macro tests whether it is safe to multiply 'n' by the size of
|
||||
** type 't' without overflows. Because 'e' is always constant, it avoids
|
||||
** the runtime division MAX_SIZET/(e).
|
||||
** (The macro is somewhat complex to avoid warnings: The 'sizeof'
|
||||
** comparison avoids a runtime comparison when overflow cannot occur.
|
||||
** The compiler should be able to optimize the real test by itself, but
|
||||
** when it does it, it may give a warning about "comparison is always
|
||||
** false due to limited range of data type"; the +1 tricks the compiler,
|
||||
** avoiding this warning but also this optimization.)
|
||||
*/
|
||||
#define luaM_testsize(n,e) \
|
||||
(sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e))
|
||||
|
||||
#define luaM_checksize(L,n,e) \
|
||||
(luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0))
|
||||
|
||||
|
||||
/*
|
||||
** Computes the minimum between 'n' and 'MAX_SIZET/sizeof(t)', so that
|
||||
** the result is not larger than 'n' and cannot overflow a 'size_t'
|
||||
** when multiplied by the size of type 't'. (Assumes that 'n' is an
|
||||
** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.)
|
||||
*/
|
||||
#define luaM_limitN(n,t) \
|
||||
((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \
|
||||
#define luaM_checksize(L,n,e) \
|
||||
(luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0))
|
||||
# 44 "./lua/lmem.h"
|
||||
#define luaM_limitN(n,t) \
|
||||
((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \
|
||||
cast_uint((MAX_SIZET/sizeof(t))))
|
||||
|
||||
|
||||
/*
|
||||
** Arrays of chars do not need any test
|
||||
*/
|
||||
#define luaM_reallocvchar(L,b,on,n) \
|
||||
|
||||
|
||||
|
||||
#define luaM_reallocvchar(L,b,on,n) \
|
||||
cast_charp(luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))
|
||||
|
||||
#define luaM_freemem(L, b, s) luaM_free_(L, (b), (s))
|
||||
#define luaM_free(L, b) luaM_free_(L, (b), sizeof(*(b)))
|
||||
#define luaM_freearray(L, b, n) luaM_free_(L, (b), (n)*sizeof(*(b)))
|
||||
#define luaM_freemem(L,b,s) luaM_free_(L, (b), (s))
|
||||
#define luaM_free(L,b) luaM_free_(L, (b), sizeof(*(b)))
|
||||
#define luaM_freearray(L,b,n) luaM_free_(L, (b), (n)*sizeof(*(b)))
|
||||
|
||||
#define luaM_new(L,t) cast(t*, luaM_malloc_(L, sizeof(t), 0))
|
||||
#define luaM_newvector(L,n,t) cast(t*, luaM_malloc_(L, (n)*sizeof(t), 0))
|
||||
#define luaM_new(L,t) cast(t*, luaM_malloc_(L, sizeof(t), 0))
|
||||
#define luaM_newvector(L,n,t) cast(t*, luaM_malloc_(L, (n)*sizeof(t), 0))
|
||||
#define luaM_newvectorchecked(L,n,t) \
|
||||
(luaM_checksize(L,n,sizeof(t)), luaM_newvector(L,n,t))
|
||||
|
||||
#define luaM_newobject(L,tag,s) luaM_malloc_(L, (s), tag)
|
||||
#define luaM_newobject(L,tag,s) luaM_malloc_(L, (s), tag)
|
||||
|
||||
#define luaM_growvector(L,v,nelems,size,t,limit,e) \
|
||||
((v)=cast(t *, luaM_growaux_(L,v,nelems,&(size),sizeof(t), \
|
||||
((v)=cast(t *, luaM_growaux_(L,v,nelems,&(size),sizeof(t), \
|
||||
luaM_limitN(limit,t),e)))
|
||||
|
||||
#define luaM_reallocvector(L, v,oldn,n,t) \
|
||||
#define luaM_reallocvector(L,v,oldn,n,t) \
|
||||
(cast(t *, luaM_realloc_(L, v, cast_sizet(oldn) * sizeof(t), \
|
||||
cast_sizet(n) * sizeof(t))))
|
||||
|
||||
|
@ -76,7 +58,7 @@
|
|||
|
||||
LUAI_FUNC l_noret luaM_toobig (lua_State *L);
|
||||
|
||||
/* not to be called directly */
|
||||
|
||||
LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
|
||||
size_t size);
|
||||
LUAI_FUNC void *luaM_saferealloc_ (lua_State *L, void *block, size_t oldsize,
|
||||
|
@ -90,4 +72,3 @@ LUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem,
|
|||
LUAI_FUNC void *luaM_malloc_ (lua_State *L, size_t size, int tag);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,405 +1,299 @@
|
|||
/*
|
||||
** $Id: lopcodes.h $
|
||||
** Opcodes for Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lopcodes.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lopcodes_h
|
||||
#define lopcodes_h
|
||||
#define lopcodes_h
|
||||
|
||||
#include "llimits.h"
|
||||
# 32 "./lua/lopcodes.h"
|
||||
enum OpMode {iABC, iABx, iAsBx, iAx, isJ};
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
We assume that instructions are unsigned 32-bit integers.
|
||||
All instructions have an opcode in the first 7 bits.
|
||||
Instructions can have the following formats:
|
||||
|
||||
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
|
||||
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
iABC C(8) | B(8) |k| A(8) | Op(7) |
|
||||
iABx Bx(17) | A(8) | Op(7) |
|
||||
iAsBx sBx (signed)(17) | A(8) | Op(7) |
|
||||
iAx Ax(25) | Op(7) |
|
||||
isJ sJ(25) | Op(7) |
|
||||
|
||||
A signed argument is represented in excess K: the represented value is
|
||||
the written unsigned value minus K, where K is half the maximum for the
|
||||
corresponding unsigned argument.
|
||||
===========================================================================*/
|
||||
|
||||
|
||||
enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
|
||||
|
||||
#define SIZE_C 8
|
||||
#define SIZE_B 8
|
||||
#define SIZE_Bx (SIZE_C + SIZE_B + 1)
|
||||
#define SIZE_A 8
|
||||
#define SIZE_Ax (SIZE_Bx + SIZE_A)
|
||||
#define SIZE_sJ (SIZE_Bx + SIZE_A)
|
||||
|
||||
/*
|
||||
** size and position of opcode arguments.
|
||||
*/
|
||||
#define SIZE_C 8
|
||||
#define SIZE_B 8
|
||||
#define SIZE_Bx (SIZE_C + SIZE_B + 1)
|
||||
#define SIZE_A 8
|
||||
#define SIZE_Ax (SIZE_Bx + SIZE_A)
|
||||
#define SIZE_sJ (SIZE_Bx + SIZE_A)
|
||||
#define SIZE_OP 7
|
||||
|
||||
#define SIZE_OP 7
|
||||
#define POS_OP 0
|
||||
|
||||
#define POS_OP 0
|
||||
#define POS_A (POS_OP + SIZE_OP)
|
||||
#define POS_k (POS_A + SIZE_A)
|
||||
#define POS_B (POS_k + 1)
|
||||
#define POS_C (POS_B + SIZE_B)
|
||||
|
||||
#define POS_A (POS_OP + SIZE_OP)
|
||||
#define POS_k (POS_A + SIZE_A)
|
||||
#define POS_B (POS_k + 1)
|
||||
#define POS_C (POS_B + SIZE_B)
|
||||
#define POS_Bx POS_k
|
||||
|
||||
#define POS_Bx POS_k
|
||||
#define POS_Ax POS_A
|
||||
|
||||
#define POS_Ax POS_A
|
||||
|
||||
#define POS_sJ POS_A
|
||||
|
||||
|
||||
/*
|
||||
** limits for opcode arguments.
|
||||
** we use (signed) 'int' to manipulate most arguments,
|
||||
** so they must fit in ints.
|
||||
*/
|
||||
|
||||
/* Check whether type 'int' has at least 'b' bits ('b' < 32) */
|
||||
#define L_INTHASBITS(b) ((UINT_MAX >> ((b) - 1)) >= 1)
|
||||
#define POS_sJ POS_A
|
||||
# 68 "./lua/lopcodes.h"
|
||||
#define L_INTHASBITS(b) ((UINT_MAX >> ((b) - 1)) >= 1)
|
||||
|
||||
|
||||
#if L_INTHASBITS(SIZE_Bx)
|
||||
#define MAXARG_Bx ((1<<SIZE_Bx)-1)
|
||||
#define MAXARG_Bx ((1<<SIZE_Bx)-1)
|
||||
#else
|
||||
#define MAXARG_Bx MAX_INT
|
||||
#define MAXARG_Bx MAX_INT
|
||||
#endif
|
||||
|
||||
#define OFFSET_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */
|
||||
#define OFFSET_sBx (MAXARG_Bx>>1)
|
||||
|
||||
|
||||
#if L_INTHASBITS(SIZE_Ax)
|
||||
#define MAXARG_Ax ((1<<SIZE_Ax)-1)
|
||||
#define MAXARG_Ax ((1<<SIZE_Ax)-1)
|
||||
#else
|
||||
#define MAXARG_Ax MAX_INT
|
||||
#define MAXARG_Ax MAX_INT
|
||||
#endif
|
||||
|
||||
#if L_INTHASBITS(SIZE_sJ)
|
||||
#define MAXARG_sJ ((1 << SIZE_sJ) - 1)
|
||||
#define MAXARG_sJ ((1 << SIZE_sJ) - 1)
|
||||
#else
|
||||
#define MAXARG_sJ MAX_INT
|
||||
#define MAXARG_sJ MAX_INT
|
||||
#endif
|
||||
|
||||
#define OFFSET_sJ (MAXARG_sJ >> 1)
|
||||
#define OFFSET_sJ (MAXARG_sJ >> 1)
|
||||
|
||||
|
||||
#define MAXARG_A ((1<<SIZE_A)-1)
|
||||
#define MAXARG_B ((1<<SIZE_B)-1)
|
||||
#define MAXARG_C ((1<<SIZE_C)-1)
|
||||
#define OFFSET_sC (MAXARG_C >> 1)
|
||||
#define MAXARG_A ((1<<SIZE_A)-1)
|
||||
#define MAXARG_B ((1<<SIZE_B)-1)
|
||||
#define MAXARG_C ((1<<SIZE_C)-1)
|
||||
#define OFFSET_sC (MAXARG_C >> 1)
|
||||
|
||||
#define int2sC(i) ((i) + OFFSET_sC)
|
||||
#define sC2int(i) ((i) - OFFSET_sC)
|
||||
#define int2sC(i) ((i) + OFFSET_sC)
|
||||
#define sC2int(i) ((i) - OFFSET_sC)
|
||||
|
||||
|
||||
/* creates a mask with 'n' 1 bits at position 'p' */
|
||||
#define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p))
|
||||
|
||||
/* creates a mask with 'n' 0 bits at position 'p' */
|
||||
#define MASK0(n,p) (~MASK1(n,p))
|
||||
|
||||
/*
|
||||
** the following macros help to manipulate instructions
|
||||
*/
|
||||
|
||||
#define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
|
||||
#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
|
||||
((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
|
||||
|
||||
#define checkopm(i,m) (getOpMode(GET_OPCODE(i)) == m)
|
||||
#define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p))
|
||||
|
||||
|
||||
#define getarg(i,pos,size) (cast_int(((i)>>(pos)) & MASK1(size,0)))
|
||||
#define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \
|
||||
#define MASK0(n,p) (~MASK1(n,p))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
|
||||
#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
|
||||
((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
|
||||
|
||||
#define checkopm(i,m) (getOpMode(GET_OPCODE(i)) == m)
|
||||
|
||||
|
||||
#define getarg(i,pos,size) (cast_int(((i)>>(pos)) & MASK1(size,0)))
|
||||
#define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \
|
||||
((cast(Instruction, v)<<pos)&MASK1(size,pos))))
|
||||
|
||||
#define GETARG_A(i) getarg(i, POS_A, SIZE_A)
|
||||
#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
|
||||
#define GETARG_A(i) getarg(i, POS_A, SIZE_A)
|
||||
#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
|
||||
|
||||
#define GETARG_B(i) check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B))
|
||||
#define GETARG_sB(i) sC2int(GETARG_B(i))
|
||||
#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
|
||||
#define GETARG_B(i) check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B))
|
||||
#define GETARG_sB(i) sC2int(GETARG_B(i))
|
||||
#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
|
||||
|
||||
#define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C))
|
||||
#define GETARG_sC(i) sC2int(GETARG_C(i))
|
||||
#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
|
||||
#define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C))
|
||||
#define GETARG_sC(i) sC2int(GETARG_C(i))
|
||||
#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
|
||||
|
||||
#define TESTARG_k(i) check_exp(checkopm(i, iABC), (cast_int(((i) & (1u << POS_k)))))
|
||||
#define GETARG_k(i) check_exp(checkopm(i, iABC), getarg(i, POS_k, 1))
|
||||
#define SETARG_k(i,v) setarg(i, v, POS_k, 1)
|
||||
#define TESTARG_k(i) check_exp(checkopm(i, iABC), (cast_int(((i) & (1u << POS_k)))))
|
||||
#define GETARG_k(i) check_exp(checkopm(i, iABC), getarg(i, POS_k, 1))
|
||||
#define SETARG_k(i,v) setarg(i, v, POS_k, 1)
|
||||
|
||||
#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx))
|
||||
#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx)
|
||||
#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx))
|
||||
#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx)
|
||||
|
||||
#define GETARG_Ax(i) check_exp(checkopm(i, iAx), getarg(i, POS_Ax, SIZE_Ax))
|
||||
#define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax)
|
||||
#define GETARG_Ax(i) check_exp(checkopm(i, iAx), getarg(i, POS_Ax, SIZE_Ax))
|
||||
#define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax)
|
||||
|
||||
#define GETARG_sBx(i) \
|
||||
check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - OFFSET_sBx)
|
||||
#define SETARG_sBx(i,b) SETARG_Bx((i),cast_uint((b)+OFFSET_sBx))
|
||||
#define GETARG_sBx(i) \
|
||||
check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - OFFSET_sBx)
|
||||
#define SETARG_sBx(i,b) SETARG_Bx((i),cast_uint((b)+OFFSET_sBx))
|
||||
|
||||
#define GETARG_sJ(i) \
|
||||
check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ)
|
||||
#define GETARG_sJ(i) \
|
||||
check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ)
|
||||
#define SETARG_sJ(i,j) \
|
||||
setarg(i, cast_uint((j)+OFFSET_sJ), POS_sJ, SIZE_sJ)
|
||||
setarg(i, cast_uint((j)+OFFSET_sJ), POS_sJ, SIZE_sJ)
|
||||
|
||||
|
||||
#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \
|
||||
| (cast(Instruction, a)<<POS_A) \
|
||||
| (cast(Instruction, b)<<POS_B) \
|
||||
| (cast(Instruction, c)<<POS_C) \
|
||||
| (cast(Instruction, k)<<POS_k))
|
||||
#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \
|
||||
| (cast(Instruction, a)<<POS_A) \
|
||||
| (cast(Instruction, b)<<POS_B) \
|
||||
| (cast(Instruction, c)<<POS_C) \
|
||||
| (cast(Instruction, k)<<POS_k))
|
||||
|
||||
#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \
|
||||
| (cast(Instruction, a)<<POS_A) \
|
||||
| (cast(Instruction, bc)<<POS_Bx))
|
||||
#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \
|
||||
| (cast(Instruction, a)<<POS_A) \
|
||||
| (cast(Instruction, bc)<<POS_Bx))
|
||||
|
||||
#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
|
||||
| (cast(Instruction, a)<<POS_Ax))
|
||||
#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
|
||||
| (cast(Instruction, a)<<POS_Ax))
|
||||
|
||||
#define CREATE_sJ(o,j,k) ((cast(Instruction, o) << POS_OP) \
|
||||
| (cast(Instruction, j) << POS_sJ) \
|
||||
| (cast(Instruction, k) << POS_k))
|
||||
#define CREATE_sJ(o,j,k) ((cast(Instruction, o) << POS_OP) \
|
||||
| (cast(Instruction, j) << POS_sJ) \
|
||||
| (cast(Instruction, k) << POS_k))
|
||||
|
||||
|
||||
#if !defined(MAXINDEXRK) /* (for debugging only) */
|
||||
#define MAXINDEXRK MAXARG_B
|
||||
#if !defined(MAXINDEXRK)
|
||||
#define MAXINDEXRK MAXARG_B
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** invalid register that fits in 8 bits
|
||||
*/
|
||||
#define NO_REG MAXARG_A
|
||||
|
||||
|
||||
/*
|
||||
** R[x] - register
|
||||
** K[x] - constant (in constant table)
|
||||
** RK(x) == if k(i) then K[x] else R[x]
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Grep "ORDER OP" if you change these enums. Opcodes marked with a (*)
|
||||
** has extra descriptions in the notes after the enumeration.
|
||||
*/
|
||||
|
||||
#define NO_REG MAXARG_A
|
||||
# 197 "./lua/lopcodes.h"
|
||||
typedef enum {
|
||||
/*----------------------------------------------------------------------
|
||||
name args description
|
||||
------------------------------------------------------------------------*/
|
||||
OP_MOVE,/* A B R[A] := R[B] */
|
||||
OP_LOADI,/* A sBx R[A] := sBx */
|
||||
OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */
|
||||
OP_LOADK,/* A Bx R[A] := K[Bx] */
|
||||
OP_LOADKX,/* A R[A] := K[extra arg] */
|
||||
OP_LOADFALSE,/* A R[A] := false */
|
||||
OP_LFALSESKIP,/*A R[A] := false; pc++ (*) */
|
||||
OP_LOADTRUE,/* A R[A] := true */
|
||||
OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */
|
||||
OP_GETUPVAL,/* A B R[A] := UpValue[B] */
|
||||
OP_SETUPVAL,/* A B UpValue[B] := R[A] */
|
||||
|
||||
OP_GETTABUP,/* A B C R[A] := UpValue[B][K[C]:string] */
|
||||
OP_GETTABLE,/* A B C R[A] := R[B][R[C]] */
|
||||
OP_GETI,/* A B C R[A] := R[B][C] */
|
||||
OP_GETFIELD,/* A B C R[A] := R[B][K[C]:string] */
|
||||
|
||||
OP_SETTABUP,/* A B C UpValue[A][K[B]:string] := RK(C) */
|
||||
OP_SETTABLE,/* A B C R[A][R[B]] := RK(C) */
|
||||
OP_SETI,/* A B C R[A][B] := RK(C) */
|
||||
OP_SETFIELD,/* A B C R[A][K[B]:string] := RK(C) */
|
||||
|
||||
OP_NEWTABLE,/* A B C k R[A] := {} */
|
||||
OP_MOVE,
|
||||
OP_LOADI,
|
||||
OP_LOADF,
|
||||
OP_LOADK,
|
||||
OP_LOADKX,
|
||||
OP_LOADFALSE,
|
||||
OP_LFALSESKIP,
|
||||
OP_LOADTRUE,
|
||||
OP_LOADNIL,
|
||||
OP_GETUPVAL,
|
||||
OP_SETUPVAL,
|
||||
|
||||
OP_SELF,/* A B C R[A+1] := R[B]; R[A] := R[B][RK(C):string] */
|
||||
OP_GETTABUP,
|
||||
OP_GETTABLE,
|
||||
OP_GETI,
|
||||
OP_GETFIELD,
|
||||
|
||||
OP_ADDI,/* A B sC R[A] := R[B] + sC */
|
||||
OP_SETTABUP,
|
||||
OP_SETTABLE,
|
||||
OP_SETI,
|
||||
OP_SETFIELD,
|
||||
|
||||
OP_ADDK,/* A B C R[A] := R[B] + K[C]:number */
|
||||
OP_SUBK,/* A B C R[A] := R[B] - K[C]:number */
|
||||
OP_MULK,/* A B C R[A] := R[B] * K[C]:number */
|
||||
OP_MODK,/* A B C R[A] := R[B] % K[C]:number */
|
||||
OP_POWK,/* A B C R[A] := R[B] ^ K[C]:number */
|
||||
OP_DIVK,/* A B C R[A] := R[B] / K[C]:number */
|
||||
OP_IDIVK,/* A B C R[A] := R[B] // K[C]:number */
|
||||
OP_NEWTABLE,
|
||||
|
||||
OP_BANDK,/* A B C R[A] := R[B] & K[C]:integer */
|
||||
OP_BORK,/* A B C R[A] := R[B] | K[C]:integer */
|
||||
OP_BXORK,/* A B C R[A] := R[B] ~ K[C]:integer */
|
||||
OP_SELF,
|
||||
|
||||
OP_SHRI,/* A B sC R[A] := R[B] >> sC */
|
||||
OP_SHLI,/* A B sC R[A] := sC << R[B] */
|
||||
OP_ADDI,
|
||||
|
||||
OP_ADD,/* A B C R[A] := R[B] + R[C] */
|
||||
OP_SUB,/* A B C R[A] := R[B] - R[C] */
|
||||
OP_MUL,/* A B C R[A] := R[B] * R[C] */
|
||||
OP_MOD,/* A B C R[A] := R[B] % R[C] */
|
||||
OP_POW,/* A B C R[A] := R[B] ^ R[C] */
|
||||
OP_DIV,/* A B C R[A] := R[B] / R[C] */
|
||||
OP_IDIV,/* A B C R[A] := R[B] // R[C] */
|
||||
OP_ADDK,
|
||||
OP_SUBK,
|
||||
OP_MULK,
|
||||
OP_MODK,
|
||||
OP_POWK,
|
||||
OP_DIVK,
|
||||
OP_IDIVK,
|
||||
|
||||
OP_BAND,/* A B C R[A] := R[B] & R[C] */
|
||||
OP_BOR,/* A B C R[A] := R[B] | R[C] */
|
||||
OP_BXOR,/* A B C R[A] := R[B] ~ R[C] */
|
||||
OP_SHL,/* A B C R[A] := R[B] << R[C] */
|
||||
OP_SHR,/* A B C R[A] := R[B] >> R[C] */
|
||||
OP_BANDK,
|
||||
OP_BORK,
|
||||
OP_BXORK,
|
||||
|
||||
OP_MMBIN,/* A B C call C metamethod over R[A] and R[B] (*) */
|
||||
OP_MMBINI,/* A sB C k call C metamethod over R[A] and sB */
|
||||
OP_MMBINK,/* A B C k call C metamethod over R[A] and K[B] */
|
||||
OP_SHRI,
|
||||
OP_SHLI,
|
||||
|
||||
OP_UNM,/* A B R[A] := -R[B] */
|
||||
OP_BNOT,/* A B R[A] := ~R[B] */
|
||||
OP_NOT,/* A B R[A] := not R[B] */
|
||||
OP_LEN,/* A B R[A] := #R[B] (length operator) */
|
||||
OP_ADD,
|
||||
OP_SUB,
|
||||
OP_MUL,
|
||||
OP_MOD,
|
||||
OP_POW,
|
||||
OP_DIV,
|
||||
OP_IDIV,
|
||||
|
||||
OP_CONCAT,/* A B R[A] := R[A].. ... ..R[A + B - 1] */
|
||||
OP_BAND,
|
||||
OP_BOR,
|
||||
OP_BXOR,
|
||||
OP_SHL,
|
||||
OP_SHR,
|
||||
|
||||
OP_CLOSE,/* A close all upvalues >= R[A] */
|
||||
OP_TBC,/* A mark variable A "to be closed" */
|
||||
OP_JMP,/* sJ pc += sJ */
|
||||
OP_EQ,/* A B k if ((R[A] == R[B]) ~= k) then pc++ */
|
||||
OP_LT,/* A B k if ((R[A] < R[B]) ~= k) then pc++ */
|
||||
OP_LE,/* A B k if ((R[A] <= R[B]) ~= k) then pc++ */
|
||||
OP_MMBIN,
|
||||
OP_MMBINI,
|
||||
OP_MMBINK,
|
||||
|
||||
OP_EQK,/* A B k if ((R[A] == K[B]) ~= k) then pc++ */
|
||||
OP_EQI,/* A sB k if ((R[A] == sB) ~= k) then pc++ */
|
||||
OP_LTI,/* A sB k if ((R[A] < sB) ~= k) then pc++ */
|
||||
OP_LEI,/* A sB k if ((R[A] <= sB) ~= k) then pc++ */
|
||||
OP_GTI,/* A sB k if ((R[A] > sB) ~= k) then pc++ */
|
||||
OP_GEI,/* A sB k if ((R[A] >= sB) ~= k) then pc++ */
|
||||
OP_UNM,
|
||||
OP_BNOT,
|
||||
OP_NOT,
|
||||
OP_LEN,
|
||||
|
||||
OP_TEST,/* A k if (not R[A] == k) then pc++ */
|
||||
OP_TESTSET,/* A B k if (not R[B] == k) then pc++ else R[A] := R[B] (*) */
|
||||
OP_CONCAT,
|
||||
|
||||
OP_CALL,/* A B C R[A], ... ,R[A+C-2] := R[A](R[A+1], ... ,R[A+B-1]) */
|
||||
OP_TAILCALL,/* A B C k return R[A](R[A+1], ... ,R[A+B-1]) */
|
||||
OP_CLOSE,
|
||||
OP_TBC,
|
||||
OP_JMP,
|
||||
OP_EQ,
|
||||
OP_LT,
|
||||
OP_LE,
|
||||
|
||||
OP_RETURN,/* A B C k return R[A], ... ,R[A+B-2] (see note) */
|
||||
OP_RETURN0,/* return */
|
||||
OP_RETURN1,/* A return R[A] */
|
||||
OP_EQK,
|
||||
OP_EQI,
|
||||
OP_LTI,
|
||||
OP_LEI,
|
||||
OP_GTI,
|
||||
OP_GEI,
|
||||
|
||||
OP_FORLOOP,/* A Bx update counters; if loop continues then pc-=Bx; */
|
||||
OP_FORPREP,/* A Bx <check values and prepare counters>;
|
||||
if not to run then pc+=Bx+1; */
|
||||
OP_TEST,
|
||||
OP_TESTSET,
|
||||
|
||||
OP_TFORPREP,/* A Bx create upvalue for R[A + 3]; pc+=Bx */
|
||||
OP_TFORCALL,/* A C R[A+4], ... ,R[A+3+C] := R[A](R[A+1], R[A+2]); */
|
||||
OP_TFORLOOP,/* A Bx if R[A+2] ~= nil then { R[A]=R[A+2]; pc -= Bx } */
|
||||
OP_CALL,
|
||||
OP_TAILCALL,
|
||||
|
||||
OP_SETLIST,/* A B C k R[A][C+i] := R[A+i], 1 <= i <= B */
|
||||
OP_RETURN,
|
||||
OP_RETURN0,
|
||||
OP_RETURN1,
|
||||
|
||||
OP_CLOSURE,/* A Bx R[A] := closure(KPROTO[Bx]) */
|
||||
OP_FORLOOP,
|
||||
OP_FORPREP,
|
||||
|
||||
OP_VARARG,/* A C R[A], R[A+1], ..., R[A+C-2] = vararg */
|
||||
|
||||
OP_VARARGPREP,/*A (adjust vararg parameters) */
|
||||
OP_TFORPREP,
|
||||
OP_TFORCALL,
|
||||
OP_TFORLOOP,
|
||||
|
||||
OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
|
||||
OP_SETLIST,
|
||||
|
||||
OP_CLOSURE,
|
||||
|
||||
OP_VARARG,
|
||||
|
||||
OP_VARARGPREP,
|
||||
|
||||
OP_EXTRAARG
|
||||
} OpCode;
|
||||
|
||||
|
||||
#define NUM_OPCODES ((int)(OP_EXTRAARG) + 1)
|
||||
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
Notes:
|
||||
|
||||
(*) Opcode OP_LFALSESKIP is used to convert a condition to a boolean
|
||||
value, in a code equivalent to (not cond ? false : true). (It
|
||||
produces false and skips the next instruction producing true.)
|
||||
|
||||
(*) Opcodes OP_MMBIN and variants follow each arithmetic and
|
||||
bitwise opcode. If the operation succeeds, it skips this next
|
||||
opcode. Otherwise, this opcode calls the corresponding metamethod.
|
||||
|
||||
(*) Opcode OP_TESTSET is used in short-circuit expressions that need
|
||||
both to jump and to produce a value, such as (a = b or c).
|
||||
|
||||
(*) In OP_CALL, if (B == 0) then B = top - A. If (C == 0), then
|
||||
'top' is set to last_result+1, so next open instruction (OP_CALL,
|
||||
OP_RETURN*, OP_SETLIST) may use 'top'.
|
||||
|
||||
(*) In OP_VARARG, if (C == 0) then use actual number of varargs and
|
||||
set top (like in OP_CALL with C == 0).
|
||||
|
||||
(*) In OP_RETURN, if (B == 0) then return up to 'top'.
|
||||
|
||||
(*) In OP_LOADKX and OP_NEWTABLE, the next instruction is always
|
||||
OP_EXTRAARG.
|
||||
|
||||
(*) In OP_SETLIST, if (B == 0) then real B = 'top'; if k, then
|
||||
real C = EXTRAARG _ C (the bits of EXTRAARG concatenated with the
|
||||
bits of C).
|
||||
|
||||
(*) In OP_NEWTABLE, B is log2 of the hash size (which is always a
|
||||
power of 2) plus 1, or zero for size zero. If not k, the array size
|
||||
is C. Otherwise, the array size is EXTRAARG _ C.
|
||||
|
||||
(*) For comparisons, k specifies what condition the test should accept
|
||||
(true or false).
|
||||
|
||||
(*) In OP_MMBINI/OP_MMBINK, k means the arguments were flipped
|
||||
(the constant is the first operand).
|
||||
|
||||
(*) All 'skips' (pc++) assume that next instruction is a jump.
|
||||
|
||||
(*) In instructions OP_RETURN/OP_TAILCALL, 'k' specifies that the
|
||||
function builds upvalues, which may need to be closed. C > 0 means
|
||||
the function is vararg, so that its 'func' must be corrected before
|
||||
returning; in this case, (C - 1) is its number of fixed parameters.
|
||||
|
||||
(*) In comparisons with an immediate operand, C signals whether the
|
||||
original operand was a float. (It must be corrected in case of
|
||||
metamethods.)
|
||||
|
||||
===========================================================================*/
|
||||
|
||||
|
||||
/*
|
||||
** masks for instruction properties. The format is:
|
||||
** bits 0-2: op mode
|
||||
** bit 3: instruction set register A
|
||||
** bit 4: operator is a test (next instruction must be a jump)
|
||||
** bit 5: instruction uses 'L->top' set by previous instruction (when B == 0)
|
||||
** bit 6: instruction sets 'L->top' for next instruction (when C == 0)
|
||||
** bit 7: instruction is an MM instruction (call a metamethod)
|
||||
*/
|
||||
|
||||
#define NUM_OPCODES ((int)(OP_EXTRAARG) + 1)
|
||||
# 381 "./lua/lopcodes.h"
|
||||
LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];)
|
||||
|
||||
#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 7))
|
||||
#define testAMode(m) (luaP_opmodes[m] & (1 << 3))
|
||||
#define testTMode(m) (luaP_opmodes[m] & (1 << 4))
|
||||
#define testITMode(m) (luaP_opmodes[m] & (1 << 5))
|
||||
#define testOTMode(m) (luaP_opmodes[m] & (1 << 6))
|
||||
#define testMMMode(m) (luaP_opmodes[m] & (1 << 7))
|
||||
#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 7))
|
||||
#define testAMode(m) (luaP_opmodes[m] & (1 << 3))
|
||||
#define testTMode(m) (luaP_opmodes[m] & (1 << 4))
|
||||
#define testITMode(m) (luaP_opmodes[m] & (1 << 5))
|
||||
#define testOTMode(m) (luaP_opmodes[m] & (1 << 6))
|
||||
#define testMMMode(m) (luaP_opmodes[m] & (1 << 7))
|
||||
|
||||
/* "out top" (set top for next instruction) */
|
||||
#define isOT(i) \
|
||||
((testOTMode(GET_OPCODE(i)) && GETARG_C(i) == 0) || \
|
||||
|
||||
#define isOT(i) \
|
||||
((testOTMode(GET_OPCODE(i)) && GETARG_C(i) == 0) || \
|
||||
GET_OPCODE(i) == OP_TAILCALL)
|
||||
|
||||
/* "in top" (uses top from previous instruction) */
|
||||
#define isIT(i) (testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0)
|
||||
|
||||
#define opmode(mm,ot,it,t,a,m) \
|
||||
#define isIT(i) (testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0)
|
||||
|
||||
#define opmode(mm,ot,it,t,a,m) \
|
||||
(((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m))
|
||||
|
||||
|
||||
/* number of list items to accumulate before a SETLIST instruction */
|
||||
#define LFIELDS_PER_FLUSH 50
|
||||
|
||||
#define LFIELDS_PER_FLUSH 50
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
/*
|
||||
** $Id: lopnames.h $
|
||||
** Opcode names
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lopnames.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(lopnames_h)
|
||||
#define lopnames_h
|
||||
#define lopnames_h
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
/* ORDER OP */
|
||||
|
||||
|
||||
static const char *const opnames[] = {
|
||||
"MOVE",
|
||||
|
@ -100,4 +101,3 @@ static const char *const opnames[] = {
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,165 +1,155 @@
|
|||
/*
|
||||
** $Id: lparser.h $
|
||||
** Lua Parser
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lparser.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lparser_h
|
||||
#define lparser_h
|
||||
#define lparser_h
|
||||
|
||||
#include "llimits.h"
|
||||
#include "lobject.h"
|
||||
#include "lzio.h"
|
||||
|
||||
|
||||
/*
|
||||
** Expression and variable descriptor.
|
||||
** Code generation for variables and expressions can be delayed to allow
|
||||
** optimizations; An 'expdesc' structure describes a potentially-delayed
|
||||
** variable/expression. It has a description of its "main" value plus a
|
||||
** list of conditional jumps that can also produce its value (generated
|
||||
** by short-circuit operators 'and'/'or').
|
||||
*/
|
||||
|
||||
/* kinds of variables/expressions */
|
||||
# 25 "./lua/lparser.h"
|
||||
typedef enum {
|
||||
VVOID, /* when 'expdesc' describes the last expression of a list,
|
||||
this kind means an empty list (so, no expression) */
|
||||
VNIL, /* constant nil */
|
||||
VTRUE, /* constant true */
|
||||
VFALSE, /* constant false */
|
||||
VK, /* constant in 'k'; info = index of constant in 'k' */
|
||||
VKFLT, /* floating constant; nval = numerical float value */
|
||||
VKINT, /* integer constant; ival = numerical integer value */
|
||||
VKSTR, /* string constant; strval = TString address;
|
||||
(string is fixed by the lexer) */
|
||||
VNONRELOC, /* expression has its value in a fixed register;
|
||||
info = result register */
|
||||
VLOCAL, /* local variable; var.ridx = register index;
|
||||
var.vidx = relative index in 'actvar.arr' */
|
||||
VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */
|
||||
VCONST, /* compile-time <const> variable;
|
||||
info = absolute index in 'actvar.arr' */
|
||||
VINDEXED, /* indexed variable;
|
||||
ind.t = table register;
|
||||
ind.idx = key's R index */
|
||||
VINDEXUP, /* indexed upvalue;
|
||||
ind.t = table upvalue;
|
||||
ind.idx = key's K index */
|
||||
VINDEXI, /* indexed variable with constant integer;
|
||||
ind.t = table register;
|
||||
ind.idx = key's value */
|
||||
VINDEXSTR, /* indexed variable with literal string;
|
||||
ind.t = table register;
|
||||
ind.idx = key's K index */
|
||||
VJMP, /* expression is a test/comparison;
|
||||
info = pc of corresponding jump instruction */
|
||||
VRELOC, /* expression can put result in any register;
|
||||
info = instruction pc */
|
||||
VCALL, /* expression is a function call; info = instruction pc */
|
||||
VVARARG /* vararg expression; info = instruction pc */
|
||||
VVOID,
|
||||
|
||||
VNIL,
|
||||
VTRUE,
|
||||
VFALSE,
|
||||
VK,
|
||||
VKFLT,
|
||||
VKINT,
|
||||
VKSTR,
|
||||
|
||||
VNONRELOC,
|
||||
|
||||
VLOCAL,
|
||||
|
||||
VUPVAL,
|
||||
VCONST,
|
||||
|
||||
VINDEXED,
|
||||
|
||||
|
||||
VINDEXUP,
|
||||
|
||||
|
||||
VINDEXI,
|
||||
|
||||
|
||||
VINDEXSTR,
|
||||
|
||||
|
||||
VJMP,
|
||||
|
||||
VRELOC,
|
||||
|
||||
VCALL,
|
||||
VVARARG
|
||||
} expkind;
|
||||
|
||||
|
||||
#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR)
|
||||
#define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR)
|
||||
#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR)
|
||||
#define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR)
|
||||
|
||||
|
||||
typedef struct expdesc {
|
||||
expkind k;
|
||||
union {
|
||||
lua_Integer ival; /* for VKINT */
|
||||
lua_Number nval; /* for VKFLT */
|
||||
TString *strval; /* for VKSTR */
|
||||
int info; /* for generic use */
|
||||
struct { /* for indexed variables */
|
||||
short idx; /* index (R or "long" K) */
|
||||
lu_byte t; /* table (register or upvalue) */
|
||||
lua_Integer ival;
|
||||
lua_Number nval;
|
||||
TString *strval;
|
||||
int info;
|
||||
struct {
|
||||
short idx;
|
||||
lu_byte t;
|
||||
} ind;
|
||||
struct { /* for local variables */
|
||||
lu_byte ridx; /* register holding the variable */
|
||||
unsigned short vidx; /* compiler index (in 'actvar.arr') */
|
||||
struct {
|
||||
lu_byte ridx;
|
||||
unsigned short vidx;
|
||||
} var;
|
||||
} u;
|
||||
int t; /* patch list of 'exit when true' */
|
||||
int f; /* patch list of 'exit when false' */
|
||||
int t;
|
||||
int f;
|
||||
} expdesc;
|
||||
|
||||
|
||||
/* kinds of variables */
|
||||
#define VDKREG 0 /* regular */
|
||||
#define RDKCONST 1 /* constant */
|
||||
#define RDKTOCLOSE 2 /* to-be-closed */
|
||||
#define RDKCTC 3 /* compile-time constant */
|
||||
|
||||
/* description of an active local variable */
|
||||
#define VDKREG 0
|
||||
#define RDKCONST 1
|
||||
#define RDKTOCLOSE 2
|
||||
#define RDKCTC 3
|
||||
|
||||
|
||||
typedef union Vardesc {
|
||||
struct {
|
||||
TValuefields; /* constant value (if it is a compile-time constant) */
|
||||
TValuefields;
|
||||
lu_byte kind;
|
||||
lu_byte ridx; /* register holding the variable */
|
||||
short pidx; /* index of the variable in the Proto's 'locvars' array */
|
||||
TString *name; /* variable name */
|
||||
lu_byte ridx;
|
||||
short pidx;
|
||||
TString *name;
|
||||
} vd;
|
||||
TValue k; /* constant value (if any) */
|
||||
TValue k;
|
||||
} Vardesc;
|
||||
|
||||
|
||||
|
||||
/* description of pending goto statements and label statements */
|
||||
|
||||
typedef struct Labeldesc {
|
||||
TString *name; /* label identifier */
|
||||
int pc; /* position in code */
|
||||
int line; /* line where it appeared */
|
||||
lu_byte nactvar; /* number of active variables in that position */
|
||||
lu_byte close; /* goto that escapes upvalues */
|
||||
TString *name;
|
||||
int pc;
|
||||
int line;
|
||||
lu_byte nactvar;
|
||||
lu_byte close;
|
||||
} Labeldesc;
|
||||
|
||||
|
||||
/* list of labels or gotos */
|
||||
|
||||
typedef struct Labellist {
|
||||
Labeldesc *arr; /* array */
|
||||
int n; /* number of entries in use */
|
||||
int size; /* array size */
|
||||
Labeldesc *arr;
|
||||
int n;
|
||||
int size;
|
||||
} Labellist;
|
||||
|
||||
|
||||
/* dynamic structures used by the parser */
|
||||
|
||||
typedef struct Dyndata {
|
||||
struct { /* list of all active local variables */
|
||||
struct {
|
||||
Vardesc *arr;
|
||||
int n;
|
||||
int size;
|
||||
} actvar;
|
||||
Labellist gt; /* list of pending gotos */
|
||||
Labellist label; /* list of active labels */
|
||||
Labellist gt;
|
||||
Labellist label;
|
||||
} Dyndata;
|
||||
|
||||
|
||||
/* control of blocks */
|
||||
struct BlockCnt; /* defined in lparser.c */
|
||||
|
||||
struct BlockCnt;
|
||||
|
||||
|
||||
|
||||
/* state needed to generate code for a given function */
|
||||
typedef struct FuncState {
|
||||
Proto *f; /* current function header */
|
||||
struct FuncState *prev; /* enclosing function */
|
||||
struct LexState *ls; /* lexical state */
|
||||
struct BlockCnt *bl; /* chain of current blocks */
|
||||
int pc; /* next position to code (equivalent to 'ncode') */
|
||||
int lasttarget; /* 'label' of last 'jump label' */
|
||||
int previousline; /* last line that was saved in 'lineinfo' */
|
||||
int nk; /* number of elements in 'k' */
|
||||
int np; /* number of elements in 'p' */
|
||||
int nabslineinfo; /* number of elements in 'abslineinfo' */
|
||||
int firstlocal; /* index of first local var (in Dyndata array) */
|
||||
int firstlabel; /* index of first label (in 'dyd->label->arr') */
|
||||
short ndebugvars; /* number of elements in 'f->locvars' */
|
||||
lu_byte nactvar; /* number of active local variables */
|
||||
lu_byte nups; /* number of upvalues */
|
||||
lu_byte freereg; /* first free register */
|
||||
lu_byte iwthabs; /* instructions issued since last absolute line info */
|
||||
lu_byte needclose; /* function needs to close upvalues when returning */
|
||||
Proto *f;
|
||||
struct FuncState *prev;
|
||||
struct LexState *ls;
|
||||
struct BlockCnt *bl;
|
||||
int pc;
|
||||
int lasttarget;
|
||||
int previousline;
|
||||
int nk;
|
||||
int np;
|
||||
int nabslineinfo;
|
||||
int firstlocal;
|
||||
int firstlabel;
|
||||
short ndebugvars;
|
||||
lu_byte nactvar;
|
||||
lu_byte nups;
|
||||
lu_byte freereg;
|
||||
lu_byte iwthabs;
|
||||
lu_byte needclose;
|
||||
} FuncState;
|
||||
|
||||
|
||||
|
|
|
@ -1,45 +1,45 @@
|
|||
/*
|
||||
** $Id: lprefix.h $
|
||||
** Definitions for Lua code that must come before any other header file
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lprefix.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lprefix_h
|
||||
#define lprefix_h
|
||||
#define lprefix_h
|
||||
|
||||
|
||||
/*
|
||||
** Allows POSIX/XSI stuff
|
||||
*/
|
||||
#if !defined(LUA_USE_C89) /* { */
|
||||
|
||||
|
||||
|
||||
#if !defined(LUA_USE_C89)
|
||||
|
||||
#if !defined(_XOPEN_SOURCE)
|
||||
#define _XOPEN_SOURCE 600
|
||||
#define _XOPEN_SOURCE 600
|
||||
#elif _XOPEN_SOURCE == 0
|
||||
#undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */
|
||||
#undef _XOPEN_SOURCE
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Allows manipulation of large files in gcc and some other compilers
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS)
|
||||
#define _LARGEFILE_SOURCE 1
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define _LARGEFILE_SOURCE 1
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#endif
|
||||
|
||||
#endif /* } */
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Windows stuff
|
||||
*/
|
||||
#if defined(_WIN32) /* { */
|
||||
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#endif /* } */
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,392 +1,269 @@
|
|||
/*
|
||||
** $Id: lstate.h $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lstate.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lstate_h
|
||||
#define lstate_h
|
||||
#define lstate_h
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lobject.h"
|
||||
#include "ltm.h"
|
||||
#include "lzio.h"
|
||||
# 99 "./lua/lstate.h"
|
||||
#define yieldable(L) (((L)->nCcalls & 0xffff0000) == 0)
|
||||
|
||||
|
||||
/*
|
||||
** Some notes about garbage-collected objects: All objects in Lua must
|
||||
** be kept somehow accessible until being freed, so all objects always
|
||||
** belong to one (and only one) of these lists, using field 'next' of
|
||||
** the 'CommonHeader' for the link:
|
||||
**
|
||||
** 'allgc': all objects not marked for finalization;
|
||||
** 'finobj': all objects marked for finalization;
|
||||
** 'tobefnz': all objects ready to be finalized;
|
||||
** 'fixedgc': all objects that are not to be collected (currently
|
||||
** only small strings, such as reserved words).
|
||||
**
|
||||
** For the generational collector, some of these lists have marks for
|
||||
** generations. Each mark points to the first element in the list for
|
||||
** that particular generation; that generation goes until the next mark.
|
||||
**
|
||||
** 'allgc' -> 'survival': new objects;
|
||||
** 'survival' -> 'old': objects that survived one collection;
|
||||
** 'old1' -> 'reallyold': objects that became old in last collection;
|
||||
** 'reallyold' -> NULL: objects old for more than one cycle.
|
||||
**
|
||||
** 'finobj' -> 'finobjsur': new objects marked for finalization;
|
||||
** 'finobjsur' -> 'finobjold1': survived """";
|
||||
** 'finobjold1' -> 'finobjrold': just old """";
|
||||
** 'finobjrold' -> NULL: really old """".
|
||||
**
|
||||
** All lists can contain elements older than their main ages, due
|
||||
** to 'luaC_checkfinalizer' and 'udata2finalize', which move
|
||||
** objects between the normal lists and the "marked for finalization"
|
||||
** lists. Moreover, barriers can age young objects in young lists as
|
||||
** OLD0, which then become OLD1. However, a list never contains
|
||||
** elements younger than their main ages.
|
||||
**
|
||||
** The generational collector also uses a pointer 'firstold1', which
|
||||
** points to the first OLD1 object in the list. It is used to optimize
|
||||
** 'markold'. (Potentially OLD1 objects can be anywhere between 'allgc'
|
||||
** and 'reallyold', but often the list has no OLD1 objects or they are
|
||||
** after 'old1'.) Note the difference between it and 'old1':
|
||||
** 'firstold1': no OLD1 objects before this point; there can be all
|
||||
** ages after it.
|
||||
** 'old1': no objects younger than OLD1 after this point.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Moreover, there is another set of lists that control gray objects.
|
||||
** These lists are linked by fields 'gclist'. (All objects that
|
||||
** can become gray have such a field. The field is not the same
|
||||
** in all objects, but it always has this name.) Any gray object
|
||||
** must belong to one of these lists, and all objects in these lists
|
||||
** must be gray (with two exceptions explained below):
|
||||
**
|
||||
** 'gray': regular gray objects, still waiting to be visited.
|
||||
** 'grayagain': objects that must be revisited at the atomic phase.
|
||||
** That includes
|
||||
** - black objects got in a write barrier;
|
||||
** - all kinds of weak tables during propagation phase;
|
||||
** - all threads.
|
||||
** 'weak': tables with weak values to be cleared;
|
||||
** 'ephemeron': ephemeron tables with white->white entries;
|
||||
** 'allweak': tables with weak keys and/or weak values to be cleared.
|
||||
**
|
||||
** The exceptions to that "gray rule" are:
|
||||
** - TOUCHED2 objects in generational mode stay in a gray list (because
|
||||
** they must be visited again at the end of the cycle), but they are
|
||||
** marked black because assignments to them must activate barriers (to
|
||||
** move them back to TOUCHED1).
|
||||
** - Open upvales are kept gray to avoid barriers, but they stay out
|
||||
** of gray lists. (They don't even have a 'gclist' field.)
|
||||
*/
|
||||
#define getCcalls(L) ((L)->nCcalls & 0xffff)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** About 'nCcalls': This count has two parts: the lower 16 bits counts
|
||||
** the number of recursive invocations in the C stack; the higher
|
||||
** 16 bits counts the number of non-yieldable calls in the stack.
|
||||
** (They are together so that we can change and save both with one
|
||||
** instruction.)
|
||||
*/
|
||||
#define incnny(L) ((L)->nCcalls += 0x10000)
|
||||
|
||||
|
||||
/* true if this thread does not have non-yieldable calls in the stack */
|
||||
#define yieldable(L) (((L)->nCcalls & 0xffff0000) == 0)
|
||||
|
||||
/* real number of C calls */
|
||||
#define getCcalls(L) ((L)->nCcalls & 0xffff)
|
||||
#define decnny(L) ((L)->nCcalls -= 0x10000)
|
||||
|
||||
|
||||
/* Increment the number of non-yieldable calls */
|
||||
#define incnny(L) ((L)->nCcalls += 0x10000)
|
||||
|
||||
/* Decrement the number of non-yieldable calls */
|
||||
#define decnny(L) ((L)->nCcalls -= 0x10000)
|
||||
|
||||
/* Non-yieldable call increment */
|
||||
#define nyci (0x10000 | 1)
|
||||
#define nyci (0x10000 | 1)
|
||||
|
||||
|
||||
|
||||
|
||||
struct lua_longjmp;
|
||||
|
||||
|
||||
|
||||
|
||||
struct lua_longjmp; /* defined in ldo.c */
|
||||
|
||||
|
||||
/*
|
||||
** Atomic type (relative to signals) to better ensure that 'lua_sethook'
|
||||
** is thread safe
|
||||
*/
|
||||
#if !defined(l_signalT)
|
||||
#include <signal.h>
|
||||
#define l_signalT sig_atomic_t
|
||||
#define l_signalT sig_atomic_t
|
||||
#endif
|
||||
# 137 "./lua/lstate.h"
|
||||
#define EXTRA_STACK 5
|
||||
|
||||
|
||||
/*
|
||||
** Extra stack space to handle TM calls and some other extras. This
|
||||
** space is not included in 'stack_last'. It is used only to avoid stack
|
||||
** checks, either because the element will be promptly popped or because
|
||||
** there will be a stack check soon after the push. Function frames
|
||||
** never use this extra space, so it does not need to be kept clean.
|
||||
*/
|
||||
#define EXTRA_STACK 5
|
||||
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
|
||||
|
||||
#define stacksize(th) cast_int((th)->stack_last - (th)->stack)
|
||||
|
||||
|
||||
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
|
||||
|
||||
#define stacksize(th) cast_int((th)->stack_last - (th)->stack)
|
||||
|
||||
|
||||
/* kinds of Garbage Collection */
|
||||
#define KGC_INC 0 /* incremental gc */
|
||||
#define KGC_GEN 1 /* generational gc */
|
||||
#define KGC_INC 0
|
||||
#define KGC_GEN 1
|
||||
|
||||
|
||||
typedef struct stringtable {
|
||||
TString **hash;
|
||||
int nuse; /* number of elements */
|
||||
int nuse;
|
||||
int size;
|
||||
} stringtable;
|
||||
|
||||
|
||||
/*
|
||||
** Information about a call.
|
||||
** About union 'u':
|
||||
** - field 'l' is used only for Lua functions;
|
||||
** - field 'c' is used only for C functions.
|
||||
** About union 'u2':
|
||||
** - field 'funcidx' is used only by C functions while doing a
|
||||
** protected call;
|
||||
** - field 'nyield' is used only while a function is "doing" an
|
||||
** yield (from the yield until the next resume);
|
||||
** - field 'nres' is used only while closing tbc variables when
|
||||
** returning from a function;
|
||||
** - field 'transferinfo' is used only during call/returnhooks,
|
||||
** before the function starts or after it ends.
|
||||
*/
|
||||
# 172 "./lua/lstate.h"
|
||||
typedef struct CallInfo {
|
||||
StkId func; /* function index in the stack */
|
||||
StkId top; /* top for this function */
|
||||
struct CallInfo *previous, *next; /* dynamic call link */
|
||||
StkId func;
|
||||
StkId top;
|
||||
struct CallInfo *previous, *next;
|
||||
union {
|
||||
struct { /* only for Lua functions */
|
||||
struct {
|
||||
const Instruction *savedpc;
|
||||
volatile l_signalT trap;
|
||||
int nextraargs; /* # of extra arguments in vararg functions */
|
||||
int nextraargs;
|
||||
} l;
|
||||
struct { /* only for C functions */
|
||||
lua_KFunction k; /* continuation in case of yields */
|
||||
struct {
|
||||
lua_KFunction k;
|
||||
ptrdiff_t old_errfunc;
|
||||
lua_KContext ctx; /* context info. in case of yields */
|
||||
lua_KContext ctx;
|
||||
} c;
|
||||
} u;
|
||||
union {
|
||||
int funcidx; /* called-function index */
|
||||
int nyield; /* number of values yielded */
|
||||
int nres; /* number of values returned */
|
||||
struct { /* info about transferred values (for call/return hooks) */
|
||||
unsigned short ftransfer; /* offset of first value transferred */
|
||||
unsigned short ntransfer; /* number of values transferred */
|
||||
int funcidx;
|
||||
int nyield;
|
||||
int nres;
|
||||
struct {
|
||||
unsigned short ftransfer;
|
||||
unsigned short ntransfer;
|
||||
} transferinfo;
|
||||
} u2;
|
||||
short nresults; /* expected number of results from this function */
|
||||
short nresults;
|
||||
unsigned short callstatus;
|
||||
} CallInfo;
|
||||
|
||||
|
||||
/*
|
||||
** Bits in CallInfo status
|
||||
*/
|
||||
#define CIST_OAH (1<<0) /* original value of 'allowhook' */
|
||||
#define CIST_C (1<<1) /* call is running a C function */
|
||||
#define CIST_FRESH (1<<2) /* call is on a fresh "luaV_execute" frame */
|
||||
#define CIST_HOOKED (1<<3) /* call is running a debug hook */
|
||||
#define CIST_YPCALL (1<<4) /* doing a yieldable protected call */
|
||||
#define CIST_TAIL (1<<5) /* call was tail called */
|
||||
#define CIST_HOOKYIELD (1<<6) /* last hook called yielded */
|
||||
#define CIST_FIN (1<<7) /* function "called" a finalizer */
|
||||
#define CIST_TRAN (1<<8) /* 'ci' has transfer information */
|
||||
#define CIST_CLSRET (1<<9) /* function is closing tbc variables */
|
||||
/* Bits 10-12 are used for CIST_RECST (see below) */
|
||||
#define CIST_RECST 10
|
||||
|
||||
|
||||
|
||||
#define CIST_OAH (1<<0)
|
||||
#define CIST_C (1<<1)
|
||||
#define CIST_FRESH (1<<2)
|
||||
#define CIST_HOOKED (1<<3)
|
||||
#define CIST_YPCALL (1<<4)
|
||||
#define CIST_TAIL (1<<5)
|
||||
#define CIST_HOOKYIELD (1<<6)
|
||||
#define CIST_FIN (1<<7)
|
||||
#define CIST_TRAN (1<<8)
|
||||
#define CIST_CLSRET (1<<9)
|
||||
|
||||
#define CIST_RECST 10
|
||||
#if defined(LUA_COMPAT_LT_LE)
|
||||
#define CIST_LEQ (1<<13) /* using __lt for __le */
|
||||
#define CIST_LEQ (1<<13)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Field CIST_RECST stores the "recover status", used to keep the error
|
||||
** status while closing to-be-closed variables in coroutines, so that
|
||||
** Lua can correctly resume after an yield from a __close method called
|
||||
** because of an error. (Three bits are enough for error status.)
|
||||
*/
|
||||
#define getcistrecst(ci) (((ci)->callstatus >> CIST_RECST) & 7)
|
||||
#define setcistrecst(ci,st) \
|
||||
check_exp(((st) & 7) == (st), /* status must fit in three bits */ \
|
||||
((ci)->callstatus = ((ci)->callstatus & ~(7 << CIST_RECST)) \
|
||||
# 228 "./lua/lstate.h"
|
||||
#define getcistrecst(ci) (((ci)->callstatus >> CIST_RECST) & 7)
|
||||
#define setcistrecst(ci,st) \
|
||||
check_exp(((st) & 7) == (st), \
|
||||
((ci)->callstatus = ((ci)->callstatus & ~(7 << CIST_RECST)) \
|
||||
| ((st) << CIST_RECST)))
|
||||
|
||||
|
||||
/* active function is a Lua function */
|
||||
#define isLua(ci) (!((ci)->callstatus & CIST_C))
|
||||
|
||||
/* call is running Lua code (not a hook) */
|
||||
#define isLuacode(ci) (!((ci)->callstatus & (CIST_C | CIST_HOOKED)))
|
||||
|
||||
/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
|
||||
#define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v))
|
||||
#define getoah(st) ((st) & CIST_OAH)
|
||||
#define isLua(ci) (!((ci)->callstatus & CIST_C))
|
||||
|
||||
|
||||
#define isLuacode(ci) (!((ci)->callstatus & (CIST_C | CIST_HOOKED)))
|
||||
|
||||
|
||||
#define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v))
|
||||
#define getoah(st) ((st) & CIST_OAH)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** 'global state', shared by all threads of this state
|
||||
*/
|
||||
typedef struct global_State {
|
||||
lua_Alloc frealloc; /* function to reallocate memory */
|
||||
void *ud; /* auxiliary data to 'frealloc' */
|
||||
l_mem totalbytes; /* number of bytes currently allocated - GCdebt */
|
||||
l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
|
||||
lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
|
||||
lu_mem lastatomic; /* see function 'genstep' in file 'lgc.c' */
|
||||
stringtable strt; /* hash table for strings */
|
||||
lua_Alloc frealloc;
|
||||
void *ud;
|
||||
l_mem totalbytes;
|
||||
l_mem GCdebt;
|
||||
lu_mem GCestimate;
|
||||
lu_mem lastatomic;
|
||||
stringtable strt;
|
||||
TValue l_registry;
|
||||
TValue nilvalue; /* a nil value */
|
||||
unsigned int seed; /* randomized seed for hashes */
|
||||
TValue nilvalue;
|
||||
unsigned int seed;
|
||||
lu_byte currentwhite;
|
||||
lu_byte gcstate; /* state of garbage collector */
|
||||
lu_byte gckind; /* kind of GC running */
|
||||
lu_byte gcstopem; /* stops emergency collections */
|
||||
lu_byte genminormul; /* control for minor generational collections */
|
||||
lu_byte genmajormul; /* control for major generational collections */
|
||||
lu_byte gcstp; /* control whether GC is running */
|
||||
lu_byte gcemergency; /* true if this is an emergency collection */
|
||||
lu_byte gcpause; /* size of pause between successive GCs */
|
||||
lu_byte gcstepmul; /* GC "speed" */
|
||||
lu_byte gcstepsize; /* (log2 of) GC granularity */
|
||||
GCObject *allgc; /* list of all collectable objects */
|
||||
GCObject **sweepgc; /* current position of sweep in list */
|
||||
GCObject *finobj; /* list of collectable objects with finalizers */
|
||||
GCObject *gray; /* list of gray objects */
|
||||
GCObject *grayagain; /* list of objects to be traversed atomically */
|
||||
GCObject *weak; /* list of tables with weak values */
|
||||
GCObject *ephemeron; /* list of ephemeron tables (weak keys) */
|
||||
GCObject *allweak; /* list of all-weak tables */
|
||||
GCObject *tobefnz; /* list of userdata to be GC */
|
||||
GCObject *fixedgc; /* list of objects not to be collected */
|
||||
/* fields for generational collector */
|
||||
GCObject *survival; /* start of objects that survived one GC cycle */
|
||||
GCObject *old1; /* start of old1 objects */
|
||||
GCObject *reallyold; /* objects more than one cycle old ("really old") */
|
||||
GCObject *firstold1; /* first OLD1 object in the list (if any) */
|
||||
GCObject *finobjsur; /* list of survival objects with finalizers */
|
||||
GCObject *finobjold1; /* list of old1 objects with finalizers */
|
||||
GCObject *finobjrold; /* list of really old objects with finalizers */
|
||||
struct lua_State *twups; /* list of threads with open upvalues */
|
||||
lua_CFunction panic; /* to be called in unprotected errors */
|
||||
lu_byte gcstate;
|
||||
lu_byte gckind;
|
||||
lu_byte gcstopem;
|
||||
lu_byte genminormul;
|
||||
lu_byte genmajormul;
|
||||
lu_byte gcstp;
|
||||
lu_byte gcemergency;
|
||||
lu_byte gcpause;
|
||||
lu_byte gcstepmul;
|
||||
lu_byte gcstepsize;
|
||||
GCObject *allgc;
|
||||
GCObject **sweepgc;
|
||||
GCObject *finobj;
|
||||
GCObject *gray;
|
||||
GCObject *grayagain;
|
||||
GCObject *weak;
|
||||
GCObject *ephemeron;
|
||||
GCObject *allweak;
|
||||
GCObject *tobefnz;
|
||||
GCObject *fixedgc;
|
||||
|
||||
GCObject *survival;
|
||||
GCObject *old1;
|
||||
GCObject *reallyold;
|
||||
GCObject *firstold1;
|
||||
GCObject *finobjsur;
|
||||
GCObject *finobjold1;
|
||||
GCObject *finobjrold;
|
||||
struct lua_State *twups;
|
||||
lua_CFunction panic;
|
||||
struct lua_State *mainthread;
|
||||
TString *memerrmsg; /* message for memory-allocation errors */
|
||||
TString *tmname[TM_N]; /* array with tag-method names */
|
||||
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
|
||||
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
|
||||
lua_WarnFunction warnf; /* warning function */
|
||||
void *ud_warn; /* auxiliary data to 'warnf' */
|
||||
TString *memerrmsg;
|
||||
TString *tmname[TM_N];
|
||||
struct Table *mt[LUA_NUMTAGS];
|
||||
TString *strcache[STRCACHE_N][STRCACHE_M];
|
||||
lua_WarnFunction warnf;
|
||||
void *ud_warn;
|
||||
} global_State;
|
||||
|
||||
|
||||
/*
|
||||
** 'per thread' state
|
||||
*/
|
||||
|
||||
|
||||
|
||||
struct lua_State {
|
||||
CommonHeader;
|
||||
lu_byte status;
|
||||
lu_byte allowhook;
|
||||
unsigned short nci; /* number of items in 'ci' list */
|
||||
StkId top; /* first free slot in the stack */
|
||||
unsigned short nci;
|
||||
StkId top;
|
||||
global_State *l_G;
|
||||
CallInfo *ci; /* call info for current function */
|
||||
StkId stack_last; /* end of stack (last element + 1) */
|
||||
StkId stack; /* stack base */
|
||||
UpVal *openupval; /* list of open upvalues in this stack */
|
||||
StkId tbclist; /* list of to-be-closed variables */
|
||||
CallInfo *ci;
|
||||
StkId stack_last;
|
||||
StkId stack;
|
||||
UpVal *openupval;
|
||||
StkId tbclist;
|
||||
GCObject *gclist;
|
||||
struct lua_State *twups; /* list of threads with open upvalues */
|
||||
struct lua_longjmp *errorJmp; /* current error recover point */
|
||||
CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
|
||||
struct lua_State *twups;
|
||||
struct lua_longjmp *errorJmp;
|
||||
CallInfo base_ci;
|
||||
volatile lua_Hook hook;
|
||||
ptrdiff_t errfunc; /* current error handling function (stack index) */
|
||||
l_uint32 nCcalls; /* number of nested (non-yieldable | C) calls */
|
||||
int oldpc; /* last pc traced */
|
||||
ptrdiff_t errfunc;
|
||||
l_uint32 nCcalls;
|
||||
int oldpc;
|
||||
int basehookcount;
|
||||
int hookcount;
|
||||
volatile l_signalT hookmask;
|
||||
};
|
||||
|
||||
|
||||
#define G(L) (L->l_G)
|
||||
|
||||
/*
|
||||
** 'g->nilvalue' being a nil value flags that the state was completely
|
||||
** build.
|
||||
*/
|
||||
#define completestate(g) ttisnil(&g->nilvalue)
|
||||
#define G(L) (L->l_G)
|
||||
|
||||
|
||||
/*
|
||||
** Union of all collectable objects (only for conversions)
|
||||
** ISO C99, 6.5.2.3 p.5:
|
||||
** "if a union contains several structures that share a common initial
|
||||
** sequence [...], and if the union object currently contains one
|
||||
** of these structures, it is permitted to inspect the common initial
|
||||
** part of any of them anywhere that a declaration of the complete type
|
||||
** of the union is visible."
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define completestate(g) ttisnil(&g->nilvalue)
|
||||
# 348 "./lua/lstate.h"
|
||||
union GCUnion {
|
||||
GCObject gc; /* common header */
|
||||
GCObject gc;
|
||||
struct TString ts;
|
||||
struct Udata u;
|
||||
union Closure cl;
|
||||
struct Table h;
|
||||
struct Proto p;
|
||||
struct lua_State th; /* thread */
|
||||
struct lua_State th;
|
||||
struct UpVal upv;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** ISO C99, 6.7.2.1 p.14:
|
||||
** "A pointer to a union object, suitably converted, points to each of
|
||||
** its members [...], and vice versa."
|
||||
*/
|
||||
#define cast_u(o) cast(union GCUnion *, (o))
|
||||
|
||||
/* macros to convert a GCObject into a specific value */
|
||||
#define gco2ts(o) \
|
||||
check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))
|
||||
#define gco2u(o) check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u))
|
||||
#define gco2lcl(o) check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l))
|
||||
#define gco2ccl(o) check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c))
|
||||
#define gco2cl(o) \
|
||||
check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
|
||||
#define gco2t(o) check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h))
|
||||
#define gco2p(o) check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p))
|
||||
#define gco2th(o) check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th))
|
||||
#define gco2upv(o) check_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv))
|
||||
|
||||
|
||||
/*
|
||||
** macro to convert a Lua object into a GCObject
|
||||
** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
|
||||
*/
|
||||
#define obj2gco(v) check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))
|
||||
|
||||
|
||||
/* actual number of total bytes allocated */
|
||||
#define gettotalbytes(g) cast(lu_mem, (g)->totalbytes + (g)->GCdebt)
|
||||
|
||||
#define cast_u(o) cast(union GCUnion *, (o))
|
||||
|
||||
|
||||
#define gco2ts(o) \
|
||||
check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))
|
||||
#define gco2u(o) check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u))
|
||||
#define gco2lcl(o) check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l))
|
||||
#define gco2ccl(o) check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c))
|
||||
#define gco2cl(o) \
|
||||
check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
|
||||
#define gco2t(o) check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h))
|
||||
#define gco2p(o) check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p))
|
||||
#define gco2th(o) check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th))
|
||||
#define gco2upv(o) check_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define obj2gco(v) check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))
|
||||
|
||||
|
||||
|
||||
#define gettotalbytes(g) cast(lu_mem, (g)->totalbytes + (g)->GCdebt)
|
||||
|
||||
LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
|
||||
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
|
||||
|
@ -401,4 +278,3 @@ LUAI_FUNC int luaE_resetthread (lua_State *L, int status);
|
|||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,44 +1,45 @@
|
|||
/*
|
||||
** $Id: lstring.h $
|
||||
** String table (keep all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lstring.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lstring_h
|
||||
#define lstring_h
|
||||
#define lstring_h
|
||||
|
||||
#include "lgc.h"
|
||||
#include "lobject.h"
|
||||
#include "lstate.h"
|
||||
|
||||
|
||||
/*
|
||||
** Memory-allocation error message must be preallocated (it cannot
|
||||
** be created after memory is exhausted)
|
||||
*/
|
||||
#define MEMERRMSG "not enough memory"
|
||||
|
||||
|
||||
/*
|
||||
** Size of a TString: Size of the header plus space for the string
|
||||
** itself (including final '\0').
|
||||
*/
|
||||
#define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char))
|
||||
|
||||
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
|
||||
|
||||
#define MEMERRMSG "not enough memory"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char))
|
||||
|
||||
#define luaS_newliteral(L,s) (luaS_newlstr(L, "" s, \
|
||||
(sizeof(s)/sizeof(char))-1))
|
||||
|
||||
|
||||
/*
|
||||
** test whether a string is a reserved word
|
||||
*/
|
||||
#define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0)
|
||||
|
||||
|
||||
/*
|
||||
** equality for short strings, which are always internalized
|
||||
*/
|
||||
#define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b))
|
||||
|
||||
#define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b))
|
||||
|
||||
|
||||
LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
|
||||
|
|
|
@ -1,38 +1,39 @@
|
|||
/*
|
||||
** $Id: ltable.h $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/ltable.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef ltable_h
|
||||
#define ltable_h
|
||||
#define ltable_h
|
||||
|
||||
#include "lobject.h"
|
||||
|
||||
|
||||
#define gnode(t,i) (&(t)->node[i])
|
||||
#define gval(n) (&(n)->i_val)
|
||||
#define gnext(n) ((n)->u.next)
|
||||
#define gnode(t,i) (&(t)->node[i])
|
||||
#define gval(n) (&(n)->i_val)
|
||||
#define gnext(n) ((n)->u.next)
|
||||
|
||||
|
||||
/*
|
||||
** Clear all bits of fast-access metamethods, which means that the table
|
||||
** may have any of these metamethods. (First access that fails after the
|
||||
** clearing will set the bit again.)
|
||||
*/
|
||||
#define invalidateTMcache(t) ((t)->flags &= ~maskflags)
|
||||
|
||||
|
||||
/* true when 't' is using 'dummynode' as its hash part */
|
||||
#define isdummy(t) ((t)->lastfree == NULL)
|
||||
|
||||
|
||||
/* allocated size for hash nodes */
|
||||
#define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t))
|
||||
|
||||
#define invalidateTMcache(t) ((t)->flags &= ~maskflags)
|
||||
|
||||
|
||||
/* returns the Node, given the value of a table entry */
|
||||
#define nodefromval(v) cast(Node *, (v))
|
||||
|
||||
#define isdummy(t) ((t)->lastfree == NULL)
|
||||
|
||||
|
||||
|
||||
#define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t))
|
||||
|
||||
|
||||
|
||||
#define nodefromval(v) cast(Node *, (v))
|
||||
|
||||
|
||||
LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
|
||||
|
|
|
@ -1,27 +1,28 @@
|
|||
/*
|
||||
** $Id: ltm.h $
|
||||
** Tag methods
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/ltm.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef ltm_h
|
||||
#define ltm_h
|
||||
#define ltm_h
|
||||
|
||||
|
||||
#include "lobject.h"
|
||||
|
||||
|
||||
/*
|
||||
* WARNING: if you change the order of this enumeration,
|
||||
* grep "ORDER TM" and "ORDER OP"
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
TM_INDEX,
|
||||
TM_NEWINDEX,
|
||||
TM_GC,
|
||||
TM_MODE,
|
||||
TM_LEN,
|
||||
TM_EQ, /* last tag method with fast access */
|
||||
TM_EQ,
|
||||
TM_ADD,
|
||||
TM_SUB,
|
||||
TM_MUL,
|
||||
|
@ -41,32 +42,25 @@ typedef enum {
|
|||
TM_CONCAT,
|
||||
TM_CALL,
|
||||
TM_CLOSE,
|
||||
TM_N /* number of elements in the enum */
|
||||
TM_N
|
||||
} TMS;
|
||||
# 54 "./lua/ltm.h"
|
||||
#define maskflags (~(~0u << (TM_EQ + 1)))
|
||||
|
||||
|
||||
/*
|
||||
** Mask with 1 in all fast-access methods. A 1 in any of these bits
|
||||
** in the flag of a (meta)table means the metatable does not have the
|
||||
** corresponding metamethod field. (Bit 7 of the flag is used for
|
||||
** 'isrealasize'.)
|
||||
*/
|
||||
#define maskflags (~(~0u << (TM_EQ + 1)))
|
||||
|
||||
|
||||
/*
|
||||
** Test whether there is no tagmethod.
|
||||
** (Because tagmethods use raw accesses, the result may be an "empty" nil.)
|
||||
*/
|
||||
#define notm(tm) ttisnil(tm)
|
||||
|
||||
|
||||
#define notm(tm) ttisnil(tm)
|
||||
|
||||
|
||||
#define gfasttm(g,et,e) ((et) == NULL ? NULL : \
|
||||
((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
|
||||
|
||||
#define fasttm(l,et,e) gfasttm(G(l), et, e)
|
||||
#define fasttm(l,et,e) gfasttm(G(l), et, e)
|
||||
|
||||
#define ttypename(x) luaT_typenames_[(x) + 1]
|
||||
#define ttypename(x) luaT_typenames_[(x) + 1]
|
||||
|
||||
LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];)
|
||||
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
/*
|
||||
** $Id: lua.h $
|
||||
** Lua - A Scripting Language
|
||||
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
|
||||
** See Copyright Notice at the end of this file
|
||||
*/
|
||||
|
||||
|
||||
# 1 "./lua/lua.h"
|
||||
# 9 "./lua/lua.h"
|
||||
#ifndef lua_h
|
||||
#define lua_h
|
||||
#define lua_h
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
@ -16,144 +10,144 @@
|
|||
#include "luaconf.h"
|
||||
|
||||
|
||||
#define LUA_VERSION_MAJOR "5"
|
||||
#define LUA_VERSION_MINOR "4"
|
||||
#define LUA_VERSION_RELEASE "4"
|
||||
#define LUA_VERSION_MAJOR "5"
|
||||
#define LUA_VERSION_MINOR "4"
|
||||
#define LUA_VERSION_RELEASE "4"
|
||||
|
||||
#define LUA_VERSION_NUM 504
|
||||
#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 4)
|
||||
#define LUA_VERSION_NUM 504
|
||||
#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 4)
|
||||
|
||||
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
|
||||
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
|
||||
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2022 Lua.org, PUC-Rio"
|
||||
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
|
||||
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
|
||||
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
|
||||
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2022 Lua.org, PUC-Rio"
|
||||
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
|
||||
|
||||
|
||||
/* mark for precompiled code ('<esc>Lua') */
|
||||
#define LUA_SIGNATURE "\x1bLua"
|
||||
|
||||
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
|
||||
#define LUA_MULTRET (-1)
|
||||
#define LUA_SIGNATURE "\x1bLua"
|
||||
|
||||
|
||||
/*
|
||||
** Pseudo-indices
|
||||
** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
|
||||
** space after that to help overflow detection)
|
||||
*/
|
||||
#define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
|
||||
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
|
||||
#define LUA_MULTRET (-1)
|
||||
|
||||
|
||||
/* thread status */
|
||||
#define LUA_OK 0
|
||||
#define LUA_YIELD 1
|
||||
#define LUA_ERRRUN 2
|
||||
#define LUA_ERRSYNTAX 3
|
||||
#define LUA_ERRMEM 4
|
||||
#define LUA_ERRERR 5
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
|
||||
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
|
||||
|
||||
|
||||
|
||||
#define LUA_OK 0
|
||||
#define LUA_YIELD 1
|
||||
#define LUA_ERRRUN 2
|
||||
#define LUA_ERRSYNTAX 3
|
||||
#define LUA_ERRMEM 4
|
||||
#define LUA_ERRERR 5
|
||||
|
||||
|
||||
typedef struct lua_State lua_State;
|
||||
|
||||
|
||||
/*
|
||||
** basic types
|
||||
*/
|
||||
#define LUA_TNONE (-1)
|
||||
|
||||
#define LUA_TNIL 0
|
||||
#define LUA_TBOOLEAN 1
|
||||
#define LUA_TLIGHTUSERDATA 2
|
||||
#define LUA_TNUMBER 3
|
||||
#define LUA_TSTRING 4
|
||||
#define LUA_TTABLE 5
|
||||
#define LUA_TFUNCTION 6
|
||||
#define LUA_TUSERDATA 7
|
||||
#define LUA_TTHREAD 8
|
||||
|
||||
#define LUA_NUMTYPES 9
|
||||
|
||||
|
||||
|
||||
/* minimum Lua stack available to a C function */
|
||||
#define LUA_MINSTACK 20
|
||||
#define LUA_TNONE (-1)
|
||||
|
||||
#define LUA_TNIL 0
|
||||
#define LUA_TBOOLEAN 1
|
||||
#define LUA_TLIGHTUSERDATA 2
|
||||
#define LUA_TNUMBER 3
|
||||
#define LUA_TSTRING 4
|
||||
#define LUA_TTABLE 5
|
||||
#define LUA_TFUNCTION 6
|
||||
#define LUA_TUSERDATA 7
|
||||
#define LUA_TTHREAD 8
|
||||
|
||||
#define LUA_NUMTYPES 9
|
||||
|
||||
|
||||
/* predefined values in the registry */
|
||||
#define LUA_RIDX_MAINTHREAD 1
|
||||
#define LUA_RIDX_GLOBALS 2
|
||||
#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
|
||||
|
||||
|
||||
/* type of numbers in Lua */
|
||||
#define LUA_MINSTACK 20
|
||||
|
||||
|
||||
|
||||
#define LUA_RIDX_MAINTHREAD 1
|
||||
#define LUA_RIDX_GLOBALS 2
|
||||
#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
|
||||
|
||||
|
||||
|
||||
typedef LUA_NUMBER lua_Number;
|
||||
|
||||
|
||||
/* type for integer functions */
|
||||
|
||||
typedef LUA_INTEGER lua_Integer;
|
||||
|
||||
/* unsigned integer type */
|
||||
|
||||
typedef LUA_UNSIGNED lua_Unsigned;
|
||||
|
||||
/* type for continuation-function contexts */
|
||||
|
||||
typedef LUA_KCONTEXT lua_KContext;
|
||||
|
||||
|
||||
/*
|
||||
** Type for C functions registered with Lua
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef int (*lua_CFunction) (lua_State *L);
|
||||
|
||||
/*
|
||||
** Type for continuation functions
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);
|
||||
|
||||
|
||||
/*
|
||||
** Type for functions that read/write blocks when loading/dumping Lua chunks
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
|
||||
|
||||
typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
|
||||
|
||||
|
||||
/*
|
||||
** Type for memory-allocation functions
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
|
||||
|
||||
|
||||
/*
|
||||
** Type for warning functions
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** generic extra include file
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if defined(LUA_USER_H)
|
||||
#include LUA_USER_H
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** RCS ident string
|
||||
*/
|
||||
|
||||
|
||||
|
||||
extern const char lua_ident[];
|
||||
|
||||
|
||||
/*
|
||||
** state manipulation
|
||||
*/
|
||||
|
||||
|
||||
|
||||
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
|
||||
LUA_API void (lua_close) (lua_State *L);
|
||||
LUA_API void (lua_close) (lua_State *L);
|
||||
LUA_API lua_State *(lua_newthread) (lua_State *L);
|
||||
LUA_API int (lua_resetthread) (lua_State *L);
|
||||
LUA_API int (lua_resetthread) (lua_State *L);
|
||||
|
||||
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
|
||||
|
||||
|
@ -161,92 +155,92 @@ LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
|
|||
LUA_API lua_Number (lua_version) (lua_State *L);
|
||||
|
||||
|
||||
/*
|
||||
** basic stack manipulation
|
||||
*/
|
||||
LUA_API int (lua_absindex) (lua_State *L, int idx);
|
||||
LUA_API int (lua_gettop) (lua_State *L);
|
||||
LUA_API void (lua_settop) (lua_State *L, int idx);
|
||||
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
|
||||
LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
|
||||
LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
|
||||
LUA_API int (lua_checkstack) (lua_State *L, int n);
|
||||
|
||||
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
|
||||
|
||||
|
||||
/*
|
||||
** access functions (stack -> C)
|
||||
*/
|
||||
|
||||
LUA_API int (lua_isnumber) (lua_State *L, int idx);
|
||||
LUA_API int (lua_isstring) (lua_State *L, int idx);
|
||||
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
|
||||
LUA_API int (lua_isinteger) (lua_State *L, int idx);
|
||||
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
|
||||
LUA_API int (lua_type) (lua_State *L, int idx);
|
||||
LUA_API const char *(lua_typename) (lua_State *L, int tp);
|
||||
LUA_API int (lua_absindex) (lua_State *L, int idx);
|
||||
LUA_API int (lua_gettop) (lua_State *L);
|
||||
LUA_API void (lua_settop) (lua_State *L, int idx);
|
||||
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
|
||||
LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
|
||||
LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
|
||||
LUA_API int (lua_checkstack) (lua_State *L, int n);
|
||||
|
||||
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
|
||||
LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
|
||||
LUA_API int (lua_toboolean) (lua_State *L, int idx);
|
||||
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
|
||||
LUA_API lua_Unsigned (lua_rawlen) (lua_State *L, int idx);
|
||||
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
|
||||
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
|
||||
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
|
||||
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
|
||||
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
|
||||
|
||||
|
||||
/*
|
||||
** Comparison and arithmetic functions
|
||||
*/
|
||||
|
||||
#define LUA_OPADD 0 /* ORDER TM, ORDER OP */
|
||||
#define LUA_OPSUB 1
|
||||
#define LUA_OPMUL 2
|
||||
#define LUA_OPMOD 3
|
||||
#define LUA_OPPOW 4
|
||||
#define LUA_OPDIV 5
|
||||
#define LUA_OPIDIV 6
|
||||
#define LUA_OPBAND 7
|
||||
#define LUA_OPBOR 8
|
||||
#define LUA_OPBXOR 9
|
||||
#define LUA_OPSHL 10
|
||||
#define LUA_OPSHR 11
|
||||
#define LUA_OPUNM 12
|
||||
#define LUA_OPBNOT 13
|
||||
|
||||
LUA_API void (lua_arith) (lua_State *L, int op);
|
||||
|
||||
#define LUA_OPEQ 0
|
||||
#define LUA_OPLT 1
|
||||
#define LUA_OPLE 2
|
||||
|
||||
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
|
||||
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
|
||||
|
||||
|
||||
/*
|
||||
** push functions (C -> stack)
|
||||
*/
|
||||
LUA_API void (lua_pushnil) (lua_State *L);
|
||||
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
|
||||
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
|
||||
|
||||
|
||||
LUA_API int (lua_isnumber) (lua_State *L, int idx);
|
||||
LUA_API int (lua_isstring) (lua_State *L, int idx);
|
||||
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
|
||||
LUA_API int (lua_isinteger) (lua_State *L, int idx);
|
||||
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
|
||||
LUA_API int (lua_type) (lua_State *L, int idx);
|
||||
LUA_API const char *(lua_typename) (lua_State *L, int tp);
|
||||
|
||||
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
|
||||
LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
|
||||
LUA_API int (lua_toboolean) (lua_State *L, int idx);
|
||||
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
|
||||
LUA_API lua_Unsigned (lua_rawlen) (lua_State *L, int idx);
|
||||
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
|
||||
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
|
||||
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
|
||||
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define LUA_OPADD 0
|
||||
#define LUA_OPSUB 1
|
||||
#define LUA_OPMUL 2
|
||||
#define LUA_OPMOD 3
|
||||
#define LUA_OPPOW 4
|
||||
#define LUA_OPDIV 5
|
||||
#define LUA_OPIDIV 6
|
||||
#define LUA_OPBAND 7
|
||||
#define LUA_OPBOR 8
|
||||
#define LUA_OPBXOR 9
|
||||
#define LUA_OPSHL 10
|
||||
#define LUA_OPSHR 11
|
||||
#define LUA_OPUNM 12
|
||||
#define LUA_OPBNOT 13
|
||||
|
||||
LUA_API void (lua_arith) (lua_State *L, int op);
|
||||
|
||||
#define LUA_OPEQ 0
|
||||
#define LUA_OPLT 1
|
||||
#define LUA_OPLE 2
|
||||
|
||||
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
|
||||
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LUA_API void (lua_pushnil) (lua_State *L);
|
||||
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
|
||||
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
|
||||
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);
|
||||
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
|
||||
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
|
||||
va_list argp);
|
||||
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
|
||||
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
|
||||
LUA_API void (lua_pushboolean) (lua_State *L, int b);
|
||||
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
|
||||
LUA_API int (lua_pushthread) (lua_State *L);
|
||||
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
|
||||
LUA_API void (lua_pushboolean) (lua_State *L, int b);
|
||||
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
|
||||
LUA_API int (lua_pushthread) (lua_State *L);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** get functions (Lua -> stack)
|
||||
*/
|
||||
LUA_API int (lua_getglobal) (lua_State *L, const char *name);
|
||||
LUA_API int (lua_gettable) (lua_State *L, int idx);
|
||||
LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
|
||||
|
@ -255,197 +249,170 @@ LUA_API int (lua_rawget) (lua_State *L, int idx);
|
|||
LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
|
||||
LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
|
||||
|
||||
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
|
||||
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
|
||||
LUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue);
|
||||
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
|
||||
LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n);
|
||||
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
|
||||
LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n);
|
||||
|
||||
|
||||
/*
|
||||
** set functions (stack -> Lua)
|
||||
*/
|
||||
LUA_API void (lua_setglobal) (lua_State *L, const char *name);
|
||||
LUA_API void (lua_settable) (lua_State *L, int idx);
|
||||
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
|
||||
LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
|
||||
LUA_API void (lua_rawset) (lua_State *L, int idx);
|
||||
LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
|
||||
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
|
||||
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
|
||||
LUA_API int (lua_setiuservalue) (lua_State *L, int idx, int n);
|
||||
|
||||
|
||||
/*
|
||||
** 'load' and 'call' functions (load and run Lua code)
|
||||
*/
|
||||
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,
|
||||
|
||||
LUA_API void (lua_setglobal) (lua_State *L, const char *name);
|
||||
LUA_API void (lua_settable) (lua_State *L, int idx);
|
||||
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
|
||||
LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
|
||||
LUA_API void (lua_rawset) (lua_State *L, int idx);
|
||||
LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
|
||||
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
|
||||
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
|
||||
LUA_API int (lua_setiuservalue) (lua_State *L, int idx, int n);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,
|
||||
lua_KContext ctx, lua_KFunction k);
|
||||
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
|
||||
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
|
||||
|
||||
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
|
||||
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
|
||||
lua_KContext ctx, lua_KFunction k);
|
||||
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
|
||||
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
|
||||
|
||||
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
|
||||
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
|
||||
const char *chunkname, const char *mode);
|
||||
|
||||
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
|
||||
|
||||
|
||||
/*
|
||||
** coroutine functions
|
||||
*/
|
||||
LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx,
|
||||
|
||||
|
||||
|
||||
LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx,
|
||||
lua_KFunction k);
|
||||
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg,
|
||||
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg,
|
||||
int *nres);
|
||||
LUA_API int (lua_status) (lua_State *L);
|
||||
LUA_API int (lua_status) (lua_State *L);
|
||||
LUA_API int (lua_isyieldable) (lua_State *L);
|
||||
|
||||
#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
|
||||
#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Warning-related functions
|
||||
*/
|
||||
LUA_API void (lua_setwarnf) (lua_State *L, lua_WarnFunction f, void *ud);
|
||||
LUA_API void (lua_warning) (lua_State *L, const char *msg, int tocont);
|
||||
LUA_API void (lua_warning) (lua_State *L, const char *msg, int tocont);
|
||||
|
||||
|
||||
/*
|
||||
** garbage-collection function and options
|
||||
*/
|
||||
|
||||
#define LUA_GCSTOP 0
|
||||
#define LUA_GCRESTART 1
|
||||
#define LUA_GCCOLLECT 2
|
||||
#define LUA_GCCOUNT 3
|
||||
#define LUA_GCCOUNTB 4
|
||||
#define LUA_GCSTEP 5
|
||||
#define LUA_GCSETPAUSE 6
|
||||
#define LUA_GCSETSTEPMUL 7
|
||||
#define LUA_GCISRUNNING 9
|
||||
#define LUA_GCGEN 10
|
||||
#define LUA_GCINC 11
|
||||
|
||||
|
||||
|
||||
#define LUA_GCSTOP 0
|
||||
#define LUA_GCRESTART 1
|
||||
#define LUA_GCCOLLECT 2
|
||||
#define LUA_GCCOUNT 3
|
||||
#define LUA_GCCOUNTB 4
|
||||
#define LUA_GCSTEP 5
|
||||
#define LUA_GCSETPAUSE 6
|
||||
#define LUA_GCSETSTEPMUL 7
|
||||
#define LUA_GCISRUNNING 9
|
||||
#define LUA_GCGEN 10
|
||||
#define LUA_GCINC 11
|
||||
|
||||
LUA_API int (lua_gc) (lua_State *L, int what, ...);
|
||||
|
||||
|
||||
/*
|
||||
** miscellaneous functions
|
||||
*/
|
||||
|
||||
LUA_API int (lua_error) (lua_State *L);
|
||||
|
||||
LUA_API int (lua_next) (lua_State *L, int idx);
|
||||
|
||||
LUA_API void (lua_concat) (lua_State *L, int n);
|
||||
LUA_API void (lua_len) (lua_State *L, int idx);
|
||||
|
||||
LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
|
||||
LUA_API int (lua_error) (lua_State *L);
|
||||
|
||||
LUA_API int (lua_next) (lua_State *L, int idx);
|
||||
|
||||
LUA_API void (lua_concat) (lua_State *L, int n);
|
||||
LUA_API void (lua_len) (lua_State *L, int idx);
|
||||
|
||||
LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
|
||||
|
||||
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
|
||||
LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
|
||||
LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
|
||||
|
||||
LUA_API void (lua_toclose) (lua_State *L, int idx);
|
||||
LUA_API void (lua_closeslot) (lua_State *L, int idx);
|
||||
# 360 "./lua/lua.h"
|
||||
#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
|
||||
|
||||
#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
|
||||
#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
|
||||
|
||||
/*
|
||||
** {==============================================================
|
||||
** some useful macros
|
||||
** ===============================================================
|
||||
*/
|
||||
#define lua_pop(L,n) lua_settop(L, -(n)-1)
|
||||
|
||||
#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
|
||||
|
||||
#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
|
||||
#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
|
||||
|
||||
#define lua_pop(L,n) lua_settop(L, -(n)-1)
|
||||
|
||||
#define lua_newtable(L) lua_createtable(L, 0, 0)
|
||||
#define lua_newtable(L) lua_createtable(L, 0, 0)
|
||||
|
||||
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
|
||||
|
||||
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
|
||||
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
|
||||
|
||||
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
|
||||
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
|
||||
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
|
||||
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
|
||||
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
|
||||
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
|
||||
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
|
||||
#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
|
||||
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
|
||||
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
|
||||
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
|
||||
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
|
||||
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
|
||||
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
|
||||
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
|
||||
#define lua_isnoneornil(L,n) (lua_type(L, (n)) <= 0)
|
||||
|
||||
#define lua_pushliteral(L, s) lua_pushstring(L, "" s)
|
||||
#define lua_pushliteral(L,s) lua_pushstring(L, "" s)
|
||||
|
||||
#define lua_pushglobaltable(L) \
|
||||
((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
|
||||
#define lua_pushglobaltable(L) \
|
||||
((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
|
||||
|
||||
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
|
||||
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
|
||||
|
||||
|
||||
#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
|
||||
#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
|
||||
|
||||
#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
|
||||
#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
|
||||
|
||||
#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
|
||||
|
||||
/* }============================================================== */
|
||||
|
||||
|
||||
/*
|
||||
** {==============================================================
|
||||
** compatibility macros
|
||||
** ===============================================================
|
||||
*/
|
||||
#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
|
||||
# 404 "./lua/lua.h"
|
||||
#if defined(LUA_COMPAT_APIINTCASTS)
|
||||
|
||||
#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
|
||||
#define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
|
||||
#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
|
||||
#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
|
||||
#define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
|
||||
#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
|
||||
|
||||
#endif
|
||||
|
||||
#define lua_newuserdata(L,s) lua_newuserdatauv(L,s,1)
|
||||
#define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1)
|
||||
#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1)
|
||||
#define lua_newuserdata(L,s) lua_newuserdatauv(L,s,1)
|
||||
#define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1)
|
||||
#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1)
|
||||
|
||||
#define LUA_NUMTAGS LUA_NUMTYPES
|
||||
|
||||
/* }============================================================== */
|
||||
|
||||
/*
|
||||
** {======================================================================
|
||||
** Debug API
|
||||
** =======================================================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Event codes
|
||||
*/
|
||||
#define LUA_HOOKCALL 0
|
||||
#define LUA_HOOKRET 1
|
||||
#define LUA_HOOKLINE 2
|
||||
#define LUA_HOOKCOUNT 3
|
||||
#define LUA_NUMTAGS LUA_NUMTYPES
|
||||
# 430 "./lua/lua.h"
|
||||
#define LUA_HOOKCALL 0
|
||||
#define LUA_HOOKRET 1
|
||||
#define LUA_HOOKLINE 2
|
||||
#define LUA_HOOKCOUNT 3
|
||||
#define LUA_HOOKTAILCALL 4
|
||||
|
||||
|
||||
/*
|
||||
** Event masks
|
||||
*/
|
||||
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
|
||||
#define LUA_MASKRET (1 << LUA_HOOKRET)
|
||||
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
|
||||
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
|
||||
|
||||
typedef struct lua_Debug lua_Debug; /* activation record */
|
||||
|
||||
|
||||
/* Functions to be called by the debugger in specific events */
|
||||
|
||||
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
|
||||
#define LUA_MASKRET (1 << LUA_HOOKRET)
|
||||
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
|
||||
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
|
||||
|
||||
typedef struct lua_Debug lua_Debug;
|
||||
|
||||
|
||||
|
||||
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
|
||||
|
||||
|
||||
|
@ -457,7 +424,7 @@ LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
|
|||
LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
|
||||
|
||||
LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
|
||||
LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
|
||||
LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
|
||||
int fidx2, int n2);
|
||||
|
||||
LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
|
||||
|
@ -469,50 +436,23 @@ LUA_API int (lua_setcstacklimit) (lua_State *L, unsigned int limit);
|
|||
|
||||
struct lua_Debug {
|
||||
int event;
|
||||
const char *name; /* (n) */
|
||||
const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
|
||||
const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
|
||||
const char *source; /* (S) */
|
||||
size_t srclen; /* (S) */
|
||||
int currentline; /* (l) */
|
||||
int linedefined; /* (S) */
|
||||
int lastlinedefined; /* (S) */
|
||||
unsigned char nups; /* (u) number of upvalues */
|
||||
unsigned char nparams;/* (u) number of parameters */
|
||||
char isvararg; /* (u) */
|
||||
char istailcall; /* (t) */
|
||||
unsigned short ftransfer; /* (r) index of first value transferred */
|
||||
unsigned short ntransfer; /* (r) number of transferred values */
|
||||
char short_src[LUA_IDSIZE]; /* (S) */
|
||||
/* private part */
|
||||
struct CallInfo *i_ci; /* active function */
|
||||
const char *name;
|
||||
const char *namewhat;
|
||||
const char *what;
|
||||
const char *source;
|
||||
size_t srclen;
|
||||
int currentline;
|
||||
int linedefined;
|
||||
int lastlinedefined;
|
||||
unsigned char nups;
|
||||
unsigned char nparams;
|
||||
char isvararg;
|
||||
char istailcall;
|
||||
unsigned short ftransfer;
|
||||
unsigned short ntransfer;
|
||||
char short_src[LUA_IDSIZE];
|
||||
|
||||
struct CallInfo *i_ci;
|
||||
};
|
||||
|
||||
/* }====================================================================== */
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright (C) 1994-2022 Lua.org, PUC-Rio.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
# 518 "./lua/lua.h"
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
// lua.hpp
|
||||
// Lua header files for C++
|
||||
// <<extern "C">> not supplied automatically because Lua also compiles as C++
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,51 +1,52 @@
|
|||
/*
|
||||
** $Id: lualib.h $
|
||||
** Lua standard libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lualib.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lualib_h
|
||||
#define lualib_h
|
||||
#define lualib_h
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
|
||||
/* version suffix for environment variable names */
|
||||
#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
|
||||
|
||||
#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
|
||||
|
||||
|
||||
LUAMOD_API int (luaopen_base) (lua_State *L);
|
||||
|
||||
#define LUA_COLIBNAME "coroutine"
|
||||
#define LUA_COLIBNAME "coroutine"
|
||||
LUAMOD_API int (luaopen_coroutine) (lua_State *L);
|
||||
|
||||
#define LUA_TABLIBNAME "table"
|
||||
#define LUA_TABLIBNAME "table"
|
||||
LUAMOD_API int (luaopen_table) (lua_State *L);
|
||||
|
||||
#define LUA_IOLIBNAME "io"
|
||||
#define LUA_IOLIBNAME "io"
|
||||
LUAMOD_API int (luaopen_io) (lua_State *L);
|
||||
|
||||
#define LUA_OSLIBNAME "os"
|
||||
#define LUA_OSLIBNAME "os"
|
||||
LUAMOD_API int (luaopen_os) (lua_State *L);
|
||||
|
||||
#define LUA_STRLIBNAME "string"
|
||||
#define LUA_STRLIBNAME "string"
|
||||
LUAMOD_API int (luaopen_string) (lua_State *L);
|
||||
|
||||
#define LUA_UTF8LIBNAME "utf8"
|
||||
#define LUA_UTF8LIBNAME "utf8"
|
||||
LUAMOD_API int (luaopen_utf8) (lua_State *L);
|
||||
|
||||
#define LUA_MATHLIBNAME "math"
|
||||
#define LUA_MATHLIBNAME "math"
|
||||
LUAMOD_API int (luaopen_math) (lua_State *L);
|
||||
|
||||
#define LUA_DBLIBNAME "debug"
|
||||
#define LUA_DBLIBNAME "debug"
|
||||
LUAMOD_API int (luaopen_debug) (lua_State *L);
|
||||
|
||||
#define LUA_LOADLIBNAME "package"
|
||||
#define LUA_LOADLIBNAME "package"
|
||||
LUAMOD_API int (luaopen_package) (lua_State *L);
|
||||
|
||||
|
||||
/* open all previous libraries */
|
||||
|
||||
LUALIB_API void (luaL_openlibs) (lua_State *L);
|
||||
|
||||
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
/*
|
||||
** $Id: lundump.h $
|
||||
** load precompiled Lua chunks
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lundump.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lundump_h
|
||||
#define lundump_h
|
||||
#define lundump_h
|
||||
|
||||
#include "llimits.h"
|
||||
#include "lobject.h"
|
||||
#include "lzio.h"
|
||||
|
||||
|
||||
/* data to catch conversion errors */
|
||||
#define LUAC_DATA "\x19\x93\r\n\x1a\n"
|
||||
|
||||
#define LUAC_INT 0x5678
|
||||
#define LUAC_NUM cast_num(370.5)
|
||||
#define LUAC_DATA "\x19\x93\r\n\x1a\n"
|
||||
|
||||
/*
|
||||
** Encode major-minor version in one byte, one nibble for each
|
||||
*/
|
||||
#define MYINT(s) (s[0]-'0') /* assume one-digit numerals */
|
||||
#define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))
|
||||
#define LUAC_INT 0x5678
|
||||
#define LUAC_NUM cast_num(370.5)
|
||||
|
||||
|
||||
|
||||
|
||||
#define MYINT(s) (s[0]-'0')
|
||||
#define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))
|
||||
|
||||
#define LUAC_FORMAT 0
|
||||
|
||||
#define LUAC_FORMAT 0 /* this is the official format */
|
||||
|
||||
/* load one chunk; from lundump.c */
|
||||
LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);
|
||||
|
||||
/* dump one chunk; from ldump.c */
|
||||
|
||||
LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w,
|
||||
void* data, int strip);
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
/*
|
||||
** $Id: lvm.h $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lvm.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lvm_h
|
||||
#define lvm_h
|
||||
#define lvm_h
|
||||
|
||||
|
||||
#include "ldo.h"
|
||||
|
@ -14,57 +15,57 @@
|
|||
|
||||
|
||||
#if !defined(LUA_NOCVTN2S)
|
||||
#define cvt2str(o) ttisnumber(o)
|
||||
#define cvt2str(o) ttisnumber(o)
|
||||
#else
|
||||
#define cvt2str(o) 0 /* no conversion from numbers to strings */
|
||||
#define cvt2str(o) 0
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(LUA_NOCVTS2N)
|
||||
#define cvt2num(o) ttisstring(o)
|
||||
#define cvt2num(o) ttisstring(o)
|
||||
#else
|
||||
#define cvt2num(o) 0 /* no conversion from strings to numbers */
|
||||
#define cvt2num(o) 0
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** You can define LUA_FLOORN2I if you want to convert floats to integers
|
||||
** by flooring them (instead of raising an error if they are not
|
||||
** integral values)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(LUA_FLOORN2I)
|
||||
#define LUA_FLOORN2I F2Ieq
|
||||
#define LUA_FLOORN2I F2Ieq
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Rounding modes for float->integer coercion
|
||||
*/
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
F2Ieq, /* no rounding; accepts only integral values */
|
||||
F2Ifloor, /* takes the floor of the number */
|
||||
F2Iceil /* takes the ceil of the number */
|
||||
F2Ieq,
|
||||
F2Ifloor,
|
||||
F2Iceil
|
||||
} F2Imod;
|
||||
|
||||
|
||||
/* convert an object to a float (including string coercion) */
|
||||
|
||||
#define tonumber(o,n) \
|
||||
(ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
|
||||
(ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
|
||||
|
||||
|
||||
|
||||
/* convert an object to a float (without string coercion) */
|
||||
#define tonumberns(o,n) \
|
||||
(ttisfloat(o) ? ((n) = fltvalue(o), 1) : \
|
||||
(ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))
|
||||
(ttisfloat(o) ? ((n) = fltvalue(o), 1) : \
|
||||
(ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))
|
||||
|
||||
|
||||
|
||||
/* convert an object to an integer (including string coercion) */
|
||||
#define tointeger(o,i) \
|
||||
(l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
|
||||
: luaV_tointeger(o,i,LUA_FLOORN2I))
|
||||
|
||||
|
||||
/* convert an object to an integer (without string coercion) */
|
||||
|
||||
#define tointegerns(o,i) \
|
||||
(l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
|
||||
: luaV_tointegerns(o,i,LUA_FLOORN2I))
|
||||
|
@ -72,39 +73,31 @@ typedef enum {
|
|||
|
||||
#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))
|
||||
|
||||
#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)
|
||||
|
||||
|
||||
/*
|
||||
** fast track for 'gettable': if 't' is a table and 't[k]' is present,
|
||||
** return 1 with 'slot' pointing to 't[k]' (position of final result).
|
||||
** Otherwise, return 0 (meaning it will have to check metamethod)
|
||||
** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL
|
||||
** (otherwise). 'f' is the raw get function to use.
|
||||
*/
|
||||
#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)
|
||||
# 85 "./lua/lvm.h"
|
||||
#define luaV_fastget(L,t,k,slot,f) \
|
||||
(!ttistable(t) \
|
||||
? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
|
||||
: (slot = f(hvalue(t), k), /* else, do raw access */ \
|
||||
!isempty(slot))) /* result not empty? */
|
||||
(!ttistable(t) \
|
||||
? (slot = NULL, 0) \
|
||||
: (slot = f(hvalue(t), k), \
|
||||
!isempty(slot)))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Special case of 'luaV_fastget' for integers, inlining the fast case
|
||||
** of 'luaH_getint'.
|
||||
*/
|
||||
#define luaV_fastgeti(L,t,k,slot) \
|
||||
(!ttistable(t) \
|
||||
? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
|
||||
(!ttistable(t) \
|
||||
? (slot = NULL, 0) \
|
||||
: (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \
|
||||
? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \
|
||||
!isempty(slot))) /* result not empty? */
|
||||
!isempty(slot)))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Finish a fast set operation (when fast get succeeds). In that case,
|
||||
** 'slot' points to the place to put the value.
|
||||
*/
|
||||
#define luaV_finishfastset(L,t,slot,v) \
|
||||
{ setobj2t(L, cast(TValue *,slot), v); \
|
||||
luaC_barrierback(L, gcvalue(t), v); }
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
/*
|
||||
** $Id: lzio.h $
|
||||
** Buffered streams
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
# 1 "./lua/lzio.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef lzio_h
|
||||
#define lzio_h
|
||||
#define lzio_h
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
#include "lmem.h"
|
||||
|
||||
|
||||
#define EOZ (-1) /* end of stream */
|
||||
#define EOZ (-1)
|
||||
|
||||
typedef struct Zio ZIO;
|
||||
|
||||
#define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
|
||||
#define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
|
||||
|
||||
|
||||
typedef struct Mbuffer {
|
||||
|
@ -26,38 +27,38 @@ typedef struct Mbuffer {
|
|||
size_t buffsize;
|
||||
} Mbuffer;
|
||||
|
||||
#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
|
||||
#define luaZ_initbuffer(L,buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
|
||||
|
||||
#define luaZ_buffer(buff) ((buff)->buffer)
|
||||
#define luaZ_sizebuffer(buff) ((buff)->buffsize)
|
||||
#define luaZ_bufflen(buff) ((buff)->n)
|
||||
#define luaZ_buffer(buff) ((buff)->buffer)
|
||||
#define luaZ_sizebuffer(buff) ((buff)->buffsize)
|
||||
#define luaZ_bufflen(buff) ((buff)->n)
|
||||
|
||||
#define luaZ_buffremove(buff,i) ((buff)->n -= (i))
|
||||
#define luaZ_buffremove(buff,i) ((buff)->n -= (i))
|
||||
#define luaZ_resetbuffer(buff) ((buff)->n = 0)
|
||||
|
||||
|
||||
#define luaZ_resizebuffer(L, buff, size) \
|
||||
((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \
|
||||
(buff)->buffsize, size), \
|
||||
(buff)->buffsize = size)
|
||||
#define luaZ_resizebuffer(L,buff,size) \
|
||||
((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \
|
||||
(buff)->buffsize, size), \
|
||||
(buff)->buffsize = size)
|
||||
|
||||
#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
|
||||
#define luaZ_freebuffer(L,buff) luaZ_resizebuffer(L, buff, 0)
|
||||
|
||||
|
||||
LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
|
||||
void *data);
|
||||
LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */
|
||||
LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n);
|
||||
|
||||
|
||||
|
||||
|
||||
/* --------- Private Part ------------------ */
|
||||
|
||||
struct Zio {
|
||||
size_t n; /* bytes still unread */
|
||||
const char *p; /* current position in buffer */
|
||||
lua_Reader reader; /* reader function */
|
||||
void *data; /* additional data */
|
||||
lua_State *L; /* Lua state (for reader) */
|
||||
size_t n;
|
||||
const char *p;
|
||||
lua_Reader reader;
|
||||
void *data;
|
||||
lua_State *L;
|
||||
};
|
||||
|
||||
|
||||
|
|
2152
include/sqlite3/sqlite3.h
Normal file
2152
include/sqlite3/sqlite3.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
lib/win/sqlite3.dll
Normal file
BIN
lib/win/sqlite3.dll
Normal file
Binary file not shown.
12
qml/Config.qml
Normal file
12
qml/Config.qml
Normal file
|
@ -0,0 +1,12 @@
|
|||
import QtQuick 2.15
|
||||
|
||||
QtObject {
|
||||
// Client configuration
|
||||
|
||||
// Player property of client
|
||||
property string screenName: ""
|
||||
property string password: ""
|
||||
|
||||
// Client data
|
||||
property int roomCapacity: 0
|
||||
}
|
12
qml/Logic.js
12
qml/Logic.js
|
@ -1,4 +1,11 @@
|
|||
var callbacks = {}
|
||||
var callbacks = {};
|
||||
|
||||
callbacks["NetworkDelayTest"] = function(jsonData) {
|
||||
Backend.notifyServer("Setup", JSON.stringify([
|
||||
config.screenName,
|
||||
config.password
|
||||
]));
|
||||
}
|
||||
|
||||
callbacks["ErrorMsg"] = function(jsonData) {
|
||||
toast.show(jsonData);
|
||||
|
@ -9,11 +16,14 @@ callbacks["EnterLobby"] = function(jsonData) {
|
|||
// depth == 1 means the lobby page is not present in mainStack
|
||||
if (mainStack.depth === 1) {
|
||||
mainStack.push(lobby);
|
||||
} else {
|
||||
mainStack.pop();
|
||||
}
|
||||
mainWindow.busy = false;
|
||||
}
|
||||
|
||||
callbacks["EnterRoom"] = function(jsonData) {
|
||||
config.roomCapacity = JSON.parse(jsonData)[0];
|
||||
mainStack.push(room);
|
||||
mainWindow.busy = false;
|
||||
}
|
||||
|
|
|
@ -14,11 +14,24 @@ Item {
|
|||
text: "127.0.0.1"
|
||||
}
|
||||
TextField {
|
||||
id: screenNameEdit
|
||||
text: "player"
|
||||
}
|
||||
/*TextField {
|
||||
id: avatarEdit
|
||||
text: "liubei"
|
||||
}*/
|
||||
TextField {
|
||||
id: passwordEdit
|
||||
text: ""
|
||||
echoMode: TextInput.Password
|
||||
passwordCharacter: "*"
|
||||
}
|
||||
Button {
|
||||
text: "Join Server"
|
||||
onClicked: {
|
||||
config.screenName = screenNameEdit.text;
|
||||
config.password = passwordEdit.text;
|
||||
mainWindow.busy = true;
|
||||
toast.show("Connecting to host...");
|
||||
Backend.joinServer(server_addr.text);
|
||||
|
@ -27,6 +40,8 @@ Item {
|
|||
Button {
|
||||
text: "Console start"
|
||||
onClicked: {
|
||||
config.screenName = screenNameEdit.text;
|
||||
config.password = passwordEdit.text;
|
||||
mainWindow.busy = true;
|
||||
toast.show("Connecting to host...");
|
||||
Backend.startServer(9527);
|
||||
|
|
|
@ -43,7 +43,7 @@ Item {
|
|||
onClicked: {
|
||||
mainWindow.busy = true;
|
||||
Backend.notifyServer(
|
||||
"enter_room",
|
||||
"EnterRoom",
|
||||
JSON.stringify([roomId])
|
||||
);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ Item {
|
|||
text: "quit"
|
||||
anchors.bottom: parent.bottom
|
||||
onClicked: {
|
||||
mainStack.pop();
|
||||
Backend.notifyServer("QuitRoom", "[]");
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +31,7 @@ Item {
|
|||
TextField {
|
||||
id: lua
|
||||
Layout.fillWidth: true
|
||||
text: "player"
|
||||
text: "print \"Hello world.\""
|
||||
}
|
||||
Button {
|
||||
text: "DoLuaScript"
|
||||
|
@ -62,7 +61,19 @@ Item {
|
|||
id: photos
|
||||
model: photoModel
|
||||
Photo {
|
||||
// TODO
|
||||
general: modelData.general
|
||||
screenName: modelData.screenName
|
||||
role: modelData.role
|
||||
kingdom: modelData.kingdom
|
||||
netstate: modelData.netstate
|
||||
maxHp: modelData.maxHp
|
||||
hp: modelData.hp
|
||||
seatNumber: modelData.seatNumber
|
||||
isDead: modelData.isDead
|
||||
dying: modelData.dying
|
||||
faceturned: modelData.faceturned
|
||||
chained: modelData.chained
|
||||
drank: modelData.drank
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,10 +99,63 @@ Item {
|
|||
id: dashboard
|
||||
width: roomScene.width
|
||||
anchors.top: roomArea.bottom
|
||||
|
||||
self.general: dashboardModel.general
|
||||
self.screenName: dashboardModel.screenName
|
||||
self.role: dashboardModel.role
|
||||
self.kingdom: dashboardModel.kingdom
|
||||
self.netstate: dashboardModel.netstate
|
||||
self.maxHp: dashboardModel.maxHp
|
||||
self.hp: dashboardModel.hp
|
||||
self.seatNumber: dashboardModel.seatNumber
|
||||
self.isDead: dashboardModel.isDead
|
||||
self.dying: dashboardModel.dying
|
||||
self.faceturned: dashboardModel.faceturned
|
||||
self.chained: dashboardModel.chained
|
||||
self.drank: dashboardModel.drank
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
toast.show("Sucesessfully entered room.");
|
||||
|
||||
dashboardModel = {
|
||||
general: config.avatar,
|
||||
screenName: config.screenName,
|
||||
role: "unknown",
|
||||
kingdom: "qun",
|
||||
netstate: "online",
|
||||
maxHp: 0,
|
||||
hp: 0,
|
||||
seatNumber: 1,
|
||||
isDead: false,
|
||||
dying: false,
|
||||
faceturned: false,
|
||||
chained: false,
|
||||
drank: false
|
||||
}
|
||||
|
||||
playerNum = config.roomCapacity;
|
||||
|
||||
let i;
|
||||
for (i = 1; i < playerNum; i++) {
|
||||
photoModel.push({
|
||||
general: "",
|
||||
screenName: "",
|
||||
role: "unknown",
|
||||
kingdom: "qun",
|
||||
netstate: "online",
|
||||
maxHp: 0,
|
||||
hp: 0,
|
||||
seatNumber: i + 1,
|
||||
isDead: false,
|
||||
dying: false,
|
||||
faceturned: false,
|
||||
chained: false,
|
||||
drank: false
|
||||
});
|
||||
}
|
||||
photoModel = photoModel; // Force the Repeater reload
|
||||
|
||||
Logic.arrangePhotos();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,15 +8,15 @@ Item {
|
|||
width: 175
|
||||
height: 233
|
||||
scale: 0.8
|
||||
property string general: "liubei"
|
||||
property string general: ""
|
||||
property string screenName: ""
|
||||
property string role: "lord"
|
||||
property string kingdom: "shu"
|
||||
property string netstate: "trust"
|
||||
property string role: "unknown"
|
||||
property string kingdom: "qun"
|
||||
property string netstate: "online"
|
||||
property int handcards: 0
|
||||
property int maxHp: 4
|
||||
property int hp: 3
|
||||
property int seatNumber: 3
|
||||
property int maxHp: 0
|
||||
property int hp: 0
|
||||
property int seatNumber: 1
|
||||
property bool isDead: false
|
||||
property bool dying: false
|
||||
property bool faceturned: false
|
||||
|
@ -41,7 +41,7 @@ Item {
|
|||
color: "white"
|
||||
width: 24
|
||||
wrapMode: Text.WordWrap
|
||||
text: "刘备"
|
||||
text: ""
|
||||
}
|
||||
|
||||
HpBar {
|
||||
|
@ -60,7 +60,7 @@ Item {
|
|||
smooth: true
|
||||
visible: false
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
source: SkinBank.GENERAL_DIR + general
|
||||
source: (general != "") ? SkinBank.GENERAL_DIR + general : ""
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
|
|
|
@ -47,3 +47,59 @@ function arrangePhotos() {
|
|||
item.y = region.y;
|
||||
}
|
||||
}
|
||||
|
||||
callbacks["AddPlayer"] = function(jsonData) {
|
||||
// jsonData: string screenName, string avatar
|
||||
for (let i = 0; i < photoModel.length; i++) {
|
||||
if (photoModel[i].screenName === "") {
|
||||
let data = JSON.parse(jsonData);
|
||||
let name = data[0];
|
||||
let avatar = data[1];
|
||||
photoModel[i] = {
|
||||
general: avatar,
|
||||
screenName: name,
|
||||
role: "unknown",
|
||||
kingdom: "qun",
|
||||
netstate: "online",
|
||||
maxHp: 0,
|
||||
hp: 0,
|
||||
seatNumber: i + 1,
|
||||
isDead: false,
|
||||
dying: false,
|
||||
faceturned: false,
|
||||
chained: false,
|
||||
drank: false
|
||||
};
|
||||
photoModel = photoModel;
|
||||
arrangePhotos();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callbacks["RemovePlayer"] = function(jsonData) {
|
||||
// jsonData: string screenName
|
||||
let name = JSON.parse(jsonData)[0];
|
||||
for (let i = 0; i < photoModel.length; i++) {
|
||||
if (photoModel[i].screenName === name) {
|
||||
photoModel[i] = {
|
||||
general: "",
|
||||
screenName: "",
|
||||
role: "unknown",
|
||||
kingdom: "qun",
|
||||
netstate: "online",
|
||||
maxHp: 0,
|
||||
hp: 0,
|
||||
seatNumber: i + 1,
|
||||
isDead: false,
|
||||
dying: false,
|
||||
faceturned: false,
|
||||
chained: false,
|
||||
drank: false
|
||||
};
|
||||
photoModel = photoModel;
|
||||
arrangePhotos();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,10 @@ Window {
|
|||
visible: mainWindow.busy === true
|
||||
}
|
||||
|
||||
Config {
|
||||
id: config
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: toast
|
||||
opacity: 0
|
||||
|
|
12
server/init.sql
Normal file
12
server/init.sql
Normal file
|
@ -0,0 +1,12 @@
|
|||
CREATE TABLE userinfo (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name VARCHAR(255),
|
||||
password CHAR(64),
|
||||
avatar VARCHAR(64),
|
||||
lastLoginIp VARCHAR(64),
|
||||
banned BOOLEAN
|
||||
);
|
||||
|
||||
CREATE TABLE banip (
|
||||
ip VARCHAR(64)
|
||||
);
|
|
@ -32,16 +32,18 @@ set(freekill_HEADERS
|
|||
|
||||
if (WIN32)
|
||||
set(LUA_LIB ${PROJECT_SOURCE_DIR}/lib/win/lua54.dll)
|
||||
set(SQLITE3_LIB ${PROJECT_SOURCE_DIR}/lib/win/sqlite3.dll)
|
||||
else ()
|
||||
set(LUA_LIB lua5.4)
|
||||
set(SQLITE3_LIB sqlite3)
|
||||
endif ()
|
||||
|
||||
source_group("Include" FILES ${freekill_HEADERS})
|
||||
add_executable(FreeKill ${freekill_SRCS})
|
||||
target_link_libraries(FreeKill ${LUA_LIB} Qt5::Qml Qt5::Gui Qt5::Network Qt5::Multimedia)
|
||||
target_link_libraries(FreeKill ${LUA_LIB} ${SQLITE3_LIB} Qt5::Qml Qt5::Gui Qt5::Network Qt5::Multimedia)
|
||||
add_custom_command(
|
||||
OUTPUT ${PROJECT_SOURCE_DIR}/src/swig/freekill-wrap.cxx
|
||||
DEPENDS ${PROJECT_SOURCE_DIR}/src/swig/freekill.i
|
||||
DEPENDS ${PROJECT_SOURCE_DIR}/src/swig/*.i
|
||||
COMMENT "Generating freekill-wrap.cxx"
|
||||
COMMAND swig -c++ -lua -Wall -o
|
||||
${PROJECT_SOURCE_DIR}/src/swig/freekill-wrap.cxx
|
||||
|
|
|
@ -23,6 +23,7 @@ Client::Client(QObject* parent)
|
|||
Client::~Client()
|
||||
{
|
||||
ClientInstance = nullptr;
|
||||
lua_close(L);
|
||||
router->getSocket()->disconnectFromHost();
|
||||
router->getSocket()->deleteLater();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "global.h"
|
||||
#include <QtCore>
|
||||
#include <QFileDevice>
|
||||
|
||||
extern "C" {
|
||||
int luaopen_freekill(lua_State *);
|
||||
|
@ -25,3 +26,66 @@ bool DoLuaScript(lua_State *L, const char *script)
|
|||
return true;
|
||||
}
|
||||
|
||||
sqlite3 *OpenDatabase(const QString &filename)
|
||||
{
|
||||
sqlite3 *ret;
|
||||
int rc;
|
||||
if (!QFile::exists(filename)) {
|
||||
QFile file("./server/init.sql");
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qDebug() << "cannot open init.sql. Quit now.";
|
||||
qApp->exit(1);
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
char *err_msg;
|
||||
sqlite3_open(filename.toLatin1().data(), &ret);
|
||||
rc = sqlite3_exec(ret, in.readAll().toLatin1().data(), nullptr, nullptr, &err_msg);
|
||||
|
||||
if (rc != SQLITE_OK ) {
|
||||
qDebug() << "sqlite error:" << err_msg;
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(ret);
|
||||
qApp->exit(1);
|
||||
}
|
||||
} else {
|
||||
rc = sqlite3_open(filename.toLatin1().data(), &ret);
|
||||
if (rc != SQLITE_OK) {
|
||||
qDebug() << "Cannot open database:" << sqlite3_errmsg(ret);
|
||||
sqlite3_close(ret);
|
||||
qApp->exit(1);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// callback for handling SELECT expression
|
||||
static int callback(void *jsonDoc, int argc, char **argv, char **cols) {
|
||||
QJsonObject obj;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
QJsonArray arr = obj[QString(cols[i])].toArray();
|
||||
arr << QString(argv[i] ? argv[i] : "#null");
|
||||
obj[QString(cols[i])] = arr;
|
||||
}
|
||||
((QJsonObject *)jsonDoc)->swap(obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
QJsonObject SelectFromDatabase(sqlite3 *db, const QString &sql) {
|
||||
QJsonObject obj;
|
||||
sqlite3_exec(db, sql.toUtf8().data(), callback, (void *)&obj, nullptr);
|
||||
return obj;
|
||||
}
|
||||
|
||||
QString SelectFromDb(sqlite3 *db, const QString &sql) {
|
||||
QJsonObject obj = SelectFromDatabase(db, sql);
|
||||
return QJsonDocument(obj).toJson();
|
||||
}
|
||||
|
||||
void ExecSQL(sqlite3 *db, const QString &sql) {
|
||||
sqlite3_exec(db, sql.toUtf8().data(), nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void CloseDatabase(sqlite3 *db) {
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define _GLOBAL_H
|
||||
|
||||
#include <lua.hpp>
|
||||
#include <sqlite3.h>
|
||||
#include <QtCore>
|
||||
|
||||
// utilities
|
||||
typedef int LuaFunction;
|
||||
|
@ -9,4 +11,11 @@ typedef int LuaFunction;
|
|||
lua_State *CreateLuaState();
|
||||
bool DoLuaScript(lua_State *L, const char *script);
|
||||
|
||||
sqlite3 *OpenDatabase(const QString &filename = "./server/users.db");
|
||||
QJsonObject SelectFromDatabase(sqlite3 *db, const QString &sql);
|
||||
// For Lua
|
||||
QString SelectFromDb(sqlite3 *db, const QString &sql);
|
||||
void ExecSQL(sqlite3 *db, const QString &sql);
|
||||
void CloseDatabase(sqlite3 *db);
|
||||
|
||||
#endif // _GLOBAL_H
|
||||
|
|
|
@ -44,7 +44,7 @@ signals:
|
|||
|
||||
private:
|
||||
uint id;
|
||||
QString screenName;
|
||||
QString screenName; // screenName should not be same.
|
||||
QString avatar;
|
||||
State state;
|
||||
bool ready;
|
||||
|
|
|
@ -11,6 +11,8 @@ ClientSocket::ClientSocket(QTcpSocket* socket)
|
|||
{
|
||||
socket->setParent(this);
|
||||
this->socket = socket;
|
||||
timerSignup.setSingleShot(true);
|
||||
connect(&timerSignup, &QTimer::timeout, this, &ClientSocket::disconnectFromHost);
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QObject>
|
||||
#include <QAbstractSocket>
|
||||
#include <QHostAddress>
|
||||
#include <QTimer>
|
||||
|
||||
class QTcpSocket;
|
||||
|
||||
|
@ -21,6 +22,7 @@ public:
|
|||
bool isConnected() const;
|
||||
QString peerName() const;
|
||||
QString peerAddress() const;
|
||||
QTimer timerSignup;
|
||||
|
||||
signals:
|
||||
void message_got(const QByteArray& msg);
|
||||
|
|
|
@ -18,6 +18,9 @@ void ServerSocket::processNewConnection()
|
|||
{
|
||||
QTcpSocket *socket = server->nextPendingConnection();
|
||||
ClientSocket *connection = new ClientSocket(socket);
|
||||
connect(connection, &ClientSocket::disconnected, this, [connection](){
|
||||
connection->deleteLater();
|
||||
});
|
||||
emit new_connection(connection);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "room.h"
|
||||
#include "serverplayer.h"
|
||||
#include "server.h"
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
|
||||
Room::Room(Server* server)
|
||||
{
|
||||
|
@ -17,6 +19,7 @@ Room::Room(Server* server)
|
|||
Room::~Room()
|
||||
{
|
||||
// TODO
|
||||
disconnect();
|
||||
}
|
||||
|
||||
Server *Room::getServer() const
|
||||
|
@ -77,14 +80,33 @@ void Room::setOwner(ServerPlayer *owner)
|
|||
void Room::addPlayer(ServerPlayer *player)
|
||||
{
|
||||
if (!player) return;
|
||||
|
||||
QJsonArray jsonData;
|
||||
|
||||
// First, notify other players the new player is entering
|
||||
if (!isLobby()) {
|
||||
jsonData << player->getScreenName();
|
||||
jsonData << player->getAvatar();
|
||||
doBroadcastNotify(getPlayers(), "AddPlayer", QJsonDocument(jsonData).toJson());
|
||||
}
|
||||
|
||||
players.append(player);
|
||||
player->setRoom(this);
|
||||
if (isLobby()) {
|
||||
player->doNotify("EnterLobby", "[]");
|
||||
} else {
|
||||
player->doNotify("EnterRoom", "[]");
|
||||
// Second, let the player enter room and add other players
|
||||
jsonData = QJsonArray();
|
||||
jsonData << (int)this->capacity;
|
||||
player->doNotify("EnterRoom", QJsonDocument(jsonData).toJson());
|
||||
|
||||
foreach (ServerPlayer *p, getOtherPlayers(player)) {
|
||||
jsonData = QJsonArray();
|
||||
jsonData << p->getScreenName();
|
||||
jsonData << p->getAvatar();
|
||||
player->doNotify("AddPlayer", QJsonDocument(jsonData).toJson());
|
||||
}
|
||||
}
|
||||
qDebug() << "Player #" << player->getUid() << " entered room";
|
||||
emit playerAdded(player);
|
||||
}
|
||||
|
||||
|
@ -95,6 +117,11 @@ void Room::removePlayer(ServerPlayer *player)
|
|||
|
||||
if (isLobby()) return;
|
||||
|
||||
// player->doNotify("QuitRoom", "[]");
|
||||
QJsonArray jsonData;
|
||||
jsonData << player->getScreenName();
|
||||
doBroadcastNotify(getPlayers(), "RemovePlayer", QJsonDocument(jsonData).toJson());
|
||||
|
||||
if (isAbandoned()) {
|
||||
emit abandoned();
|
||||
} else if (player == owner) {
|
||||
|
@ -108,6 +135,13 @@ QList<ServerPlayer *> Room::getPlayers() const
|
|||
return players;
|
||||
}
|
||||
|
||||
QList<ServerPlayer *> Room::getOtherPlayers(ServerPlayer* expect) const
|
||||
{
|
||||
QList<ServerPlayer *> others = getPlayers();
|
||||
others.removeOne(expect);
|
||||
return others;
|
||||
}
|
||||
|
||||
ServerPlayer *Room::findPlayer(uint id) const
|
||||
{
|
||||
foreach (ServerPlayer *p, players) {
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
void addPlayer(ServerPlayer *player);
|
||||
void removePlayer(ServerPlayer *player);
|
||||
QList<ServerPlayer*> getPlayers() const;
|
||||
QList<ServerPlayer *> getOtherPlayers(ServerPlayer *expect) const;
|
||||
ServerPlayer *findPlayer(uint id) const;
|
||||
|
||||
void setGameLogic(GameLogic *logic);
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QRegExp>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
Server *ServerInstance;
|
||||
|
||||
|
@ -26,11 +28,16 @@ Server::Server(QObject* parent)
|
|||
L = CreateLuaState();
|
||||
DoLuaScript(L, "lua/freekill.lua");
|
||||
DoLuaScript(L, "lua/server/server.lua");
|
||||
|
||||
db = OpenDatabase();
|
||||
}
|
||||
|
||||
Server::~Server()
|
||||
{
|
||||
ServerInstance = nullptr;
|
||||
m_lobby->deleteLater();
|
||||
lua_close(L);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
bool Server::listen(const QHostAddress& address, ushort port)
|
||||
|
@ -50,9 +57,6 @@ void Server::createRoom(ServerPlayer* owner, const QString &name, uint capacity)
|
|||
m_lobby = room;
|
||||
else
|
||||
rooms.insert(room->getId(), room);
|
||||
#ifdef QT_DEBUG
|
||||
qDebug() << "Room #" << room->getId() << " created.";
|
||||
#endif
|
||||
}
|
||||
|
||||
Room *Server::findRoom(uint id) const
|
||||
|
@ -91,16 +95,117 @@ void Server::updateRoomList()
|
|||
|
||||
void Server::processNewConnection(ClientSocket* client)
|
||||
{
|
||||
qDebug() << client->peerAddress() << "connected";
|
||||
// version check, file check, ban IP, reconnect, etc
|
||||
ServerPlayer *player = new ServerPlayer(lobby());
|
||||
player->setSocket(client);
|
||||
players.insert(player->getUid(), player);
|
||||
#ifdef QT_DEBUG
|
||||
qDebug() << "ServerPlayer #" << player->getUid() << "connected.";
|
||||
qDebug() << "His address is " << client->peerAddress();
|
||||
#endif
|
||||
|
||||
lobby()->addPlayer(player);
|
||||
connect(client, &ClientSocket::disconnected, this, [client](){
|
||||
qDebug() << client->peerAddress() << "disconnected";
|
||||
});
|
||||
|
||||
// network delay test
|
||||
QJsonArray body;
|
||||
body << -2;
|
||||
body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER | Router::DEST_CLIENT);
|
||||
body << "NetworkDelayTest";
|
||||
body << "[]";
|
||||
client->send(QJsonDocument(body).toJson(QJsonDocument::Compact));
|
||||
// Note: the client should send a setup string next
|
||||
connect(client, &ClientSocket::message_got, this, &Server::processRequest);
|
||||
client->timerSignup.start(30000);
|
||||
}
|
||||
|
||||
void Server::processRequest(const QByteArray& msg)
|
||||
{
|
||||
ClientSocket *client = qobject_cast<ClientSocket *>(sender());
|
||||
client->disconnect(this, SLOT(processRequest(const QByteArray &)));
|
||||
client->timerSignup.stop();
|
||||
|
||||
bool valid = true;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(msg);
|
||||
if (doc.isNull() || !doc.isArray()) {
|
||||
valid = false;
|
||||
} else {
|
||||
if (doc.array().size() != 4
|
||||
|| doc[0] != -2
|
||||
|| doc[1] != (Router::TYPE_NOTIFICATION | Router::SRC_CLIENT | Router::DEST_SERVER)
|
||||
|| doc[2] != "Setup"
|
||||
)
|
||||
valid = false;
|
||||
else
|
||||
valid = (QJsonDocument::fromJson(doc[3].toString().toUtf8()).array().size() == 2);
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
qDebug() << "Invalid setup string:" << msg;
|
||||
QJsonArray body;
|
||||
body << -2;
|
||||
body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER | Router::DEST_CLIENT);
|
||||
body << "ErrorMsg";
|
||||
body << "INVALID SETUP STRING";
|
||||
client->send(QJsonDocument(body).toJson(QJsonDocument::Compact));
|
||||
client->disconnectFromHost();
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonArray arr = QJsonDocument::fromJson(doc[3].toString().toUtf8()).array();
|
||||
handleNameAndPassword(client, arr[0].toString(), arr[1].toString());
|
||||
}
|
||||
|
||||
void Server::handleNameAndPassword(ClientSocket *client, const QString& name, const QString& password)
|
||||
{
|
||||
// First check the name and password
|
||||
// Matches a string that does not contain special characters
|
||||
QRegExp nameExp("[^\\0000-\\0057\\0072-\\0100\\0133-\\0140\\0173-\\0177]+");
|
||||
QByteArray passwordHash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Sha256).toHex();
|
||||
bool passed = false;
|
||||
QJsonObject result;
|
||||
if (nameExp.exactMatch(name)) {
|
||||
// Then we check the database,
|
||||
QString sql_find = QString("SELECT * FROM userinfo \
|
||||
WHERE name='%1';").arg(name);
|
||||
result = SelectFromDatabase(db, sql_find);
|
||||
QJsonArray arr = result["password"].toArray();
|
||||
if (arr.isEmpty()) {
|
||||
// not present in database, register
|
||||
QString sql_reg = QString("INSERT INTO userinfo (name,password,\
|
||||
avatar,lastLoginIp,banned) VALUES ('%1','%2','%3','%4',%5);")
|
||||
.arg(name)
|
||||
.arg(QString(passwordHash))
|
||||
.arg("liubei")
|
||||
.arg(client->peerAddress())
|
||||
.arg("FALSE");
|
||||
ExecSQL(db, sql_reg);
|
||||
result = SelectFromDatabase(db, sql_find); // refresh result
|
||||
passed = true;
|
||||
} else {
|
||||
// check if password is the same
|
||||
passed = (passwordHash == arr[0].toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (passed) {
|
||||
ServerPlayer *player = new ServerPlayer(lobby());
|
||||
player->setSocket(client);
|
||||
client->disconnect(this);
|
||||
connect(client, &ClientSocket::disconnected, this, [player](){
|
||||
qDebug() << "Player" << player->getUid() << "disconnected";
|
||||
});
|
||||
player->setScreenName(name);
|
||||
player->setAvatar(result["avatar"].toArray()[0].toString());
|
||||
player->setId(result["id"].toArray()[0].toInt());
|
||||
players.insert(player->getId(), player);
|
||||
lobby()->addPlayer(player);
|
||||
} else {
|
||||
qDebug() << client->peerAddress() << "entered wrong password";
|
||||
QJsonArray body;
|
||||
body << -2;
|
||||
body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER | Router::DEST_CLIENT);
|
||||
body << "ErrorMsg";
|
||||
body << "username or password error";
|
||||
client->send(QJsonDocument(body).toJson(QJsonDocument::Compact));
|
||||
client->disconnectFromHost();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Server::onRoomAbandoned()
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QMap>
|
||||
#include <QHostAddress>
|
||||
#include <lua.hpp>
|
||||
#include <sqlite3.h>
|
||||
|
||||
class ServerSocket;
|
||||
class ClientSocket;
|
||||
|
@ -41,6 +42,7 @@ signals:
|
|||
|
||||
public slots:
|
||||
void processNewConnection(ClientSocket *client);
|
||||
void processRequest(const QByteArray &msg);
|
||||
|
||||
void onRoomAbandoned();
|
||||
void onUserDisconnected();
|
||||
|
@ -53,6 +55,9 @@ private:
|
|||
QHash<uint, ServerPlayer *> players;
|
||||
|
||||
lua_State *L;
|
||||
sqlite3 *db;
|
||||
|
||||
void handleNameAndPassword(ClientSocket *client, const QString &name, const QString &password);
|
||||
};
|
||||
|
||||
extern Server *ServerInstance;
|
||||
|
|
40
src/swig/client.i
Normal file
40
src/swig/client.i
Normal file
|
@ -0,0 +1,40 @@
|
|||
%nodefaultctor QmlBackend;
|
||||
%nodefaultdtor QmlBackend;
|
||||
class QmlBackend : public QObject {
|
||||
public:
|
||||
void emitNotifyUI(const char *command, const char *json_data);
|
||||
};
|
||||
|
||||
extern QmlBackend *Backend;
|
||||
|
||||
%nodefaultctor Client;
|
||||
%nodefaultdtor Client;
|
||||
class Client : public QObject {
|
||||
public:
|
||||
void requestServer(const QString &command,
|
||||
const QString &json_data, int timeout = -1);
|
||||
void replyToServer(const QString &command, const QString &json_data);
|
||||
void notifyServer(const QString &command, const QString &json_data);
|
||||
|
||||
LuaFunction callback;
|
||||
};
|
||||
|
||||
extern Client *ClientInstance;
|
||||
|
||||
%{
|
||||
void Client::callLua(const QString& command, const QString& json_data)
|
||||
{
|
||||
Q_ASSERT(callback);
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, callback);
|
||||
SWIG_NewPointerObj(L, this, SWIGTYPE_p_Client, 0);
|
||||
lua_pushstring(L, command.toUtf8());
|
||||
lua_pushstring(L, json_data.toUtf8());
|
||||
|
||||
int error = lua_pcall(L, 3, 0, 0);
|
||||
if (error) {
|
||||
const char *error_msg = lua_tostring(L, -1);
|
||||
qDebug() << error_msg;
|
||||
}
|
||||
}
|
||||
%}
|
|
@ -9,225 +9,9 @@
|
|||
#include "qmlbackend.h"
|
||||
%}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// type bindings
|
||||
// ------------------------------------------------------
|
||||
|
||||
// LuaFunction(int) and lua function
|
||||
%naturalvar LuaFunction;
|
||||
%typemap(in) LuaFunction
|
||||
%{
|
||||
if (lua_isfunction(L, $input)) {
|
||||
lua_pushvalue(L, $input);
|
||||
$1 = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(out) LuaFunction
|
||||
%{
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, $1);
|
||||
SWIG_arg ++;
|
||||
%}
|
||||
|
||||
// QString and lua string
|
||||
%naturalvar QString;
|
||||
|
||||
%typemap(in, checkfn = "lua_isstring") QString
|
||||
%{ $1 = lua_tostring(L, $input); %}
|
||||
|
||||
%typemap(out) QString
|
||||
%{ lua_pushstring(L, $1.toUtf8()); SWIG_arg++; %}
|
||||
|
||||
// const QString &
|
||||
%typemap(arginit) QString const &
|
||||
"QString $1_str;"
|
||||
|
||||
%typemap(in, checkfn = "lua_isstring") QString const &
|
||||
%{
|
||||
$1_str = QString::fromUtf8(lua_tostring(L, $input));
|
||||
$1 = &$1_str;
|
||||
%}
|
||||
|
||||
%typemap(out) QString const &
|
||||
%{ lua_pushstring(L, $1.toUtf8()); SWIG_arg++; %}
|
||||
|
||||
// ------------------------------------------------------
|
||||
// classes and functions
|
||||
// ------------------------------------------------------
|
||||
|
||||
class QObject {
|
||||
public:
|
||||
QString objectName();
|
||||
void setObjectName(const char *name);
|
||||
bool inherits(const char *class_name);
|
||||
bool setProperty(const char *name, const QVariant &value);
|
||||
QVariant property(const char *name) const;
|
||||
void setParent(QObject *parent);
|
||||
void deleteLater();
|
||||
};
|
||||
|
||||
class QThread {};
|
||||
|
||||
class QmlBackend : public QObject {
|
||||
public:
|
||||
void emitNotifyUI(const char *command, const char *json_data);
|
||||
};
|
||||
|
||||
extern QmlBackend *Backend;
|
||||
|
||||
class Client : public QObject {
|
||||
public:
|
||||
void requestServer(const QString &command,
|
||||
const QString &json_data, int timeout = -1);
|
||||
void replyToServer(const QString &command, const QString &json_data);
|
||||
void notifyServer(const QString &command, const QString &json_data);
|
||||
|
||||
LuaFunction callback;
|
||||
};
|
||||
|
||||
extern Client *ClientInstance;
|
||||
|
||||
%{
|
||||
void Client::callLua(const QString& command, const QString& json_data)
|
||||
{
|
||||
Q_ASSERT(callback);
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, callback);
|
||||
SWIG_NewPointerObj(L, this, SWIGTYPE_p_Client, 0);
|
||||
lua_pushstring(L, command.toUtf8());
|
||||
lua_pushstring(L, json_data.toUtf8());
|
||||
|
||||
int error = lua_pcall(L, 3, 0, 0);
|
||||
if (error) {
|
||||
const char *error_msg = lua_tostring(L, -1);
|
||||
qDebug() << error_msg;
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
class Server : public QObject {
|
||||
public:
|
||||
void createRoom(ServerPlayer *owner, const QString &name, unsigned int capacity);
|
||||
Room *findRoom(unsigned int id) const;
|
||||
Room *lobby() const;
|
||||
|
||||
ServerPlayer *findPlayer(unsigned int id) const;
|
||||
|
||||
void updateRoomList();
|
||||
|
||||
LuaFunction callback;
|
||||
};
|
||||
|
||||
%{
|
||||
void Server::callLua(const QString& command, const QString& json_data)
|
||||
{
|
||||
Q_ASSERT(callback);
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, callback);
|
||||
SWIG_NewPointerObj(L, this, SWIGTYPE_p_Server, 0);
|
||||
lua_pushstring(L, command.toUtf8());
|
||||
lua_pushstring(L, json_data.toUtf8());
|
||||
|
||||
int error = lua_pcall(L, 3, 0, 0);
|
||||
if (error) {
|
||||
const char *error_msg = lua_tostring(L, -1);
|
||||
qDebug() << error_msg;
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
extern Server *ServerInstance;
|
||||
|
||||
class Player : public QObject {
|
||||
enum State{
|
||||
Invalid,
|
||||
Online,
|
||||
Trust,
|
||||
Offline
|
||||
};
|
||||
|
||||
unsigned int getId() const;
|
||||
void setId(unsigned int id);
|
||||
|
||||
QString getScreenName() const;
|
||||
void setScreenName(const QString &name);
|
||||
|
||||
QString getAvatar() const;
|
||||
void setAvatar(const QString &avatar);
|
||||
|
||||
State getState() const;
|
||||
QString getStateString() const;
|
||||
void setState(State state);
|
||||
void setStateString(const QString &state);
|
||||
|
||||
bool isReady() const;
|
||||
void setReady(bool ready);
|
||||
};
|
||||
|
||||
class ClientPlayer : public Player {
|
||||
public:
|
||||
ClientPlayer(unsigned int id, QObject *parent = nullptr);
|
||||
~ClientPlayer();
|
||||
};
|
||||
|
||||
extern ClientPlayer *Self;
|
||||
|
||||
class ServerPlayer : public Player {
|
||||
public:
|
||||
explicit ServerPlayer(Room *room);
|
||||
~ServerPlayer();
|
||||
|
||||
unsigned int getUid() const;
|
||||
|
||||
void setSocket(ClientSocket *socket);
|
||||
|
||||
Server *getServer() const;
|
||||
Room *getRoom() const;
|
||||
void setRoom(Room *room);
|
||||
|
||||
void speak(const QString &message);
|
||||
|
||||
void doRequest(const QString &command,
|
||||
const QString &json_data, int timeout = -1);
|
||||
void doReply(const QString &command, const QString &json_data);
|
||||
void doNotify(const QString &command, const QString &json_data);
|
||||
|
||||
void prepareForRequest(const QString &command,
|
||||
const QVariant &data = QVariant());
|
||||
};
|
||||
|
||||
class Room : public QThread {
|
||||
public:
|
||||
explicit Room(Server *m_server);
|
||||
~Room();
|
||||
|
||||
// Property reader & setter
|
||||
// ==================================={
|
||||
Server *getServer() const;
|
||||
unsigned int getId() const;
|
||||
bool isLobby() const;
|
||||
QString getName() const;
|
||||
void setName(const QString &name);
|
||||
unsigned int getCapacity() const;
|
||||
void setCapacity(unsigned int capacity);
|
||||
bool isFull() const;
|
||||
bool isAbandoned() const;
|
||||
|
||||
ServerPlayer *getOwner() const;
|
||||
void setOwner(ServerPlayer *owner);
|
||||
|
||||
void addPlayer(ServerPlayer *player);
|
||||
void removePlayer(ServerPlayer *player);
|
||||
QList<ServerPlayer *> getPlayers() const;
|
||||
ServerPlayer *findPlayer(unsigned int id) const;
|
||||
|
||||
void setGameLogic(GameLogic *logic);
|
||||
GameLogic *getGameLogic() const;
|
||||
// ====================================}
|
||||
|
||||
void startGame();
|
||||
void doRequest(const QList<ServerPlayer *> targets, int timeout);
|
||||
void doNotify(const QList<ServerPlayer *> targets, int timeout);
|
||||
};
|
||||
%include "naturalvar.i"
|
||||
%include "qt.i"
|
||||
%include "player.i"
|
||||
%include "client.i"
|
||||
%include "server.i"
|
||||
%include "sqlite3.i"
|
||||
|
|
44
src/swig/naturalvar.i
Normal file
44
src/swig/naturalvar.i
Normal file
|
@ -0,0 +1,44 @@
|
|||
// ------------------------------------------------------
|
||||
// type bindings
|
||||
// ------------------------------------------------------
|
||||
|
||||
// LuaFunction(int) and lua function
|
||||
%naturalvar LuaFunction;
|
||||
%typemap(in) LuaFunction
|
||||
%{
|
||||
if (lua_isfunction(L, $input)) {
|
||||
lua_pushvalue(L, $input);
|
||||
$1 = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(out) LuaFunction
|
||||
%{
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, $1);
|
||||
SWIG_arg ++;
|
||||
%}
|
||||
|
||||
// QString and lua string
|
||||
%naturalvar QString;
|
||||
|
||||
%typemap(in, checkfn = "lua_isstring") QString
|
||||
%{ $1 = lua_tostring(L, $input); %}
|
||||
|
||||
%typemap(out) QString
|
||||
%{ lua_pushstring(L, $1.toUtf8()); SWIG_arg++; %}
|
||||
|
||||
// const QString &
|
||||
%typemap(arginit) QString const &
|
||||
"QString $1_str;"
|
||||
|
||||
%typemap(in, checkfn = "lua_isstring") QString const &
|
||||
%{
|
||||
$1_str = QString::fromUtf8(lua_tostring(L, $input));
|
||||
$1 = &$1_str;
|
||||
%}
|
||||
|
||||
%typemap(out) QString const &
|
||||
%{ lua_pushstring(L, $1.toUtf8()); SWIG_arg++; %}
|
||||
|
59
src/swig/player.i
Normal file
59
src/swig/player.i
Normal file
|
@ -0,0 +1,59 @@
|
|||
%nodefaultctor Player;
|
||||
%nodefaultdtor Player;
|
||||
class Player : public QObject {
|
||||
public:
|
||||
enum State{
|
||||
Invalid,
|
||||
Online,
|
||||
Trust,
|
||||
Offline
|
||||
};
|
||||
|
||||
unsigned int getId() const;
|
||||
void setId(unsigned int id);
|
||||
|
||||
QString getScreenName() const;
|
||||
void setScreenName(const QString &name);
|
||||
|
||||
QString getAvatar() const;
|
||||
void setAvatar(const QString &avatar);
|
||||
|
||||
State getState() const;
|
||||
QString getStateString() const;
|
||||
void setState(State state);
|
||||
void setStateString(const QString &state);
|
||||
|
||||
bool isReady() const;
|
||||
void setReady(bool ready);
|
||||
};
|
||||
|
||||
%nodefaultctor ClientPlayer;
|
||||
%nodefaultdtor ClientPlayer;
|
||||
class ClientPlayer : public Player {
|
||||
public:
|
||||
};
|
||||
|
||||
extern ClientPlayer *Self;
|
||||
|
||||
%nodefaultctor ServerPlayer;
|
||||
%nodefaultdtor ServerPlayer;
|
||||
class ServerPlayer : public Player {
|
||||
public:
|
||||
unsigned int getUid() const;
|
||||
|
||||
void setSocket(ClientSocket *socket);
|
||||
|
||||
Server *getServer() const;
|
||||
Room *getRoom() const;
|
||||
void setRoom(Room *room);
|
||||
|
||||
void speak(const QString &message);
|
||||
|
||||
void doRequest(const QString &command,
|
||||
const QString &json_data, int timeout = -1);
|
||||
void doReply(const QString &command, const QString &json_data);
|
||||
void doNotify(const QString &command, const QString &json_data);
|
||||
|
||||
void prepareForRequest(const QString &command,
|
||||
const QVariant &data = QVariant());
|
||||
};
|
12
src/swig/qt.i
Normal file
12
src/swig/qt.i
Normal file
|
@ -0,0 +1,12 @@
|
|||
class QObject {
|
||||
public:
|
||||
QString objectName();
|
||||
void setObjectName(const char *name);
|
||||
bool inherits(const char *class_name);
|
||||
bool setProperty(const char *name, const QVariant &value);
|
||||
QVariant property(const char *name) const;
|
||||
void setParent(QObject *parent);
|
||||
void deleteLater();
|
||||
};
|
||||
|
||||
class QThread {};
|
68
src/swig/server.i
Normal file
68
src/swig/server.i
Normal file
|
@ -0,0 +1,68 @@
|
|||
%nodefaultctor Server;
|
||||
%nodefaultdtor Server;
|
||||
class Server : public QObject {
|
||||
public:
|
||||
void createRoom(ServerPlayer *owner, const QString &name, unsigned int capacity);
|
||||
Room *findRoom(unsigned int id) const;
|
||||
Room *lobby() const;
|
||||
|
||||
ServerPlayer *findPlayer(unsigned int id) const;
|
||||
|
||||
void updateRoomList();
|
||||
|
||||
LuaFunction callback;
|
||||
};
|
||||
|
||||
%{
|
||||
void Server::callLua(const QString& command, const QString& json_data)
|
||||
{
|
||||
Q_ASSERT(callback);
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, callback);
|
||||
SWIG_NewPointerObj(L, this, SWIGTYPE_p_Server, 0);
|
||||
lua_pushstring(L, command.toUtf8());
|
||||
lua_pushstring(L, json_data.toUtf8());
|
||||
|
||||
int error = lua_pcall(L, 3, 0, 0);
|
||||
if (error) {
|
||||
const char *error_msg = lua_tostring(L, -1);
|
||||
qDebug() << error_msg;
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
extern Server *ServerInstance;
|
||||
|
||||
%nodefaultctor Room;
|
||||
%nodefaultdtor Room;
|
||||
class Room : public QThread {
|
||||
public:
|
||||
// Property reader & setter
|
||||
// ==================================={
|
||||
Server *getServer() const;
|
||||
unsigned int getId() const;
|
||||
bool isLobby() const;
|
||||
QString getName() const;
|
||||
void setName(const QString &name);
|
||||
unsigned int getCapacity() const;
|
||||
void setCapacity(unsigned int capacity);
|
||||
bool isFull() const;
|
||||
bool isAbandoned() const;
|
||||
|
||||
ServerPlayer *getOwner() const;
|
||||
void setOwner(ServerPlayer *owner);
|
||||
|
||||
void addPlayer(ServerPlayer *player);
|
||||
void removePlayer(ServerPlayer *player);
|
||||
QList<ServerPlayer *> getPlayers() const;
|
||||
ServerPlayer *findPlayer(unsigned int id) const;
|
||||
|
||||
void setGameLogic(GameLogic *logic);
|
||||
GameLogic *getGameLogic() const;
|
||||
// ====================================}
|
||||
|
||||
void startGame();
|
||||
void doRequest(const QList<ServerPlayer *> targets, int timeout);
|
||||
void doNotify(const QList<ServerPlayer *> targets, int timeout);
|
||||
};
|
||||
|
6
src/swig/sqlite3.i
Normal file
6
src/swig/sqlite3.i
Normal file
|
@ -0,0 +1,6 @@
|
|||
struct sqlite3;
|
||||
|
||||
sqlite3 *OpenDatabase(const QString &filename);
|
||||
QString SelectFromDb(sqlite3 *db, const QString &sql);
|
||||
void ExecSQL(sqlite3 *db, const QString &sql);
|
||||
void CloseDatabase(sqlite3 *db);
|
|
@ -25,6 +25,7 @@ void QmlBackend::startServer(ushort port)
|
|||
|
||||
void QmlBackend::joinServer(QString address)
|
||||
{
|
||||
if (ClientInstance != nullptr) return;
|
||||
class Client *client = new class Client(this);
|
||||
connect(client, &Client::error_message, [this, client](const QString &msg){
|
||||
client->deleteLater();
|
||||
|
|
Loading…
Reference in New Issue
Block a user