+
+
+#include "llimits.h"
+#include "lua.h"
+
+
+/*
+** Extra tags for non-values
+*/
+#define LUA_TPROTO LUA_NUMTAGS
+#define LUA_TUPVAL (LUA_NUMTAGS+1)
+#define LUA_TDEADKEY (LUA_NUMTAGS+2)
+
+/*
+** number of all possible tags (including LUA_TNONE but excluding DEADKEY)
+*/
+#define LUA_TOTALTAGS (LUA_TUPVAL+2)
+
+
+/*
+** tags for Tagged Values have the following use of bits:
+** bits 0-3: actual tag (a LUA_T* value)
+** bits 4-5: variant bits
+** bit 6: whether value is collectable
+*/
+
+#define VARBITS (3 << 4)
+
+
+/*
+** LUA_TFUNCTION variants:
+** 0 - Lua function
+** 1 - light C function
+** 2 - regular C function (closure)
+*/
+
+/* Variant tags for functions */
+#define LUA_TLCL (LUA_TFUNCTION | (0 << 4)) /* Lua closure */
+#define LUA_TLCF (LUA_TFUNCTION | (1 << 4)) /* light C function */
+#define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */
+
+
+/* Variant tags for strings */
+#define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */
+#define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */
+
+
+/* Bit mark for collectable types */
+#define BIT_ISCOLLECTABLE (1 << 6)
+
+/* mark a tag as collectable */
+#define ctb(t) ((t) | BIT_ISCOLLECTABLE)
+
+
+/*
+** Union of all collectable objects
+*/
+typedef union GCObject GCObject;
+
+
+/*
+** Common Header for all collectable objects (in macro form, to be
+** included in other objects)
+*/
+#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked
+
+
+/*
+** Common header in struct form
+*/
+typedef struct GCheader {
+ CommonHeader;
+} GCheader;
+
+
+
+/*
+** Union of all Lua values
+*/
+typedef union Value Value;
+
+
+#define numfield lua_Number n; /* numbers */
+
+
+
+/*
+** Tagged Values. This is the basic representation of values in Lua,
+** an actual value plus a tag with its type.
+*/
+
+#define TValuefields Value value_; int tt_
+
+typedef struct lua_TValue TValue;
+
+
+/* macro defining a nil value */
+#define NILCONSTANT {NULL}, LUA_TNIL
+
+
+#define val_(o) ((o)->value_)
+#define num_(o) (val_(o).n)
+
+
+/* raw type tag of a TValue */
+#define rttype(o) ((o)->tt_)
+
+/* tag with no variants (bits 0-3) */
+#define novariant(x) ((x) & 0x0F)
+
+/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
+#define ttype(o) (rttype(o) & 0x3F)
+
+/* type tag of a TValue with no variants (bits 0-3) */
+#define ttypenv(o) (novariant(rttype(o)))
+
+
+/* Macros to test type */
+#define checktag(o,t) (rttype(o) == (t))
+#define checktype(o,t) (ttypenv(o) == (t))
+#define ttisnumber(o) checktag((o), LUA_TNUMBER)
+#define ttisnil(o) checktag((o), LUA_TNIL)
+#define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
+#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
+#define ttisstring(o) checktype((o), LUA_TSTRING)
+#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
+#define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
+#define ttistable(o) checktag((o), ctb(LUA_TTABLE))
+#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
+#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
+#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
+#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
+#define ttislcf(o) checktag((o), LUA_TLCF)
+#define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA))
+#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
+#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY)
+
+#define ttisequal(o1,o2) (rttype(o1) == rttype(o2))
+
+/* Macros to access values */
+#define nvalue(o) check_exp(ttisnumber(o), num_(o))
+#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
+#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
+#define rawtsvalue(o) check_exp(ttisstring(o), &val_(o).gc->ts)
+#define tsvalue(o) (&rawtsvalue(o)->tsv)
+#define rawuvalue(o) check_exp(ttisuserdata(o), &val_(o).gc->u)
+#define uvalue(o) (&rawuvalue(o)->uv)
+#define clvalue(o) check_exp(ttisclosure(o), &val_(o).gc->cl)
+#define clLvalue(o) check_exp(ttisLclosure(o), &val_(o).gc->cl.l)
+#define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c)
+#define fvalue(o) check_exp(ttislcf(o), val_(o).f)
+#define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h)
+#define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
+#define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th)
+/* a dead value may get the 'gc' field, but cannot access its contents */
+#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc))
+
+#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
+
+
+#define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE)
+
+
+/* Macros for internal tests */
+#define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt)
+
+#define checkliveness(g,obj) \
+ lua_longassert(!iscollectable(obj) || \
+ (righttt(obj) && !isdead(g,gcvalue(obj))))
+
+
+/* Macros to set values */
+#define settt_(o,t) ((o)->tt_=(t))
+
+#define setnvalue(obj,x) \
+ { TValue *io=(obj); num_(io)=(x); settt_(io, LUA_TNUMBER); }
+
+#define setnilvalue(obj) settt_(obj, LUA_TNIL)
+
+#define setfvalue(obj,x) \
+ { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }
+
+#define setpvalue(obj,x) \
+ { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }
+
+#define setbvalue(obj,x) \
+ { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }
+
+#define setgcovalue(L,obj,x) \
+ { TValue *io=(obj); GCObject *i_g=(x); \
+ val_(io).gc=i_g; settt_(io, ctb(gch(i_g)->tt)); }
+
+#define setsvalue(L,obj,x) \
+ { TValue *io=(obj); \
+ TString *x_ = (x); \
+ val_(io).gc=cast(GCObject *, x_); settt_(io, ctb(x_->tsv.tt)); \
+ checkliveness(G(L),io); }
+
+#define setuvalue(L,obj,x) \
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TUSERDATA)); \
+ checkliveness(G(L),io); }
+
+#define setthvalue(L,obj,x) \
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTHREAD)); \
+ checkliveness(G(L),io); }
+
+#define setclLvalue(L,obj,x) \
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TLCL)); \
+ checkliveness(G(L),io); }
+
+#define setclCvalue(L,obj,x) \
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TCCL)); \
+ checkliveness(G(L),io); }
+
+#define sethvalue(L,obj,x) \
+ { TValue *io=(obj); \
+ val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \
+ checkliveness(G(L),io); }
+
+#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
+
+
+
+#define setobj(L,obj1,obj2) \
+ { const TValue *io2=(obj2); TValue *io1=(obj1); \
+ io1->value_ = io2->value_; io1->tt_ = io2->tt_; \
+ checkliveness(G(L),io1); }
+
+
+/*
+** different types of assignments, according to destination
+*/
+
+/* from stack to (same) stack */
+#define setobjs2s setobj
+/* to stack (not from same stack) */
+#define setobj2s setobj
+#define setsvalue2s setsvalue
+#define sethvalue2s sethvalue
+#define setptvalue2s setptvalue
+/* from table to same table */
+#define setobjt2t setobj
+/* to table */
+#define setobj2t setobj
+/* to new object */
+#define setobj2n setobj
+#define setsvalue2n setsvalue
+
+
+/* check whether a number is valid (useful only for NaN trick) */
+#define luai_checknum(L,o,c) { /* empty */ }
+
+
+/*
+** {======================================================
+** NaN Trick
+** =======================================================
+*/
+#if defined(LUA_NANTRICK)
+
+/*
+** numbers are represented in the 'd_' field. All other values have the
+** value (NNMARK | tag) in 'tt__'. A number with such pattern would be
+** a "signaled NaN", which is never generated by regular operations by
+** the CPU (nor by 'strtod')
+*/
+
+/* allows for external implementation for part of the trick */
+#if !defined(NNMARK) /* { */
+
+
+#if !defined(LUA_IEEEENDIAN)
+#error option 'LUA_NANTRICK' needs 'LUA_IEEEENDIAN'
+#endif
+
+
+#define NNMARK 0x7FF7A500
+#define NNMASK 0x7FFFFF00
+
+#undef TValuefields
+#undef NILCONSTANT
+
+#if (LUA_IEEEENDIAN == 0) /* { */
+
+/* little endian */
+#define TValuefields \
+ union { struct { Value v__; int tt__; } i; double d__; } u
+#define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}}
+/* field-access macros */
+#define v_(o) ((o)->u.i.v__)
+#define d_(o) ((o)->u.d__)
+#define tt_(o) ((o)->u.i.tt__)
+
+#else /* }{ */
+
+/* big endian */
+#define TValuefields \
+ union { struct { int tt__; Value v__; } i; double d__; } u
+#define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}}
+/* field-access macros */
+#define v_(o) ((o)->u.i.v__)
+#define d_(o) ((o)->u.d__)
+#define tt_(o) ((o)->u.i.tt__)
+
+#endif /* } */
+
+#endif /* } */
+
+
+/* correspondence with standard representation */
+#undef val_
+#define val_(o) v_(o)
+#undef num_
+#define num_(o) d_(o)
+
+
+#undef numfield
+#define numfield /* no such field; numbers are the entire struct */
+
+/* basic check to distinguish numbers from non-numbers */
+#undef ttisnumber
+#define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK)
+
+#define tag2tt(t) (NNMARK | (t))
+
+#undef rttype
+#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff)
+
+#undef settt_
+#define settt_(o,t) (tt_(o) = tag2tt(t))
+
+#undef setnvalue
+#define setnvalue(obj,x) \
+ { TValue *io_=(obj); num_(io_)=(x); lua_assert(ttisnumber(io_)); }
+
+#undef setobj
+#define setobj(L,obj1,obj2) \
+ { const TValue *o2_=(obj2); TValue *o1_=(obj1); \
+ o1_->u = o2_->u; \
+ checkliveness(G(L),o1_); }
+
+
+/*
+** these redefinitions are not mandatory, but these forms are more efficient
+*/
+
+#undef checktag
+#undef checktype
+#define checktag(o,t) (tt_(o) == tag2tt(t))
+#define checktype(o,t) (ctb(tt_(o) | VARBITS) == ctb(tag2tt(t) | VARBITS))
+
+#undef ttisequal
+#define ttisequal(o1,o2) \
+ (ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2)))
+
+
+#undef luai_checknum
+#define luai_checknum(L,o,c) { if (!ttisnumber(o)) c; }
+
+#endif
+/* }====================================================== */
+
+
+
+/*
+** {======================================================
+** types and prototypes
+** =======================================================
+*/
+
+
+union Value {
+ GCObject *gc; /* collectable objects */
+ void *p; /* light userdata */
+ int b; /* booleans */
+ lua_CFunction f; /* light C functions */
+ numfield /* numbers */
+};
+
+
+struct lua_TValue {
+ TValuefields;
+};
+
+
+typedef TValue *StkId; /* index to stack elements */
+
+
+
+
+/*
+** Header for string value; string bytes follow the end of this structure
+*/
+typedef union TString {
+ L_Umaxalign dummy; /* ensures maximum alignment for strings */
+ struct {
+ CommonHeader;
+ lu_byte extra; /* reserved words for short strings; "has hash" for longs */
+ unsigned int hash;
+ size_t len; /* number of characters in string */
+ } tsv;
+} TString;
+
+
+/* get the actual string (array of bytes) from a TString */
+#define getstr(ts) cast(const char *, (ts) + 1)
+
+/* get the actual string (array of bytes) from a Lua value */
+#define svalue(o) getstr(rawtsvalue(o))
+
+
+/*
+** Header for userdata; memory area follows the end of this structure
+*/
+typedef union Udata {
+ L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
+ struct {
+ CommonHeader;
+ struct Table *metatable;
+ struct Table *env;
+ size_t len; /* number of bytes */
+ } uv;
+} Udata;
+
+
+
+/*
+** Description of an upvalue for function prototypes
+*/
+typedef struct Upvaldesc {
+ TString *name; /* upvalue name (for debug information) */
+ lu_byte instack; /* whether it is in stack */
+ lu_byte idx; /* index of upvalue (in stack or in outer function's list) */
+} Upvaldesc;
+
+
+/*
+** Description of a local variable for function prototypes
+** (used for debug information)
+*/
+typedef struct LocVar {
+ TString *varname;
+ int startpc; /* first point where variable is active */
+ int endpc; /* first point where variable is dead */
+} LocVar;
+
+
+/*
+** Function Prototypes
+*/
+typedef struct Proto {
+ CommonHeader;
+ TValue *k; /* constants used by the function */
+ Instruction *code;
+ struct Proto **p; /* functions defined inside the function */
+ int *lineinfo; /* map from opcodes to source lines (debug information) */
+ LocVar *locvars; /* information about local variables (debug information) */
+ Upvaldesc *upvalues; /* upvalue information */
+ union Closure *cache; /* last created closure with this prototype */
+ TString *source; /* used for debug information */
+ int sizeupvalues; /* size of 'upvalues' */
+ int sizek; /* size of `k' */
+ int sizecode;
+ int sizelineinfo;
+ int sizep; /* size of `p' */
+ int sizelocvars;
+ int linedefined;
+ int lastlinedefined;
+ GCObject *gclist;
+ lu_byte numparams; /* number of fixed parameters */
+ lu_byte is_vararg;
+ lu_byte maxstacksize; /* maximum stack used by this function */
+} Proto;
+
+
+
+/*
+** Lua Upvalues
+*/
+typedef struct UpVal {
+ CommonHeader;
+ TValue *v; /* points to stack or to its own value */
+ union {
+ TValue value; /* the value (when closed) */
+ struct { /* double linked list (when open) */
+ struct UpVal *prev;
+ struct UpVal *next;
+ } l;
+ } u;
+} UpVal;
+
+
+/*
+** Closures
+*/
+
+#define ClosureHeader \
+ CommonHeader; lu_byte nupvalues; GCObject *gclist
+
+typedef struct CClosure {
+ ClosureHeader;
+ lua_CFunction f;
+ TValue upvalue[1]; /* list of upvalues */
+} CClosure;
+
+
+typedef struct LClosure {
+ ClosureHeader;
+ struct Proto *p;
+ UpVal *upvals[1]; /* list of upvalues */
+} LClosure;
+
+
+typedef union Closure {
+ CClosure c;
+ LClosure l;
+} Closure;
+
+
+#define isLfunction(o) ttisLclosure(o)
+
+#define getproto(o) (clLvalue(o)->p)
+
+
+/*
+** Tables
+*/
+
+typedef union TKey {
+ struct {
+ TValuefields;
+ struct Node *next; /* for chaining */
+ } nk;
+ TValue tvk;
+} TKey;
+
+
+typedef struct Node {
+ TValue i_val;
+ TKey i_key;
+} Node;
+
+
+typedef struct Table {
+ CommonHeader;
+ lu_byte flags; /* 1<lsizenode))
+
+
+/*
+** (address of) a fixed nil value
+*/
+#define luaO_nilobject (&luaO_nilobject_)
+
+
+LUAI_DDEC const TValue luaO_nilobject_;
+
+
+LUAI_FUNC int luaO_int2fb (unsigned int x);
+LUAI_FUNC int luaO_fb2int (int x);
+LUAI_FUNC int luaO_ceillog2 (unsigned int x);
+LUAI_FUNC lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2);
+LUAI_FUNC int luaO_str2d (const char *s, size_t len, lua_Number *result);
+LUAI_FUNC int luaO_hexavalue (int c);
+LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
+ va_list argp);
+LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
+LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
+
+
+#endif
+
diff --git a/lualib/lopcodes.c b/lualib/lopcodes.c
new file mode 100644
index 0000000..4190dc7
--- /dev/null
+++ b/lualib/lopcodes.c
@@ -0,0 +1,107 @@
+/*
+** $Id: lopcodes.c,v 1.49.1.1 2013/04/12 18:48:47 roberto Exp $
+** Opcodes for Lua virtual machine
+** See Copyright Notice in lua.h
+*/
+
+
+#define lopcodes_c
+#define LUA_CORE
+
+
+#include "lopcodes.h"
+
+
+/* ORDER OP */
+
+LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
+ "MOVE",
+ "LOADK",
+ "LOADKX",
+ "LOADBOOL",
+ "LOADNIL",
+ "GETUPVAL",
+ "GETTABUP",
+ "GETTABLE",
+ "SETTABUP",
+ "SETUPVAL",
+ "SETTABLE",
+ "NEWTABLE",
+ "SELF",
+ "ADD",
+ "SUB",
+ "MUL",
+ "DIV",
+ "MOD",
+ "POW",
+ "UNM",
+ "NOT",
+ "LEN",
+ "CONCAT",
+ "JMP",
+ "EQ",
+ "LT",
+ "LE",
+ "TEST",
+ "TESTSET",
+ "CALL",
+ "TAILCALL",
+ "RETURN",
+ "FORLOOP",
+ "FORPREP",
+ "TFORCALL",
+ "TFORLOOP",
+ "SETLIST",
+ "CLOSURE",
+ "VARARG",
+ "EXTRAARG",
+ NULL
+};
+
+
+#define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m))
+
+LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
+/* T A B C mode opcode */
+ opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */
+ ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
+ ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
+ ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */
+ ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */
+ ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */
+ ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */
+ ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */
+ ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */
+ ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */
+ ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */
+ ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */
+ ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */
+ ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */
+ ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */
+ ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */
+ ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */
+ ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */
+ ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */
+ ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */
+ ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */
+ ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */
+ ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */
+ ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */
+ ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */
+ ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */
+ ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */
+ ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */
+ ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
+ ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */
+};
+
diff --git a/lualib/lopcodes.h b/lualib/lopcodes.h
new file mode 100644
index 0000000..51f5791
--- /dev/null
+++ b/lualib/lopcodes.h
@@ -0,0 +1,288 @@
+/*
+** $Id: lopcodes.h,v 1.142.1.1 2013/04/12 18:48:47 roberto Exp $
+** Opcodes for Lua virtual machine
+** See Copyright Notice in lua.h
+*/
+
+#ifndef lopcodes_h
+#define lopcodes_h
+
+#include "llimits.h"
+
+
+/*===========================================================================
+ We assume that instructions are unsigned numbers.
+ All instructions have an opcode in the first 6 bits.
+ Instructions can have the following fields:
+ `A' : 8 bits
+ `B' : 9 bits
+ `C' : 9 bits
+ 'Ax' : 26 bits ('A', 'B', and 'C' together)
+ `Bx' : 18 bits (`B' and `C' together)
+ `sBx' : signed Bx
+
+ A signed argument is represented in excess K; that is, the number
+ value is the unsigned value minus K. K is exactly the maximum value
+ for that argument (so that -max is represented by 0, and +max is
+ represented by 2*max), which is half the maximum for the corresponding
+ unsigned argument.
+===========================================================================*/
+
+
+enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
+
+
+/*
+** size and position of opcode arguments.
+*/
+#define SIZE_C 9
+#define SIZE_B 9
+#define SIZE_Bx (SIZE_C + SIZE_B)
+#define SIZE_A 8
+#define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A)
+
+#define SIZE_OP 6
+
+#define POS_OP 0
+#define POS_A (POS_OP + SIZE_OP)
+#define POS_C (POS_A + SIZE_A)
+#define POS_B (POS_C + SIZE_C)
+#define POS_Bx POS_C
+#define POS_Ax POS_A
+
+
+/*
+** limits for opcode arguments.
+** we use (signed) int to manipulate most arguments,
+** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
+*/
+#if SIZE_Bx < LUAI_BITSINT-1
+#define MAXARG_Bx ((1<>1) /* `sBx' is signed */
+#else
+#define MAXARG_Bx MAX_INT
+#define MAXARG_sBx MAX_INT
+#endif
+
+#if SIZE_Ax < LUAI_BITSINT-1
+#define MAXARG_Ax ((1<>POS_OP) & MASK1(SIZE_OP,0)))
+#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
+ ((cast(Instruction, o)<>pos) & MASK1(size,0)))
+#define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \
+ ((cast(Instruction, v)<= R(A) + 1 */
+OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
+OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
+OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
+
+OP_TEST,/* A C if not (R(A) <=> C) then pc++ */
+OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */
+
+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 return R(A)(R(A+1), ... ,R(A+B-1)) */
+OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */
+
+OP_FORLOOP,/* A sBx R(A)+=R(A+2);
+ if R(A) = R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
+OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */
+
+OP_TFORCALL,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
+OP_TFORLOOP,/* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }*/
+
+OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */
+
+OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx]) */
+
+OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */
+
+OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
+} OpCode;
+
+
+#define NUM_OPCODES (cast(int, OP_EXTRAARG) + 1)
+
+
+
+/*===========================================================================
+ Notes:
+ (*) In OP_CALL, if (B == 0) then B = top. 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 (B == 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_SETLIST, if (B == 0) then B = `top'; if (C == 0) then next
+ 'instruction' is EXTRAARG(real C).
+
+ (*) In OP_LOADKX, the next 'instruction' is always EXTRAARG.
+
+ (*) For comparisons, A specifies what condition the test should accept
+ (true or false).
+
+ (*) All `skips' (pc++) assume that next instruction is a jump.
+
+===========================================================================*/
+
+
+/*
+** masks for instruction properties. The format is:
+** bits 0-1: op mode
+** bits 2-3: C arg mode
+** bits 4-5: B arg mode
+** bit 6: instruction set register A
+** bit 7: operator is a test (next instruction must be a jump)
+*/
+
+enum OpArgMask {
+ OpArgN, /* argument is not used */
+ OpArgU, /* argument is used */
+ OpArgR, /* argument is a register or a jump offset */
+ OpArgK /* argument is a constant or register/constant */
+};
+
+LUAI_DDEC const lu_byte luaP_opmodes[NUM_OPCODES];
+
+#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
+#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
+#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
+#define testAMode(m) (luaP_opmodes[m] & (1 << 6))
+#define testTMode(m) (luaP_opmodes[m] & (1 << 7))
+
+
+LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */
+
+
+/* number of list items to accumulate before a SETLIST instruction */
+#define LFIELDS_PER_FLUSH 50
+
+
+#endif
diff --git a/lualib/loslib.c b/lualib/loslib.c
new file mode 100644
index 0000000..052ba17
--- /dev/null
+++ b/lualib/loslib.c
@@ -0,0 +1,323 @@
+/*
+** $Id: loslib.c,v 1.40.1.1 2013/04/12 18:48:47 roberto Exp $
+** Standard Operating System library
+** See Copyright Notice in lua.h
+*/
+
+
+#include
+#include
+#include
+#include
+#include
+
+#define loslib_c
+#define LUA_LIB
+
+#include "lua.h"
+
+#include "lauxlib.h"
+#include "lualib.h"
+
+
+/*
+** list of valid conversion specifiers for the 'strftime' function
+*/
+#if !defined(LUA_STRFTIMEOPTIONS)
+
+#if !defined(LUA_USE_POSIX)
+#define LUA_STRFTIMEOPTIONS { "aAbBcdHIjmMpSUwWxXyYz%", "" }
+#else
+#define LUA_STRFTIMEOPTIONS \
+ { "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%", "" \
+ "", "E", "cCxXyY", \
+ "O", "deHImMSuUVwWy" }
+#endif
+
+#endif
+
+
+
+/*
+** By default, Lua uses tmpnam except when POSIX is available, where it
+** uses mkstemp.
+*/
+#if defined(LUA_USE_MKSTEMP)
+#include
+#define LUA_TMPNAMBUFSIZE 32
+#define lua_tmpnam(b,e) { \
+ strcpy(b, "/tmp/lua_XXXXXX"); \
+ e = mkstemp(b); \
+ if (e != -1) close(e); \
+ e = (e == -1); }
+
+#elif !defined(lua_tmpnam)
+
+#define LUA_TMPNAMBUFSIZE L_tmpnam
+#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
+
+#endif
+
+
+/*
+** By default, Lua uses gmtime/localtime, except when POSIX is available,
+** where it uses gmtime_r/localtime_r
+*/
+#if defined(LUA_USE_GMTIME_R)
+
+#define l_gmtime(t,r) gmtime_r(t,r)
+#define l_localtime(t,r) localtime_r(t,r)
+
+#elif !defined(l_gmtime)
+
+#define l_gmtime(t,r) ((void)r, gmtime(t))
+#define l_localtime(t,r) ((void)r, localtime(t))
+
+#endif
+
+
+
+static int os_execute (lua_State *L) {
+ const char *cmd = luaL_optstring(L, 1, NULL);
+ int stat = system(cmd);
+ if (cmd != NULL)
+ return luaL_execresult(L, stat);
+ else {
+ lua_pushboolean(L, stat); /* true if there is a shell */
+ return 1;
+ }
+}
+
+
+static int os_remove (lua_State *L) {
+ const char *filename = luaL_checkstring(L, 1);
+ return luaL_fileresult(L, remove(filename) == 0, filename);
+}
+
+
+static int os_rename (lua_State *L) {
+ const char *fromname = luaL_checkstring(L, 1);
+ const char *toname = luaL_checkstring(L, 2);
+ return luaL_fileresult(L, rename(fromname, toname) == 0, NULL);
+}
+
+
+static int os_tmpname (lua_State *L) {
+ char buff[LUA_TMPNAMBUFSIZE];
+ int err;
+ lua_tmpnam(buff, err);
+ if (err)
+ return luaL_error(L, "unable to generate a unique filename");
+ lua_pushstring(L, buff);
+ return 1;
+}
+
+
+static int os_getenv (lua_State *L) {
+ lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
+ return 1;
+}
+
+
+static int os_clock (lua_State *L) {
+ lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
+ return 1;
+}
+
+
+/*
+** {======================================================
+** Time/Date operations
+** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,
+** wday=%w+1, yday=%j, isdst=? }
+** =======================================================
+*/
+
+static void setfield (lua_State *L, const char *key, int value) {
+ lua_pushinteger(L, value);
+ lua_setfield(L, -2, key);
+}
+
+static void setboolfield (lua_State *L, const char *key, int value) {
+ if (value < 0) /* undefined? */
+ return; /* does not set field */
+ lua_pushboolean(L, value);
+ lua_setfield(L, -2, key);
+}
+
+static int getboolfield (lua_State *L, const char *key) {
+ int res;
+ lua_getfield(L, -1, key);
+ res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);
+ lua_pop(L, 1);
+ return res;
+}
+
+
+static int getfield (lua_State *L, const char *key, int d) {
+ int res, isnum;
+ lua_getfield(L, -1, key);
+ res = (int)lua_tointegerx(L, -1, &isnum);
+ if (!isnum) {
+ if (d < 0)
+ return luaL_error(L, "field " LUA_QS " missing in date table", key);
+ res = d;
+ }
+ lua_pop(L, 1);
+ return res;
+}
+
+
+static const char *checkoption (lua_State *L, const char *conv, char *buff) {
+ static const char *const options[] = LUA_STRFTIMEOPTIONS;
+ unsigned int i;
+ for (i = 0; i < sizeof(options)/sizeof(options[0]); i += 2) {
+ if (*conv != '\0' && strchr(options[i], *conv) != NULL) {
+ buff[1] = *conv;
+ if (*options[i + 1] == '\0') { /* one-char conversion specifier? */
+ buff[2] = '\0'; /* end buffer */
+ return conv + 1;
+ }
+ else if (*(conv + 1) != '\0' &&
+ strchr(options[i + 1], *(conv + 1)) != NULL) {
+ buff[2] = *(conv + 1); /* valid two-char conversion specifier */
+ buff[3] = '\0'; /* end buffer */
+ return conv + 2;
+ }
+ }
+ }
+ luaL_argerror(L, 1,
+ lua_pushfstring(L, "invalid conversion specifier '%%%s'", conv));
+ return conv; /* to avoid warnings */
+}
+
+
+static int os_date (lua_State *L) {
+ const char *s = luaL_optstring(L, 1, "%c");
+ time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
+ struct tm tmr, *stm;
+ if (*s == '!') { /* UTC? */
+ stm = l_gmtime(&t, &tmr);
+ s++; /* skip `!' */
+ }
+ else
+ stm = l_localtime(&t, &tmr);
+ if (stm == NULL) /* invalid date? */
+ lua_pushnil(L);
+ else if (strcmp(s, "*t") == 0) {
+ lua_createtable(L, 0, 9); /* 9 = number of fields */
+ setfield(L, "sec", stm->tm_sec);
+ setfield(L, "min", stm->tm_min);
+ setfield(L, "hour", stm->tm_hour);
+ setfield(L, "day", stm->tm_mday);
+ setfield(L, "month", stm->tm_mon+1);
+ setfield(L, "year", stm->tm_year+1900);
+ setfield(L, "wday", stm->tm_wday+1);
+ setfield(L, "yday", stm->tm_yday+1);
+ setboolfield(L, "isdst", stm->tm_isdst);
+ }
+ else {
+ char cc[4];
+ luaL_Buffer b;
+ cc[0] = '%';
+ luaL_buffinit(L, &b);
+ while (*s) {
+ if (*s != '%') /* no conversion specifier? */
+ luaL_addchar(&b, *s++);
+ else {
+ size_t reslen;
+ char buff[200]; /* should be big enough for any conversion result */
+ s = checkoption(L, s + 1, cc);
+ reslen = strftime(buff, sizeof(buff), cc, stm);
+ luaL_addlstring(&b, buff, reslen);
+ }
+ }
+ luaL_pushresult(&b);
+ }
+ return 1;
+}
+
+
+static int os_time (lua_State *L) {
+ time_t t;
+ if (lua_isnoneornil(L, 1)) /* called without args? */
+ t = time(NULL); /* get current time */
+ else {
+ struct tm ts;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ lua_settop(L, 1); /* make sure table is at the top */
+ ts.tm_sec = getfield(L, "sec", 0);
+ ts.tm_min = getfield(L, "min", 0);
+ ts.tm_hour = getfield(L, "hour", 12);
+ ts.tm_mday = getfield(L, "day", -1);
+ ts.tm_mon = getfield(L, "month", -1) - 1;
+ ts.tm_year = getfield(L, "year", -1) - 1900;
+ ts.tm_isdst = getboolfield(L, "isdst");
+ t = mktime(&ts);
+ }
+ if (t == (time_t)(-1))
+ lua_pushnil(L);
+ else
+ lua_pushnumber(L, (lua_Number)t);
+ return 1;
+}
+
+
+static int os_difftime (lua_State *L) {
+ lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
+ (time_t)(luaL_optnumber(L, 2, 0))));
+ return 1;
+}
+
+/* }====================================================== */
+
+
+static int os_setlocale (lua_State *L) {
+ static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
+ LC_NUMERIC, LC_TIME};
+ static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
+ "numeric", "time", NULL};
+ const char *l = luaL_optstring(L, 1, NULL);
+ int op = luaL_checkoption(L, 2, "all", catnames);
+ lua_pushstring(L, setlocale(cat[op], l));
+ return 1;
+}
+
+
+static int os_exit (lua_State *L) {
+ int status;
+ if (lua_isboolean(L, 1))
+ status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE);
+ else
+ status = luaL_optint(L, 1, EXIT_SUCCESS);
+ if (lua_toboolean(L, 2))
+ lua_close(L);
+ if (L) exit(status); /* 'if' to avoid warnings for unreachable 'return' */
+ return 0;
+}
+
+
+static const luaL_Reg syslib[] = {
+ {"clock", os_clock},
+ {"date", os_date},
+ {"difftime", os_difftime},
+ {"execute", os_execute},
+ {"exit", os_exit},
+ {"getenv", os_getenv},
+ {"remove", os_remove},
+ {"rename", os_rename},
+ {"setlocale", os_setlocale},
+ {"time", os_time},
+ {"tmpname", os_tmpname},
+ {NULL, NULL}
+};
+
+/* }====================================================== */
+
+
+
+LUAMOD_API int luaopen_os (lua_State *L) {
+ luaL_newlib(L, syslib);
+ return 1;
+}
+
diff --git a/lualib/lparser.c b/lualib/lparser.c
new file mode 100644
index 0000000..9e1a9ca
--- /dev/null
+++ b/lualib/lparser.c
@@ -0,0 +1,1638 @@
+/*
+** $Id: lparser.c,v 2.130.1.1 2013/04/12 18:48:47 roberto Exp $
+** Lua Parser
+** See Copyright Notice in lua.h
+*/
+
+
+#include
+
+#define lparser_c
+#define LUA_CORE
+
+#include "lua.h"
+
+#include "lcode.h"
+#include "ldebug.h"
+#include "ldo.h"
+#include "lfunc.h"
+#include "llex.h"
+#include "lmem.h"
+#include "lobject.h"
+#include "lopcodes.h"
+#include "lparser.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "ltable.h"
+
+
+
+/* maximum number of local variables per function (must be smaller
+ than 250, due to the bytecode format) */
+#define MAXVARS 200
+
+
+#define hasmultret(k) ((k) == VCALL || (k) == VVARARG)
+
+
+
+/*
+** nodes for block list (list of active blocks)
+*/
+typedef struct BlockCnt {
+ struct BlockCnt *previous; /* chain */
+ short firstlabel; /* index of first label in this block */
+ short firstgoto; /* index of first pending goto in this block */
+ lu_byte nactvar; /* # active locals outside the block */
+ lu_byte upval; /* true if some variable in the block is an upvalue */
+ lu_byte isloop; /* true if `block' is a loop */
+} BlockCnt;
+
+
+
+/*
+** prototypes for recursive non-terminal functions
+*/
+static void statement (LexState *ls);
+static void expr (LexState *ls, expdesc *v);
+
+
+static void anchor_token (LexState *ls) {
+ /* last token from outer function must be EOS */
+ lua_assert(ls->fs != NULL || ls->t.token == TK_EOS);
+ if (ls->t.token == TK_NAME || ls->t.token == TK_STRING) {
+ TString *ts = ls->t.seminfo.ts;
+ luaX_newstring(ls, getstr(ts), ts->tsv.len);
+ }
+}
+
+
+/* semantic error */
+static l_noret semerror (LexState *ls, const char *msg) {
+ ls->t.token = 0; /* remove 'near to' from final message */
+ luaX_syntaxerror(ls, msg);
+}
+
+
+static l_noret error_expected (LexState *ls, int token) {
+ luaX_syntaxerror(ls,
+ luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
+}
+
+
+static l_noret errorlimit (FuncState *fs, int limit, const char *what) {
+ lua_State *L = fs->ls->L;
+ const char *msg;
+ int line = fs->f->linedefined;
+ const char *where = (line == 0)
+ ? "main function"
+ : luaO_pushfstring(L, "function at line %d", line);
+ msg = luaO_pushfstring(L, "too many %s (limit is %d) in %s",
+ what, limit, where);
+ luaX_syntaxerror(fs->ls, msg);
+}
+
+
+static void checklimit (FuncState *fs, int v, int l, const char *what) {
+ if (v > l) errorlimit(fs, l, what);
+}
+
+
+static int testnext (LexState *ls, int c) {
+ if (ls->t.token == c) {
+ luaX_next(ls);
+ return 1;
+ }
+ else return 0;
+}
+
+
+static void check (LexState *ls, int c) {
+ if (ls->t.token != c)
+ error_expected(ls, c);
+}
+
+
+static void checknext (LexState *ls, int c) {
+ check(ls, c);
+ luaX_next(ls);
+}
+
+
+#define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); }
+
+
+
+static void check_match (LexState *ls, int what, int who, int where) {
+ if (!testnext(ls, what)) {
+ if (where == ls->linenumber)
+ error_expected(ls, what);
+ else {
+ luaX_syntaxerror(ls, luaO_pushfstring(ls->L,
+ "%s expected (to close %s at line %d)",
+ luaX_token2str(ls, what), luaX_token2str(ls, who), where));
+ }
+ }
+}
+
+
+static TString *str_checkname (LexState *ls) {
+ TString *ts;
+ check(ls, TK_NAME);
+ ts = ls->t.seminfo.ts;
+ luaX_next(ls);
+ return ts;
+}
+
+
+static void init_exp (expdesc *e, expkind k, int i) {
+ e->f = e->t = NO_JUMP;
+ e->k = k;
+ e->u.info = i;
+}
+
+
+static void codestring (LexState *ls, expdesc *e, TString *s) {
+ init_exp(e, VK, luaK_stringK(ls->fs, s));
+}
+
+
+static void checkname (LexState *ls, expdesc *e) {
+ codestring(ls, e, str_checkname(ls));
+}
+
+
+static int registerlocalvar (LexState *ls, TString *varname) {
+ FuncState *fs = ls->fs;
+ Proto *f = fs->f;
+ int oldsize = f->sizelocvars;
+ luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
+ LocVar, SHRT_MAX, "local variables");
+ while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
+ f->locvars[fs->nlocvars].varname = varname;
+ luaC_objbarrier(ls->L, f, varname);
+ return fs->nlocvars++;
+}
+
+
+static void new_localvar (LexState *ls, TString *name) {
+ FuncState *fs = ls->fs;
+ Dyndata *dyd = ls->dyd;
+ int reg = registerlocalvar(ls, name);
+ checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
+ MAXVARS, "local variables");
+ luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
+ dyd->actvar.size, Vardesc, MAX_INT, "local variables");
+ dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
+}
+
+
+static void new_localvarliteral_ (LexState *ls, const char *name, size_t sz) {
+ new_localvar(ls, luaX_newstring(ls, name, sz));
+}
+
+#define new_localvarliteral(ls,v) \
+ new_localvarliteral_(ls, "" v, (sizeof(v)/sizeof(char))-1)
+
+
+static LocVar *getlocvar (FuncState *fs, int i) {
+ int idx = fs->ls->dyd->actvar.arr[fs->firstlocal + i].idx;
+ lua_assert(idx < fs->nlocvars);
+ return &fs->f->locvars[idx];
+}
+
+
+static void adjustlocalvars (LexState *ls, int nvars) {
+ FuncState *fs = ls->fs;
+ fs->nactvar = cast_byte(fs->nactvar + nvars);
+ for (; nvars; nvars--) {
+ getlocvar(fs, fs->nactvar - nvars)->startpc = fs->pc;
+ }
+}
+
+
+static void removevars (FuncState *fs, int tolevel) {
+ fs->ls->dyd->actvar.n -= (fs->nactvar - tolevel);
+ while (fs->nactvar > tolevel)
+ getlocvar(fs, --fs->nactvar)->endpc = fs->pc;
+}
+
+
+static int searchupvalue (FuncState *fs, TString *name) {
+ int i;
+ Upvaldesc *up = fs->f->upvalues;
+ for (i = 0; i < fs->nups; i++) {
+ if (luaS_eqstr(up[i].name, name)) return i;
+ }
+ return -1; /* not found */
+}
+
+
+static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
+ Proto *f = fs->f;
+ int oldsize = f->sizeupvalues;
+ checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
+ luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,
+ Upvaldesc, MAXUPVAL, "upvalues");
+ while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
+ f->upvalues[fs->nups].instack = (v->k == VLOCAL);
+ f->upvalues[fs->nups].idx = cast_byte(v->u.info);
+ f->upvalues[fs->nups].name = name;
+ luaC_objbarrier(fs->ls->L, f, name);
+ return fs->nups++;
+}
+
+
+static int searchvar (FuncState *fs, TString *n) {
+ int i;
+ for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) {
+ if (luaS_eqstr(n, getlocvar(fs, i)->varname))
+ return i;
+ }
+ return -1; /* not found */
+}
+
+
+/*
+ Mark block where variable at given level was defined
+ (to emit close instructions later).
+*/
+static void markupval (FuncState *fs, int level) {
+ BlockCnt *bl = fs->bl;
+ while (bl->nactvar > level) bl = bl->previous;
+ bl->upval = 1;
+}
+
+
+/*
+ Find variable with given name 'n'. If it is an upvalue, add this
+ upvalue into all intermediate functions.
+*/
+static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
+ if (fs == NULL) /* no more levels? */
+ return VVOID; /* default is global */
+ else {
+ int v = searchvar(fs, n); /* look up locals at current level */
+ if (v >= 0) { /* found? */
+ init_exp(var, VLOCAL, v); /* variable is local */
+ if (!base)
+ markupval(fs, v); /* local will be used as an upval */
+ return VLOCAL;
+ }
+ else { /* not found as local at current level; try upvalues */
+ int idx = searchupvalue(fs, n); /* try existing upvalues */
+ if (idx < 0) { /* not found? */
+ if (singlevaraux(fs->prev, n, var, 0) == VVOID) /* try upper levels */
+ return VVOID; /* not found; is a global */
+ /* else was LOCAL or UPVAL */
+ idx = newupvalue(fs, n, var); /* will be a new upvalue */
+ }
+ init_exp(var, VUPVAL, idx);
+ return VUPVAL;
+ }
+ }
+}
+
+
+static void singlevar (LexState *ls, expdesc *var) {
+ TString *varname = str_checkname(ls);
+ FuncState *fs = ls->fs;
+ if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
+ expdesc key;
+ singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
+ lua_assert(var->k == VLOCAL || var->k == VUPVAL);
+ codestring(ls, &key, varname); /* key is variable name */
+ luaK_indexed(fs, var, &key); /* env[varname] */
+ }
+}
+
+
+static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
+ FuncState *fs = ls->fs;
+ int extra = nvars - nexps;
+ if (hasmultret(e->k)) {
+ extra++; /* includes call itself */
+ if (extra < 0) extra = 0;
+ luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
+ if (extra > 1) luaK_reserveregs(fs, extra-1);
+ }
+ else {
+ if (e->k != VVOID) luaK_exp2nextreg(fs, e); /* close last expression */
+ if (extra > 0) {
+ int reg = fs->freereg;
+ luaK_reserveregs(fs, extra);
+ luaK_nil(fs, reg, extra);
+ }
+ }
+}
+
+
+static void enterlevel (LexState *ls) {
+ lua_State *L = ls->L;
+ ++L->nCcalls;
+ checklimit(ls->fs, L->nCcalls, LUAI_MAXCCALLS, "C levels");
+}
+
+
+#define leavelevel(ls) ((ls)->L->nCcalls--)
+
+
+static void closegoto (LexState *ls, int g, Labeldesc *label) {
+ int i;
+ FuncState *fs = ls->fs;
+ Labellist *gl = &ls->dyd->gt;
+ Labeldesc *gt = &gl->arr[g];
+ lua_assert(luaS_eqstr(gt->name, label->name));
+ if (gt->nactvar < label->nactvar) {
+ TString *vname = getlocvar(fs, gt->nactvar)->varname;
+ const char *msg = luaO_pushfstring(ls->L,
+ " at line %d jumps into the scope of local " LUA_QS,
+ getstr(gt->name), gt->line, getstr(vname));
+ semerror(ls, msg);
+ }
+ luaK_patchlist(fs, gt->pc, label->pc);
+ /* remove goto from pending list */
+ for (i = g; i < gl->n - 1; i++)
+ gl->arr[i] = gl->arr[i + 1];
+ gl->n--;
+}
+
+
+/*
+** try to close a goto with existing labels; this solves backward jumps
+*/
+static int findlabel (LexState *ls, int g) {
+ int i;
+ BlockCnt *bl = ls->fs->bl;
+ Dyndata *dyd = ls->dyd;
+ Labeldesc *gt = &dyd->gt.arr[g];
+ /* check labels in current block for a match */
+ for (i = bl->firstlabel; i < dyd->label.n; i++) {
+ Labeldesc *lb = &dyd->label.arr[i];
+ if (luaS_eqstr(lb->name, gt->name)) { /* correct label? */
+ if (gt->nactvar > lb->nactvar &&
+ (bl->upval || dyd->label.n > bl->firstlabel))
+ luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
+ closegoto(ls, g, lb); /* close it */
+ return 1;
+ }
+ }
+ return 0; /* label not found; cannot close goto */
+}
+
+
+static int newlabelentry (LexState *ls, Labellist *l, TString *name,
+ int line, int pc) {
+ int n = l->n;
+ luaM_growvector(ls->L, l->arr, n, l->size,
+ Labeldesc, SHRT_MAX, "labels/gotos");
+ l->arr[n].name = name;
+ l->arr[n].line = line;
+ l->arr[n].nactvar = ls->fs->nactvar;
+ l->arr[n].pc = pc;
+ l->n++;
+ return n;
+}
+
+
+/*
+** check whether new label 'lb' matches any pending gotos in current
+** block; solves forward jumps
+*/
+static void findgotos (LexState *ls, Labeldesc *lb) {
+ Labellist *gl = &ls->dyd->gt;
+ int i = ls->fs->bl->firstgoto;
+ while (i < gl->n) {
+ if (luaS_eqstr(gl->arr[i].name, lb->name))
+ closegoto(ls, i, lb);
+ else
+ i++;
+ }
+}
+
+
+/*
+** "export" pending gotos to outer level, to check them against
+** outer labels; if the block being exited has upvalues, and
+** the goto exits the scope of any variable (which can be the
+** upvalue), close those variables being exited.
+*/
+static void movegotosout (FuncState *fs, BlockCnt *bl) {
+ int i = bl->firstgoto;
+ Labellist *gl = &fs->ls->dyd->gt;
+ /* correct pending gotos to current block and try to close it
+ with visible labels */
+ while (i < gl->n) {
+ Labeldesc *gt = &gl->arr[i];
+ if (gt->nactvar > bl->nactvar) {
+ if (bl->upval)
+ luaK_patchclose(fs, gt->pc, bl->nactvar);
+ gt->nactvar = bl->nactvar;
+ }
+ if (!findlabel(fs->ls, i))
+ i++; /* move to next one */
+ }
+}
+
+
+static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop) {
+ bl->isloop = isloop;
+ bl->nactvar = fs->nactvar;
+ bl->firstlabel = fs->ls->dyd->label.n;
+ bl->firstgoto = fs->ls->dyd->gt.n;
+ bl->upval = 0;
+ bl->previous = fs->bl;
+ fs->bl = bl;
+ lua_assert(fs->freereg == fs->nactvar);
+}
+
+
+/*
+** create a label named "break" to resolve break statements
+*/
+static void breaklabel (LexState *ls) {
+ TString *n = luaS_new(ls->L, "break");
+ int l = newlabelentry(ls, &ls->dyd->label, n, 0, ls->fs->pc);
+ findgotos(ls, &ls->dyd->label.arr[l]);
+}
+
+/*
+** generates an error for an undefined 'goto'; choose appropriate
+** message when label name is a reserved word (which can only be 'break')
+*/
+static l_noret undefgoto (LexState *ls, Labeldesc *gt) {
+ const char *msg = isreserved(gt->name)
+ ? "<%s> at line %d not inside a loop"
+ : "no visible label " LUA_QS " for at line %d";
+ msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
+ semerror(ls, msg);
+}
+
+
+static void leaveblock (FuncState *fs) {
+ BlockCnt *bl = fs->bl;
+ LexState *ls = fs->ls;
+ if (bl->previous && bl->upval) {
+ /* create a 'jump to here' to close upvalues */
+ int j = luaK_jump(fs);
+ luaK_patchclose(fs, j, bl->nactvar);
+ luaK_patchtohere(fs, j);
+ }
+ if (bl->isloop)
+ breaklabel(ls); /* close pending breaks */
+ fs->bl = bl->previous;
+ removevars(fs, bl->nactvar);
+ lua_assert(bl->nactvar == fs->nactvar);
+ fs->freereg = fs->nactvar; /* free registers */
+ ls->dyd->label.n = bl->firstlabel; /* remove local labels */
+ if (bl->previous) /* inner block? */
+ movegotosout(fs, bl); /* update pending gotos to outer block */
+ else if (bl->firstgoto < ls->dyd->gt.n) /* pending gotos in outer block? */
+ undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]); /* error */
+}
+
+
+/*
+** adds a new prototype into list of prototypes
+*/
+static Proto *addprototype (LexState *ls) {
+ Proto *clp;
+ lua_State *L = ls->L;
+ FuncState *fs = ls->fs;
+ Proto *f = fs->f; /* prototype of current function */
+ if (fs->np >= f->sizep) {
+ int oldsize = f->sizep;
+ luaM_growvector(L, f->p, fs->np, f->sizep, Proto *, MAXARG_Bx, "functions");
+ while (oldsize < f->sizep) f->p[oldsize++] = NULL;
+ }
+ f->p[fs->np++] = clp = luaF_newproto(L);
+ luaC_objbarrier(L, f, clp);
+ return clp;
+}
+
+
+/*
+** codes instruction to create new closure in parent function.
+** The OP_CLOSURE instruction must use the last available register,
+** so that, if it invokes the GC, the GC knows which registers
+** are in use at that time.
+*/
+static void codeclosure (LexState *ls, expdesc *v) {
+ FuncState *fs = ls->fs->prev;
+ init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np - 1));
+ luaK_exp2nextreg(fs, v); /* fix it at the last register */
+}
+
+
+static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
+ lua_State *L = ls->L;
+ Proto *f;
+ fs->prev = ls->fs; /* linked list of funcstates */
+ fs->ls = ls;
+ ls->fs = fs;
+ fs->pc = 0;
+ fs->lasttarget = 0;
+ fs->jpc = NO_JUMP;
+ fs->freereg = 0;
+ fs->nk = 0;
+ fs->np = 0;
+ fs->nups = 0;
+ fs->nlocvars = 0;
+ fs->nactvar = 0;
+ fs->firstlocal = ls->dyd->actvar.n;
+ fs->bl = NULL;
+ f = fs->f;
+ f->source = ls->source;
+ f->maxstacksize = 2; /* registers 0/1 are always valid */
+ fs->h = luaH_new(L);
+ /* anchor table of constants (to avoid being collected) */
+ sethvalue2s(L, L->top, fs->h);
+ incr_top(L);
+ enterblock(fs, bl, 0);
+}
+
+
+static void close_func (LexState *ls) {
+ lua_State *L = ls->L;
+ FuncState *fs = ls->fs;
+ Proto *f = fs->f;
+ luaK_ret(fs, 0, 0); /* final return */
+ leaveblock(fs);
+ luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
+ f->sizecode = fs->pc;
+ luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
+ f->sizelineinfo = fs->pc;
+ luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
+ f->sizek = fs->nk;
+ luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
+ f->sizep = fs->np;
+ luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
+ f->sizelocvars = fs->nlocvars;
+ luaM_reallocvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);
+ f->sizeupvalues = fs->nups;
+ lua_assert(fs->bl == NULL);
+ ls->fs = fs->prev;
+ /* last token read was anchored in defunct function; must re-anchor it */
+ anchor_token(ls);
+ L->top--; /* pop table of constants */
+ luaC_checkGC(L);
+}
+
+
+
+/*============================================================*/
+/* GRAMMAR RULES */
+/*============================================================*/
+
+
+/*
+** check whether current token is in the follow set of a block.
+** 'until' closes syntactical blocks, but do not close scope,
+** so it handled in separate.
+*/
+static int block_follow (LexState *ls, int withuntil) {
+ switch (ls->t.token) {
+ case TK_ELSE: case TK_ELSEIF:
+ case TK_END: case TK_EOS:
+ return 1;
+ case TK_UNTIL: return withuntil;
+ default: return 0;
+ }
+}
+
+
+static void statlist (LexState *ls) {
+ /* statlist -> { stat [`;'] } */
+ while (!block_follow(ls, 1)) {
+ if (ls->t.token == TK_RETURN) {
+ statement(ls);
+ return; /* 'return' must be last statement */
+ }
+ statement(ls);
+ }
+}
+
+
+static void fieldsel (LexState *ls, expdesc *v) {
+ /* fieldsel -> ['.' | ':'] NAME */
+ FuncState *fs = ls->fs;
+ expdesc key;
+ luaK_exp2anyregup(fs, v);
+ luaX_next(ls); /* skip the dot or colon */
+ checkname(ls, &key);
+ luaK_indexed(fs, v, &key);
+}
+
+
+static void yindex (LexState *ls, expdesc *v) {
+ /* index -> '[' expr ']' */
+ luaX_next(ls); /* skip the '[' */
+ expr(ls, v);
+ luaK_exp2val(ls->fs, v);
+ checknext(ls, ']');
+}
+
+
+/*
+** {======================================================================
+** Rules for Constructors
+** =======================================================================
+*/
+
+
+struct ConsControl {
+ expdesc v; /* last list item read */
+ expdesc *t; /* table descriptor */
+ int nh; /* total number of `record' elements */
+ int na; /* total number of array elements */
+ int tostore; /* number of array elements pending to be stored */
+};
+
+
+static void recfield (LexState *ls, struct ConsControl *cc) {
+ /* recfield -> (NAME | `['exp1`]') = exp1 */
+ FuncState *fs = ls->fs;
+ int reg = ls->fs->freereg;
+ expdesc key, val;
+ int rkkey;
+ if (ls->t.token == TK_NAME) {
+ checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
+ checkname(ls, &key);
+ }
+ else /* ls->t.token == '[' */
+ yindex(ls, &key);
+ cc->nh++;
+ checknext(ls, '=');
+ rkkey = luaK_exp2RK(fs, &key);
+ expr(ls, &val);
+ luaK_codeABC(fs, OP_SETTABLE, cc->t->u.info, rkkey, luaK_exp2RK(fs, &val));
+ fs->freereg = reg; /* free registers */
+}
+
+
+static void closelistfield (FuncState *fs, struct ConsControl *cc) {
+ if (cc->v.k == VVOID) return; /* there is no list item */
+ luaK_exp2nextreg(fs, &cc->v);
+ cc->v.k = VVOID;
+ if (cc->tostore == LFIELDS_PER_FLUSH) {
+ luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore); /* flush */
+ cc->tostore = 0; /* no more items pending */
+ }
+}
+
+
+static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
+ if (cc->tostore == 0) return;
+ if (hasmultret(cc->v.k)) {
+ luaK_setmultret(fs, &cc->v);
+ luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);
+ cc->na--; /* do not count last expression (unknown number of elements) */
+ }
+ else {
+ if (cc->v.k != VVOID)
+ luaK_exp2nextreg(fs, &cc->v);
+ luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);
+ }
+}
+
+
+static void listfield (LexState *ls, struct ConsControl *cc) {
+ /* listfield -> exp */
+ expr(ls, &cc->v);
+ checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
+ cc->na++;
+ cc->tostore++;
+}
+
+
+static void field (LexState *ls, struct ConsControl *cc) {
+ /* field -> listfield | recfield */
+ switch(ls->t.token) {
+ case TK_NAME: { /* may be 'listfield' or 'recfield' */
+ if (luaX_lookahead(ls) != '=') /* expression? */
+ listfield(ls, cc);
+ else
+ recfield(ls, cc);
+ break;
+ }
+ case '[': {
+ recfield(ls, cc);
+ break;
+ }
+ default: {
+ listfield(ls, cc);
+ break;
+ }
+ }
+}
+
+
+static void constructor (LexState *ls, expdesc *t) {
+ /* constructor -> '{' [ field { sep field } [sep] ] '}'
+ sep -> ',' | ';' */
+ FuncState *fs = ls->fs;
+ int line = ls->linenumber;
+ int pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
+ struct ConsControl cc;
+ cc.na = cc.nh = cc.tostore = 0;
+ cc.t = t;
+ init_exp(t, VRELOCABLE, pc);
+ init_exp(&cc.v, VVOID, 0); /* no value (yet) */
+ luaK_exp2nextreg(ls->fs, t); /* fix it at stack top */
+ checknext(ls, '{');
+ do {
+ lua_assert(cc.v.k == VVOID || cc.tostore > 0);
+ if (ls->t.token == '}') break;
+ closelistfield(fs, &cc);
+ field(ls, &cc);
+ } while (testnext(ls, ',') || testnext(ls, ';'));
+ check_match(ls, '}', '{', line);
+ lastlistfield(fs, &cc);
+ SETARG_B(fs->f->code[pc], luaO_int2fb(cc.na)); /* set initial array size */
+ SETARG_C(fs->f->code[pc], luaO_int2fb(cc.nh)); /* set initial table size */
+}
+
+/* }====================================================================== */
+
+
+
+static void parlist (LexState *ls) {
+ /* parlist -> [ param { `,' param } ] */
+ FuncState *fs = ls->fs;
+ Proto *f = fs->f;
+ int nparams = 0;
+ f->is_vararg = 0;
+ if (ls->t.token != ')') { /* is `parlist' not empty? */
+ do {
+ switch (ls->t.token) {
+ case TK_NAME: { /* param -> NAME */
+ new_localvar(ls, str_checkname(ls));
+ nparams++;
+ break;
+ }
+ case TK_DOTS: { /* param -> `...' */
+ luaX_next(ls);
+ f->is_vararg = 1;
+ break;
+ }
+ default: luaX_syntaxerror(ls, " or " LUA_QL("...") " expected");
+ }
+ } while (!f->is_vararg && testnext(ls, ','));
+ }
+ adjustlocalvars(ls, nparams);
+ f->numparams = cast_byte(fs->nactvar);
+ luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
+}
+
+
+static void body (LexState *ls, expdesc *e, int ismethod, int line) {
+ /* body -> `(' parlist `)' block END */
+ FuncState new_fs;
+ BlockCnt bl;
+ new_fs.f = addprototype(ls);
+ new_fs.f->linedefined = line;
+ open_func(ls, &new_fs, &bl);
+ checknext(ls, '(');
+ if (ismethod) {
+ new_localvarliteral(ls, "self"); /* create 'self' parameter */
+ adjustlocalvars(ls, 1);
+ }
+ parlist(ls);
+ checknext(ls, ')');
+ statlist(ls);
+ new_fs.f->lastlinedefined = ls->linenumber;
+ check_match(ls, TK_END, TK_FUNCTION, line);
+ codeclosure(ls, e);
+ close_func(ls);
+}
+
+
+static int explist (LexState *ls, expdesc *v) {
+ /* explist -> expr { `,' expr } */
+ int n = 1; /* at least one expression */
+ expr(ls, v);
+ while (testnext(ls, ',')) {
+ luaK_exp2nextreg(ls->fs, v);
+ expr(ls, v);
+ n++;
+ }
+ return n;
+}
+
+
+static void funcargs (LexState *ls, expdesc *f, int line) {
+ FuncState *fs = ls->fs;
+ expdesc args;
+ int base, nparams;
+ switch (ls->t.token) {
+ case '(': { /* funcargs -> `(' [ explist ] `)' */
+ luaX_next(ls);
+ if (ls->t.token == ')') /* arg list is empty? */
+ args.k = VVOID;
+ else {
+ explist(ls, &args);
+ luaK_setmultret(fs, &args);
+ }
+ check_match(ls, ')', '(', line);
+ break;
+ }
+ case '{': { /* funcargs -> constructor */
+ constructor(ls, &args);
+ break;
+ }
+ case TK_STRING: { /* funcargs -> STRING */
+ codestring(ls, &args, ls->t.seminfo.ts);
+ luaX_next(ls); /* must use `seminfo' before `next' */
+ break;
+ }
+ default: {
+ luaX_syntaxerror(ls, "function arguments expected");
+ }
+ }
+ lua_assert(f->k == VNONRELOC);
+ base = f->u.info; /* base register for call */
+ if (hasmultret(args.k))
+ nparams = LUA_MULTRET; /* open call */
+ else {
+ if (args.k != VVOID)
+ luaK_exp2nextreg(fs, &args); /* close last argument */
+ nparams = fs->freereg - (base+1);
+ }
+ init_exp(f, VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
+ luaK_fixline(fs, line);
+ fs->freereg = base+1; /* call remove function and arguments and leaves
+ (unless changed) one result */
+}
+
+
+
+
+/*
+** {======================================================================
+** Expression parsing
+** =======================================================================
+*/
+
+
+static void primaryexp (LexState *ls, expdesc *v) {
+ /* primaryexp -> NAME | '(' expr ')' */
+ switch (ls->t.token) {
+ case '(': {
+ int line = ls->linenumber;
+ luaX_next(ls);
+ expr(ls, v);
+ check_match(ls, ')', '(', line);
+ luaK_dischargevars(ls->fs, v);
+ return;
+ }
+ case TK_NAME: {
+ singlevar(ls, v);
+ return;
+ }
+ default: {
+ luaX_syntaxerror(ls, "unexpected symbol");
+ }
+ }
+}
+
+
+static void suffixedexp (LexState *ls, expdesc *v) {
+ /* suffixedexp ->
+ primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs } */
+ FuncState *fs = ls->fs;
+ int line = ls->linenumber;
+ primaryexp(ls, v);
+ for (;;) {
+ switch (ls->t.token) {
+ case '.': { /* fieldsel */
+ fieldsel(ls, v);
+ break;
+ }
+ case '[': { /* `[' exp1 `]' */
+ expdesc key;
+ luaK_exp2anyregup(fs, v);
+ yindex(ls, &key);
+ luaK_indexed(fs, v, &key);
+ break;
+ }
+ case ':': { /* `:' NAME funcargs */
+ expdesc key;
+ luaX_next(ls);
+ checkname(ls, &key);
+ luaK_self(fs, v, &key);
+ funcargs(ls, v, line);
+ break;
+ }
+ case '(': case TK_STRING: case '{': { /* funcargs */
+ luaK_exp2nextreg(fs, v);
+ funcargs(ls, v, line);
+ break;
+ }
+ default: return;
+ }
+ }
+}
+
+
+static void simpleexp (LexState *ls, expdesc *v) {
+ /* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
+ constructor | FUNCTION body | suffixedexp */
+ switch (ls->t.token) {
+ case TK_NUMBER: {
+ init_exp(v, VKNUM, 0);
+ v->u.nval = ls->t.seminfo.r;
+ break;
+ }
+ case TK_STRING: {
+ codestring(ls, v, ls->t.seminfo.ts);
+ break;
+ }
+ case TK_NIL: {
+ init_exp(v, VNIL, 0);
+ break;
+ }
+ case TK_TRUE: {
+ init_exp(v, VTRUE, 0);
+ break;
+ }
+ case TK_FALSE: {
+ init_exp(v, VFALSE, 0);
+ break;
+ }
+ case TK_DOTS: { /* vararg */
+ FuncState *fs = ls->fs;
+ check_condition(ls, fs->f->is_vararg,
+ "cannot use " LUA_QL("...") " outside a vararg function");
+ init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
+ break;
+ }
+ case '{': { /* constructor */
+ constructor(ls, v);
+ return;
+ }
+ case TK_FUNCTION: {
+ luaX_next(ls);
+ body(ls, v, 0, ls->linenumber);
+ return;
+ }
+ default: {
+ suffixedexp(ls, v);
+ return;
+ }
+ }
+ luaX_next(ls);
+}
+
+
+static UnOpr getunopr (int op) {
+ switch (op) {
+ case TK_NOT: return OPR_NOT;
+ case '-': return OPR_MINUS;
+ case '#': return OPR_LEN;
+ default: return OPR_NOUNOPR;
+ }
+}
+
+
+static BinOpr getbinopr (int op) {
+ switch (op) {
+ case '+': return OPR_ADD;
+ case '-': return OPR_SUB;
+ case '*': return OPR_MUL;
+ case '/': return OPR_DIV;
+ case '%': return OPR_MOD;
+ case '^': return OPR_POW;
+ case TK_CONCAT: return OPR_CONCAT;
+ case TK_NE: return OPR_NE;
+ case TK_EQ: return OPR_EQ;
+ case '<': return OPR_LT;
+ case TK_LE: return OPR_LE;
+ case '>': return OPR_GT;
+ case TK_GE: return OPR_GE;
+ case TK_AND: return OPR_AND;
+ case TK_OR: return OPR_OR;
+ default: return OPR_NOBINOPR;
+ }
+}
+
+
+static const struct {
+ lu_byte left; /* left priority for each binary operator */
+ lu_byte right; /* right priority */
+} priority[] = { /* ORDER OPR */
+ {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */
+ {10, 9}, {5, 4}, /* ^, .. (right associative) */
+ {3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
+ {3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
+ {2, 2}, {1, 1} /* and, or */
+};
+
+#define UNARY_PRIORITY 8 /* priority for unary operators */
+
+
+/*
+** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
+** where `binop' is any binary operator with a priority higher than `limit'
+*/
+static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
+ BinOpr op;
+ UnOpr uop;
+ enterlevel(ls);
+ uop = getunopr(ls->t.token);
+ if (uop != OPR_NOUNOPR) {
+ int line = ls->linenumber;
+ luaX_next(ls);
+ subexpr(ls, v, UNARY_PRIORITY);
+ luaK_prefix(ls->fs, uop, v, line);
+ }
+ else simpleexp(ls, v);
+ /* expand while operators have priorities higher than `limit' */
+ op = getbinopr(ls->t.token);
+ while (op != OPR_NOBINOPR && priority[op].left > limit) {
+ expdesc v2;
+ BinOpr nextop;
+ int line = ls->linenumber;
+ luaX_next(ls);
+ luaK_infix(ls->fs, op, v);
+ /* read sub-expression with higher priority */
+ nextop = subexpr(ls, &v2, priority[op].right);
+ luaK_posfix(ls->fs, op, v, &v2, line);
+ op = nextop;
+ }
+ leavelevel(ls);
+ return op; /* return first untreated operator */
+}
+
+
+static void expr (LexState *ls, expdesc *v) {
+ subexpr(ls, v, 0);
+}
+
+/* }==================================================================== */
+
+
+
+/*
+** {======================================================================
+** Rules for Statements
+** =======================================================================
+*/
+
+
+static void block (LexState *ls) {
+ /* block -> statlist */
+ FuncState *fs = ls->fs;
+ BlockCnt bl;
+ enterblock(fs, &bl, 0);
+ statlist(ls);
+ leaveblock(fs);
+}
+
+
+/*
+** structure to chain all variables in the left-hand side of an
+** assignment
+*/
+struct LHS_assign {
+ struct LHS_assign *prev;
+ expdesc v; /* variable (global, local, upvalue, or indexed) */
+};
+
+
+/*
+** check whether, in an assignment to an upvalue/local variable, the
+** upvalue/local variable is begin used in a previous assignment to a
+** table. If so, save original upvalue/local value in a safe place and
+** use this safe copy in the previous assignment.
+*/
+static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
+ FuncState *fs = ls->fs;
+ int extra = fs->freereg; /* eventual position to save local variable */
+ int conflict = 0;
+ for (; lh; lh = lh->prev) { /* check all previous assignments */
+ if (lh->v.k == VINDEXED) { /* assigning to a table? */
+ /* table is the upvalue/local being assigned now? */
+ if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) {
+ conflict = 1;
+ lh->v.u.ind.vt = VLOCAL;
+ lh->v.u.ind.t = extra; /* previous assignment will use safe copy */
+ }
+ /* index is the local being assigned? (index cannot be upvalue) */
+ if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) {
+ conflict = 1;
+ lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
+ }
+ }
+ }
+ if (conflict) {
+ /* copy upvalue/local value to a temporary (in position 'extra') */
+ OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
+ luaK_codeABC(fs, op, extra, v->u.info, 0);
+ luaK_reserveregs(fs, 1);
+ }
+}
+
+
+static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) {
+ expdesc e;
+ check_condition(ls, vkisvar(lh->v.k), "syntax error");
+ if (testnext(ls, ',')) { /* assignment -> ',' suffixedexp assignment */
+ struct LHS_assign nv;
+ nv.prev = lh;
+ suffixedexp(ls, &nv.v);
+ if (nv.v.k != VINDEXED)
+ check_conflict(ls, lh, &nv.v);
+ checklimit(ls->fs, nvars + ls->L->nCcalls, LUAI_MAXCCALLS,
+ "C levels");
+ assignment(ls, &nv, nvars+1);
+ }
+ else { /* assignment -> `=' explist */
+ int nexps;
+ checknext(ls, '=');
+ nexps = explist(ls, &e);
+ if (nexps != nvars) {
+ adjust_assign(ls, nvars, nexps, &e);
+ if (nexps > nvars)
+ ls->fs->freereg -= nexps - nvars; /* remove extra values */
+ }
+ else {
+ luaK_setoneret(ls->fs, &e); /* close last expression */
+ luaK_storevar(ls->fs, &lh->v, &e);
+ return; /* avoid default */
+ }
+ }
+ init_exp(&e, VNONRELOC, ls->fs->freereg-1); /* default assignment */
+ luaK_storevar(ls->fs, &lh->v, &e);
+}
+
+
+static int cond (LexState *ls) {
+ /* cond -> exp */
+ expdesc v;
+ expr(ls, &v); /* read condition */
+ if (v.k == VNIL) v.k = VFALSE; /* `falses' are all equal here */
+ luaK_goiftrue(ls->fs, &v);
+ return v.f;
+}
+
+
+static void gotostat (LexState *ls, int pc) {
+ int line = ls->linenumber;
+ TString *label;
+ int g;
+ if (testnext(ls, TK_GOTO))
+ label = str_checkname(ls);
+ else {
+ luaX_next(ls); /* skip break */
+ label = luaS_new(ls->L, "break");
+ }
+ g = newlabelentry(ls, &ls->dyd->gt, label, line, pc);
+ findlabel(ls, g); /* close it if label already defined */
+}
+
+
+/* check for repeated labels on the same block */
+static void checkrepeated (FuncState *fs, Labellist *ll, TString *label) {
+ int i;
+ for (i = fs->bl->firstlabel; i < ll->n; i++) {
+ if (luaS_eqstr(label, ll->arr[i].name)) {
+ const char *msg = luaO_pushfstring(fs->ls->L,
+ "label " LUA_QS " already defined on line %d",
+ getstr(label), ll->arr[i].line);
+ semerror(fs->ls, msg);
+ }
+ }
+}
+
+
+/* skip no-op statements */
+static void skipnoopstat (LexState *ls) {
+ while (ls->t.token == ';' || ls->t.token == TK_DBCOLON)
+ statement(ls);
+}
+
+
+static void labelstat (LexState *ls, TString *label, int line) {
+ /* label -> '::' NAME '::' */
+ FuncState *fs = ls->fs;
+ Labellist *ll = &ls->dyd->label;
+ int l; /* index of new label being created */
+ checkrepeated(fs, ll, label); /* check for repeated labels */
+ checknext(ls, TK_DBCOLON); /* skip double colon */
+ /* create new entry for this label */
+ l = newlabelentry(ls, ll, label, line, fs->pc);
+ skipnoopstat(ls); /* skip other no-op statements */
+ if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
+ /* assume that locals are already out of scope */
+ ll->arr[l].nactvar = fs->bl->nactvar;
+ }
+ findgotos(ls, &ll->arr[l]);
+}
+
+
+static void whilestat (LexState *ls, int line) {
+ /* whilestat -> WHILE cond DO block END */
+ FuncState *fs = ls->fs;
+ int whileinit;
+ int condexit;
+ BlockCnt bl;
+ luaX_next(ls); /* skip WHILE */
+ whileinit = luaK_getlabel(fs);
+ condexit = cond(ls);
+ enterblock(fs, &bl, 1);
+ checknext(ls, TK_DO);
+ block(ls);
+ luaK_jumpto(fs, whileinit);
+ check_match(ls, TK_END, TK_WHILE, line);
+ leaveblock(fs);
+ luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
+}
+
+
+static void repeatstat (LexState *ls, int line) {
+ /* repeatstat -> REPEAT block UNTIL cond */
+ int condexit;
+ FuncState *fs = ls->fs;
+ int repeat_init = luaK_getlabel(fs);
+ BlockCnt bl1, bl2;
+ enterblock(fs, &bl1, 1); /* loop block */
+ enterblock(fs, &bl2, 0); /* scope block */
+ luaX_next(ls); /* skip REPEAT */
+ statlist(ls);
+ check_match(ls, TK_UNTIL, TK_REPEAT, line);
+ condexit = cond(ls); /* read condition (inside scope block) */
+ if (bl2.upval) /* upvalues? */
+ luaK_patchclose(fs, condexit, bl2.nactvar);
+ leaveblock(fs); /* finish scope */
+ luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
+ leaveblock(fs); /* finish loop */
+}
+
+
+static int exp1 (LexState *ls) {
+ expdesc e;
+ int reg;
+ expr(ls, &e);
+ luaK_exp2nextreg(ls->fs, &e);
+ lua_assert(e.k == VNONRELOC);
+ reg = e.u.info;
+ return reg;
+}
+
+
+static void forbody (LexState *ls, int base, int line, int nvars, int isnum) {
+ /* forbody -> DO block */
+ BlockCnt bl;
+ FuncState *fs = ls->fs;
+ int prep, endfor;
+ adjustlocalvars(ls, 3); /* control variables */
+ checknext(ls, TK_DO);
+ prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
+ enterblock(fs, &bl, 0); /* scope for declared variables */
+ adjustlocalvars(ls, nvars);
+ luaK_reserveregs(fs, nvars);
+ block(ls);
+ leaveblock(fs); /* end of scope for declared variables */
+ luaK_patchtohere(fs, prep);
+ if (isnum) /* numeric for? */
+ endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);
+ else { /* generic for */
+ luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);
+ luaK_fixline(fs, line);
+ endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);
+ }
+ luaK_patchlist(fs, endfor, prep + 1);
+ luaK_fixline(fs, line);
+}
+
+
+static void fornum (LexState *ls, TString *varname, int line) {
+ /* fornum -> NAME = exp1,exp1[,exp1] forbody */
+ FuncState *fs = ls->fs;
+ int base = fs->freereg;
+ new_localvarliteral(ls, "(for index)");
+ new_localvarliteral(ls, "(for limit)");
+ new_localvarliteral(ls, "(for step)");
+ new_localvar(ls, varname);
+ checknext(ls, '=');
+ exp1(ls); /* initial value */
+ checknext(ls, ',');
+ exp1(ls); /* limit */
+ if (testnext(ls, ','))
+ exp1(ls); /* optional step */
+ else { /* default step = 1 */
+ luaK_codek(fs, fs->freereg, luaK_numberK(fs, 1));
+ luaK_reserveregs(fs, 1);
+ }
+ forbody(ls, base, line, 1, 1);
+}
+
+
+static void forlist (LexState *ls, TString *indexname) {
+ /* forlist -> NAME {,NAME} IN explist forbody */
+ FuncState *fs = ls->fs;
+ expdesc e;
+ int nvars = 4; /* gen, state, control, plus at least one declared var */
+ int line;
+ int base = fs->freereg;
+ /* create control variables */
+ new_localvarliteral(ls, "(for generator)");
+ new_localvarliteral(ls, "(for state)");
+ new_localvarliteral(ls, "(for control)");
+ /* create declared variables */
+ new_localvar(ls, indexname);
+ while (testnext(ls, ',')) {
+ new_localvar(ls, str_checkname(ls));
+ nvars++;
+ }
+ checknext(ls, TK_IN);
+ line = ls->linenumber;
+ adjust_assign(ls, 3, explist(ls, &e), &e);
+ luaK_checkstack(fs, 3); /* extra space to call generator */
+ forbody(ls, base, line, nvars - 3, 0);
+}
+
+
+static void forstat (LexState *ls, int line) {
+ /* forstat -> FOR (fornum | forlist) END */
+ FuncState *fs = ls->fs;
+ TString *varname;
+ BlockCnt bl;
+ enterblock(fs, &bl, 1); /* scope for loop and control variables */
+ luaX_next(ls); /* skip `for' */
+ varname = str_checkname(ls); /* first variable name */
+ switch (ls->t.token) {
+ case '=': fornum(ls, varname, line); break;
+ case ',': case TK_IN: forlist(ls, varname); break;
+ default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
+ }
+ check_match(ls, TK_END, TK_FOR, line);
+ leaveblock(fs); /* loop scope (`break' jumps to this point) */
+}
+
+
+static void test_then_block (LexState *ls, int *escapelist) {
+ /* test_then_block -> [IF | ELSEIF] cond THEN block */
+ BlockCnt bl;
+ FuncState *fs = ls->fs;
+ expdesc v;
+ int jf; /* instruction to skip 'then' code (if condition is false) */
+ luaX_next(ls); /* skip IF or ELSEIF */
+ expr(ls, &v); /* read condition */
+ checknext(ls, TK_THEN);
+ if (ls->t.token == TK_GOTO || ls->t.token == TK_BREAK) {
+ luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */
+ enterblock(fs, &bl, 0); /* must enter block before 'goto' */
+ gotostat(ls, v.t); /* handle goto/break */
+ skipnoopstat(ls); /* skip other no-op statements */
+ if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
+ leaveblock(fs);
+ return; /* and that is it */
+ }
+ else /* must skip over 'then' part if condition is false */
+ jf = luaK_jump(fs);
+ }
+ else { /* regular case (not goto/break) */
+ luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */
+ enterblock(fs, &bl, 0);
+ jf = v.f;
+ }
+ statlist(ls); /* `then' part */
+ leaveblock(fs);
+ if (ls->t.token == TK_ELSE ||
+ ls->t.token == TK_ELSEIF) /* followed by 'else'/'elseif'? */
+ luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */
+ luaK_patchtohere(fs, jf);
+}
+
+
+static void ifstat (LexState *ls, int line) {
+ /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
+ FuncState *fs = ls->fs;
+ int escapelist = NO_JUMP; /* exit list for finished parts */
+ test_then_block(ls, &escapelist); /* IF cond THEN block */
+ while (ls->t.token == TK_ELSEIF)
+ test_then_block(ls, &escapelist); /* ELSEIF cond THEN block */
+ if (testnext(ls, TK_ELSE))
+ block(ls); /* `else' part */
+ check_match(ls, TK_END, TK_IF, line);
+ luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
+}
+
+
+static void localfunc (LexState *ls) {
+ expdesc b;
+ FuncState *fs = ls->fs;
+ new_localvar(ls, str_checkname(ls)); /* new local variable */
+ adjustlocalvars(ls, 1); /* enter its scope */
+ body(ls, &b, 0, ls->linenumber); /* function created in next register */
+ /* debug information will only see the variable after this point! */
+ getlocvar(fs, b.u.info)->startpc = fs->pc;
+}
+
+
+static void localstat (LexState *ls) {
+ /* stat -> LOCAL NAME {`,' NAME} [`=' explist] */
+ int nvars = 0;
+ int nexps;
+ expdesc e;
+ do {
+ new_localvar(ls, str_checkname(ls));
+ nvars++;
+ } while (testnext(ls, ','));
+ if (testnext(ls, '='))
+ nexps = explist(ls, &e);
+ else {
+ e.k = VVOID;
+ nexps = 0;
+ }
+ adjust_assign(ls, nvars, nexps, &e);
+ adjustlocalvars(ls, nvars);
+}
+
+
+static int funcname (LexState *ls, expdesc *v) {
+ /* funcname -> NAME {fieldsel} [`:' NAME] */
+ int ismethod = 0;
+ singlevar(ls, v);
+ while (ls->t.token == '.')
+ fieldsel(ls, v);
+ if (ls->t.token == ':') {
+ ismethod = 1;
+ fieldsel(ls, v);
+ }
+ return ismethod;
+}
+
+
+static void funcstat (LexState *ls, int line) {
+ /* funcstat -> FUNCTION funcname body */
+ int ismethod;
+ expdesc v, b;
+ luaX_next(ls); /* skip FUNCTION */
+ ismethod = funcname(ls, &v);
+ body(ls, &b, ismethod, line);
+ luaK_storevar(ls->fs, &v, &b);
+ luaK_fixline(ls->fs, line); /* definition `happens' in the first line */
+}
+
+
+static void exprstat (LexState *ls) {
+ /* stat -> func | assignment */
+ FuncState *fs = ls->fs;
+ struct LHS_assign v;
+ suffixedexp(ls, &v.v);
+ if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
+ v.prev = NULL;
+ assignment(ls, &v, 1);
+ }
+ else { /* stat -> func */
+ check_condition(ls, v.v.k == VCALL, "syntax error");
+ SETARG_C(getcode(fs, &v.v), 1); /* call statement uses no results */
+ }
+}
+
+
+static void retstat (LexState *ls) {
+ /* stat -> RETURN [explist] [';'] */
+ FuncState *fs = ls->fs;
+ expdesc e;
+ int first, nret; /* registers with returned values */
+ if (block_follow(ls, 1) || ls->t.token == ';')
+ first = nret = 0; /* return no values */
+ else {
+ nret = explist(ls, &e); /* optional return values */
+ if (hasmultret(e.k)) {
+ luaK_setmultret(fs, &e);
+ if (e.k == VCALL && nret == 1) { /* tail call? */
+ SET_OPCODE(getcode(fs,&e), OP_TAILCALL);
+ lua_assert(GETARG_A(getcode(fs,&e)) == fs->nactvar);
+ }
+ first = fs->nactvar;
+ nret = LUA_MULTRET; /* return all values */
+ }
+ else {
+ if (nret == 1) /* only one single value? */
+ first = luaK_exp2anyreg(fs, &e);
+ else {
+ luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */
+ first = fs->nactvar; /* return all `active' values */
+ lua_assert(nret == fs->freereg - first);
+ }
+ }
+ }
+ luaK_ret(fs, first, nret);
+ testnext(ls, ';'); /* skip optional semicolon */
+}
+
+
+static void statement (LexState *ls) {
+ int line = ls->linenumber; /* may be needed for error messages */
+ enterlevel(ls);
+ switch (ls->t.token) {
+ case ';': { /* stat -> ';' (empty statement) */
+ luaX_next(ls); /* skip ';' */
+ break;
+ }
+ case TK_IF: { /* stat -> ifstat */
+ ifstat(ls, line);
+ break;
+ }
+ case TK_WHILE: { /* stat -> whilestat */
+ whilestat(ls, line);
+ break;
+ }
+ case TK_DO: { /* stat -> DO block END */
+ luaX_next(ls); /* skip DO */
+ block(ls);
+ check_match(ls, TK_END, TK_DO, line);
+ break;
+ }
+ case TK_FOR: { /* stat -> forstat */
+ forstat(ls, line);
+ break;
+ }
+ case TK_REPEAT: { /* stat -> repeatstat */
+ repeatstat(ls, line);
+ break;
+ }
+ case TK_FUNCTION: { /* stat -> funcstat */
+ funcstat(ls, line);
+ break;
+ }
+ case TK_LOCAL: { /* stat -> localstat */
+ luaX_next(ls); /* skip LOCAL */
+ if (testnext(ls, TK_FUNCTION)) /* local function? */
+ localfunc(ls);
+ else
+ localstat(ls);
+ break;
+ }
+ case TK_DBCOLON: { /* stat -> label */
+ luaX_next(ls); /* skip double colon */
+ labelstat(ls, str_checkname(ls), line);
+ break;
+ }
+ case TK_RETURN: { /* stat -> retstat */
+ luaX_next(ls); /* skip RETURN */
+ retstat(ls);
+ break;
+ }
+ case TK_BREAK: /* stat -> breakstat */
+ case TK_GOTO: { /* stat -> 'goto' NAME */
+ gotostat(ls, luaK_jump(ls->fs));
+ break;
+ }
+ default: { /* stat -> func | assignment */
+ exprstat(ls);
+ break;
+ }
+ }
+ lua_assert(ls->fs->f->maxstacksize >= ls->fs->freereg &&
+ ls->fs->freereg >= ls->fs->nactvar);
+ ls->fs->freereg = ls->fs->nactvar; /* free registers */
+ leavelevel(ls);
+}
+
+/* }====================================================================== */
+
+
+/*
+** compiles the main function, which is a regular vararg function with an
+** upvalue named LUA_ENV
+*/
+static void mainfunc (LexState *ls, FuncState *fs) {
+ BlockCnt bl;
+ expdesc v;
+ open_func(ls, fs, &bl);
+ fs->f->is_vararg = 1; /* main function is always vararg */
+ init_exp(&v, VLOCAL, 0); /* create and... */
+ newupvalue(fs, ls->envn, &v); /* ...set environment upvalue */
+ luaX_next(ls); /* read first token */
+ statlist(ls); /* parse main body */
+ check(ls, TK_EOS);
+ close_func(ls);
+}
+
+
+Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
+ Dyndata *dyd, const char *name, int firstchar) {
+ LexState lexstate;
+ FuncState funcstate;
+ Closure *cl = luaF_newLclosure(L, 1); /* create main closure */
+ /* anchor closure (to avoid being collected) */
+ setclLvalue(L, L->top, cl);
+ incr_top(L);
+ funcstate.f = cl->l.p = luaF_newproto(L);
+ funcstate.f->source = luaS_new(L, name); /* create and anchor TString */
+ lexstate.buff = buff;
+ lexstate.dyd = dyd;
+ dyd->actvar.n = dyd->gt.n = dyd->label.n = 0;
+ luaX_setinput(L, &lexstate, z, funcstate.f->source, firstchar);
+ mainfunc(&lexstate, &funcstate);
+ lua_assert(!funcstate.prev && funcstate.nups == 1 && !lexstate.fs);
+ /* all scopes should be correctly finished */
+ lua_assert(dyd->actvar.n == 0 && dyd->gt.n == 0 && dyd->label.n == 0);
+ return cl; /* it's on the stack too */
+}
+
diff --git a/lualib/lparser.h b/lualib/lparser.h
new file mode 100644
index 0000000..0346e3c
--- /dev/null
+++ b/lualib/lparser.h
@@ -0,0 +1,119 @@
+/*
+** $Id: lparser.h,v 1.70.1.1 2013/04/12 18:48:47 roberto Exp $
+** Lua Parser
+** See Copyright Notice in lua.h
+*/
+
+#ifndef lparser_h
+#define lparser_h
+
+#include "llimits.h"
+#include "lobject.h"
+#include "lzio.h"
+
+
+/*
+** Expression descriptor
+*/
+
+typedef enum {
+ VVOID, /* no value */
+ VNIL,
+ VTRUE,
+ VFALSE,
+ VK, /* info = index of constant in `k' */
+ VKNUM, /* nval = numerical value */
+ VNONRELOC, /* info = result register */
+ VLOCAL, /* info = local register */
+ VUPVAL, /* info = index of upvalue in 'upvalues' */
+ VINDEXED, /* t = table register/upvalue; idx = index R/K */
+ VJMP, /* info = instruction pc */
+ VRELOCABLE, /* info = instruction pc */
+ VCALL, /* info = instruction pc */
+ VVARARG /* info = instruction pc */
+} expkind;
+
+
+#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED)
+#define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL)
+
+typedef struct expdesc {
+ expkind k;
+ union {
+ struct { /* for indexed variables (VINDEXED) */
+ short idx; /* index (R/K) */
+ lu_byte t; /* table (register or upvalue) */
+ lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
+ } ind;
+ int info; /* for generic use */
+ lua_Number nval; /* for VKNUM */
+ } u;
+ int t; /* patch list of `exit when true' */
+ int f; /* patch list of `exit when false' */
+} expdesc;
+
+
+/* description of active local variable */
+typedef struct Vardesc {
+ short idx; /* variable index in stack */
+} 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; /* local level where it appears in current block */
+} Labeldesc;
+
+
+/* list of labels or gotos */
+typedef struct Labellist {
+ Labeldesc *arr; /* array */
+ int n; /* number of entries in use */
+ int size; /* array size */
+} Labellist;
+
+
+/* dynamic structures used by the parser */
+typedef struct Dyndata {
+ struct { /* list of active local variables */
+ Vardesc *arr;
+ int n;
+ int size;
+ } actvar;
+ Labellist gt; /* list of pending gotos */
+ Labellist label; /* list of active labels */
+} Dyndata;
+
+
+/* control of blocks */
+struct BlockCnt; /* defined in lparser.c */
+
+
+/* state needed to generate code for a given function */
+typedef struct FuncState {
+ Proto *f; /* current function header */
+ Table *h; /* table to find (and reuse) elements in `k' */
+ 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 jpc; /* list of pending jumps to `pc' */
+ int nk; /* number of elements in `k' */
+ int np; /* number of elements in `p' */
+ int firstlocal; /* index of first local var (in Dyndata array) */
+ short nlocvars; /* 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 */
+} FuncState;
+
+
+LUAI_FUNC Closure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
+ Dyndata *dyd, const char *name, int firstchar);
+
+
+#endif
diff --git a/lualib/lstate.c b/lualib/lstate.c
new file mode 100644
index 0000000..c7f2672
--- /dev/null
+++ b/lualib/lstate.c
@@ -0,0 +1,323 @@
+/*
+** $Id: lstate.c,v 2.99.1.2 2013/11/08 17:45:31 roberto Exp $
+** Global State
+** See Copyright Notice in lua.h
+*/
+
+
+#include
+#include
+
+#define lstate_c
+#define LUA_CORE
+
+#include "lua.h"
+
+#include "lapi.h"
+#include "ldebug.h"
+#include "ldo.h"
+#include "lfunc.h"
+#include "lgc.h"
+#include "llex.h"
+#include "lmem.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "ltable.h"
+#include "ltm.h"
+
+
+#if !defined(LUAI_GCPAUSE)
+#define LUAI_GCPAUSE 200 /* 200% */
+#endif
+
+#if !defined(LUAI_GCMAJOR)
+#define LUAI_GCMAJOR 200 /* 200% */
+#endif
+
+#if !defined(LUAI_GCMUL)
+#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
+#endif
+
+
+#define MEMERRMSG "not enough memory"
+
+
+/*
+** a macro to help the creation of a unique random seed when a state is
+** created; the seed is used to randomize hashes.
+*/
+#if !defined(luai_makeseed)
+#include
+#define luai_makeseed() cast(unsigned int, time(NULL))
+#endif
+
+
+
+/*
+** thread state + extra space
+*/
+typedef struct LX {
+#if defined(LUAI_EXTRASPACE)
+ char buff[LUAI_EXTRASPACE];
+#endif
+ lua_State l;
+} LX;
+
+
+/*
+** Main thread combines a thread state and the global state
+*/
+typedef struct LG {
+ LX l;
+ global_State g;
+} LG;
+
+
+
+#define fromstate(L) (cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l)))
+
+
+/*
+** Compute an initial seed as random as possible. In ANSI, rely on
+** Address Space Layout Randomization (if present) to increase
+** randomness..
+*/
+#define addbuff(b,p,e) \
+ { size_t t = cast(size_t, e); \
+ memcpy(buff + p, &t, sizeof(t)); p += sizeof(t); }
+
+static unsigned int makeseed (lua_State *L) {
+ char buff[4 * sizeof(size_t)];
+ unsigned int h = luai_makeseed();
+ int p = 0;
+ addbuff(buff, p, L); /* heap variable */
+ addbuff(buff, p, &h); /* local variable */
+ addbuff(buff, p, luaO_nilobject); /* global variable */
+ addbuff(buff, p, &lua_newstate); /* public function */
+ lua_assert(p == sizeof(buff));
+ return luaS_hash(buff, p, h);
+}
+
+
+/*
+** set GCdebt to a new value keeping the value (totalbytes + GCdebt)
+** invariant
+*/
+void luaE_setdebt (global_State *g, l_mem debt) {
+ g->totalbytes -= (debt - g->GCdebt);
+ g->GCdebt = debt;
+}
+
+
+CallInfo *luaE_extendCI (lua_State *L) {
+ CallInfo *ci = luaM_new(L, CallInfo);
+ lua_assert(L->ci->next == NULL);
+ L->ci->next = ci;
+ ci->previous = L->ci;
+ ci->next = NULL;
+ return ci;
+}
+
+
+void luaE_freeCI (lua_State *L) {
+ CallInfo *ci = L->ci;
+ CallInfo *next = ci->next;
+ ci->next = NULL;
+ while ((ci = next) != NULL) {
+ next = ci->next;
+ luaM_free(L, ci);
+ }
+}
+
+
+static void stack_init (lua_State *L1, lua_State *L) {
+ int i; CallInfo *ci;
+ /* initialize stack array */
+ L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue);
+ L1->stacksize = BASIC_STACK_SIZE;
+ for (i = 0; i < BASIC_STACK_SIZE; i++)
+ setnilvalue(L1->stack + i); /* erase new stack */
+ L1->top = L1->stack;
+ L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK;
+ /* initialize first ci */
+ ci = &L1->base_ci;
+ ci->next = ci->previous = NULL;
+ ci->callstatus = 0;
+ ci->func = L1->top;
+ setnilvalue(L1->top++); /* 'function' entry for this 'ci' */
+ ci->top = L1->top + LUA_MINSTACK;
+ L1->ci = ci;
+}
+
+
+static void freestack (lua_State *L) {
+ if (L->stack == NULL)
+ return; /* stack not completely built yet */
+ L->ci = &L->base_ci; /* free the entire 'ci' list */
+ luaE_freeCI(L);
+ luaM_freearray(L, L->stack, L->stacksize); /* free stack array */
+}
+
+
+/*
+** Create registry table and its predefined values
+*/
+static void init_registry (lua_State *L, global_State *g) {
+ TValue mt;
+ /* create registry */
+ Table *registry = luaH_new(L);
+ sethvalue(L, &g->l_registry, registry);
+ luaH_resize(L, registry, LUA_RIDX_LAST, 0);
+ /* registry[LUA_RIDX_MAINTHREAD] = L */
+ setthvalue(L, &mt, L);
+ luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &mt);
+ /* registry[LUA_RIDX_GLOBALS] = table of globals */
+ sethvalue(L, &mt, luaH_new(L));
+ luaH_setint(L, registry, LUA_RIDX_GLOBALS, &mt);
+}
+
+
+/*
+** open parts of the state that may cause memory-allocation errors
+*/
+static void f_luaopen (lua_State *L, void *ud) {
+ global_State *g = G(L);
+ UNUSED(ud);
+ stack_init(L, L); /* init stack */
+ init_registry(L, g);
+ luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
+ luaT_init(L);
+ luaX_init(L);
+ /* pre-create memory-error message */
+ g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
+ luaS_fix(g->memerrmsg); /* it should never be collected */
+ g->gcrunning = 1; /* allow gc */
+ g->version = lua_version(NULL);
+ luai_userstateopen(L);
+}
+
+
+/*
+** preinitialize a state with consistent values without allocating
+** any memory (to avoid errors)
+*/
+static void preinit_state (lua_State *L, global_State *g) {
+ G(L) = g;
+ L->stack = NULL;
+ L->ci = NULL;
+ L->stacksize = 0;
+ L->errorJmp = NULL;
+ L->nCcalls = 0;
+ L->hook = NULL;
+ L->hookmask = 0;
+ L->basehookcount = 0;
+ L->allowhook = 1;
+ resethookcount(L);
+ L->openupval = NULL;
+ L->nny = 1;
+ L->status = LUA_OK;
+ L->errfunc = 0;
+}
+
+
+static void close_state (lua_State *L) {
+ global_State *g = G(L);
+ luaF_close(L, L->stack); /* close all upvalues for this thread */
+ luaC_freeallobjects(L); /* collect all objects */
+ if (g->version) /* closing a fully built state? */
+ luai_userstateclose(L);
+ luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
+ luaZ_freebuffer(L, &g->buff);
+ freestack(L);
+ lua_assert(gettotalbytes(g) == sizeof(LG));
+ (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */
+}
+
+
+LUA_API lua_State *lua_newthread (lua_State *L) {
+ lua_State *L1;
+ lua_lock(L);
+ luaC_checkGC(L);
+ L1 = &luaC_newobj(L, LUA_TTHREAD, sizeof(LX), NULL, offsetof(LX, l))->th;
+ setthvalue(L, L->top, L1);
+ api_incr_top(L);
+ preinit_state(L1, G(L));
+ L1->hookmask = L->hookmask;
+ L1->basehookcount = L->basehookcount;
+ L1->hook = L->hook;
+ resethookcount(L1);
+ luai_userstatethread(L, L1);
+ stack_init(L1, L); /* init stack */
+ lua_unlock(L);
+ return L1;
+}
+
+
+void luaE_freethread (lua_State *L, lua_State *L1) {
+ LX *l = fromstate(L1);
+ luaF_close(L1, L1->stack); /* close all upvalues for this thread */
+ lua_assert(L1->openupval == NULL);
+ luai_userstatefree(L, L1);
+ freestack(L1);
+ luaM_free(L, l);
+}
+
+
+LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
+ int i;
+ lua_State *L;
+ global_State *g;
+ LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG)));
+ if (l == NULL) return NULL;
+ L = &l->l.l;
+ g = &l->g;
+ L->next = NULL;
+ L->tt = LUA_TTHREAD;
+ g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
+ L->marked = luaC_white(g);
+ g->gckind = KGC_NORMAL;
+ preinit_state(L, g);
+ g->frealloc = f;
+ g->ud = ud;
+ g->mainthread = L;
+ g->seed = makeseed(L);
+ g->uvhead.u.l.prev = &g->uvhead;
+ g->uvhead.u.l.next = &g->uvhead;
+ g->gcrunning = 0; /* no GC while building state */
+ g->GCestimate = 0;
+ g->strt.size = 0;
+ g->strt.nuse = 0;
+ g->strt.hash = NULL;
+ setnilvalue(&g->l_registry);
+ luaZ_initbuffer(L, &g->buff);
+ g->panic = NULL;
+ g->version = NULL;
+ g->gcstate = GCSpause;
+ g->allgc = NULL;
+ g->finobj = NULL;
+ g->tobefnz = NULL;
+ g->sweepgc = g->sweepfin = NULL;
+ g->gray = g->grayagain = NULL;
+ g->weak = g->ephemeron = g->allweak = NULL;
+ g->totalbytes = sizeof(LG);
+ g->GCdebt = 0;
+ g->gcpause = LUAI_GCPAUSE;
+ g->gcmajorinc = LUAI_GCMAJOR;
+ g->gcstepmul = LUAI_GCMUL;
+ for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
+ if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
+ /* memory allocation error: free partial state */
+ close_state(L);
+ L = NULL;
+ }
+ return L;
+}
+
+
+LUA_API void lua_close (lua_State *L) {
+ L = G(L)->mainthread; /* only the main thread can be closed */
+ lua_lock(L);
+ close_state(L);
+}
+
+
diff --git a/lualib/lstate.h b/lualib/lstate.h
new file mode 100644
index 0000000..daffd9a
--- /dev/null
+++ b/lualib/lstate.h
@@ -0,0 +1,228 @@
+/*
+** $Id: lstate.h,v 2.82.1.1 2013/04/12 18:48:47 roberto Exp $
+** Global State
+** See Copyright Notice in lua.h
+*/
+
+#ifndef lstate_h
+#define lstate_h
+
+#include "lua.h"
+
+#include "lobject.h"
+#include "ltm.h"
+#include "lzio.h"
+
+
+/*
+
+** Some notes about garbage-collected objects: All objects in Lua must
+** be kept somehow accessible until being freed.
+**
+** Lua keeps most objects linked in list g->allgc. The link uses field
+** 'next' of the CommonHeader.
+**
+** Strings are kept in several lists headed by the array g->strt.hash.
+**
+** Open upvalues are not subject to independent garbage collection. They
+** are collected together with their respective threads. Lua keeps a
+** double-linked list with all open upvalues (g->uvhead) so that it can
+** mark objects referred by them. (They are always gray, so they must
+** be remarked in the atomic step. Usually their contents would be marked
+** when traversing the respective threads, but the thread may already be
+** dead, while the upvalue is still accessible through closures.)
+**
+** Objects with finalizers are kept in the list g->finobj.
+**
+** The list g->tobefnz links all objects being finalized.
+
+*/
+
+
+struct lua_longjmp; /* defined in ldo.c */
+
+
+
+/* extra stack space to handle TM calls and some other extras */
+#define EXTRA_STACK 5
+
+
+#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
+
+
+/* kinds of Garbage Collection */
+#define KGC_NORMAL 0
+#define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */
+#define KGC_GEN 2 /* generational collection */
+
+
+typedef struct stringtable {
+ GCObject **hash;
+ lu_int32 nuse; /* number of elements */
+ int size;
+} stringtable;
+
+
+/*
+** information about a call
+*/
+typedef struct CallInfo {
+ StkId func; /* function index in the stack */
+ StkId top; /* top for this function */
+ struct CallInfo *previous, *next; /* dynamic call link */
+ short nresults; /* expected number of results from this function */
+ lu_byte callstatus;
+ ptrdiff_t extra;
+ union {
+ struct { /* only for Lua functions */
+ StkId base; /* base for this function */
+ const Instruction *savedpc;
+ } l;
+ struct { /* only for C functions */
+ int ctx; /* context info. in case of yields */
+ lua_CFunction k; /* continuation in case of yields */
+ ptrdiff_t old_errfunc;
+ lu_byte old_allowhook;
+ lu_byte status;
+ } c;
+ } u;
+} CallInfo;
+
+
+/*
+** Bits in CallInfo status
+*/
+#define CIST_LUA (1<<0) /* call is running a Lua function */
+#define CIST_HOOKED (1<<1) /* call is running a debug hook */
+#define CIST_REENTRY (1<<2) /* call is running on same invocation of
+ luaV_execute of previous call */
+#define CIST_YIELDED (1<<3) /* call reentered after suspension */
+#define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
+#define CIST_STAT (1<<5) /* call has an error status (pcall) */
+#define CIST_TAIL (1<<6) /* call was tail called */
+#define CIST_HOOKYIELD (1<<7) /* last hook called yielded */
+
+
+#define isLua(ci) ((ci)->callstatus & CIST_LUA)
+
+
+/*
+** `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' */
+ lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */
+ l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
+ lu_mem GCmemtrav; /* memory traversed by the GC */
+ lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
+ stringtable strt; /* hash table for strings */
+ TValue l_registry;
+ unsigned int seed; /* randomized seed for hashes */
+ lu_byte currentwhite;
+ lu_byte gcstate; /* state of garbage collector */
+ lu_byte gckind; /* kind of GC running */
+ lu_byte gcrunning; /* true if GC is running */
+ int sweepstrgc; /* position of sweep in `strt' */
+ GCObject *allgc; /* list of all collectable objects */
+ GCObject *finobj; /* list of collectable objects with finalizers */
+ GCObject **sweepgc; /* current position of sweep in list 'allgc' */
+ GCObject **sweepfin; /* current position of sweep in list 'finobj' */
+ 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 */
+ UpVal uvhead; /* head of double-linked list of all open upvalues */
+ Mbuffer buff; /* temporary buffer for string concatenation */
+ int gcpause; /* size of pause between successive GCs */
+ int gcmajorinc; /* pause between major collections (only in gen. mode) */
+ int gcstepmul; /* GC `granularity' */
+ lua_CFunction panic; /* to be called in unprotected errors */
+ struct lua_State *mainthread;
+ const lua_Number *version; /* pointer to version number */
+ TString *memerrmsg; /* memory-error message */
+ TString *tmname[TM_N]; /* array with tag-method names */
+ struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
+} global_State;
+
+
+/*
+** `per thread' state
+*/
+struct lua_State {
+ CommonHeader;
+ lu_byte status;
+ StkId top; /* first free slot in the stack */
+ global_State *l_G;
+ CallInfo *ci; /* call info for current function */
+ const Instruction *oldpc; /* last pc traced */
+ StkId stack_last; /* last free slot in the stack */
+ StkId stack; /* stack base */
+ int stacksize;
+ unsigned short nny; /* number of non-yieldable calls in stack */
+ unsigned short nCcalls; /* number of nested C calls */
+ lu_byte hookmask;
+ lu_byte allowhook;
+ int basehookcount;
+ int hookcount;
+ lua_Hook hook;
+ GCObject *openupval; /* list of open upvalues in this stack */
+ GCObject *gclist;
+ struct lua_longjmp *errorJmp; /* current error recover point */
+ ptrdiff_t errfunc; /* current error handling function (stack index) */
+ CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
+};
+
+
+#define G(L) (L->l_G)
+
+
+/*
+** Union of all collectable objects
+*/
+union GCObject {
+ GCheader gch; /* common header */
+ union TString ts;
+ union Udata u;
+ union Closure cl;
+ struct Table h;
+ struct Proto p;
+ struct UpVal uv;
+ struct lua_State th; /* thread */
+};
+
+
+#define gch(o) (&(o)->gch)
+
+/* macros to convert a GCObject into a specific value */
+#define rawgco2ts(o) \
+ check_exp(novariant((o)->gch.tt) == LUA_TSTRING, &((o)->ts))
+#define gco2ts(o) (&rawgco2ts(o)->tsv)
+#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
+#define gco2u(o) (&rawgco2u(o)->uv)
+#define gco2lcl(o) check_exp((o)->gch.tt == LUA_TLCL, &((o)->cl.l))
+#define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c))
+#define gco2cl(o) \
+ check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl))
+#define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
+#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
+#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
+#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
+
+/* macro to convert any Lua object into a GCObject */
+#define obj2gco(v) (cast(GCObject *, (v)))
+
+
+/* actual number of total bytes allocated */
+#define gettotalbytes(g) ((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);
+LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
+LUAI_FUNC void luaE_freeCI (lua_State *L);
+
+
+#endif
+
diff --git a/lualib/lstring.c b/lualib/lstring.c
new file mode 100644
index 0000000..af96c89
--- /dev/null
+++ b/lualib/lstring.c
@@ -0,0 +1,185 @@
+/*
+** $Id: lstring.c,v 2.26.1.1 2013/04/12 18:48:47 roberto Exp $
+** String table (keeps all strings handled by Lua)
+** See Copyright Notice in lua.h
+*/
+
+
+#include
+
+#define lstring_c
+#define LUA_CORE
+
+#include "lua.h"
+
+#include "lmem.h"
+#include "lobject.h"
+#include "lstate.h"
+#include "lstring.h"
+
+
+/*
+** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to
+** compute its hash
+*/
+#if !defined(LUAI_HASHLIMIT)
+#define LUAI_HASHLIMIT 5
+#endif
+
+
+/*
+** equality for long strings
+*/
+int luaS_eqlngstr (TString *a, TString *b) {
+ size_t len = a->tsv.len;
+ lua_assert(a->tsv.tt == LUA_TLNGSTR && b->tsv.tt == LUA_TLNGSTR);
+ return (a == b) || /* same instance or... */
+ ((len == b->tsv.len) && /* equal length and ... */
+ (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */
+}
+
+
+/*
+** equality for strings
+*/
+int luaS_eqstr (TString *a, TString *b) {
+ return (a->tsv.tt == b->tsv.tt) &&
+ (a->tsv.tt == LUA_TSHRSTR ? eqshrstr(a, b) : luaS_eqlngstr(a, b));
+}
+
+
+unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {
+ unsigned int h = seed ^ cast(unsigned int, l);
+ size_t l1;
+ size_t step = (l >> LUAI_HASHLIMIT) + 1;
+ for (l1 = l; l1 >= step; l1 -= step)
+ h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1]));
+ return h;
+}
+
+
+/*
+** resizes the string table
+*/
+void luaS_resize (lua_State *L, int newsize) {
+ int i;
+ stringtable *tb = &G(L)->strt;
+ /* cannot resize while GC is traversing strings */
+ luaC_runtilstate(L, ~bitmask(GCSsweepstring));
+ if (newsize > tb->size) {
+ luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
+ for (i = tb->size; i < newsize; i++) tb->hash[i] = NULL;
+ }
+ /* rehash */
+ for (i=0; isize; i++) {
+ GCObject *p = tb->hash[i];
+ tb->hash[i] = NULL;
+ while (p) { /* for each node in the list */
+ GCObject *next = gch(p)->next; /* save next */
+ unsigned int h = lmod(gco2ts(p)->hash, newsize); /* new position */
+ gch(p)->next = tb->hash[h]; /* chain it */
+ tb->hash[h] = p;
+ resetoldbit(p); /* see MOVE OLD rule */
+ p = next;
+ }
+ }
+ if (newsize < tb->size) {
+ /* shrinking slice must be empty */
+ lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);
+ luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
+ }
+ tb->size = newsize;
+}
+
+
+/*
+** creates a new string object
+*/
+static TString *createstrobj (lua_State *L, const char *str, size_t l,
+ int tag, unsigned int h, GCObject **list) {
+ TString *ts;
+ size_t totalsize; /* total size of TString object */
+ totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
+ ts = &luaC_newobj(L, tag, totalsize, list, 0)->ts;
+ ts->tsv.len = l;
+ ts->tsv.hash = h;
+ ts->tsv.extra = 0;
+ memcpy(ts+1, str, l*sizeof(char));
+ ((char *)(ts+1))[l] = '\0'; /* ending 0 */
+ return ts;
+}
+
+
+/*
+** creates a new short string, inserting it into string table
+*/
+static TString *newshrstr (lua_State *L, const char *str, size_t l,
+ unsigned int h) {
+ GCObject **list; /* (pointer to) list where it will be inserted */
+ stringtable *tb = &G(L)->strt;
+ TString *s;
+ if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
+ luaS_resize(L, tb->size*2); /* too crowded */
+ list = &tb->hash[lmod(h, tb->size)];
+ s = createstrobj(L, str, l, LUA_TSHRSTR, h, list);
+ tb->nuse++;
+ return s;
+}
+
+
+/*
+** checks whether short string exists and reuses it or creates a new one
+*/
+static TString *internshrstr (lua_State *L, const char *str, size_t l) {
+ GCObject *o;
+ global_State *g = G(L);
+ unsigned int h = luaS_hash(str, l, g->seed);
+ for (o = g->strt.hash[lmod(h, g->strt.size)];
+ o != NULL;
+ o = gch(o)->next) {
+ TString *ts = rawgco2ts(o);
+ if (h == ts->tsv.hash &&
+ l == ts->tsv.len &&
+ (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {
+ if (isdead(G(L), o)) /* string is dead (but was not collected yet)? */
+ changewhite(o); /* resurrect it */
+ return ts;
+ }
+ }
+ return newshrstr(L, str, l, h); /* not found; create a new string */
+}
+
+
+/*
+** new string (with explicit length)
+*/
+TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
+ if (l <= LUAI_MAXSHORTLEN) /* short string? */
+ return internshrstr(L, str, l);
+ else {
+ if (l + 1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
+ luaM_toobig(L);
+ return createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed, NULL);
+ }
+}
+
+
+/*
+** new zero-terminated string
+*/
+TString *luaS_new (lua_State *L, const char *str) {
+ return luaS_newlstr(L, str, strlen(str));
+}
+
+
+Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
+ Udata *u;
+ if (s > MAX_SIZET - sizeof(Udata))
+ luaM_toobig(L);
+ u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u;
+ u->uv.len = s;
+ u->uv.metatable = NULL;
+ u->uv.env = e;
+ return u;
+}
+
diff --git a/lualib/lstring.h b/lualib/lstring.h
new file mode 100644
index 0000000..260e7f1
--- /dev/null
+++ b/lualib/lstring.h
@@ -0,0 +1,46 @@
+/*
+** $Id: lstring.h,v 1.49.1.1 2013/04/12 18:48:47 roberto Exp $
+** String table (keep all strings handled by Lua)
+** See Copyright Notice in lua.h
+*/
+
+#ifndef lstring_h
+#define lstring_h
+
+#include "lgc.h"
+#include "lobject.h"
+#include "lstate.h"
+
+
+#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char))
+
+#define sizeudata(u) (sizeof(union Udata)+(u)->len)
+
+#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
+ (sizeof(s)/sizeof(char))-1))
+
+#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
+
+
+/*
+** test whether a string is a reserved word
+*/
+#define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0)
+
+
+/*
+** equality for short strings, which are always internalized
+*/
+#define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b))
+
+
+LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
+LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);
+LUAI_FUNC int luaS_eqstr (TString *a, TString *b);
+LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
+LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
+LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
+LUAI_FUNC TString *luaS_new (lua_State *L, const char *str);
+
+
+#endif
diff --git a/lualib/lstrlib.c b/lualib/lstrlib.c
new file mode 100644
index 0000000..9261fd2
--- /dev/null
+++ b/lualib/lstrlib.c
@@ -0,0 +1,1019 @@
+/*
+** $Id: lstrlib.c,v 1.178.1.1 2013/04/12 18:48:47 roberto Exp $
+** Standard library for string operations and pattern-matching
+** See Copyright Notice in lua.h
+*/
+
+
+#include
+#include
+#include
+#include
+#include
+
+#define lstrlib_c
+#define LUA_LIB
+
+#include "lua.h"
+
+#include "lauxlib.h"
+#include "lualib.h"
+
+
+/*
+** maximum number of captures that a pattern can do during
+** pattern-matching. This limit is arbitrary.
+*/
+#if !defined(LUA_MAXCAPTURES)
+#define LUA_MAXCAPTURES 32
+#endif
+
+
+/* macro to `unsign' a character */
+#define uchar(c) ((unsigned char)(c))
+
+
+
+static int str_len (lua_State *L) {
+ size_t l;
+ luaL_checklstring(L, 1, &l);
+ lua_pushinteger(L, (lua_Integer)l);
+ return 1;
+}
+
+
+/* translate a relative string position: negative means back from end */
+static size_t posrelat (ptrdiff_t pos, size_t len) {
+ if (pos >= 0) return (size_t)pos;
+ else if (0u - (size_t)pos > len) return 0;
+ else return len - ((size_t)-pos) + 1;
+}
+
+
+static int str_sub (lua_State *L) {
+ size_t l;
+ const char *s = luaL_checklstring(L, 1, &l);
+ size_t start = posrelat(luaL_checkinteger(L, 2), l);
+ size_t end = posrelat(luaL_optinteger(L, 3, -1), l);
+ if (start < 1) start = 1;
+ if (end > l) end = l;
+ if (start <= end)
+ lua_pushlstring(L, s + start - 1, end - start + 1);
+ else lua_pushliteral(L, "");
+ return 1;
+}
+
+
+static int str_reverse (lua_State *L) {
+ size_t l, i;
+ luaL_Buffer b;
+ const char *s = luaL_checklstring(L, 1, &l);
+ char *p = luaL_buffinitsize(L, &b, l);
+ for (i = 0; i < l; i++)
+ p[i] = s[l - i - 1];
+ luaL_pushresultsize(&b, l);
+ return 1;
+}
+
+
+static int str_lower (lua_State *L) {
+ size_t l;
+ size_t i;
+ luaL_Buffer b;
+ const char *s = luaL_checklstring(L, 1, &l);
+ char *p = luaL_buffinitsize(L, &b, l);
+ for (i=0; i> 1)
+
+static int str_rep (lua_State *L) {
+ size_t l, lsep;
+ const char *s = luaL_checklstring(L, 1, &l);
+ int n = luaL_checkint(L, 2);
+ const char *sep = luaL_optlstring(L, 3, "", &lsep);
+ if (n <= 0) lua_pushliteral(L, "");
+ else if (l + lsep < l || l + lsep >= MAXSIZE / n) /* may overflow? */
+ return luaL_error(L, "resulting string too large");
+ else {
+ size_t totallen = n * l + (n - 1) * lsep;
+ luaL_Buffer b;
+ char *p = luaL_buffinitsize(L, &b, totallen);
+ while (n-- > 1) { /* first n-1 copies (followed by separator) */
+ memcpy(p, s, l * sizeof(char)); p += l;
+ if (lsep > 0) { /* avoid empty 'memcpy' (may be expensive) */
+ memcpy(p, sep, lsep * sizeof(char)); p += lsep;
+ }
+ }
+ memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */
+ luaL_pushresultsize(&b, totallen);
+ }
+ return 1;
+}
+
+
+static int str_byte (lua_State *L) {
+ size_t l;
+ const char *s = luaL_checklstring(L, 1, &l);
+ size_t posi = posrelat(luaL_optinteger(L, 2, 1), l);
+ size_t pose = posrelat(luaL_optinteger(L, 3, posi), l);
+ int n, i;
+ if (posi < 1) posi = 1;
+ if (pose > l) pose = l;
+ if (posi > pose) return 0; /* empty interval; return no values */
+ n = (int)(pose - posi + 1);
+ if (posi + n <= pose) /* (size_t -> int) overflow? */
+ return luaL_error(L, "string slice too long");
+ luaL_checkstack(L, n, "string slice too long");
+ for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED)
+ return luaL_error(ms->L, "invalid capture index %%%d", l + 1);
+ return l;
+}
+
+
+static int capture_to_close (MatchState *ms) {
+ int level = ms->level;
+ for (level--; level>=0; level--)
+ if (ms->capture[level].len == CAP_UNFINISHED) return level;
+ return luaL_error(ms->L, "invalid pattern capture");
+}
+
+
+static const char *classend (MatchState *ms, const char *p) {
+ switch (*p++) {
+ case L_ESC: {
+ if (p == ms->p_end)
+ luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")");
+ return p+1;
+ }
+ case '[': {
+ if (*p == '^') p++;
+ do { /* look for a `]' */
+ if (p == ms->p_end)
+ luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")");
+ if (*(p++) == L_ESC && p < ms->p_end)
+ p++; /* skip escapes (e.g. `%]') */
+ } while (*p != ']');
+ return p+1;
+ }
+ default: {
+ return p;
+ }
+ }
+}
+
+
+static int match_class (int c, int cl) {
+ int res;
+ switch (tolower(cl)) {
+ case 'a' : res = isalpha(c); break;
+ case 'c' : res = iscntrl(c); break;
+ case 'd' : res = isdigit(c); break;
+ case 'g' : res = isgraph(c); break;
+ case 'l' : res = islower(c); break;
+ case 'p' : res = ispunct(c); break;
+ case 's' : res = isspace(c); break;
+ case 'u' : res = isupper(c); break;
+ case 'w' : res = isalnum(c); break;
+ case 'x' : res = isxdigit(c); break;
+ case 'z' : res = (c == 0); break; /* deprecated option */
+ default: return (cl == c);
+ }
+ return (islower(cl) ? res : !res);
+}
+
+
+static int matchbracketclass (int c, const char *p, const char *ec) {
+ int sig = 1;
+ if (*(p+1) == '^') {
+ sig = 0;
+ p++; /* skip the `^' */
+ }
+ while (++p < ec) {
+ if (*p == L_ESC) {
+ p++;
+ if (match_class(c, uchar(*p)))
+ return sig;
+ }
+ else if ((*(p+1) == '-') && (p+2 < ec)) {
+ p+=2;
+ if (uchar(*(p-2)) <= c && c <= uchar(*p))
+ return sig;
+ }
+ else if (uchar(*p) == c) return sig;
+ }
+ return !sig;
+}
+
+
+static int singlematch (MatchState *ms, const char *s, const char *p,
+ const char *ep) {
+ if (s >= ms->src_end)
+ return 0;
+ else {
+ int c = uchar(*s);
+ switch (*p) {
+ case '.': return 1; /* matches any char */
+ case L_ESC: return match_class(c, uchar(*(p+1)));
+ case '[': return matchbracketclass(c, p, ep-1);
+ default: return (uchar(*p) == c);
+ }
+ }
+}
+
+
+static const char *matchbalance (MatchState *ms, const char *s,
+ const char *p) {
+ if (p >= ms->p_end - 1)
+ luaL_error(ms->L, "malformed pattern "
+ "(missing arguments to " LUA_QL("%%b") ")");
+ if (*s != *p) return NULL;
+ else {
+ int b = *p;
+ int e = *(p+1);
+ int cont = 1;
+ while (++s < ms->src_end) {
+ if (*s == e) {
+ if (--cont == 0) return s+1;
+ }
+ else if (*s == b) cont++;
+ }
+ }
+ return NULL; /* string ends out of balance */
+}
+
+
+static const char *max_expand (MatchState *ms, const char *s,
+ const char *p, const char *ep) {
+ ptrdiff_t i = 0; /* counts maximum expand for item */
+ while (singlematch(ms, s + i, p, ep))
+ i++;
+ /* keeps trying to match with the maximum repetitions */
+ while (i>=0) {
+ const char *res = match(ms, (s+i), ep+1);
+ if (res) return res;
+ i--; /* else didn't match; reduce 1 repetition to try again */
+ }
+ return NULL;
+}
+
+
+static const char *min_expand (MatchState *ms, const char *s,
+ const char *p, const char *ep) {
+ for (;;) {
+ const char *res = match(ms, s, ep+1);
+ if (res != NULL)
+ return res;
+ else if (singlematch(ms, s, p, ep))
+ s++; /* try with one more repetition */
+ else return NULL;
+ }
+}
+
+
+static const char *start_capture (MatchState *ms, const char *s,
+ const char *p, int what) {
+ const char *res;
+ int level = ms->level;
+ if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures");
+ ms->capture[level].init = s;
+ ms->capture[level].len = what;
+ ms->level = level+1;
+ if ((res=match(ms, s, p)) == NULL) /* match failed? */
+ ms->level--; /* undo capture */
+ return res;
+}
+
+
+static const char *end_capture (MatchState *ms, const char *s,
+ const char *p) {
+ int l = capture_to_close(ms);
+ const char *res;
+ ms->capture[l].len = s - ms->capture[l].init; /* close capture */
+ if ((res = match(ms, s, p)) == NULL) /* match failed? */
+ ms->capture[l].len = CAP_UNFINISHED; /* undo capture */
+ return res;
+}
+
+
+static const char *match_capture (MatchState *ms, const char *s, int l) {
+ size_t len;
+ l = check_capture(ms, l);
+ len = ms->capture[l].len;
+ if ((size_t)(ms->src_end-s) >= len &&
+ memcmp(ms->capture[l].init, s, len) == 0)
+ return s+len;
+ else return NULL;
+}
+
+
+static const char *match (MatchState *ms, const char *s, const char *p) {
+ if (ms->matchdepth-- == 0)
+ luaL_error(ms->L, "pattern too complex");
+ init: /* using goto's to optimize tail recursion */
+ if (p != ms->p_end) { /* end of pattern? */
+ switch (*p) {
+ case '(': { /* start capture */
+ if (*(p + 1) == ')') /* position capture? */
+ s = start_capture(ms, s, p + 2, CAP_POSITION);
+ else
+ s = start_capture(ms, s, p + 1, CAP_UNFINISHED);
+ break;
+ }
+ case ')': { /* end capture */
+ s = end_capture(ms, s, p + 1);
+ break;
+ }
+ case '$': {
+ if ((p + 1) != ms->p_end) /* is the `$' the last char in pattern? */
+ goto dflt; /* no; go to default */
+ s = (s == ms->src_end) ? s : NULL; /* check end of string */
+ break;
+ }
+ case L_ESC: { /* escaped sequences not in the format class[*+?-]? */
+ switch (*(p + 1)) {
+ case 'b': { /* balanced string? */
+ s = matchbalance(ms, s, p + 2);
+ if (s != NULL) {
+ p += 4; goto init; /* return match(ms, s, p + 4); */
+ } /* else fail (s == NULL) */
+ break;
+ }
+ case 'f': { /* frontier? */
+ const char *ep; char previous;
+ p += 2;
+ if (*p != '[')
+ luaL_error(ms->L, "missing " LUA_QL("[") " after "
+ LUA_QL("%%f") " in pattern");
+ ep = classend(ms, p); /* points to what is next */
+ previous = (s == ms->src_init) ? '\0' : *(s - 1);
+ if (!matchbracketclass(uchar(previous), p, ep - 1) &&
+ matchbracketclass(uchar(*s), p, ep - 1)) {
+ p = ep; goto init; /* return match(ms, s, ep); */
+ }
+ s = NULL; /* match failed */
+ break;
+ }
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ case '8': case '9': { /* capture results (%0-%9)? */
+ s = match_capture(ms, s, uchar(*(p + 1)));
+ if (s != NULL) {
+ p += 2; goto init; /* return match(ms, s, p + 2) */
+ }
+ break;
+ }
+ default: goto dflt;
+ }
+ break;
+ }
+ default: dflt: { /* pattern class plus optional suffix */
+ const char *ep = classend(ms, p); /* points to optional suffix */
+ /* does not match at least once? */
+ if (!singlematch(ms, s, p, ep)) {
+ if (*ep == '*' || *ep == '?' || *ep == '-') { /* accept empty? */
+ p = ep + 1; goto init; /* return match(ms, s, ep + 1); */
+ }
+ else /* '+' or no suffix */
+ s = NULL; /* fail */
+ }
+ else { /* matched once */
+ switch (*ep) { /* handle optional suffix */
+ case '?': { /* optional */
+ const char *res;
+ if ((res = match(ms, s + 1, ep + 1)) != NULL)
+ s = res;
+ else {
+ p = ep + 1; goto init; /* else return match(ms, s, ep + 1); */
+ }
+ break;
+ }
+ case '+': /* 1 or more repetitions */
+ s++; /* 1 match already done */
+ /* go through */
+ case '*': /* 0 or more repetitions */
+ s = max_expand(ms, s, p, ep);
+ break;
+ case '-': /* 0 or more repetitions (minimum) */
+ s = min_expand(ms, s, p, ep);
+ break;
+ default: /* no suffix */
+ s++; p = ep; goto init; /* return match(ms, s + 1, ep); */
+ }
+ }
+ break;
+ }
+ }
+ }
+ ms->matchdepth++;
+ return s;
+}
+
+
+
+static const char *lmemfind (const char *s1, size_t l1,
+ const char *s2, size_t l2) {
+ if (l2 == 0) return s1; /* empty strings are everywhere */
+ else if (l2 > l1) return NULL; /* avoids a negative `l1' */
+ else {
+ const char *init; /* to search for a `*s2' inside `s1' */
+ l2--; /* 1st char will be checked by `memchr' */
+ l1 = l1-l2; /* `s2' cannot be found after that */
+ while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
+ init++; /* 1st char is already checked */
+ if (memcmp(init, s2+1, l2) == 0)
+ return init-1;
+ else { /* correct `l1' and `s1' to try again */
+ l1 -= init-s1;
+ s1 = init;
+ }
+ }
+ return NULL; /* not found */
+ }
+}
+
+
+static void push_onecapture (MatchState *ms, int i, const char *s,
+ const char *e) {
+ if (i >= ms->level) {
+ if (i == 0) /* ms->level == 0, too */
+ lua_pushlstring(ms->L, s, e - s); /* add whole match */
+ else
+ luaL_error(ms->L, "invalid capture index");
+ }
+ else {
+ ptrdiff_t l = ms->capture[i].len;
+ if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
+ if (l == CAP_POSITION)
+ lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
+ else
+ lua_pushlstring(ms->L, ms->capture[i].init, l);
+ }
+}
+
+
+static int push_captures (MatchState *ms, const char *s, const char *e) {
+ int i;
+ int nlevels = (ms->level == 0 && s) ? 1 : ms->level;
+ luaL_checkstack(ms->L, nlevels, "too many captures");
+ for (i = 0; i < nlevels; i++)
+ push_onecapture(ms, i, s, e);
+ return nlevels; /* number of strings pushed */
+}
+
+
+/* check whether pattern has no special characters */
+static int nospecials (const char *p, size_t l) {
+ size_t upto = 0;
+ do {
+ if (strpbrk(p + upto, SPECIALS))
+ return 0; /* pattern has a special character */
+ upto += strlen(p + upto) + 1; /* may have more after \0 */
+ } while (upto <= l);
+ return 1; /* no special chars found */
+}
+
+
+static int str_find_aux (lua_State *L, int find) {
+ size_t ls, lp;
+ const char *s = luaL_checklstring(L, 1, &ls);
+ const char *p = luaL_checklstring(L, 2, &lp);
+ size_t init = posrelat(luaL_optinteger(L, 3, 1), ls);
+ if (init < 1) init = 1;
+ else if (init > ls + 1) { /* start after string's end? */
+ lua_pushnil(L); /* cannot find anything */
+ return 1;
+ }
+ /* explicit request or no special characters? */
+ if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {
+ /* do a plain search */
+ const char *s2 = lmemfind(s + init - 1, ls - init + 1, p, lp);
+ if (s2) {
+ lua_pushinteger(L, s2 - s + 1);
+ lua_pushinteger(L, s2 - s + lp);
+ return 2;
+ }
+ }
+ else {
+ MatchState ms;
+ const char *s1 = s + init - 1;
+ int anchor = (*p == '^');
+ if (anchor) {
+ p++; lp--; /* skip anchor character */
+ }
+ ms.L = L;
+ ms.matchdepth = MAXCCALLS;
+ ms.src_init = s;
+ ms.src_end = s + ls;
+ ms.p_end = p + lp;
+ do {
+ const char *res;
+ ms.level = 0;
+ lua_assert(ms.matchdepth == MAXCCALLS);
+ if ((res=match(&ms, s1, p)) != NULL) {
+ if (find) {
+ lua_pushinteger(L, s1 - s + 1); /* start */
+ lua_pushinteger(L, res - s); /* end */
+ return push_captures(&ms, NULL, 0) + 2;
+ }
+ else
+ return push_captures(&ms, s1, res);
+ }
+ } while (s1++ < ms.src_end && !anchor);
+ }
+ lua_pushnil(L); /* not found */
+ return 1;
+}
+
+
+static int str_find (lua_State *L) {
+ return str_find_aux(L, 1);
+}
+
+
+static int str_match (lua_State *L) {
+ return str_find_aux(L, 0);
+}
+
+
+static int gmatch_aux (lua_State *L) {
+ MatchState ms;
+ size_t ls, lp;
+ const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
+ const char *p = lua_tolstring(L, lua_upvalueindex(2), &lp);
+ const char *src;
+ ms.L = L;
+ ms.matchdepth = MAXCCALLS;
+ ms.src_init = s;
+ ms.src_end = s+ls;
+ ms.p_end = p + lp;
+ for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));
+ src <= ms.src_end;
+ src++) {
+ const char *e;
+ ms.level = 0;
+ lua_assert(ms.matchdepth == MAXCCALLS);
+ if ((e = match(&ms, src, p)) != NULL) {
+ lua_Integer newstart = e-s;
+ if (e == src) newstart++; /* empty match? go at least one position */
+ lua_pushinteger(L, newstart);
+ lua_replace(L, lua_upvalueindex(3));
+ return push_captures(&ms, src, e);
+ }
+ }
+ return 0; /* not found */
+}
+
+
+static int gmatch (lua_State *L) {
+ luaL_checkstring(L, 1);
+ luaL_checkstring(L, 2);
+ lua_settop(L, 2);
+ lua_pushinteger(L, 0);
+ lua_pushcclosure(L, gmatch_aux, 3);
+ return 1;
+}
+
+
+static void add_s (MatchState *ms, luaL_Buffer *b, const char *s,
+ const char *e) {
+ size_t l, i;
+ const char *news = lua_tolstring(ms->L, 3, &l);
+ for (i = 0; i < l; i++) {
+ if (news[i] != L_ESC)
+ luaL_addchar(b, news[i]);
+ else {
+ i++; /* skip ESC */
+ if (!isdigit(uchar(news[i]))) {
+ if (news[i] != L_ESC)
+ luaL_error(ms->L, "invalid use of " LUA_QL("%c")
+ " in replacement string", L_ESC);
+ luaL_addchar(b, news[i]);
+ }
+ else if (news[i] == '0')
+ luaL_addlstring(b, s, e - s);
+ else {
+ push_onecapture(ms, news[i] - '1', s, e);
+ luaL_addvalue(b); /* add capture to accumulated result */
+ }
+ }
+ }
+}
+
+
+static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
+ const char *e, int tr) {
+ lua_State *L = ms->L;
+ switch (tr) {
+ case LUA_TFUNCTION: {
+ int n;
+ lua_pushvalue(L, 3);
+ n = push_captures(ms, s, e);
+ lua_call(L, n, 1);
+ break;
+ }
+ case LUA_TTABLE: {
+ push_onecapture(ms, 0, s, e);
+ lua_gettable(L, 3);
+ break;
+ }
+ default: { /* LUA_TNUMBER or LUA_TSTRING */
+ add_s(ms, b, s, e);
+ return;
+ }
+ }
+ if (!lua_toboolean(L, -1)) { /* nil or false? */
+ lua_pop(L, 1);
+ lua_pushlstring(L, s, e - s); /* keep original text */
+ }
+ else if (!lua_isstring(L, -1))
+ luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
+ luaL_addvalue(b); /* add result to accumulator */
+}
+
+
+static int str_gsub (lua_State *L) {
+ size_t srcl, lp;
+ const char *src = luaL_checklstring(L, 1, &srcl);
+ const char *p = luaL_checklstring(L, 2, &lp);
+ int tr = lua_type(L, 3);
+ size_t max_s = luaL_optinteger(L, 4, srcl+1);
+ int anchor = (*p == '^');
+ size_t n = 0;
+ MatchState ms;
+ luaL_Buffer b;
+ luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
+ tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
+ "string/function/table expected");
+ luaL_buffinit(L, &b);
+ if (anchor) {
+ p++; lp--; /* skip anchor character */
+ }
+ ms.L = L;
+ ms.matchdepth = MAXCCALLS;
+ ms.src_init = src;
+ ms.src_end = src+srcl;
+ ms.p_end = p + lp;
+ while (n < max_s) {
+ const char *e;
+ ms.level = 0;
+ lua_assert(ms.matchdepth == MAXCCALLS);
+ e = match(&ms, src, p);
+ if (e) {
+ n++;
+ add_value(&ms, &b, src, e, tr);
+ }
+ if (e && e>src) /* non empty match? */
+ src = e; /* skip it */
+ else if (src < ms.src_end)
+ luaL_addchar(&b, *src++);
+ else break;
+ if (anchor) break;
+ }
+ luaL_addlstring(&b, src, ms.src_end-src);
+ luaL_pushresult(&b);
+ lua_pushinteger(L, n); /* number of substitutions */
+ return 2;
+}
+
+/* }====================================================== */
+
+
+
+/*
+** {======================================================
+** STRING FORMAT
+** =======================================================
+*/
+
+/*
+** LUA_INTFRMLEN is the length modifier for integer conversions in
+** 'string.format'; LUA_INTFRM_T is the integer type corresponding to
+** the previous length
+*/
+#if !defined(LUA_INTFRMLEN) /* { */
+#if defined(LUA_USE_LONGLONG)
+
+#define LUA_INTFRMLEN "ll"
+#define LUA_INTFRM_T long long
+
+#else
+
+#define LUA_INTFRMLEN "l"
+#define LUA_INTFRM_T long
+
+#endif
+#endif /* } */
+
+
+/*
+** LUA_FLTFRMLEN is the length modifier for float conversions in
+** 'string.format'; LUA_FLTFRM_T is the float type corresponding to
+** the previous length
+*/
+#if !defined(LUA_FLTFRMLEN)
+
+#define LUA_FLTFRMLEN ""
+#define LUA_FLTFRM_T double
+
+#endif
+
+
+/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
+#define MAX_ITEM 512
+/* valid flags in a format specification */
+#define FLAGS "-+ #0"
+/*
+** maximum size of each format specification (such as '%-099.99d')
+** (+10 accounts for %99.99x plus margin of error)
+*/
+#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
+
+
+static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
+ size_t l;
+ const char *s = luaL_checklstring(L, arg, &l);
+ luaL_addchar(b, '"');
+ while (l--) {
+ if (*s == '"' || *s == '\\' || *s == '\n') {
+ luaL_addchar(b, '\\');
+ luaL_addchar(b, *s);
+ }
+ else if (*s == '\0' || iscntrl(uchar(*s))) {
+ char buff[10];
+ if (!isdigit(uchar(*(s+1))))
+ sprintf(buff, "\\%d", (int)uchar(*s));
+ else
+ sprintf(buff, "\\%03d", (int)uchar(*s));
+ luaL_addstring(b, buff);
+ }
+ else
+ luaL_addchar(b, *s);
+ s++;
+ }
+ luaL_addchar(b, '"');
+}
+
+static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
+ const char *p = strfrmt;
+ while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
+ if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char))
+ luaL_error(L, "invalid format (repeated flags)");
+ if (isdigit(uchar(*p))) p++; /* skip width */
+ if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
+ if (*p == '.') {
+ p++;
+ if (isdigit(uchar(*p))) p++; /* skip precision */
+ if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
+ }
+ if (isdigit(uchar(*p)))
+ luaL_error(L, "invalid format (width or precision too long)");
+ *(form++) = '%';
+ memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char));
+ form += p - strfrmt + 1;
+ *form = '\0';
+ return p;
+}
+
+
+/*
+** add length modifier into formats
+*/
+static void addlenmod (char *form, const char *lenmod) {
+ size_t l = strlen(form);
+ size_t lm = strlen(lenmod);
+ char spec = form[l - 1];
+ strcpy(form + l - 1, lenmod);
+ form[l + lm - 1] = spec;
+ form[l + lm] = '\0';
+}
+
+
+static int str_format (lua_State *L) {
+ int top = lua_gettop(L);
+ int arg = 1;
+ size_t sfl;
+ const char *strfrmt = luaL_checklstring(L, arg, &sfl);
+ const char *strfrmt_end = strfrmt+sfl;
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ while (strfrmt < strfrmt_end) {
+ if (*strfrmt != L_ESC)
+ luaL_addchar(&b, *strfrmt++);
+ else if (*++strfrmt == L_ESC)
+ luaL_addchar(&b, *strfrmt++); /* %% */
+ else { /* format item */
+ char form[MAX_FORMAT]; /* to store the format (`%...') */
+ char *buff = luaL_prepbuffsize(&b, MAX_ITEM); /* to put formatted item */
+ int nb = 0; /* number of bytes in added item */
+ if (++arg > top)
+ luaL_argerror(L, arg, "no value");
+ strfrmt = scanformat(L, strfrmt, form);
+ switch (*strfrmt++) {
+ case 'c': {
+ nb = sprintf(buff, form, luaL_checkint(L, arg));
+ break;
+ }
+ case 'd': case 'i': {
+ lua_Number n = luaL_checknumber(L, arg);
+ LUA_INTFRM_T ni = (LUA_INTFRM_T)n;
+ lua_Number diff = n - (lua_Number)ni;
+ luaL_argcheck(L, -1 < diff && diff < 1, arg,
+ "not a number in proper range");
+ addlenmod(form, LUA_INTFRMLEN);
+ nb = sprintf(buff, form, ni);
+ break;
+ }
+ case 'o': case 'u': case 'x': case 'X': {
+ lua_Number n = luaL_checknumber(L, arg);
+ unsigned LUA_INTFRM_T ni = (unsigned LUA_INTFRM_T)n;
+ lua_Number diff = n - (lua_Number)ni;
+ luaL_argcheck(L, -1 < diff && diff < 1, arg,
+ "not a non-negative number in proper range");
+ addlenmod(form, LUA_INTFRMLEN);
+ nb = sprintf(buff, form, ni);
+ break;
+ }
+ case 'e': case 'E': case 'f':
+#if defined(LUA_USE_AFORMAT)
+ case 'a': case 'A':
+#endif
+ case 'g': case 'G': {
+ addlenmod(form, LUA_FLTFRMLEN);
+ nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
+ break;
+ }
+ case 'q': {
+ addquoted(L, &b, arg);
+ break;
+ }
+ case 's': {
+ size_t l;
+ const char *s = luaL_tolstring(L, arg, &l);
+ if (!strchr(form, '.') && l >= 100) {
+ /* no precision and string is too long to be formatted;
+ keep original string */
+ luaL_addvalue(&b);
+ break;
+ }
+ else {
+ nb = sprintf(buff, form, s);
+ lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
+ break;
+ }
+ }
+ default: { /* also treat cases `pnLlh' */
+ return luaL_error(L, "invalid option " LUA_QL("%%%c") " to "
+ LUA_QL("format"), *(strfrmt - 1));
+ }
+ }
+ luaL_addsize(&b, nb);
+ }
+ }
+ luaL_pushresult(&b);
+ return 1;
+}
+
+/* }====================================================== */
+
+
+static const luaL_Reg strlib[] = {
+ {"byte", str_byte},
+ {"char", str_char},
+ {"dump", str_dump},
+ {"find", str_find},
+ {"format", str_format},
+ {"gmatch", gmatch},
+ {"gsub", str_gsub},
+ {"len", str_len},
+ {"lower", str_lower},
+ {"match", str_match},
+ {"rep", str_rep},
+ {"reverse", str_reverse},
+ {"sub", str_sub},
+ {"upper", str_upper},
+ {NULL, NULL}
+};
+
+
+static void createmetatable (lua_State *L) {
+ lua_createtable(L, 0, 1); /* table to be metatable for strings */
+ lua_pushliteral(L, ""); /* dummy string */
+ lua_pushvalue(L, -2); /* copy table */
+ lua_setmetatable(L, -2); /* set table as metatable for strings */
+ lua_pop(L, 1); /* pop dummy string */
+ lua_pushvalue(L, -2); /* get string library */
+ lua_setfield(L, -2, "__index"); /* metatable.__index = string */
+ lua_pop(L, 1); /* pop metatable */
+}
+
+
+/*
+** Open string library
+*/
+LUAMOD_API int luaopen_string (lua_State *L) {
+ luaL_newlib(L, strlib);
+ createmetatable(L);
+ return 1;
+}
+
diff --git a/lualib/ltable.c b/lualib/ltable.c
new file mode 100644
index 0000000..5d76f97
--- /dev/null
+++ b/lualib/ltable.c
@@ -0,0 +1,588 @@
+/*
+** $Id: ltable.c,v 2.72.1.1 2013/04/12 18:48:47 roberto Exp $
+** Lua tables (hash)
+** See Copyright Notice in lua.h
+*/
+
+
+/*
+** Implementation of tables (aka arrays, objects, or hash tables).
+** Tables keep its elements in two parts: an array part and a hash part.
+** Non-negative integer keys are all candidates to be kept in the array
+** part. The actual size of the array is the largest `n' such that at
+** least half the slots between 0 and n are in use.
+** Hash uses a mix of chained scatter table with Brent's variation.
+** A main invariant of these tables is that, if an element is not
+** in its main position (i.e. the `original' position that its hash gives
+** to it), then the colliding element is in its own main position.
+** Hence even when the load factor reaches 100%, performance remains good.
+*/
+
+#include
+
+#define ltable_c
+#define LUA_CORE
+
+#include "lua.h"
+
+#include "ldebug.h"
+#include "ldo.h"
+#include "lgc.h"
+#include "lmem.h"
+#include "lobject.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "ltable.h"
+#include "lvm.h"
+
+
+/*
+** max size of array part is 2^MAXBITS
+*/
+#if LUAI_BITSINT >= 32
+#define MAXBITS 30
+#else
+#define MAXBITS (LUAI_BITSINT-2)
+#endif
+
+#define MAXASIZE (1 << MAXBITS)
+
+
+#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
+
+#define hashstr(t,str) hashpow2(t, (str)->tsv.hash)
+#define hashboolean(t,p) hashpow2(t, p)
+
+
+/*
+** for some types, it is better to avoid modulus by power of 2, as
+** they tend to have many 2 factors.
+*/
+#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1))))
+
+
+#define hashpointer(t,p) hashmod(t, IntPoint(p))
+
+
+#define dummynode (&dummynode_)
+
+#define isdummy(n) ((n) == dummynode)
+
+static const Node dummynode_ = {
+ {NILCONSTANT}, /* value */
+ {{NILCONSTANT, NULL}} /* key */
+};
+
+
+/*
+** hash for lua_Numbers
+*/
+static Node *hashnum (const Table *t, lua_Number n) {
+ int i;
+ luai_hashnum(i, n);
+ if (i < 0) {
+ if (cast(unsigned int, i) == 0u - i) /* use unsigned to avoid overflows */
+ i = 0; /* handle INT_MIN */
+ i = -i; /* must be a positive value */
+ }
+ return hashmod(t, i);
+}
+
+
+
+/*
+** returns the `main' position of an element in a table (that is, the index
+** of its hash value)
+*/
+static Node *mainposition (const Table *t, const TValue *key) {
+ switch (ttype(key)) {
+ case LUA_TNUMBER:
+ return hashnum(t, nvalue(key));
+ case LUA_TLNGSTR: {
+ TString *s = rawtsvalue(key);
+ if (s->tsv.extra == 0) { /* no hash? */
+ s->tsv.hash = luaS_hash(getstr(s), s->tsv.len, s->tsv.hash);
+ s->tsv.extra = 1; /* now it has its hash */
+ }
+ return hashstr(t, rawtsvalue(key));
+ }
+ case LUA_TSHRSTR:
+ return hashstr(t, rawtsvalue(key));
+ case LUA_TBOOLEAN:
+ return hashboolean(t, bvalue(key));
+ case LUA_TLIGHTUSERDATA:
+ return hashpointer(t, pvalue(key));
+ case LUA_TLCF:
+ return hashpointer(t, fvalue(key));
+ default:
+ return hashpointer(t, gcvalue(key));
+ }
+}
+
+
+/*
+** returns the index for `key' if `key' is an appropriate key to live in
+** the array part of the table, -1 otherwise.
+*/
+static int arrayindex (const TValue *key) {
+ if (ttisnumber(key)) {
+ lua_Number n = nvalue(key);
+ int k;
+ lua_number2int(k, n);
+ if (luai_numeq(cast_num(k), n))
+ return k;
+ }
+ return -1; /* `key' did not match some condition */
+}
+
+
+/*
+** returns the index of a `key' for table traversals. First goes all
+** elements in the array part, then elements in the hash part. The
+** beginning of a traversal is signaled by -1.
+*/
+static int findindex (lua_State *L, Table *t, StkId key) {
+ int i;
+ if (ttisnil(key)) return -1; /* first iteration */
+ i = arrayindex(key);
+ if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
+ return i-1; /* yes; that's the index (corrected to C) */
+ else {
+ Node *n = mainposition(t, key);
+ for (;;) { /* check whether `key' is somewhere in the chain */
+ /* key may be dead already, but it is ok to use it in `next' */
+ if (luaV_rawequalobj(gkey(n), key) ||
+ (ttisdeadkey(gkey(n)) && iscollectable(key) &&
+ deadvalue(gkey(n)) == gcvalue(key))) {
+ i = cast_int(n - gnode(t, 0)); /* key index in hash table */
+ /* hash elements are numbered after array ones */
+ return i + t->sizearray;
+ }
+ else n = gnext(n);
+ if (n == NULL)
+ luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
+ }
+ }
+}
+
+
+int luaH_next (lua_State *L, Table *t, StkId key) {
+ int i = findindex(L, t, key); /* find original element */
+ for (i++; i < t->sizearray; i++) { /* try first array part */
+ if (!ttisnil(&t->array[i])) { /* a non-nil value? */
+ setnvalue(key, cast_num(i+1));
+ setobj2s(L, key+1, &t->array[i]);
+ return 1;
+ }
+ }
+ for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
+ if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
+ setobj2s(L, key, gkey(gnode(t, i)));
+ setobj2s(L, key+1, gval(gnode(t, i)));
+ return 1;
+ }
+ }
+ return 0; /* no more elements */
+}
+
+
+/*
+** {=============================================================
+** Rehash
+** ==============================================================
+*/
+
+
+static int computesizes (int nums[], int *narray) {
+ int i;
+ int twotoi; /* 2^i */
+ int a = 0; /* number of elements smaller than 2^i */
+ int na = 0; /* number of elements to go to array part */
+ int n = 0; /* optimal size for array part */
+ for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
+ if (nums[i] > 0) {
+ a += nums[i];
+ if (a > twotoi/2) { /* more than half elements present? */
+ n = twotoi; /* optimal size (till now) */
+ na = a; /* all elements smaller than n will go to array part */
+ }
+ }
+ if (a == *narray) break; /* all elements already counted */
+ }
+ *narray = n;
+ lua_assert(*narray/2 <= na && na <= *narray);
+ return na;
+}
+
+
+static int countint (const TValue *key, int *nums) {
+ int k = arrayindex(key);
+ if (0 < k && k <= MAXASIZE) { /* is `key' an appropriate array index? */
+ nums[luaO_ceillog2(k)]++; /* count as such */
+ return 1;
+ }
+ else
+ return 0;
+}
+
+
+static int numusearray (const Table *t, int *nums) {
+ int lg;
+ int ttlg; /* 2^lg */
+ int ause = 0; /* summation of `nums' */
+ int i = 1; /* count to traverse all array keys */
+ for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */
+ int lc = 0; /* counter */
+ int lim = ttlg;
+ if (lim > t->sizearray) {
+ lim = t->sizearray; /* adjust upper limit */
+ if (i > lim)
+ break; /* no more elements to count */
+ }
+ /* count elements in range (2^(lg-1), 2^lg] */
+ for (; i <= lim; i++) {
+ if (!ttisnil(&t->array[i-1]))
+ lc++;
+ }
+ nums[lg] += lc;
+ ause += lc;
+ }
+ return ause;
+}
+
+
+static int numusehash (const Table *t, int *nums, int *pnasize) {
+ int totaluse = 0; /* total number of elements */
+ int ause = 0; /* summation of `nums' */
+ int i = sizenode(t);
+ while (i--) {
+ Node *n = &t->node[i];
+ if (!ttisnil(gval(n))) {
+ ause += countint(gkey(n), nums);
+ totaluse++;
+ }
+ }
+ *pnasize += ause;
+ return totaluse;
+}
+
+
+static void setarrayvector (lua_State *L, Table *t, int size) {
+ int i;
+ luaM_reallocvector(L, t->array, t->sizearray, size, TValue);
+ for (i=t->sizearray; iarray[i]);
+ t->sizearray = size;
+}
+
+
+static void setnodevector (lua_State *L, Table *t, int size) {
+ int lsize;
+ if (size == 0) { /* no elements to hash part? */
+ t->node = cast(Node *, dummynode); /* use common `dummynode' */
+ lsize = 0;
+ }
+ else {
+ int i;
+ lsize = luaO_ceillog2(size);
+ if (lsize > MAXBITS)
+ luaG_runerror(L, "table overflow");
+ size = twoto(lsize);
+ t->node = luaM_newvector(L, size, Node);
+ for (i=0; ilsizenode = cast_byte(lsize);
+ t->lastfree = gnode(t, size); /* all positions are free */
+}
+
+
+void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
+ int i;
+ int oldasize = t->sizearray;
+ int oldhsize = t->lsizenode;
+ Node *nold = t->node; /* save old hash ... */
+ if (nasize > oldasize) /* array part must grow? */
+ setarrayvector(L, t, nasize);
+ /* create new hash part with appropriate size */
+ setnodevector(L, t, nhsize);
+ if (nasize < oldasize) { /* array part must shrink? */
+ t->sizearray = nasize;
+ /* re-insert elements from vanishing slice */
+ for (i=nasize; iarray[i]))
+ luaH_setint(L, t, i + 1, &t->array[i]);
+ }
+ /* shrink array */
+ luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
+ }
+ /* re-insert elements from hash part */
+ for (i = twoto(oldhsize) - 1; i >= 0; i--) {
+ Node *old = nold+i;
+ if (!ttisnil(gval(old))) {
+ /* doesn't need barrier/invalidate cache, as entry was
+ already present in the table */
+ setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
+ }
+ }
+ if (!isdummy(nold))
+ luaM_freearray(L, nold, cast(size_t, twoto(oldhsize))); /* free old array */
+}
+
+
+void luaH_resizearray (lua_State *L, Table *t, int nasize) {
+ int nsize = isdummy(t->node) ? 0 : sizenode(t);
+ luaH_resize(L, t, nasize, nsize);
+}
+
+
+static void rehash (lua_State *L, Table *t, const TValue *ek) {
+ int nasize, na;
+ int nums[MAXBITS+1]; /* nums[i] = number of keys with 2^(i-1) < k <= 2^i */
+ int i;
+ int totaluse;
+ for (i=0; i<=MAXBITS; i++) nums[i] = 0; /* reset counts */
+ nasize = numusearray(t, nums); /* count keys in array part */
+ totaluse = nasize; /* all those keys are integer keys */
+ totaluse += numusehash(t, nums, &nasize); /* count keys in hash part */
+ /* count extra key */
+ nasize += countint(ek, nums);
+ totaluse++;
+ /* compute new size for array part */
+ na = computesizes(nums, &nasize);
+ /* resize the table to new computed sizes */
+ luaH_resize(L, t, nasize, totaluse - na);
+}
+
+
+
+/*
+** }=============================================================
+*/
+
+
+Table *luaH_new (lua_State *L) {
+ Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), NULL, 0)->h;
+ t->metatable = NULL;
+ t->flags = cast_byte(~0);
+ t->array = NULL;
+ t->sizearray = 0;
+ setnodevector(L, t, 0);
+ return t;
+}
+
+
+void luaH_free (lua_State *L, Table *t) {
+ if (!isdummy(t->node))
+ luaM_freearray(L, t->node, cast(size_t, sizenode(t)));
+ luaM_freearray(L, t->array, t->sizearray);
+ luaM_free(L, t);
+}
+
+
+static Node *getfreepos (Table *t) {
+ while (t->lastfree > t->node) {
+ t->lastfree--;
+ if (ttisnil(gkey(t->lastfree)))
+ return t->lastfree;
+ }
+ return NULL; /* could not find a free place */
+}
+
+
+
+/*
+** inserts a new key into a hash table; first, check whether key's main
+** position is free. If not, check whether colliding node is in its main
+** position or not: if it is not, move colliding node to an empty place and
+** put new key in its main position; otherwise (colliding node is in its main
+** position), new key goes to an empty position.
+*/
+TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
+ Node *mp;
+ if (ttisnil(key)) luaG_runerror(L, "table index is nil");
+ else if (ttisnumber(key) && luai_numisnan(L, nvalue(key)))
+ luaG_runerror(L, "table index is NaN");
+ mp = mainposition(t, key);
+ if (!ttisnil(gval(mp)) || isdummy(mp)) { /* main position is taken? */
+ Node *othern;
+ Node *n = getfreepos(t); /* get a free place */
+ if (n == NULL) { /* cannot find a free place? */
+ rehash(L, t, key); /* grow table */
+ /* whatever called 'newkey' take care of TM cache and GC barrier */
+ return luaH_set(L, t, key); /* insert key into grown table */
+ }
+ lua_assert(!isdummy(n));
+ othern = mainposition(t, gkey(mp));
+ if (othern != mp) { /* is colliding node out of its main position? */
+ /* yes; move colliding node into free position */
+ while (gnext(othern) != mp) othern = gnext(othern); /* find previous */
+ gnext(othern) = n; /* redo the chain with `n' in place of `mp' */
+ *n = *mp; /* copy colliding node into free pos. (mp->next also goes) */
+ gnext(mp) = NULL; /* now `mp' is free */
+ setnilvalue(gval(mp));
+ }
+ else { /* colliding node is in its own main position */
+ /* new node will go into free position */
+ gnext(n) = gnext(mp); /* chain new position */
+ gnext(mp) = n;
+ mp = n;
+ }
+ }
+ setobj2t(L, gkey(mp), key);
+ luaC_barrierback(L, obj2gco(t), key);
+ lua_assert(ttisnil(gval(mp)));
+ return gval(mp);
+}
+
+
+/*
+** search function for integers
+*/
+const TValue *luaH_getint (Table *t, int key) {
+ /* (1 <= key && key <= t->sizearray) */
+ if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
+ return &t->array[key-1];
+ else {
+ lua_Number nk = cast_num(key);
+ Node *n = hashnum(t, nk);
+ do { /* check whether `key' is somewhere in the chain */
+ if (ttisnumber(gkey(n)) && luai_numeq(nvalue(gkey(n)), nk))
+ return gval(n); /* that's it */
+ else n = gnext(n);
+ } while (n);
+ return luaO_nilobject;
+ }
+}
+
+
+/*
+** search function for short strings
+*/
+const TValue *luaH_getstr (Table *t, TString *key) {
+ Node *n = hashstr(t, key);
+ lua_assert(key->tsv.tt == LUA_TSHRSTR);
+ do { /* check whether `key' is somewhere in the chain */
+ if (ttisshrstring(gkey(n)) && eqshrstr(rawtsvalue(gkey(n)), key))
+ return gval(n); /* that's it */
+ else n = gnext(n);
+ } while (n);
+ return luaO_nilobject;
+}
+
+
+/*
+** main search function
+*/
+const TValue *luaH_get (Table *t, const TValue *key) {
+ switch (ttype(key)) {
+ case LUA_TSHRSTR: return luaH_getstr(t, rawtsvalue(key));
+ case LUA_TNIL: return luaO_nilobject;
+ case LUA_TNUMBER: {
+ int k;
+ lua_Number n = nvalue(key);
+ lua_number2int(k, n);
+ if (luai_numeq(cast_num(k), n)) /* index is int? */
+ return luaH_getint(t, k); /* use specialized version */
+ /* else go through */
+ }
+ default: {
+ Node *n = mainposition(t, key);
+ do { /* check whether `key' is somewhere in the chain */
+ if (luaV_rawequalobj(gkey(n), key))
+ return gval(n); /* that's it */
+ else n = gnext(n);
+ } while (n);
+ return luaO_nilobject;
+ }
+ }
+}
+
+
+/*
+** beware: when using this function you probably need to check a GC
+** barrier and invalidate the TM cache.
+*/
+TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
+ const TValue *p = luaH_get(t, key);
+ if (p != luaO_nilobject)
+ return cast(TValue *, p);
+ else return luaH_newkey(L, t, key);
+}
+
+
+void luaH_setint (lua_State *L, Table *t, int key, TValue *value) {
+ const TValue *p = luaH_getint(t, key);
+ TValue *cell;
+ if (p != luaO_nilobject)
+ cell = cast(TValue *, p);
+ else {
+ TValue k;
+ setnvalue(&k, cast_num(key));
+ cell = luaH_newkey(L, t, &k);
+ }
+ setobj2t(L, cell, value);
+}
+
+
+static int unbound_search (Table *t, unsigned int j) {
+ unsigned int i = j; /* i is zero or a present index */
+ j++;
+ /* find `i' and `j' such that i is present and j is not */
+ while (!ttisnil(luaH_getint(t, j))) {
+ i = j;
+ j *= 2;
+ if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
+ /* table was built with bad purposes: resort to linear search */
+ i = 1;
+ while (!ttisnil(luaH_getint(t, i))) i++;
+ return i - 1;
+ }
+ }
+ /* now do a binary search between them */
+ while (j - i > 1) {
+ unsigned int m = (i+j)/2;
+ if (ttisnil(luaH_getint(t, m))) j = m;
+ else i = m;
+ }
+ return i;
+}
+
+
+/*
+** Try to find a boundary in table `t'. A `boundary' is an integer index
+** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
+*/
+int luaH_getn (Table *t) {
+ unsigned int j = t->sizearray;
+ if (j > 0 && ttisnil(&t->array[j - 1])) {
+ /* there is a boundary in the array part: (binary) search for it */
+ unsigned int i = 0;
+ while (j - i > 1) {
+ unsigned int m = (i+j)/2;
+ if (ttisnil(&t->array[m - 1])) j = m;
+ else i = m;
+ }
+ return i;
+ }
+ /* else must find a boundary in hash part */
+ else if (isdummy(t->node)) /* hash part is empty? */
+ return j; /* that is easy... */
+ else return unbound_search(t, j);
+}
+
+
+
+#if defined(LUA_DEBUG)
+
+Node *luaH_mainposition (const Table *t, const TValue *key) {
+ return mainposition(t, key);
+}
+
+int luaH_isdummy (Node *n) { return isdummy(n); }
+
+#endif
diff --git a/lualib/ltable.h b/lualib/ltable.h
new file mode 100644
index 0000000..d69449b
--- /dev/null
+++ b/lualib/ltable.h
@@ -0,0 +1,45 @@
+/*
+** $Id: ltable.h,v 2.16.1.2 2013/08/30 15:49:41 roberto Exp $
+** Lua tables (hash)
+** See Copyright Notice in lua.h
+*/
+
+#ifndef ltable_h
+#define ltable_h
+
+#include "lobject.h"
+
+
+#define gnode(t,i) (&(t)->node[i])
+#define gkey(n) (&(n)->i_key.tvk)
+#define gval(n) (&(n)->i_val)
+#define gnext(n) ((n)->i_key.nk.next)
+
+#define invalidateTMcache(t) ((t)->flags = 0)
+
+/* returns the key, given the value of a table entry */
+#define keyfromval(v) \
+ (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
+
+
+LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
+LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value);
+LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
+LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
+LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);
+LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
+LUAI_FUNC Table *luaH_new (lua_State *L);
+LUAI_FUNC void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize);
+LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize);
+LUAI_FUNC void luaH_free (lua_State *L, Table *t);
+LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
+LUAI_FUNC int luaH_getn (Table *t);
+
+
+#if defined(LUA_DEBUG)
+LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
+LUAI_FUNC int luaH_isdummy (Node *n);
+#endif
+
+
+#endif
diff --git a/lualib/ltablib.c b/lualib/ltablib.c
new file mode 100644
index 0000000..6001224
--- /dev/null
+++ b/lualib/ltablib.c
@@ -0,0 +1,283 @@
+/*
+** $Id: ltablib.c,v 1.65.1.1 2013/04/12 18:48:47 roberto Exp $
+** Library for Table Manipulation
+** See Copyright Notice in lua.h
+*/
+
+
+#include
+
+#define ltablib_c
+#define LUA_LIB
+
+#include "lua.h"
+
+#include "lauxlib.h"
+#include "lualib.h"
+
+
+#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_len(L, n))
+
+
+
+#if defined(LUA_COMPAT_MAXN)
+static int maxn (lua_State *L) {
+ lua_Number max = 0;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ lua_pushnil(L); /* first key */
+ while (lua_next(L, 1)) {
+ lua_pop(L, 1); /* remove value */
+ if (lua_type(L, -1) == LUA_TNUMBER) {
+ lua_Number v = lua_tonumber(L, -1);
+ if (v > max) max = v;
+ }
+ }
+ lua_pushnumber(L, max);
+ return 1;
+}
+#endif
+
+
+static int tinsert (lua_State *L) {
+ int e = aux_getn(L, 1) + 1; /* first empty element */
+ int pos; /* where to insert new element */
+ switch (lua_gettop(L)) {
+ case 2: { /* called with only 2 arguments */
+ pos = e; /* insert new element at the end */
+ break;
+ }
+ case 3: {
+ int i;
+ pos = luaL_checkint(L, 2); /* 2nd argument is the position */
+ luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds");
+ for (i = e; i > pos; i--) { /* move up elements */
+ lua_rawgeti(L, 1, i-1);
+ lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
+ }
+ break;
+ }
+ default: {
+ return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
+ }
+ }
+ lua_rawseti(L, 1, pos); /* t[pos] = v */
+ return 0;
+}
+
+
+static int tremove (lua_State *L) {
+ int size = aux_getn(L, 1);
+ int pos = luaL_optint(L, 2, size);
+ if (pos != size) /* validate 'pos' if given */
+ luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds");
+ lua_rawgeti(L, 1, pos); /* result = t[pos] */
+ for ( ; pos < size; pos++) {
+ lua_rawgeti(L, 1, pos+1);
+ lua_rawseti(L, 1, pos); /* t[pos] = t[pos+1] */
+ }
+ lua_pushnil(L);
+ lua_rawseti(L, 1, pos); /* t[pos] = nil */
+ return 1;
+}
+
+
+static void addfield (lua_State *L, luaL_Buffer *b, int i) {
+ lua_rawgeti(L, 1, i);
+ if (!lua_isstring(L, -1))
+ luaL_error(L, "invalid value (%s) at index %d in table for "
+ LUA_QL("concat"), luaL_typename(L, -1), i);
+ luaL_addvalue(b);
+}
+
+
+static int tconcat (lua_State *L) {
+ luaL_Buffer b;
+ size_t lsep;
+ int i, last;
+ const char *sep = luaL_optlstring(L, 2, "", &lsep);
+ luaL_checktype(L, 1, LUA_TTABLE);
+ i = luaL_optint(L, 3, 1);
+ last = luaL_opt(L, luaL_checkint, 4, luaL_len(L, 1));
+ luaL_buffinit(L, &b);
+ for (; i < last; i++) {
+ addfield(L, &b, i);
+ luaL_addlstring(&b, sep, lsep);
+ }
+ if (i == last) /* add last value (if interval was not empty) */
+ addfield(L, &b, i);
+ luaL_pushresult(&b);
+ return 1;
+}
+
+
+/*
+** {======================================================
+** Pack/unpack
+** =======================================================
+*/
+
+static int pack (lua_State *L) {
+ int n = lua_gettop(L); /* number of elements to pack */
+ lua_createtable(L, n, 1); /* create result table */
+ lua_pushinteger(L, n);
+ lua_setfield(L, -2, "n"); /* t.n = number of elements */
+ if (n > 0) { /* at least one element? */
+ int i;
+ lua_pushvalue(L, 1);
+ lua_rawseti(L, -2, 1); /* insert first element */
+ lua_replace(L, 1); /* move table into index 1 */
+ for (i = n; i >= 2; i--) /* assign other elements */
+ lua_rawseti(L, 1, i);
+ }
+ return 1; /* return table */
+}
+
+
+static int unpack (lua_State *L) {
+ int i, e, n;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ i = luaL_optint(L, 2, 1);
+ e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1));
+ if (i > e) return 0; /* empty range */
+ n = e - i + 1; /* number of elements */
+ if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
+ return luaL_error(L, "too many results to unpack");
+ lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
+ while (i++ < e) /* push arg[i + 1...e] */
+ lua_rawgeti(L, 1, i);
+ return n;
+}
+
+/* }====================================================== */
+
+
+
+/*
+** {======================================================
+** Quicksort
+** (based on `Algorithms in MODULA-3', Robert Sedgewick;
+** Addison-Wesley, 1993.)
+** =======================================================
+*/
+
+
+static void set2 (lua_State *L, int i, int j) {
+ lua_rawseti(L, 1, i);
+ lua_rawseti(L, 1, j);
+}
+
+static int sort_comp (lua_State *L, int a, int b) {
+ if (!lua_isnil(L, 2)) { /* function? */
+ int res;
+ lua_pushvalue(L, 2);
+ lua_pushvalue(L, a-1); /* -1 to compensate function */
+ lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */
+ lua_call(L, 2, 1);
+ res = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+ return res;
+ }
+ else /* a < b? */
+ return lua_compare(L, a, b, LUA_OPLT);
+}
+
+static void auxsort (lua_State *L, int l, int u) {
+ while (l < u) { /* for tail recursion */
+ int i, j;
+ /* sort elements a[l], a[(l+u)/2] and a[u] */
+ lua_rawgeti(L, 1, l);
+ lua_rawgeti(L, 1, u);
+ if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */
+ set2(L, l, u); /* swap a[l] - a[u] */
+ else
+ lua_pop(L, 2);
+ if (u-l == 1) break; /* only 2 elements */
+ i = (l+u)/2;
+ lua_rawgeti(L, 1, i);
+ lua_rawgeti(L, 1, l);
+ if (sort_comp(L, -2, -1)) /* a[i]= P */
+ while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
+ if (i>=u) luaL_error(L, "invalid order function for sorting");
+ lua_pop(L, 1); /* remove a[i] */
+ }
+ /* repeat --j until a[j] <= P */
+ while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
+ if (j<=l) luaL_error(L, "invalid order function for sorting");
+ lua_pop(L, 1); /* remove a[j] */
+ }
+ if (j
+
+#define ltm_c
+#define LUA_CORE
+
+#include "lua.h"
+
+#include "lobject.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "ltable.h"
+#include "ltm.h"
+
+
+static const char udatatypename[] = "userdata";
+
+LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {
+ "no value",
+ "nil", "boolean", udatatypename, "number",
+ "string", "table", "function", udatatypename, "thread",
+ "proto", "upval" /* these last two cases are used for tests only */
+};
+
+
+void luaT_init (lua_State *L) {
+ static const char *const luaT_eventname[] = { /* ORDER TM */
+ "__index", "__newindex",
+ "__gc", "__mode", "__len", "__eq",
+ "__add", "__sub", "__mul", "__div", "__mod",
+ "__pow", "__unm", "__lt", "__le",
+ "__concat", "__call"
+ };
+ int i;
+ for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]);
+ luaS_fix(G(L)->tmname[i]); /* never collect these names */
+ }
+}
+
+
+/*
+** function to be used with macro "fasttm": optimized for absence of
+** tag methods
+*/
+const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
+ const TValue *tm = luaH_getstr(events, ename);
+ lua_assert(event <= TM_EQ);
+ if (ttisnil(tm)) { /* no tag method? */
+ events->flags |= cast_byte(1u<metatable;
+ break;
+ case LUA_TUSERDATA:
+ mt = uvalue(o)->metatable;
+ break;
+ default:
+ mt = G(L)->mt[ttypenv(o)];
+ }
+ return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
+}
+
diff --git a/lualib/ltm.h b/lualib/ltm.h
new file mode 100644
index 0000000..7f89c84
--- /dev/null
+++ b/lualib/ltm.h
@@ -0,0 +1,57 @@
+/*
+** $Id: ltm.h,v 2.11.1.1 2013/04/12 18:48:47 roberto Exp $
+** Tag methods
+** See Copyright Notice in lua.h
+*/
+
+#ifndef ltm_h
+#define ltm_h
+
+
+#include "lobject.h"
+
+
+/*
+* WARNING: if you change the order of this enumeration,
+* grep "ORDER TM"
+*/
+typedef enum {
+ TM_INDEX,
+ TM_NEWINDEX,
+ TM_GC,
+ TM_MODE,
+ TM_LEN,
+ TM_EQ, /* last tag method with `fast' access */
+ TM_ADD,
+ TM_SUB,
+ TM_MUL,
+ TM_DIV,
+ TM_MOD,
+ TM_POW,
+ TM_UNM,
+ TM_LT,
+ TM_LE,
+ TM_CONCAT,
+ TM_CALL,
+ TM_N /* number of elements in the enum */
+} TMS;
+
+
+
+#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 ttypename(x) luaT_typenames_[(x) + 1]
+#define objtypename(x) ttypename(ttypenv(x))
+
+LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS];
+
+
+LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
+LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
+ TMS event);
+LUAI_FUNC void luaT_init (lua_State *L);
+
+#endif
diff --git a/lualib/lua.c b/lualib/lua.c
new file mode 100644
index 0000000..4345e55
--- /dev/null
+++ b/lualib/lua.c
@@ -0,0 +1,497 @@
+/*
+** $Id: lua.c,v 1.206.1.1 2013/04/12 18:48:47 roberto Exp $
+** Lua stand-alone interpreter
+** See Copyright Notice in lua.h
+*/
+
+
+#include
+#include
+#include
+#include
+
+#define lua_c
+
+#include "lua.h"
+
+#include "lauxlib.h"
+#include "lualib.h"
+
+
+#if !defined(LUA_PROMPT)
+#define LUA_PROMPT "> "
+#define LUA_PROMPT2 ">> "
+#endif
+
+#if !defined(LUA_PROGNAME)
+#define LUA_PROGNAME "lua"
+#endif
+
+#if !defined(LUA_MAXINPUT)
+#define LUA_MAXINPUT 512
+#endif
+
+#if !defined(LUA_INIT)
+#define LUA_INIT "LUA_INIT"
+#endif
+
+#define LUA_INITVERSION \
+ LUA_INIT "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
+
+
+/*
+** lua_stdin_is_tty detects whether the standard input is a 'tty' (that
+** is, whether we're running lua interactively).
+*/
+#if defined(LUA_USE_ISATTY)
+#include
+#define lua_stdin_is_tty() isatty(0)
+#elif defined(LUA_WIN)
+#include
+#include
+#define lua_stdin_is_tty() _isatty(_fileno(stdin))
+#else
+#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
+#endif
+
+
+/*
+** lua_readline defines how to show a prompt and then read a line from
+** the standard input.
+** lua_saveline defines how to "save" a read line in a "history".
+** lua_freeline defines how to free a line read by lua_readline.
+*/
+#if defined(LUA_USE_READLINE)
+
+#include
+#include
+#include
+#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
+#define lua_saveline(L,idx) \
+ if (lua_rawlen(L,idx) > 0) /* non-empty line? */ \
+ add_history(lua_tostring(L, idx)); /* add it to history */
+#define lua_freeline(L,b) ((void)L, free(b))
+
+#elif !defined(lua_readline)
+
+#define lua_readline(L,b,p) \
+ ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
+ fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
+#define lua_saveline(L,idx) { (void)L; (void)idx; }
+#define lua_freeline(L,b) { (void)L; (void)b; }
+
+#endif
+
+
+
+
+static lua_State *globalL = NULL;
+
+static const char *progname = LUA_PROGNAME;
+
+
+
+static void lstop (lua_State *L, lua_Debug *ar) {
+ (void)ar; /* unused arg. */
+ lua_sethook(L, NULL, 0, 0);
+ luaL_error(L, "interrupted!");
+}
+
+
+static void laction (int i) {
+ signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
+ terminate process (default action) */
+ lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
+}
+
+
+static void print_usage (const char *badoption) {
+ luai_writestringerror("%s: ", progname);
+ if (badoption[1] == 'e' || badoption[1] == 'l')
+ luai_writestringerror("'%s' needs argument\n", badoption);
+ else
+ luai_writestringerror("unrecognized option '%s'\n", badoption);
+ luai_writestringerror(
+ "usage: %s [options] [script [args]]\n"
+ "Available options are:\n"
+ " -e stat execute string " LUA_QL("stat") "\n"
+ " -i enter interactive mode after executing " LUA_QL("script") "\n"
+ " -l name require library " LUA_QL("name") "\n"
+ " -v show version information\n"
+ " -E ignore environment variables\n"
+ " -- stop handling options\n"
+ " - stop handling options and execute stdin\n"
+ ,
+ progname);
+}
+
+
+static void l_message (const char *pname, const char *msg) {
+ if (pname) luai_writestringerror("%s: ", pname);
+ luai_writestringerror("%s\n", msg);
+}
+
+
+static int report (lua_State *L, int status) {
+ if (status != LUA_OK && !lua_isnil(L, -1)) {
+ const char *msg = lua_tostring(L, -1);
+ if (msg == NULL) msg = "(error object is not a string)";
+ l_message(progname, msg);
+ lua_pop(L, 1);
+ /* force a complete garbage collection in case of errors */
+ lua_gc(L, LUA_GCCOLLECT, 0);
+ }
+ return status;
+}
+
+
+/* the next function is called unprotected, so it must avoid errors */
+static void finalreport (lua_State *L, int status) {
+ if (status != LUA_OK) {
+ const char *msg = (lua_type(L, -1) == LUA_TSTRING) ? lua_tostring(L, -1)
+ : NULL;
+ if (msg == NULL) msg = "(error object is not a string)";
+ l_message(progname, msg);
+ lua_pop(L, 1);
+ }
+}
+
+
+static int traceback (lua_State *L) {
+ const char *msg = lua_tostring(L, 1);
+ if (msg)
+ luaL_traceback(L, L, msg, 1);
+ else if (!lua_isnoneornil(L, 1)) { /* is there an error object? */
+ if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */
+ lua_pushliteral(L, "(no error message)");
+ }
+ return 1;
+}
+
+
+static int docall (lua_State *L, int narg, int nres) {
+ int status;
+ int base = lua_gettop(L) - narg; /* function index */
+ lua_pushcfunction(L, traceback); /* push traceback function */
+ lua_insert(L, base); /* put it under chunk and args */
+ globalL = L; /* to be available to 'laction' */
+ signal(SIGINT, laction);
+ status = lua_pcall(L, narg, nres, base);
+ signal(SIGINT, SIG_DFL);
+ lua_remove(L, base); /* remove traceback function */
+ return status;
+}
+
+
+static void print_version (void) {
+ luai_writestring(LUA_COPYRIGHT, strlen(LUA_COPYRIGHT));
+ luai_writeline();
+}
+
+
+static int getargs (lua_State *L, char **argv, int n) {
+ int narg;
+ int i;
+ int argc = 0;
+ while (argv[argc]) argc++; /* count total number of arguments */
+ narg = argc - (n + 1); /* number of arguments to the script */
+ luaL_checkstack(L, narg + 3, "too many arguments to script");
+ for (i=n+1; i < argc; i++)
+ lua_pushstring(L, argv[i]);
+ lua_createtable(L, narg, n + 1);
+ for (i=0; i < argc; i++) {
+ lua_pushstring(L, argv[i]);
+ lua_rawseti(L, -2, i - n);
+ }
+ return narg;
+}
+
+
+static int dofile (lua_State *L, const char *name) {
+ int status = luaL_loadfile(L, name);
+ if (status == LUA_OK) status = docall(L, 0, 0);
+ return report(L, status);
+}
+
+
+static int dostring (lua_State *L, const char *s, const char *name) {
+ int status = luaL_loadbuffer(L, s, strlen(s), name);
+ if (status == LUA_OK) status = docall(L, 0, 0);
+ return report(L, status);
+}
+
+
+static int dolibrary (lua_State *L, const char *name) {
+ int status;
+ lua_getglobal(L, "require");
+ lua_pushstring(L, name);
+ status = docall(L, 1, 1); /* call 'require(name)' */
+ if (status == LUA_OK)
+ lua_setglobal(L, name); /* global[name] = require return */
+ return report(L, status);
+}
+
+
+static const char *get_prompt (lua_State *L, int firstline) {
+ const char *p;
+ lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
+ p = lua_tostring(L, -1);
+ if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
+ return p;
+}
+
+/* mark in error messages for incomplete statements */
+#define EOFMARK ""
+#define marklen (sizeof(EOFMARK)/sizeof(char) - 1)
+
+static int incomplete (lua_State *L, int status) {
+ if (status == LUA_ERRSYNTAX) {
+ size_t lmsg;
+ const char *msg = lua_tolstring(L, -1, &lmsg);
+ if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) {
+ lua_pop(L, 1);
+ return 1;
+ }
+ }
+ return 0; /* else... */
+}
+
+
+static int pushline (lua_State *L, int firstline) {
+ char buffer[LUA_MAXINPUT];
+ char *b = buffer;
+ size_t l;
+ const char *prmt = get_prompt(L, firstline);
+ int readstatus = lua_readline(L, b, prmt);
+ lua_pop(L, 1); /* remove result from 'get_prompt' */
+ if (readstatus == 0)
+ return 0; /* no input */
+ l = strlen(b);
+ if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
+ b[l-1] = '\0'; /* remove it */
+ if (firstline && b[0] == '=') /* first line starts with `=' ? */
+ lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
+ else
+ lua_pushstring(L, b);
+ lua_freeline(L, b);
+ return 1;
+}
+
+
+static int loadline (lua_State *L) {
+ int status;
+ lua_settop(L, 0);
+ if (!pushline(L, 1))
+ return -1; /* no input */
+ for (;;) { /* repeat until gets a complete line */
+ size_t l;
+ const char *line = lua_tolstring(L, 1, &l);
+ status = luaL_loadbuffer(L, line, l, "=stdin");
+ if (!incomplete(L, status)) break; /* cannot try to add lines? */
+ if (!pushline(L, 0)) /* no more input? */
+ return -1;
+ lua_pushliteral(L, "\n"); /* add a new line... */
+ lua_insert(L, -2); /* ...between the two lines */
+ lua_concat(L, 3); /* join them */
+ }
+ lua_saveline(L, 1);
+ lua_remove(L, 1); /* remove line */
+ return status;
+}
+
+
+static void dotty (lua_State *L) {
+ int status;
+ const char *oldprogname = progname;
+ progname = NULL;
+ while ((status = loadline(L)) != -1) {
+ if (status == LUA_OK) status = docall(L, 0, LUA_MULTRET);
+ report(L, status);
+ if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */
+ luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
+ lua_getglobal(L, "print");
+ lua_insert(L, 1);
+ if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK)
+ l_message(progname, lua_pushfstring(L,
+ "error calling " LUA_QL("print") " (%s)",
+ lua_tostring(L, -1)));
+ }
+ }
+ lua_settop(L, 0); /* clear stack */
+ luai_writeline();
+ progname = oldprogname;
+}
+
+
+static int handle_script (lua_State *L, char **argv, int n) {
+ int status;
+ const char *fname;
+ int narg = getargs(L, argv, n); /* collect arguments */
+ lua_setglobal(L, "arg");
+ fname = argv[n];
+ if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
+ fname = NULL; /* stdin */
+ status = luaL_loadfile(L, fname);
+ lua_insert(L, -(narg+1));
+ if (status == LUA_OK)
+ status = docall(L, narg, LUA_MULTRET);
+ else
+ lua_pop(L, narg);
+ return report(L, status);
+}
+
+
+/* check that argument has no extra characters at the end */
+#define noextrachars(x) {if ((x)[2] != '\0') return -1;}
+
+
+/* indices of various argument indicators in array args */
+#define has_i 0 /* -i */
+#define has_v 1 /* -v */
+#define has_e 2 /* -e */
+#define has_E 3 /* -E */
+
+#define num_has 4 /* number of 'has_*' */
+
+
+static int collectargs (char **argv, int *args) {
+ int i;
+ for (i = 1; argv[i] != NULL; i++) {
+ if (argv[i][0] != '-') /* not an option? */
+ return i;
+ switch (argv[i][1]) { /* option */
+ case '-':
+ noextrachars(argv[i]);
+ return (argv[i+1] != NULL ? i+1 : 0);
+ case '\0':
+ return i;
+ case 'E':
+ args[has_E] = 1;
+ break;
+ case 'i':
+ noextrachars(argv[i]);
+ args[has_i] = 1; /* go through */
+ case 'v':
+ noextrachars(argv[i]);
+ args[has_v] = 1;
+ break;
+ case 'e':
+ args[has_e] = 1; /* go through */
+ case 'l': /* both options need an argument */
+ if (argv[i][2] == '\0') { /* no concatenated argument? */
+ i++; /* try next 'argv' */
+ if (argv[i] == NULL || argv[i][0] == '-')
+ return -(i - 1); /* no next argument or it is another option */
+ }
+ break;
+ default: /* invalid option; return its index... */
+ return -i; /* ...as a negative value */
+ }
+ }
+ return 0;
+}
+
+
+static int runargs (lua_State *L, char **argv, int n) {
+ int i;
+ for (i = 1; i < n; i++) {
+ lua_assert(argv[i][0] == '-');
+ switch (argv[i][1]) { /* option */
+ case 'e': {
+ const char *chunk = argv[i] + 2;
+ if (*chunk == '\0') chunk = argv[++i];
+ lua_assert(chunk != NULL);
+ if (dostring(L, chunk, "=(command line)") != LUA_OK)
+ return 0;
+ break;
+ }
+ case 'l': {
+ const char *filename = argv[i] + 2;
+ if (*filename == '\0') filename = argv[++i];
+ lua_assert(filename != NULL);
+ if (dolibrary(L, filename) != LUA_OK)
+ return 0; /* stop if file fails */
+ break;
+ }
+ default: break;
+ }
+ }
+ return 1;
+}
+
+
+static int handle_luainit (lua_State *L) {
+ const char *name = "=" LUA_INITVERSION;
+ const char *init = getenv(name + 1);
+ if (init == NULL) {
+ name = "=" LUA_INIT;
+ init = getenv(name + 1); /* try alternative name */
+ }
+ if (init == NULL) return LUA_OK;
+ else if (init[0] == '@')
+ return dofile(L, init+1);
+ else
+ return dostring(L, init, name);
+}
+
+
+static int pmain (lua_State *L) {
+ int argc = (int)lua_tointeger(L, 1);
+ char **argv = (char **)lua_touserdata(L, 2);
+ int script;
+ int args[num_has];
+ args[has_i] = args[has_v] = args[has_e] = args[has_E] = 0;
+ if (argv[0] && argv[0][0]) progname = argv[0];
+ script = collectargs(argv, args);
+ if (script < 0) { /* invalid arg? */
+ print_usage(argv[-script]);
+ return 0;
+ }
+ if (args[has_v]) print_version();
+ if (args[has_E]) { /* option '-E'? */
+ lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
+ lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
+ }
+ /* open standard libraries */
+ luaL_checkversion(L);
+ lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
+ luaL_openlibs(L); /* open libraries */
+ lua_gc(L, LUA_GCRESTART, 0);
+ if (!args[has_E] && handle_luainit(L) != LUA_OK)
+ return 0; /* error running LUA_INIT */
+ /* execute arguments -e and -l */
+ if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
+ /* execute main script (if there is one) */
+ if (script && handle_script(L, argv, script) != LUA_OK) return 0;
+ if (args[has_i]) /* -i option? */
+ dotty(L);
+ else if (script == 0 && !args[has_e] && !args[has_v]) { /* no arguments? */
+ if (lua_stdin_is_tty()) {
+ print_version();
+ dotty(L);
+ }
+ else dofile(L, NULL); /* executes stdin as a file */
+ }
+ lua_pushboolean(L, 1); /* signal no errors */
+ return 1;
+}
+
+
+int main (int argc, char **argv) {
+ int status, result;
+ lua_State *L = luaL_newstate(); /* create state */
+ if (L == NULL) {
+ l_message(argv[0], "cannot create state: not enough memory");
+ return EXIT_FAILURE;
+ }
+ /* call 'pmain' in protected mode */
+ lua_pushcfunction(L, &pmain);
+ lua_pushinteger(L, argc); /* 1st argument */
+ lua_pushlightuserdata(L, argv); /* 2nd argument */
+ status = lua_pcall(L, 2, 1, 0);
+ result = lua_toboolean(L, -1); /* get result */
+ finalreport(L, status);
+ lua_close(L);
+ return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
diff --git a/lualib/lua.h b/lualib/lua.h
new file mode 100644
index 0000000..149a2c3
--- /dev/null
+++ b/lualib/lua.h
@@ -0,0 +1,444 @@
+/*
+** $Id: lua.h,v 1.285.1.2 2013/11/11 12:09:16 roberto Exp $
+** Lua - A Scripting Language
+** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
+** See Copyright Notice at the end of this file
+*/
+
+
+#ifndef lua_h
+#define lua_h
+
+#include
+#include
+
+
+#include "luaconf.h"
+
+
+#define LUA_VERSION_MAJOR "5"
+#define LUA_VERSION_MINOR "2"
+#define LUA_VERSION_NUM 502
+#define LUA_VERSION_RELEASE "3"
+
+#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-2013 Lua.org, PUC-Rio"
+#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
+
+
+/* mark for precompiled code ('Lua') */
+#define LUA_SIGNATURE "\033Lua"
+
+/* option for multiple returns in 'lua_pcall' and 'lua_call' */
+#define LUA_MULTRET (-1)
+
+
+/*
+** pseudo-indices
+*/
+#define LUA_REGISTRYINDEX LUAI_FIRSTPSEUDOIDX
+#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
+
+
+/* thread status */
+#define LUA_OK 0
+#define LUA_YIELD 1
+#define LUA_ERRRUN 2
+#define LUA_ERRSYNTAX 3
+#define LUA_ERRMEM 4
+#define LUA_ERRGCMM 5
+#define LUA_ERRERR 6
+
+
+typedef struct lua_State lua_State;
+
+typedef int (*lua_CFunction) (lua_State *L);
+
+
+/*
+** 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);
+
+
+/*
+** prototype for memory-allocation functions
+*/
+typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
+
+
+/*
+** 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_NUMTAGS 9
+
+
+
+/* minimum Lua stack available to a C function */
+#define LUA_MINSTACK 20
+
+
+/* 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 */
+typedef LUA_NUMBER lua_Number;
+
+
+/* type for integer functions */
+typedef LUA_INTEGER lua_Integer;
+
+/* unsigned integer type */
+typedef LUA_UNSIGNED lua_Unsigned;
+
+
+
+/*
+** 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 lua_State *(lua_newthread) (lua_State *L);
+
+LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
+
+
+LUA_API const 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_remove) (lua_State *L, int idx);
+LUA_API void (lua_insert) (lua_State *L, int idx);
+LUA_API void (lua_replace) (lua_State *L, int idx);
+LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
+LUA_API int (lua_checkstack) (lua_State *L, int sz);
+
+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_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 lua_Unsigned (lua_tounsignedx) (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 size_t (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);
+
+
+/*
+** Comparison and arithmetic functions
+*/
+
+#define LUA_OPADD 0 /* ORDER TM */
+#define LUA_OPSUB 1
+#define LUA_OPMUL 2
+#define LUA_OPDIV 3
+#define LUA_OPMOD 4
+#define LUA_OPPOW 5
+#define LUA_OPUNM 6
+
+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 void (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
+LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
+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);
+
+
+/*
+** get functions (Lua -> stack)
+*/
+LUA_API void (lua_getglobal) (lua_State *L, const char *var);
+LUA_API void (lua_gettable) (lua_State *L, int idx);
+LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
+LUA_API void (lua_rawget) (lua_State *L, int idx);
+LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
+LUA_API void (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_newuserdata) (lua_State *L, size_t sz);
+LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
+LUA_API void (lua_getuservalue) (lua_State *L, int idx);
+
+
+/*
+** set functions (stack -> Lua)
+*/
+LUA_API void (lua_setglobal) (lua_State *L, const char *var);
+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_rawset) (lua_State *L, int idx);
+LUA_API void (lua_rawseti) (lua_State *L, int idx, int 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 void (lua_setuservalue) (lua_State *L, int idx);
+
+
+/*
+** 'load' and 'call' functions (load and run Lua code)
+*/
+LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
+ lua_CFunction k);
+#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
+
+LUA_API int (lua_getctx) (lua_State *L, int *ctx);
+
+LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
+ int ctx, lua_CFunction k);
+#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,
+ const char *chunkname,
+ const char *mode);
+
+LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
+
+
+/*
+** coroutine functions
+*/
+LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx,
+ lua_CFunction k);
+#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
+LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
+LUA_API int (lua_status) (lua_State *L);
+
+/*
+** 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_GCSETMAJORINC 8
+#define LUA_GCISRUNNING 9
+#define LUA_GCGEN 10
+#define LUA_GCINC 11
+
+LUA_API int (lua_gc) (lua_State *L, int what, int data);
+
+
+/*
+** 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 lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
+LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
+
+
+
+/*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*/
+
+#define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)
+#define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)
+#define lua_tounsigned(L,i) lua_tounsignedx(L,i,NULL)
+
+#define lua_pop(L,n) lua_settop(L, -(n)-1)
+
+#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_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_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
+
+#define lua_pushglobaltable(L) \
+ lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
+
+#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
+
+
+
+/*
+** {======================================================================
+** Debug API
+** =======================================================================
+*/
+
+
+/*
+** Event codes
+*/
+#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 */
+typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
+
+
+LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
+LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
+LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
+LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
+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,
+ int fidx2, int n2);
+
+LUA_API int (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
+LUA_API lua_Hook (lua_gethook) (lua_State *L);
+LUA_API int (lua_gethookmask) (lua_State *L);
+LUA_API int (lua_gethookcount) (lua_State *L);
+
+
+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) */
+ 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) */
+ char short_src[LUA_IDSIZE]; /* (S) */
+ /* private part */
+ struct CallInfo *i_ci; /* active function */
+};
+
+/* }====================================================================== */
+
+
+/******************************************************************************
+* Copyright (C) 1994-2013 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.
+******************************************************************************/
+
+
+#endif
diff --git a/lualib/lua.hpp b/lualib/lua.hpp
new file mode 100644
index 0000000..ec417f5
--- /dev/null
+++ b/lualib/lua.hpp
@@ -0,0 +1,9 @@
+// lua.hpp
+// Lua header files for C++
+// <> not supplied automatically because Lua also compiles as C++
+
+extern "C" {
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+}
diff --git a/lualib/luac.c b/lualib/luac.c
new file mode 100644
index 0000000..7409706
--- /dev/null
+++ b/lualib/luac.c
@@ -0,0 +1,432 @@
+/*
+** $Id: luac.c,v 1.69 2011/11/29 17:46:33 lhf Exp $
+** Lua compiler (saves bytecodes to files; also list bytecodes)
+** See Copyright Notice in lua.h
+*/
+
+#include
+#include
+#include
+#include
+
+#define luac_c
+#define LUA_CORE
+
+#include "lua.h"
+#include "lauxlib.h"
+
+#include "lobject.h"
+#include "lstate.h"
+#include "lundump.h"
+
+static void PrintFunction(const Proto* f, int full);
+#define luaU_print PrintFunction
+
+#define PROGNAME "luac" /* default program name */
+#define OUTPUT PROGNAME ".out" /* default output file */
+
+static int listing=0; /* list bytecodes? */
+static int dumping=1; /* dump bytecodes? */
+static int stripping=0; /* strip debug information? */
+static char Output[]={ OUTPUT }; /* default output file name */
+static const char* output=Output; /* actual output file name */
+static const char* progname=PROGNAME; /* actual program name */
+
+static void fatal(const char* message)
+{
+ fprintf(stderr,"%s: %s\n",progname,message);
+ exit(EXIT_FAILURE);
+}
+
+static void cannot(const char* what)
+{
+ fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno));
+ exit(EXIT_FAILURE);
+}
+
+static void usage(const char* message)
+{
+ if (*message=='-')
+ fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message);
+ else
+ fprintf(stderr,"%s: %s\n",progname,message);
+ fprintf(stderr,
+ "usage: %s [options] [filenames]\n"
+ "Available options are:\n"
+ " -l list (use -l -l for full listing)\n"
+ " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
+ " -p parse only\n"
+ " -s strip debug information\n"
+ " -v show version information\n"
+ " -- stop handling options\n"
+ " - stop handling options and process stdin\n"
+ ,progname,Output);
+ exit(EXIT_FAILURE);
+}
+
+#define IS(s) (strcmp(argv[i],s)==0)
+
+static int doargs(int argc, char* argv[])
+{
+ int i;
+ int version=0;
+ if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];
+ for (i=1; itop+(i))
+
+static const Proto* combine(lua_State* L, int n)
+{
+ if (n==1)
+ return toproto(L,-1);
+ else
+ {
+ Proto* f;
+ int i=n;
+ if (lua_load(L,reader,&i,"=(" PROGNAME ")",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));
+ f=toproto(L,-1);
+ for (i=0; ip[i]=toproto(L,i-n-1);
+ if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;
+ }
+ f->sizelineinfo=0;
+ return f;
+ }
+}
+
+static int writer(lua_State* L, const void* p, size_t size, void* u)
+{
+ UNUSED(L);
+ return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
+}
+
+static int pmain(lua_State* L)
+{
+ int argc=(int)lua_tointeger(L,1);
+ char** argv=(char**)lua_touserdata(L,2);
+ const Proto* f;
+ int i;
+ if (!lua_checkstack(L,argc)) fatal("too many input files");
+ for (i=0; i1);
+ if (dumping)
+ {
+ FILE* D= (output==NULL) ? stdout : fopen(output,"wb");
+ if (D==NULL) cannot("open");
+ lua_lock(L);
+ luaU_dump(L,f,writer,D,stripping);
+ lua_unlock(L);
+ if (ferror(D)) cannot("write");
+ if (fclose(D)) cannot("close");
+ }
+ return 0;
+}
+
+int main(int argc, char* argv[])
+{
+ lua_State* L;
+ int i=doargs(argc,argv);
+ argc-=i; argv+=i;
+ if (argc<=0) usage("no input files given");
+ L=luaL_newstate();
+ if (L==NULL) fatal("cannot create state: not enough memory");
+ lua_pushcfunction(L,&pmain);
+ lua_pushinteger(L,argc);
+ lua_pushlightuserdata(L,argv);
+ if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
+ lua_close(L);
+ return EXIT_SUCCESS;
+}
+
+/*
+** $Id: print.c,v 1.69 2013/07/04 01:03:46 lhf Exp $
+** print bytecodes
+** See Copyright Notice in lua.h
+*/
+
+#include
+#include
+
+#define luac_c
+#define LUA_CORE
+
+#include "ldebug.h"
+#include "lobject.h"
+#include "lopcodes.h"
+
+#define VOID(p) ((const void*)(p))
+
+static void PrintString(const TString* ts)
+{
+ const char* s=getstr(ts);
+ size_t i,n=ts->tsv.len;
+ printf("%c",'"');
+ for (i=0; ik[i];
+ switch (ttypenv(o))
+ {
+ case LUA_TNIL:
+ printf("nil");
+ break;
+ case LUA_TBOOLEAN:
+ printf(bvalue(o) ? "true" : "false");
+ break;
+ case LUA_TNUMBER:
+ printf(LUA_NUMBER_FMT,nvalue(o));
+ break;
+ case LUA_TSTRING:
+ PrintString(rawtsvalue(o));
+ break;
+ default: /* cannot happen */
+ printf("? type=%d",ttype(o));
+ break;
+ }
+}
+
+#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
+#define MYK(x) (-1-(x))
+
+static void PrintCode(const Proto* f)
+{
+ const Instruction* code=f->code;
+ int pc,n=f->sizecode;
+ for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t");
+ printf("%-9s\t",luaP_opnames[o]);
+ switch (getOpMode(o))
+ {
+ case iABC:
+ printf("%d",a);
+ if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (MYK(INDEXK(b))) : b);
+ if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (MYK(INDEXK(c))) : c);
+ break;
+ case iABx:
+ printf("%d",a);
+ if (getBMode(o)==OpArgK) printf(" %d",MYK(bx));
+ if (getBMode(o)==OpArgU) printf(" %d",bx);
+ break;
+ case iAsBx:
+ printf("%d %d",a,sbx);
+ break;
+ case iAx:
+ printf("%d",MYK(ax));
+ break;
+ }
+ switch (o)
+ {
+ case OP_LOADK:
+ printf("\t; "); PrintConstant(f,bx);
+ break;
+ case OP_GETUPVAL:
+ case OP_SETUPVAL:
+ printf("\t; %s",UPVALNAME(b));
+ break;
+ case OP_GETTABUP:
+ printf("\t; %s",UPVALNAME(b));
+ if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
+ break;
+ case OP_SETTABUP:
+ printf("\t; %s",UPVALNAME(a));
+ if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); }
+ if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
+ break;
+ case OP_GETTABLE:
+ case OP_SELF:
+ if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
+ break;
+ case OP_SETTABLE:
+ case OP_ADD:
+ case OP_SUB:
+ case OP_MUL:
+ case OP_DIV:
+ case OP_POW:
+ case OP_EQ:
+ case OP_LT:
+ case OP_LE:
+ if (ISK(b) || ISK(c))
+ {
+ printf("\t; ");
+ if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
+ printf(" ");
+ if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
+ }
+ break;
+ case OP_JMP:
+ case OP_FORLOOP:
+ case OP_FORPREP:
+ case OP_TFORLOOP:
+ printf("\t; to %d",sbx+pc+2);
+ break;
+ case OP_CLOSURE:
+ printf("\t; %p",VOID(f->p[bx]));
+ break;
+ case OP_SETLIST:
+ if (c==0) printf("\t; %d",(int)code[++pc]); else printf("\t; %d",c);
+ break;
+ case OP_EXTRAARG:
+ printf("\t; "); PrintConstant(f,ax);
+ break;
+ default:
+ break;
+ }
+ printf("\n");
+ }
+}
+
+#define SS(x) ((x==1)?"":"s")
+#define S(x) (int)(x),SS(x)
+
+static void PrintHeader(const Proto* f)
+{
+ const char* s=f->source ? getstr(f->source) : "=?";
+ if (*s=='@' || *s=='=')
+ s++;
+ else if (*s==LUA_SIGNATURE[0])
+ s="(bstring)";
+ else
+ s="(string)";
+ printf("\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
+ (f->linedefined==0)?"main":"function",s,
+ f->linedefined,f->lastlinedefined,
+ S(f->sizecode),VOID(f));
+ printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
+ (int)(f->numparams),f->is_vararg?"+":"",SS(f->numparams),
+ S(f->maxstacksize),S(f->sizeupvalues));
+ printf("%d local%s, %d constant%s, %d function%s\n",
+ S(f->sizelocvars),S(f->sizek),S(f->sizep));
+}
+
+static void PrintDebug(const Proto* f)
+{
+ int i,n;
+ n=f->sizek;
+ printf("constants (%d) for %p:\n",n,VOID(f));
+ for (i=0; isizelocvars;
+ printf("locals (%d) for %p:\n",n,VOID(f));
+ for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
+ }
+ n=f->sizeupvalues;
+ printf("upvalues (%d) for %p:\n",n,VOID(f));
+ for (i=0; iupvalues[i].instack,f->upvalues[i].idx);
+ }
+}
+
+static void PrintFunction(const Proto* f, int full)
+{
+ int i,n=f->sizep;
+ PrintHeader(f);
+ PrintCode(f);
+ if (full) PrintDebug(f);
+ for (i=0; ip[i],full);
+}
diff --git a/lualib/luaconf.h b/lualib/luaconf.h
new file mode 100644
index 0000000..18be9a9
--- /dev/null
+++ b/lualib/luaconf.h
@@ -0,0 +1,551 @@
+/*
+** $Id: luaconf.h,v 1.176.1.1 2013/04/12 18:48:47 roberto Exp $
+** Configuration file for Lua
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef lconfig_h
+#define lconfig_h
+
+#include
+#include
+
+
+/*
+** ==================================================================
+** Search for "@@" to find all configurable definitions.
+** ===================================================================
+*/
+
+
+/*
+@@ LUA_ANSI controls the use of non-ansi features.
+** CHANGE it (define it) if you want Lua to avoid the use of any
+** non-ansi feature or library.
+*/
+#if !defined(LUA_ANSI) && defined(__STRICT_ANSI__)
+#define LUA_ANSI
+#endif
+
+
+#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE)
+#define LUA_WIN /* enable goodies for regular Windows platforms */
+#endif
+
+#if defined(LUA_WIN)
+#define LUA_DL_DLL
+#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
+#endif
+
+
+
+#if defined(LUA_USE_LINUX)
+#define LUA_USE_POSIX
+#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
+#define LUA_USE_READLINE /* needs some extra libraries */
+#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
+#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
+#define LUA_USE_LONGLONG /* assume support for long long */
+#endif
+
+#if defined(LUA_USE_MACOSX)
+#define LUA_USE_POSIX
+#define LUA_USE_DLOPEN /* does not need -ldl */
+#define LUA_USE_READLINE /* needs an extra library: -lreadline */
+#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
+#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
+#define LUA_USE_LONGLONG /* assume support for long long */
+#endif
+
+
+
+/*
+@@ LUA_USE_POSIX includes all functionality listed as X/Open System
+@* Interfaces Extension (XSI).
+** CHANGE it (define it) if your system is XSI compatible.
+*/
+#if defined(LUA_USE_POSIX)
+#define LUA_USE_MKSTEMP
+#define LUA_USE_ISATTY
+#define LUA_USE_POPEN
+#define LUA_USE_ULONGJMP
+#define LUA_USE_GMTIME_R
+#endif
+
+
+
+/*
+@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
+@* Lua libraries.
+@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
+@* C libraries.
+** CHANGE them if your machine has a non-conventional directory
+** hierarchy or if you want to install your libraries in
+** non-conventional directories.
+*/
+#if defined(_WIN32) /* { */
+/*
+** In Windows, any exclamation mark ('!') in the path is replaced by the
+** path of the directory of the executable file of the current process.
+*/
+#define LUA_LDIR "!\\lua\\"
+#define LUA_CDIR "!\\"
+#define LUA_PATH_DEFAULT \
+ LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
+ LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" ".\\?.lua"
+#define LUA_CPATH_DEFAULT \
+ LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" ".\\?.dll"
+
+#else /* }{ */
+
+#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
+#define LUA_ROOT "/usr/local/"
+#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR
+#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR
+#define LUA_PATH_DEFAULT \
+ LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
+ LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" "./?.lua"
+#define LUA_CPATH_DEFAULT \
+ LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
+#endif /* } */
+
+
+/*
+@@ LUA_DIRSEP is the directory separator (for submodules).
+** CHANGE it if your machine does not use "/" as the directory separator
+** and is not Windows. (On Windows Lua automatically uses "\".)
+*/
+#if defined(_WIN32)
+#define LUA_DIRSEP "\\"
+#else
+#define LUA_DIRSEP "/"
+#endif
+
+
+/*
+@@ LUA_ENV is the name of the variable that holds the current
+@@ environment, used to access global names.
+** CHANGE it if you do not like this name.
+*/
+#define LUA_ENV "_ENV"
+
+
+/*
+@@ LUA_API is a mark for all core API functions.
+@@ LUALIB_API is a mark for all auxiliary library functions.
+@@ LUAMOD_API is a mark for all standard library opening functions.
+** CHANGE them if you need to define those functions in some special way.
+** For instance, if you want to create one Windows DLL with the core and
+** the libraries, you may want to use the following definition (define
+** LUA_BUILD_AS_DLL to get it).
+*/
+#if defined(LUA_BUILD_AS_DLL) /* { */
+
+#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
+#define LUA_API __declspec(dllexport)
+#else /* }{ */
+#define LUA_API __declspec(dllimport)
+#endif /* } */
+
+#else /* }{ */
+
+#define LUA_API extern
+
+#endif /* } */
+
+
+/* more often than not the libs go together with the core */
+#define LUALIB_API LUA_API
+#define LUAMOD_API LUALIB_API
+
+
+/*
+@@ LUAI_FUNC is a mark for all extern functions that are not to be
+@* exported to outside modules.
+@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
+@* that are not to be exported to outside modules (LUAI_DDEF for
+@* definitions and LUAI_DDEC for declarations).
+** CHANGE them if you need to mark them in some special way. Elf/gcc
+** (versions 3.2 and later) mark them as "hidden" to optimize access
+** when Lua is compiled as a shared library. Not all elf targets support
+** this attribute. Unfortunately, gcc does not offer a way to check
+** whether the target offers that support, and those without support
+** give a warning about it. To avoid these warnings, change to the
+** default definition.
+*/
+#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
+ defined(__ELF__) /* { */
+#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
+#define LUAI_DDEC LUAI_FUNC
+#define LUAI_DDEF /* empty */
+
+#else /* }{ */
+#define LUAI_FUNC extern
+#define LUAI_DDEC extern
+#define LUAI_DDEF /* empty */
+#endif /* } */
+
+
+
+/*
+@@ LUA_QL describes how error messages quote program elements.
+** CHANGE it if you want a different appearance.
+*/
+#define LUA_QL(x) "'" x "'"
+#define LUA_QS LUA_QL("%s")
+
+
+/*
+@@ LUA_IDSIZE gives the maximum size for the description of the source
+@* of a function in debug information.
+** CHANGE it if you want a different size.
+*/
+#define LUA_IDSIZE 60
+
+
+/*
+@@ luai_writestring/luai_writeline define how 'print' prints its results.
+** They are only used in libraries and the stand-alone program. (The #if
+** avoids including 'stdio.h' everywhere.)
+*/
+#if defined(LUA_LIB) || defined(lua_c)
+#include
+#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
+#define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
+#endif
+
+/*
+@@ luai_writestringerror defines how to print error messages.
+** (A format string with one argument is enough for Lua...)
+*/
+#define luai_writestringerror(s,p) \
+ (fprintf(stderr, (s), (p)), fflush(stderr))
+
+
+/*
+@@ LUAI_MAXSHORTLEN is the 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.)
+*/
+#define LUAI_MAXSHORTLEN 40
+
+
+
+/*
+** {==================================================================
+** Compatibility with previous versions
+** ===================================================================
+*/
+
+/*
+@@ LUA_COMPAT_ALL controls all compatibility options.
+** You can define it to get all options, or change specific options
+** to fit your specific needs.
+*/
+#if defined(LUA_COMPAT_ALL) /* { */
+
+/*
+@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
+** You can replace it with 'table.unpack'.
+*/
+#define LUA_COMPAT_UNPACK
+
+/*
+@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
+** You can replace it with 'package.searchers'.
+*/
+#define LUA_COMPAT_LOADERS
+
+/*
+@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
+** You can call your C function directly (with light C functions).
+*/
+#define lua_cpcall(L,f,u) \
+ (lua_pushcfunction(L, (f)), \
+ lua_pushlightuserdata(L,(u)), \
+ lua_pcall(L,1,0,0))
+
+
+/*
+@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
+** You can rewrite 'log10(x)' as 'log(x, 10)'.
+*/
+#define LUA_COMPAT_LOG10
+
+/*
+@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
+** library. You can rewrite 'loadstring(s)' as 'load(s)'.
+*/
+#define LUA_COMPAT_LOADSTRING
+
+/*
+@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
+*/
+#define LUA_COMPAT_MAXN
+
+/*
+@@ The following macros supply trivial compatibility for some
+** changes in the API. The macros themselves document how to
+** change your code to avoid using them.
+*/
+#define lua_strlen(L,i) lua_rawlen(L, (i))
+
+#define lua_objlen(L,i) lua_rawlen(L, (i))
+
+#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
+#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
+
+/*
+@@ LUA_COMPAT_MODULE controls compatibility with previous
+** module functions 'module' (Lua) and 'luaL_register' (C).
+*/
+#define LUA_COMPAT_MODULE
+
+#endif /* } */
+
+/* }================================================================== */
+
+
+
+/*
+@@ LUAI_BITSINT defines the number of bits in an int.
+** CHANGE here if Lua cannot automatically detect the number of bits of
+** your machine. Probably you do not need to change this.
+*/
+/* avoid overflows in comparison */
+#if INT_MAX-20 < 32760 /* { */
+#define LUAI_BITSINT 16
+#elif INT_MAX > 2147483640L /* }{ */
+/* int has at least 32 bits */
+#define LUAI_BITSINT 32
+#else /* }{ */
+#error "you must define LUA_BITSINT with number of bits in an integer"
+#endif /* } */
+
+
+/*
+@@ LUA_INT32 is an signed integer with exactly 32 bits.
+@@ LUAI_UMEM is an unsigned integer big enough to count the total
+@* memory used by Lua.
+@@ LUAI_MEM is a signed integer big enough to count the total memory
+@* used by Lua.
+** CHANGE here if for some weird reason the default definitions are not
+** good enough for your machine. Probably you do not need to change
+** this.
+*/
+#if LUAI_BITSINT >= 32 /* { */
+#define LUA_INT32 int
+#define LUAI_UMEM size_t
+#define LUAI_MEM ptrdiff_t
+#else /* }{ */
+/* 16-bit ints */
+#define LUA_INT32 long
+#define LUAI_UMEM unsigned long
+#define LUAI_MEM long
+#endif /* } */
+
+
+/*
+@@ LUAI_MAXSTACK limits the size of the Lua stack.
+** CHANGE it if you need a different limit. This limit is arbitrary;
+** its only purpose is to stop Lua to consume unlimited stack
+** space (and to reserve some numbers for pseudo-indices).
+*/
+#if LUAI_BITSINT >= 32
+#define LUAI_MAXSTACK 1000000
+#else
+#define LUAI_MAXSTACK 15000
+#endif
+
+/* reserve some space for error handling */
+#define LUAI_FIRSTPSEUDOIDX (-LUAI_MAXSTACK - 1000)
+
+
+
+
+/*
+@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
+** CHANGE it if it uses too much C-stack space.
+*/
+#define LUAL_BUFFERSIZE BUFSIZ
+
+
+
+
+/*
+** {==================================================================
+@@ LUA_NUMBER is the type of numbers in Lua.
+** CHANGE the following definitions only if you want to build Lua
+** with a number type different from double. You may also need to
+** change lua_number2int & lua_number2integer.
+** ===================================================================
+*/
+
+#define LUA_NUMBER_DOUBLE
+#define LUA_NUMBER double
+
+/*
+@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
+@* over a number.
+*/
+#define LUAI_UACNUMBER double
+
+
+/*
+@@ LUA_NUMBER_SCAN is the format for reading numbers.
+@@ LUA_NUMBER_FMT is the format for writing numbers.
+@@ lua_number2str converts a number to a string.
+@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
+*/
+#define LUA_NUMBER_SCAN "%lf"
+#define LUA_NUMBER_FMT "%.14g"
+#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
+#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
+
+
+/*
+@@ l_mathop allows the addition of an 'l' or 'f' to all math operations
+*/
+#define l_mathop(x) (x)
+
+
+/*
+@@ lua_str2number converts a decimal numeric string to a number.
+@@ lua_strx2number converts an hexadecimal numeric string to a number.
+** In C99, 'strtod' does both conversions. C89, however, has no function
+** to convert floating hexadecimal strings to numbers. For these
+** systems, you can leave 'lua_strx2number' undefined and Lua will
+** provide its own implementation.
+*/
+#define lua_str2number(s,p) strtod((s), (p))
+
+#if defined(LUA_USE_STRTODHEX)
+#define lua_strx2number(s,p) strtod((s), (p))
+#endif
+
+
+/*
+@@ The luai_num* macros define the primitive operations over numbers.
+*/
+
+/* the following operations need the math library */
+#if defined(lobject_c) || defined(lvm_c)
+#include
+#define luai_nummod(L,a,b) ((a) - l_mathop(floor)((a)/(b))*(b))
+#define luai_numpow(L,a,b) (l_mathop(pow)(a,b))
+#endif
+
+/* these are quite standard operations */
+#if defined(LUA_CORE)
+#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_numdiv(L,a,b) ((a)/(b))
+#define luai_numunm(L,a) (-(a))
+#define luai_numeq(a,b) ((a)==(b))
+#define luai_numlt(L,a,b) ((a)<(b))
+#define luai_numle(L,a,b) ((a)<=(b))
+#define luai_numisnan(L,a) (!luai_numeq((a), (a)))
+#endif
+
+
+
+/*
+@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
+** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
+** machines, ptrdiff_t gives a good choice between int or long.)
+*/
+#define LUA_INTEGER ptrdiff_t
+
+/*
+@@ LUA_UNSIGNED is the integral type used by lua_pushunsigned/lua_tounsigned.
+** It must have at least 32 bits.
+*/
+#define LUA_UNSIGNED unsigned LUA_INT32
+
+
+
+/*
+** Some tricks with doubles
+*/
+
+#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
+/*
+** The next definitions activate some tricks to speed up the
+** conversion from doubles to integer types, mainly to LUA_UNSIGNED.
+**
+@@ LUA_MSASMTRICK uses Microsoft assembler to avoid clashes with a
+** DirectX idiosyncrasy.
+**
+@@ LUA_IEEE754TRICK uses a trick that should work on any machine
+** using IEEE754 with a 32-bit integer type.
+**
+@@ LUA_IEEELL extends the trick to LUA_INTEGER; should only be
+** defined when LUA_INTEGER is a 32-bit integer.
+**
+@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
+** (0 for little endian, 1 for big endian); if not defined, Lua will
+** check it dynamically for LUA_IEEE754TRICK (but not for LUA_NANTRICK).
+**
+@@ LUA_NANTRICK controls the use of a trick to pack all types into
+** a single double value, using NaN values to represent non-number
+** values. The trick only works on 32-bit machines (ints and pointers
+** are 32-bit values) with numbers represented as IEEE 754-2008 doubles
+** with conventional endianess (12345678 or 87654321), in CPUs that do
+** not produce signaling NaN values (all NaNs are quiet).
+*/
+
+/* Microsoft compiler on a Pentium (32 bit) ? */
+#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
+
+#define LUA_MSASMTRICK
+#define LUA_IEEEENDIAN 0
+#define LUA_NANTRICK
+
+
+/* pentium 32 bits? */
+#elif defined(__i386__) || defined(__i386) || defined(__X86__) /* }{ */
+
+#define LUA_IEEE754TRICK
+#define LUA_IEEELL
+#define LUA_IEEEENDIAN 0
+#define LUA_NANTRICK
+
+/* pentium 64 bits? */
+#elif defined(__x86_64) /* }{ */
+
+#define LUA_IEEE754TRICK
+#define LUA_IEEEENDIAN 0
+
+#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */
+
+#define LUA_IEEE754TRICK
+#define LUA_IEEEENDIAN 1
+
+#else /* }{ */
+
+/* assume IEEE754 and a 32-bit integer type */
+#define LUA_IEEE754TRICK
+
+#endif /* } */
+
+#endif /* } */
+
+/* }================================================================== */
+
+
+
+
+/* =================================================================== */
+
+/*
+** Local configuration. You can use this space to add your redefinitions
+** without modifying the main part of the file.
+*/
+
+
+
+#endif
+
diff --git a/lualib/lualib.h b/lualib/lualib.h
new file mode 100644
index 0000000..da82005
--- /dev/null
+++ b/lualib/lualib.h
@@ -0,0 +1,55 @@
+/*
+** $Id: lualib.h,v 1.43.1.1 2013/04/12 18:48:47 roberto Exp $
+** Lua standard libraries
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef lualib_h
+#define lualib_h
+
+#include "lua.h"
+
+
+
+LUAMOD_API int (luaopen_base) (lua_State *L);
+
+#define LUA_COLIBNAME "coroutine"
+LUAMOD_API int (luaopen_coroutine) (lua_State *L);
+
+#define LUA_TABLIBNAME "table"
+LUAMOD_API int (luaopen_table) (lua_State *L);
+
+#define LUA_IOLIBNAME "io"
+LUAMOD_API int (luaopen_io) (lua_State *L);
+
+#define LUA_OSLIBNAME "os"
+LUAMOD_API int (luaopen_os) (lua_State *L);
+
+#define LUA_STRLIBNAME "string"
+LUAMOD_API int (luaopen_string) (lua_State *L);
+
+#define LUA_BITLIBNAME "bit32"
+LUAMOD_API int (luaopen_bit32) (lua_State *L);
+
+#define LUA_MATHLIBNAME "math"
+LUAMOD_API int (luaopen_math) (lua_State *L);
+
+#define LUA_DBLIBNAME "debug"
+LUAMOD_API int (luaopen_debug) (lua_State *L);
+
+#define LUA_LOADLIBNAME "package"
+LUAMOD_API int (luaopen_package) (lua_State *L);
+
+
+/* open all previous libraries */
+LUALIB_API void (luaL_openlibs) (lua_State *L);
+
+
+
+#if !defined(lua_assert)
+#define lua_assert(x) ((void)0)
+#endif
+
+
+#endif
diff --git a/lualib/lundump.c b/lualib/lundump.c
new file mode 100644
index 0000000..4163cb5
--- /dev/null
+++ b/lualib/lundump.c
@@ -0,0 +1,258 @@
+/*
+** $Id: lundump.c,v 2.22.1.1 2013/04/12 18:48:47 roberto Exp $
+** load precompiled Lua chunks
+** See Copyright Notice in lua.h
+*/
+
+#include
+
+#define lundump_c
+#define LUA_CORE
+
+#include "lua.h"
+
+#include "ldebug.h"
+#include "ldo.h"
+#include "lfunc.h"
+#include "lmem.h"
+#include "lobject.h"
+#include "lstring.h"
+#include "lundump.h"
+#include "lzio.h"
+
+typedef struct {
+ lua_State* L;
+ ZIO* Z;
+ Mbuffer* b;
+ const char* name;
+} LoadState;
+
+static l_noret error(LoadState* S, const char* why)
+{
+ luaO_pushfstring(S->L,"%s: %s precompiled chunk",S->name,why);
+ luaD_throw(S->L,LUA_ERRSYNTAX);
+}
+
+#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
+#define LoadByte(S) (lu_byte)LoadChar(S)
+#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
+#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
+
+#if !defined(luai_verifycode)
+#define luai_verifycode(L,b,f) /* empty */
+#endif
+
+static void LoadBlock(LoadState* S, void* b, size_t size)
+{
+ if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated");
+}
+
+static int LoadChar(LoadState* S)
+{
+ char x;
+ LoadVar(S,x);
+ return x;
+}
+
+static int LoadInt(LoadState* S)
+{
+ int x;
+ LoadVar(S,x);
+ if (x<0) error(S,"corrupted");
+ return x;
+}
+
+static lua_Number LoadNumber(LoadState* S)
+{
+ lua_Number x;
+ LoadVar(S,x);
+ return x;
+}
+
+static TString* LoadString(LoadState* S)
+{
+ size_t size;
+ LoadVar(S,size);
+ if (size==0)
+ return NULL;
+ else
+ {
+ char* s=luaZ_openspace(S->L,S->b,size);
+ LoadBlock(S,s,size*sizeof(char));
+ return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
+ }
+}
+
+static void LoadCode(LoadState* S, Proto* f)
+{
+ int n=LoadInt(S);
+ f->code=luaM_newvector(S->L,n,Instruction);
+ f->sizecode=n;
+ LoadVector(S,f->code,n,sizeof(Instruction));
+}
+
+static void LoadFunction(LoadState* S, Proto* f);
+
+static void LoadConstants(LoadState* S, Proto* f)
+{
+ int i,n;
+ n=LoadInt(S);
+ f->k=luaM_newvector(S->L,n,TValue);
+ f->sizek=n;
+ for (i=0; ik[i]);
+ for (i=0; ik[i];
+ int t=LoadChar(S);
+ switch (t)
+ {
+ case LUA_TNIL:
+ setnilvalue(o);
+ break;
+ case LUA_TBOOLEAN:
+ setbvalue(o,LoadChar(S));
+ break;
+ case LUA_TNUMBER:
+ setnvalue(o,LoadNumber(S));
+ break;
+ case LUA_TSTRING:
+ setsvalue2n(S->L,o,LoadString(S));
+ break;
+ default: lua_assert(0);
+ }
+ }
+ n=LoadInt(S);
+ f->p=luaM_newvector(S->L,n,Proto*);
+ f->sizep=n;
+ for (i=0; ip[i]=NULL;
+ for (i=0; ip[i]=luaF_newproto(S->L);
+ LoadFunction(S,f->p[i]);
+ }
+}
+
+static void LoadUpvalues(LoadState* S, Proto* f)
+{
+ int i,n;
+ n=LoadInt(S);
+ f->upvalues=luaM_newvector(S->L,n,Upvaldesc);
+ f->sizeupvalues=n;
+ for (i=0; iupvalues[i].name=NULL;
+ for (i=0; iupvalues[i].instack=LoadByte(S);
+ f->upvalues[i].idx=LoadByte(S);
+ }
+}
+
+static void LoadDebug(LoadState* S, Proto* f)
+{
+ int i,n;
+ f->source=LoadString(S);
+ n=LoadInt(S);
+ f->lineinfo=luaM_newvector(S->L,n,int);
+ f->sizelineinfo=n;
+ LoadVector(S,f->lineinfo,n,sizeof(int));
+ n=LoadInt(S);
+ f->locvars=luaM_newvector(S->L,n,LocVar);
+ f->sizelocvars=n;
+ for (i=0; ilocvars[i].varname=NULL;
+ for (i=0; ilocvars[i].varname=LoadString(S);
+ f->locvars[i].startpc=LoadInt(S);
+ f->locvars[i].endpc=LoadInt(S);
+ }
+ n=LoadInt(S);
+ for (i=0; iupvalues[i].name=LoadString(S);
+}
+
+static void LoadFunction(LoadState* S, Proto* f)
+{
+ f->linedefined=LoadInt(S);
+ f->lastlinedefined=LoadInt(S);
+ f->numparams=LoadByte(S);
+ f->is_vararg=LoadByte(S);
+ f->maxstacksize=LoadByte(S);
+ LoadCode(S,f);
+ LoadConstants(S,f);
+ LoadUpvalues(S,f);
+ LoadDebug(S,f);
+}
+
+/* the code below must be consistent with the code in luaU_header */
+#define N0 LUAC_HEADERSIZE
+#define N1 (sizeof(LUA_SIGNATURE)-sizeof(char))
+#define N2 N1+2
+#define N3 N2+6
+
+static void LoadHeader(LoadState* S)
+{
+ lu_byte h[LUAC_HEADERSIZE];
+ lu_byte s[LUAC_HEADERSIZE];
+ luaU_header(h);
+ memcpy(s,h,sizeof(char)); /* first char already read */
+ LoadBlock(S,s+sizeof(char),LUAC_HEADERSIZE-sizeof(char));
+ if (memcmp(h,s,N0)==0) return;
+ if (memcmp(h,s,N1)!=0) error(S,"not a");
+ if (memcmp(h,s,N2)!=0) error(S,"version mismatch in");
+ if (memcmp(h,s,N3)!=0) error(S,"incompatible"); else error(S,"corrupted");
+}
+
+/*
+** load precompiled chunk
+*/
+Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
+{
+ LoadState S;
+ Closure* cl;
+ if (*name=='@' || *name=='=')
+ S.name=name+1;
+ else if (*name==LUA_SIGNATURE[0])
+ S.name="binary string";
+ else
+ S.name=name;
+ S.L=L;
+ S.Z=Z;
+ S.b=buff;
+ LoadHeader(&S);
+ cl=luaF_newLclosure(L,1);
+ setclLvalue(L,L->top,cl); incr_top(L);
+ cl->l.p=luaF_newproto(L);
+ LoadFunction(&S,cl->l.p);
+ if (cl->l.p->sizeupvalues != 1)
+ {
+ Proto* p=cl->l.p;
+ cl=luaF_newLclosure(L,cl->l.p->sizeupvalues);
+ cl->l.p=p;
+ setclLvalue(L,L->top-1,cl);
+ }
+ luai_verifycode(L,buff,cl->l.p);
+ return cl;
+}
+
+#define MYINT(s) (s[0]-'0')
+#define VERSION MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)
+#define FORMAT 0 /* this is the official format */
+
+/*
+* make header for precompiled chunks
+* if you change the code below be sure to update LoadHeader and FORMAT above
+* and LUAC_HEADERSIZE in lundump.h
+*/
+void luaU_header (lu_byte* h)
+{
+ int x=1;
+ memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-sizeof(char));
+ h+=sizeof(LUA_SIGNATURE)-sizeof(char);
+ *h++=cast_byte(VERSION);
+ *h++=cast_byte(FORMAT);
+ *h++=cast_byte(*(char*)&x); /* endianness */
+ *h++=cast_byte(sizeof(int));
+ *h++=cast_byte(sizeof(size_t));
+ *h++=cast_byte(sizeof(Instruction));
+ *h++=cast_byte(sizeof(lua_Number));
+ *h++=cast_byte(((lua_Number)0.5)==0); /* is lua_Number integral? */
+ memcpy(h,LUAC_TAIL,sizeof(LUAC_TAIL)-sizeof(char));
+}
diff --git a/lualib/lundump.h b/lualib/lundump.h
new file mode 100644
index 0000000..5255db2
--- /dev/null
+++ b/lualib/lundump.h
@@ -0,0 +1,28 @@
+/*
+** $Id: lundump.h,v 1.39.1.1 2013/04/12 18:48:47 roberto Exp $
+** load precompiled Lua chunks
+** See Copyright Notice in lua.h
+*/
+
+#ifndef lundump_h
+#define lundump_h
+
+#include "lobject.h"
+#include "lzio.h"
+
+/* load one chunk; from lundump.c */
+LUAI_FUNC Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
+
+/* make header; from lundump.c */
+LUAI_FUNC void luaU_header (lu_byte* h);
+
+/* dump one chunk; from ldump.c */
+LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
+
+/* data to catch conversion errors */
+#define LUAC_TAIL "\x19\x93\r\n\x1a\n"
+
+/* size in bytes of header of binary files */
+#define LUAC_HEADERSIZE (sizeof(LUA_SIGNATURE)-sizeof(char)+2+6+sizeof(LUAC_TAIL)-sizeof(char))
+
+#endif
diff --git a/lualib/lvm.c b/lualib/lvm.c
new file mode 100644
index 0000000..141b9fd
--- /dev/null
+++ b/lualib/lvm.c
@@ -0,0 +1,867 @@
+/*
+** $Id: lvm.c,v 2.155.1.1 2013/04/12 18:48:47 roberto Exp $
+** Lua virtual machine
+** See Copyright Notice in lua.h
+*/
+
+
+#include
+#include
+#include
+
+#define lvm_c
+#define LUA_CORE
+
+#include "lua.h"
+
+#include "ldebug.h"
+#include "ldo.h"
+#include "lfunc.h"
+#include "lgc.h"
+#include "lobject.h"
+#include "lopcodes.h"
+#include "lstate.h"
+#include "lstring.h"
+#include "ltable.h"
+#include "ltm.h"
+#include "lvm.h"
+
+
+
+/* limit for table tag-method chains (to avoid loops) */
+#define MAXTAGLOOP 100
+
+
+const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
+ lua_Number num;
+ if (ttisnumber(obj)) return obj;
+ if (ttisstring(obj) && luaO_str2d(svalue(obj), tsvalue(obj)->len, &num)) {
+ setnvalue(n, num);
+ return n;
+ }
+ else
+ return NULL;
+}
+
+
+int luaV_tostring (lua_State *L, StkId obj) {
+ if (!ttisnumber(obj))
+ return 0;
+ else {
+ char s[LUAI_MAXNUMBER2STR];
+ lua_Number n = nvalue(obj);
+ int l = lua_number2str(s, n);
+ setsvalue2s(L, obj, luaS_newlstr(L, s, l));
+ return 1;
+ }
+}
+
+
+static void traceexec (lua_State *L) {
+ CallInfo *ci = L->ci;
+ lu_byte mask = L->hookmask;
+ int counthook = ((mask & LUA_MASKCOUNT) && L->hookcount == 0);
+ if (counthook)
+ resethookcount(L); /* reset count */
+ if (ci->callstatus & CIST_HOOKYIELD) { /* called hook last time? */
+ ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
+ return; /* do not call hook again (VM yielded, so it did not move) */
+ }
+ if (counthook)
+ luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */
+ if (mask & LUA_MASKLINE) {
+ Proto *p = ci_func(ci)->p;
+ int npc = pcRel(ci->u.l.savedpc, p);
+ int newline = getfuncline(p, npc);
+ if (npc == 0 || /* call linehook when enter a new function, */
+ ci->u.l.savedpc <= L->oldpc || /* when jump back (loop), or when */
+ newline != getfuncline(p, pcRel(L->oldpc, p))) /* enter a new line */
+ luaD_hook(L, LUA_HOOKLINE, newline); /* call line hook */
+ }
+ L->oldpc = ci->u.l.savedpc;
+ if (L->status == LUA_YIELD) { /* did hook yield? */
+ if (counthook)
+ L->hookcount = 1; /* undo decrement to zero */
+ ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
+ ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
+ ci->func = L->top - 1; /* protect stack below results */
+ luaD_throw(L, LUA_YIELD);
+ }
+}
+
+
+static void callTM (lua_State *L, const TValue *f, const TValue *p1,
+ const TValue *p2, TValue *p3, int hasres) {
+ ptrdiff_t result = savestack(L, p3);
+ setobj2s(L, L->top++, f); /* push function */
+ setobj2s(L, L->top++, p1); /* 1st argument */
+ setobj2s(L, L->top++, p2); /* 2nd argument */
+ if (!hasres) /* no result? 'p3' is third argument */
+ setobj2s(L, L->top++, p3); /* 3rd argument */
+ /* metamethod may yield only when called from Lua code */
+ luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci));
+ if (hasres) { /* if has result, move it to its place */
+ p3 = restorestack(L, result);
+ setobjs2s(L, p3, --L->top);
+ }
+}
+
+
+void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
+ int loop;
+ for (loop = 0; loop < MAXTAGLOOP; loop++) {
+ const TValue *tm;
+ if (ttistable(t)) { /* `t' is a table? */
+ Table *h = hvalue(t);
+ const TValue *res = luaH_get(h, key); /* do a primitive get */
+ if (!ttisnil(res) || /* result is not nil? */
+ (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
+ setobj2s(L, val, res);
+ return;
+ }
+ /* else will try the tag method */
+ }
+ else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
+ luaG_typeerror(L, t, "index");
+ if (ttisfunction(tm)) {
+ callTM(L, tm, t, key, val, 1);
+ return;
+ }
+ t = tm; /* else repeat with 'tm' */
+ }
+ luaG_runerror(L, "loop in gettable");
+}
+
+
+void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
+ int loop;
+ for (loop = 0; loop < MAXTAGLOOP; loop++) {
+ const TValue *tm;
+ if (ttistable(t)) { /* `t' is a table? */
+ Table *h = hvalue(t);
+ TValue *oldval = cast(TValue *, luaH_get(h, key));
+ /* if previous value is not nil, there must be a previous entry
+ in the table; moreover, a metamethod has no relevance */
+ if (!ttisnil(oldval) ||
+ /* previous value is nil; must check the metamethod */
+ ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
+ /* no metamethod; is there a previous entry in the table? */
+ (oldval != luaO_nilobject ||
+ /* no previous entry; must create one. (The next test is
+ always true; we only need the assignment.) */
+ (oldval = luaH_newkey(L, h, key), 1)))) {
+ /* no metamethod and (now) there is an entry with given key */
+ setobj2t(L, oldval, val); /* assign new value to that entry */
+ invalidateTMcache(h);
+ luaC_barrierback(L, obj2gco(h), val);
+ return;
+ }
+ /* else will try the metamethod */
+ }
+ else /* not a table; check metamethod */
+ if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
+ luaG_typeerror(L, t, "index");
+ /* there is a metamethod */
+ if (ttisfunction(tm)) {
+ callTM(L, tm, t, key, val, 0);
+ return;
+ }
+ t = tm; /* else repeat with 'tm' */
+ }
+ luaG_runerror(L, "loop in settable");
+}
+
+
+static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
+ StkId res, TMS event) {
+ const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
+ if (ttisnil(tm))
+ tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
+ if (ttisnil(tm)) return 0;
+ callTM(L, tm, p1, p2, res, 1);
+ return 1;
+}
+
+
+static const TValue *get_equalTM (lua_State *L, Table *mt1, Table *mt2,
+ TMS event) {
+ const TValue *tm1 = fasttm(L, mt1, event);
+ const TValue *tm2;
+ if (tm1 == NULL) return NULL; /* no metamethod */
+ if (mt1 == mt2) return tm1; /* same metatables => same metamethods */
+ tm2 = fasttm(L, mt2, event);
+ if (tm2 == NULL) return NULL; /* no metamethod */
+ if (luaV_rawequalobj(tm1, tm2)) /* same metamethods? */
+ return tm1;
+ return NULL;
+}
+
+
+static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
+ TMS event) {
+ if (!call_binTM(L, p1, p2, L->top, event))
+ return -1; /* no metamethod */
+ else
+ return !l_isfalse(L->top);
+}
+
+
+static int l_strcmp (const TString *ls, const TString *rs) {
+ const char *l = getstr(ls);
+ size_t ll = ls->tsv.len;
+ const char *r = getstr(rs);
+ size_t lr = rs->tsv.len;
+ for (;;) {
+ int temp = strcoll(l, r);
+ if (temp != 0) return temp;
+ else { /* strings are equal up to a `\0' */
+ size_t len = strlen(l); /* index of first `\0' in both strings */
+ if (len == lr) /* r is finished? */
+ return (len == ll) ? 0 : 1;
+ else if (len == ll) /* l is finished? */
+ return -1; /* l is smaller than r (because r is not finished) */
+ /* both strings longer than `len'; go on comparing (after the `\0') */
+ len++;
+ l += len; ll -= len; r += len; lr -= len;
+ }
+ }
+}
+
+
+int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
+ int res;
+ if (ttisnumber(l) && ttisnumber(r))
+ return luai_numlt(L, nvalue(l), nvalue(r));
+ else if (ttisstring(l) && ttisstring(r))
+ return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
+ else if ((res = call_orderTM(L, l, r, TM_LT)) < 0)
+ luaG_ordererror(L, l, r);
+ return res;
+}
+
+
+int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
+ int res;
+ if (ttisnumber(l) && ttisnumber(r))
+ return luai_numle(L, nvalue(l), nvalue(r));
+ else if (ttisstring(l) && ttisstring(r))
+ return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
+ else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */
+ return res;
+ else if ((res = call_orderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */
+ luaG_ordererror(L, l, r);
+ return !res;
+}
+
+
+/*
+** equality of Lua values. L == NULL means raw equality (no metamethods)
+*/
+int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2) {
+ const TValue *tm;
+ lua_assert(ttisequal(t1, t2));
+ switch (ttype(t1)) {
+ case LUA_TNIL: return 1;
+ case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
+ case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
+ case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
+ case LUA_TLCF: return fvalue(t1) == fvalue(t2);
+ case LUA_TSHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2));
+ case LUA_TLNGSTR: return luaS_eqlngstr(rawtsvalue(t1), rawtsvalue(t2));
+ case LUA_TUSERDATA: {
+ if (uvalue(t1) == uvalue(t2)) return 1;
+ else if (L == NULL) return 0;
+ tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ);
+ break; /* will try TM */
+ }
+ case LUA_TTABLE: {
+ if (hvalue(t1) == hvalue(t2)) return 1;
+ else if (L == NULL) return 0;
+ tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
+ break; /* will try TM */
+ }
+ default:
+ lua_assert(iscollectable(t1));
+ return gcvalue(t1) == gcvalue(t2);
+ }
+ if (tm == NULL) return 0; /* no TM? */
+ callTM(L, tm, t1, t2, L->top, 1); /* call TM */
+ return !l_isfalse(L->top);
+}
+
+
+void luaV_concat (lua_State *L, int total) {
+ lua_assert(total >= 2);
+ do {
+ StkId top = L->top;
+ int n = 2; /* number of elements handled in this pass (at least 2) */
+ if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
+ if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
+ luaG_concaterror(L, top-2, top-1);
+ }
+ else if (tsvalue(top-1)->len == 0) /* second operand is empty? */
+ (void)tostring(L, top - 2); /* result is first operand */
+ else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) {
+ setobjs2s(L, top - 2, top - 1); /* result is second op. */
+ }
+ else {
+ /* at least two non-empty string values; get as many as possible */
+ size_t tl = tsvalue(top-1)->len;
+ char *buffer;
+ int i;
+ /* collect total length */
+ for (i = 1; i < total && tostring(L, top-i-1); i++) {
+ size_t l = tsvalue(top-i-1)->len;
+ if (l >= (MAX_SIZET/sizeof(char)) - tl)
+ luaG_runerror(L, "string length overflow");
+ tl += l;
+ }
+ buffer = luaZ_openspace(L, &G(L)->buff, tl);
+ tl = 0;
+ n = i;
+ do { /* concat all strings */
+ size_t l = tsvalue(top-i)->len;
+ memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
+ tl += l;
+ } while (--i > 0);
+ setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
+ }
+ total -= n-1; /* got 'n' strings to create 1 new */
+ L->top -= n-1; /* popped 'n' strings and pushed one */
+ } while (total > 1); /* repeat until only 1 result left */
+}
+
+
+void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
+ const TValue *tm;
+ switch (ttypenv(rb)) {
+ case LUA_TTABLE: {
+ Table *h = hvalue(rb);
+ tm = fasttm(L, h->metatable, TM_LEN);
+ if (tm) break; /* metamethod? break switch to call it */
+ setnvalue(ra, cast_num(luaH_getn(h))); /* else primitive len */
+ return;
+ }
+ case LUA_TSTRING: {
+ setnvalue(ra, cast_num(tsvalue(rb)->len));
+ return;
+ }
+ default: { /* try metamethod */
+ tm = luaT_gettmbyobj(L, rb, TM_LEN);
+ if (ttisnil(tm)) /* no metamethod? */
+ luaG_typeerror(L, rb, "get length of");
+ break;
+ }
+ }
+ callTM(L, tm, rb, rb, ra, 1);
+}
+
+
+void luaV_arith (lua_State *L, StkId ra, const TValue *rb,
+ const TValue *rc, TMS op) {
+ TValue tempb, tempc;
+ const TValue *b, *c;
+ if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
+ (c = luaV_tonumber(rc, &tempc)) != NULL) {
+ lua_Number res = luaO_arith(op - TM_ADD + LUA_OPADD, nvalue(b), nvalue(c));
+ setnvalue(ra, res);
+ }
+ else if (!call_binTM(L, rb, rc, ra, op))
+ luaG_aritherror(L, rb, rc);
+}
+
+
+/*
+** check whether cached closure in prototype 'p' may be reused, that is,
+** whether there is a cached closure with the same upvalues needed by
+** new closure to be created.
+*/
+static Closure *getcached (Proto *p, UpVal **encup, StkId base) {
+ Closure *c = p->cache;
+ if (c != NULL) { /* is there a cached closure? */
+ int nup = p->sizeupvalues;
+ Upvaldesc *uv = p->upvalues;
+ int i;
+ for (i = 0; i < nup; i++) { /* check whether it has right upvalues */
+ TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v;
+ if (c->l.upvals[i]->v != v)
+ return NULL; /* wrong upvalue; cannot reuse closure */
+ }
+ }
+ return c; /* return cached closure (or NULL if no cached closure) */
+}
+
+
+/*
+** create a new Lua closure, push it in the stack, and initialize
+** its upvalues. Note that the call to 'luaC_barrierproto' must come
+** before the assignment to 'p->cache', as the function needs the
+** original value of that field.
+*/
+static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
+ StkId ra) {
+ int nup = p->sizeupvalues;
+ Upvaldesc *uv = p->upvalues;
+ int i;
+ Closure *ncl = luaF_newLclosure(L, nup);
+ ncl->l.p = p;
+ setclLvalue(L, ra, ncl); /* anchor new closure in stack */
+ for (i = 0; i < nup; i++) { /* fill in its upvalues */
+ if (uv[i].instack) /* upvalue refers to local variable? */
+ ncl->l.upvals[i] = luaF_findupval(L, base + uv[i].idx);
+ else /* get upvalue from enclosing function */
+ ncl->l.upvals[i] = encup[uv[i].idx];
+ }
+ luaC_barrierproto(L, p, ncl);
+ p->cache = ncl; /* save it on cache for reuse */
+}
+
+
+/*
+** finish execution of an opcode interrupted by an yield
+*/
+void luaV_finishOp (lua_State *L) {
+ CallInfo *ci = L->ci;
+ StkId base = ci->u.l.base;
+ Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
+ OpCode op = GET_OPCODE(inst);
+ switch (op) { /* finish its execution */
+ case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV:
+ case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN:
+ case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {
+ setobjs2s(L, base + GETARG_A(inst), --L->top);
+ break;
+ }
+ case OP_LE: case OP_LT: case OP_EQ: {
+ int res = !l_isfalse(L->top - 1);
+ L->top--;
+ /* metamethod should not be called when operand is K */
+ lua_assert(!ISK(GETARG_B(inst)));
+ if (op == OP_LE && /* "<=" using "<" instead? */
+ ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE)))
+ res = !res; /* invert result */
+ lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);
+ if (res != GETARG_A(inst)) /* condition failed? */
+ ci->u.l.savedpc++; /* skip jump instruction */
+ break;
+ }
+ case OP_CONCAT: {
+ StkId top = L->top - 1; /* top when 'call_binTM' was called */
+ int b = GETARG_B(inst); /* first element to concatenate */
+ int total = cast_int(top - 1 - (base + b)); /* yet to concatenate */
+ setobj2s(L, top - 2, top); /* put TM result in proper position */
+ if (total > 1) { /* are there elements to concat? */
+ L->top = top - 1; /* top is one after last element (at top-2) */
+ luaV_concat(L, total); /* concat them (may yield again) */
+ }
+ /* move final result to final position */
+ setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);
+ L->top = ci->top; /* restore top */
+ break;
+ }
+ case OP_TFORCALL: {
+ lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_TFORLOOP);
+ L->top = ci->top; /* correct top */
+ break;
+ }
+ case OP_CALL: {
+ if (GETARG_C(inst) - 1 >= 0) /* nresults >= 0? */
+ L->top = ci->top; /* adjust results */
+ break;
+ }
+ case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
+ break;
+ default: lua_assert(0);
+ }
+}
+
+
+
+/*
+** some macros for common tasks in `luaV_execute'
+*/
+
+#if !defined luai_runtimecheck
+#define luai_runtimecheck(L, c) /* void */
+#endif
+
+
+#define RA(i) (base+GETARG_A(i))
+/* to be used after possible stack reallocation */
+#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))
+#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
+#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
+ ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))
+#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
+ ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))
+#define KBx(i) \
+ (k + (GETARG_Bx(i) != 0 ? GETARG_Bx(i) - 1 : GETARG_Ax(*ci->u.l.savedpc++)))
+
+
+/* execute a jump instruction */
+#define dojump(ci,i,e) \
+ { int a = GETARG_A(i); \
+ if (a > 0) luaF_close(L, ci->u.l.base + a - 1); \
+ ci->u.l.savedpc += GETARG_sBx(i) + e; }
+
+/* for test instructions, execute the jump instruction that follows it */
+#define donextjump(ci) { i = *ci->u.l.savedpc; dojump(ci, i, 1); }
+
+
+#define Protect(x) { {x;}; base = ci->u.l.base; }
+
+#define checkGC(L,c) \
+ Protect( luaC_condGC(L,{L->top = (c); /* limit of live values */ \
+ luaC_step(L); \
+ L->top = ci->top;}) /* restore top */ \
+ luai_threadyield(L); )
+
+
+#define arith_op(op,tm) { \
+ TValue *rb = RKB(i); \
+ TValue *rc = RKC(i); \
+ if (ttisnumber(rb) && ttisnumber(rc)) { \
+ lua_Number nb = nvalue(rb), nc = nvalue(rc); \
+ setnvalue(ra, op(L, nb, nc)); \
+ } \
+ else { Protect(luaV_arith(L, ra, rb, rc, tm)); } }
+
+
+#define vmdispatch(o) switch(o)
+#define vmcase(l,b) case l: {b} break;
+#define vmcasenb(l,b) case l: {b} /* nb = no break */
+
+void luaV_execute (lua_State *L) {
+ CallInfo *ci = L->ci;
+ LClosure *cl;
+ TValue *k;
+ StkId base;
+ newframe: /* reentry point when frame changes (call/return) */
+ lua_assert(ci == L->ci);
+ cl = clLvalue(ci->func);
+ k = cl->p->k;
+ base = ci->u.l.base;
+ /* main loop of interpreter */
+ for (;;) {
+ Instruction i = *(ci->u.l.savedpc++);
+ StkId ra;
+ if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
+ (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
+ Protect(traceexec(L));
+ }
+ /* WARNING: several calls may realloc the stack and invalidate `ra' */
+ ra = RA(i);
+ lua_assert(base == ci->u.l.base);
+ lua_assert(base <= L->top && L->top < L->stack + L->stacksize);
+ vmdispatch (GET_OPCODE(i)) {
+ vmcase(OP_MOVE,
+ setobjs2s(L, ra, RB(i));
+ )
+ vmcase(OP_LOADK,
+ TValue *rb = k + GETARG_Bx(i);
+ setobj2s(L, ra, rb);
+ )
+ vmcase(OP_LOADKX,
+ TValue *rb;
+ lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);
+ rb = k + GETARG_Ax(*ci->u.l.savedpc++);
+ setobj2s(L, ra, rb);
+ )
+ vmcase(OP_LOADBOOL,
+ setbvalue(ra, GETARG_B(i));
+ if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */
+ )
+ vmcase(OP_LOADNIL,
+ int b = GETARG_B(i);
+ do {
+ setnilvalue(ra++);
+ } while (b--);
+ )
+ vmcase(OP_GETUPVAL,
+ int b = GETARG_B(i);
+ setobj2s(L, ra, cl->upvals[b]->v);
+ )
+ vmcase(OP_GETTABUP,
+ int b = GETARG_B(i);
+ Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra));
+ )
+ vmcase(OP_GETTABLE,
+ Protect(luaV_gettable(L, RB(i), RKC(i), ra));
+ )
+ vmcase(OP_SETTABUP,
+ int a = GETARG_A(i);
+ Protect(luaV_settable(L, cl->upvals[a]->v, RKB(i), RKC(i)));
+ )
+ vmcase(OP_SETUPVAL,
+ UpVal *uv = cl->upvals[GETARG_B(i)];
+ setobj(L, uv->v, ra);
+ luaC_barrier(L, uv, ra);
+ )
+ vmcase(OP_SETTABLE,
+ Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
+ )
+ vmcase(OP_NEWTABLE,
+ int b = GETARG_B(i);
+ int c = GETARG_C(i);
+ Table *t = luaH_new(L);
+ sethvalue(L, ra, t);
+ if (b != 0 || c != 0)
+ luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));
+ checkGC(L, ra + 1);
+ )
+ vmcase(OP_SELF,
+ StkId rb = RB(i);
+ setobjs2s(L, ra+1, rb);
+ Protect(luaV_gettable(L, rb, RKC(i), ra));
+ )
+ vmcase(OP_ADD,
+ arith_op(luai_numadd, TM_ADD);
+ )
+ vmcase(OP_SUB,
+ arith_op(luai_numsub, TM_SUB);
+ )
+ vmcase(OP_MUL,
+ arith_op(luai_nummul, TM_MUL);
+ )
+ vmcase(OP_DIV,
+ arith_op(luai_numdiv, TM_DIV);
+ )
+ vmcase(OP_MOD,
+ arith_op(luai_nummod, TM_MOD);
+ )
+ vmcase(OP_POW,
+ arith_op(luai_numpow, TM_POW);
+ )
+ vmcase(OP_UNM,
+ TValue *rb = RB(i);
+ if (ttisnumber(rb)) {
+ lua_Number nb = nvalue(rb);
+ setnvalue(ra, luai_numunm(L, nb));
+ }
+ else {
+ Protect(luaV_arith(L, ra, rb, rb, TM_UNM));
+ }
+ )
+ vmcase(OP_NOT,
+ TValue *rb = RB(i);
+ int res = l_isfalse(rb); /* next assignment may change this value */
+ setbvalue(ra, res);
+ )
+ vmcase(OP_LEN,
+ Protect(luaV_objlen(L, ra, RB(i)));
+ )
+ vmcase(OP_CONCAT,
+ int b = GETARG_B(i);
+ int c = GETARG_C(i);
+ StkId rb;
+ L->top = base + c + 1; /* mark the end of concat operands */
+ Protect(luaV_concat(L, c - b + 1));
+ ra = RA(i); /* 'luav_concat' may invoke TMs and move the stack */
+ rb = b + base;
+ setobjs2s(L, ra, rb);
+ checkGC(L, (ra >= rb ? ra + 1 : rb));
+ L->top = ci->top; /* restore top */
+ )
+ vmcase(OP_JMP,
+ dojump(ci, i, 0);
+ )
+ vmcase(OP_EQ,
+ TValue *rb = RKB(i);
+ TValue *rc = RKC(i);
+ Protect(
+ if (cast_int(equalobj(L, rb, rc)) != GETARG_A(i))
+ ci->u.l.savedpc++;
+ else
+ donextjump(ci);
+ )
+ )
+ vmcase(OP_LT,
+ Protect(
+ if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i))
+ ci->u.l.savedpc++;
+ else
+ donextjump(ci);
+ )
+ )
+ vmcase(OP_LE,
+ Protect(
+ if (luaV_lessequal(L, RKB(i), RKC(i)) != GETARG_A(i))
+ ci->u.l.savedpc++;
+ else
+ donextjump(ci);
+ )
+ )
+ vmcase(OP_TEST,
+ if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra))
+ ci->u.l.savedpc++;
+ else
+ donextjump(ci);
+ )
+ vmcase(OP_TESTSET,
+ TValue *rb = RB(i);
+ if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb))
+ ci->u.l.savedpc++;
+ else {
+ setobjs2s(L, ra, rb);
+ donextjump(ci);
+ }
+ )
+ vmcase(OP_CALL,
+ int b = GETARG_B(i);
+ int nresults = GETARG_C(i) - 1;
+ if (b != 0) L->top = ra+b; /* else previous instruction set top */
+ if (luaD_precall(L, ra, nresults)) { /* C function? */
+ if (nresults >= 0) L->top = ci->top; /* adjust results */
+ base = ci->u.l.base;
+ }
+ else { /* Lua function */
+ ci = L->ci;
+ ci->callstatus |= CIST_REENTRY;
+ goto newframe; /* restart luaV_execute over new Lua function */
+ }
+ )
+ vmcase(OP_TAILCALL,
+ int b = GETARG_B(i);
+ if (b != 0) L->top = ra+b; /* else previous instruction set top */
+ lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
+ if (luaD_precall(L, ra, LUA_MULTRET)) /* C function? */
+ base = ci->u.l.base;
+ else {
+ /* tail call: put called frame (n) in place of caller one (o) */
+ CallInfo *nci = L->ci; /* called frame */
+ CallInfo *oci = nci->previous; /* caller frame */
+ StkId nfunc = nci->func; /* called function */
+ StkId ofunc = oci->func; /* caller function */
+ /* last stack slot filled by 'precall' */
+ StkId lim = nci->u.l.base + getproto(nfunc)->numparams;
+ int aux;
+ /* close all upvalues from previous call */
+ if (cl->p->sizep > 0) luaF_close(L, oci->u.l.base);
+ /* move new frame into old one */
+ for (aux = 0; nfunc + aux < lim; aux++)
+ setobjs2s(L, ofunc + aux, nfunc + aux);
+ oci->u.l.base = ofunc + (nci->u.l.base - nfunc); /* correct base */
+ oci->top = L->top = ofunc + (L->top - nfunc); /* correct top */
+ oci->u.l.savedpc = nci->u.l.savedpc;
+ oci->callstatus |= CIST_TAIL; /* function was tail called */
+ ci = L->ci = oci; /* remove new frame */
+ lua_assert(L->top == oci->u.l.base + getproto(ofunc)->maxstacksize);
+ goto newframe; /* restart luaV_execute over new Lua function */
+ }
+ )
+ vmcasenb(OP_RETURN,
+ int b = GETARG_B(i);
+ if (b != 0) L->top = ra+b-1;
+ if (cl->p->sizep > 0) luaF_close(L, base);
+ b = luaD_poscall(L, ra);
+ if (!(ci->callstatus & CIST_REENTRY)) /* 'ci' still the called one */
+ return; /* external invocation: return */
+ else { /* invocation via reentry: continue execution */
+ ci = L->ci;
+ if (b) L->top = ci->top;
+ lua_assert(isLua(ci));
+ lua_assert(GET_OPCODE(*((ci)->u.l.savedpc - 1)) == OP_CALL);
+ goto newframe; /* restart luaV_execute over new Lua function */
+ }
+ )
+ vmcase(OP_FORLOOP,
+ lua_Number step = nvalue(ra+2);
+ lua_Number idx = luai_numadd(L, nvalue(ra), step); /* increment index */
+ lua_Number limit = nvalue(ra+1);
+ if (luai_numlt(L, 0, step) ? luai_numle(L, idx, limit)
+ : luai_numle(L, limit, idx)) {
+ ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
+ setnvalue(ra, idx); /* update internal index... */
+ setnvalue(ra+3, idx); /* ...and external index */
+ }
+ )
+ vmcase(OP_FORPREP,
+ const TValue *init = ra;
+ const TValue *plimit = ra+1;
+ const TValue *pstep = ra+2;
+ if (!tonumber(init, ra))
+ luaG_runerror(L, LUA_QL("for") " initial value must be a number");
+ else if (!tonumber(plimit, ra+1))
+ luaG_runerror(L, LUA_QL("for") " limit must be a number");
+ else if (!tonumber(pstep, ra+2))
+ luaG_runerror(L, LUA_QL("for") " step must be a number");
+ setnvalue(ra, luai_numsub(L, nvalue(ra), nvalue(pstep)));
+ ci->u.l.savedpc += GETARG_sBx(i);
+ )
+ vmcasenb(OP_TFORCALL,
+ StkId cb = ra + 3; /* call base */
+ setobjs2s(L, cb+2, ra+2);
+ setobjs2s(L, cb+1, ra+1);
+ setobjs2s(L, cb, ra);
+ L->top = cb + 3; /* func. + 2 args (state and index) */
+ Protect(luaD_call(L, cb, GETARG_C(i), 1));
+ L->top = ci->top;
+ i = *(ci->u.l.savedpc++); /* go to next instruction */
+ ra = RA(i);
+ lua_assert(GET_OPCODE(i) == OP_TFORLOOP);
+ goto l_tforloop;
+ )
+ vmcase(OP_TFORLOOP,
+ l_tforloop:
+ if (!ttisnil(ra + 1)) { /* continue loop? */
+ setobjs2s(L, ra, ra + 1); /* save control variable */
+ ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
+ }
+ )
+ vmcase(OP_SETLIST,
+ int n = GETARG_B(i);
+ int c = GETARG_C(i);
+ int last;
+ Table *h;
+ if (n == 0) n = cast_int(L->top - ra) - 1;
+ if (c == 0) {
+ lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_EXTRAARG);
+ c = GETARG_Ax(*ci->u.l.savedpc++);
+ }
+ luai_runtimecheck(L, ttistable(ra));
+ h = hvalue(ra);
+ last = ((c-1)*LFIELDS_PER_FLUSH) + n;
+ if (last > h->sizearray) /* needs more space? */
+ luaH_resizearray(L, h, last); /* pre-allocate it at once */
+ for (; n > 0; n--) {
+ TValue *val = ra+n;
+ luaH_setint(L, h, last--, val);
+ luaC_barrierback(L, obj2gco(h), val);
+ }
+ L->top = ci->top; /* correct top (in case of previous open call) */
+ )
+ vmcase(OP_CLOSURE,
+ Proto *p = cl->p->p[GETARG_Bx(i)];
+ Closure *ncl = getcached(p, cl->upvals, base); /* cached closure */
+ if (ncl == NULL) /* no match? */
+ pushclosure(L, p, cl->upvals, base, ra); /* create a new one */
+ else
+ setclLvalue(L, ra, ncl); /* push cashed closure */
+ checkGC(L, ra + 1);
+ )
+ vmcase(OP_VARARG,
+ int b = GETARG_B(i) - 1;
+ int j;
+ int n = cast_int(base - ci->func) - cl->p->numparams - 1;
+ if (b < 0) { /* B == 0? */
+ b = n; /* get all var. arguments */
+ Protect(luaD_checkstack(L, n));
+ ra = RA(i); /* previous call may change the stack */
+ L->top = ra + n;
+ }
+ for (j = 0; j < b; j++) {
+ if (j < n) {
+ setobjs2s(L, ra + j, base - n + j);
+ }
+ else {
+ setnilvalue(ra + j);
+ }
+ }
+ )
+ vmcase(OP_EXTRAARG,
+ lua_assert(0);
+ )
+ }
+ }
+}
+
diff --git a/lualib/lvm.h b/lualib/lvm.h
new file mode 100644
index 0000000..5380270
--- /dev/null
+++ b/lualib/lvm.h
@@ -0,0 +1,44 @@
+/*
+** $Id: lvm.h,v 2.18.1.1 2013/04/12 18:48:47 roberto Exp $
+** Lua virtual machine
+** See Copyright Notice in lua.h
+*/
+
+#ifndef lvm_h
+#define lvm_h
+
+
+#include "ldo.h"
+#include "lobject.h"
+#include "ltm.h"
+
+
+#define tostring(L,o) (ttisstring(o) || (luaV_tostring(L, o)))
+
+#define tonumber(o,n) (ttisnumber(o) || (((o) = luaV_tonumber(o,n)) != NULL))
+
+#define equalobj(L,o1,o2) (ttisequal(o1, o2) && luaV_equalobj_(L, o1, o2))
+
+#define luaV_rawequalobj(o1,o2) equalobj(NULL,o1,o2)
+
+
+/* not to called directly */
+LUAI_FUNC int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2);
+
+
+LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
+LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);
+LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
+LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
+LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
+ StkId val);
+LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
+ StkId val);
+LUAI_FUNC void luaV_finishOp (lua_State *L);
+LUAI_FUNC void luaV_execute (lua_State *L);
+LUAI_FUNC void luaV_concat (lua_State *L, int total);
+LUAI_FUNC void luaV_arith (lua_State *L, StkId ra, const TValue *rb,
+ const TValue *rc, TMS op);
+LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);
+
+#endif
diff --git a/lualib/lzio.c b/lualib/lzio.c
new file mode 100644
index 0000000..20efea9
--- /dev/null
+++ b/lualib/lzio.c
@@ -0,0 +1,76 @@
+/*
+** $Id: lzio.c,v 1.35.1.1 2013/04/12 18:48:47 roberto Exp $
+** Buffered streams
+** See Copyright Notice in lua.h
+*/
+
+
+#include
+
+#define lzio_c
+#define LUA_CORE
+
+#include "lua.h"
+
+#include "llimits.h"
+#include "lmem.h"
+#include "lstate.h"
+#include "lzio.h"
+
+
+int luaZ_fill (ZIO *z) {
+ size_t size;
+ lua_State *L = z->L;
+ const char *buff;
+ lua_unlock(L);
+ buff = z->reader(L, z->data, &size);
+ lua_lock(L);
+ if (buff == NULL || size == 0)
+ return EOZ;
+ z->n = size - 1; /* discount char being returned */
+ z->p = buff;
+ return cast_uchar(*(z->p++));
+}
+
+
+void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
+ z->L = L;
+ z->reader = reader;
+ z->data = data;
+ z->n = 0;
+ z->p = NULL;
+}
+
+
+/* --------------------------------------------------------------- read --- */
+size_t luaZ_read (ZIO *z, void *b, size_t n) {
+ while (n) {
+ size_t m;
+ if (z->n == 0) { /* no bytes in buffer? */
+ if (luaZ_fill(z) == EOZ) /* try to read more */
+ return n; /* no more input; return number of missing bytes */
+ else {
+ z->n++; /* luaZ_fill consumed first byte; put it back */
+ z->p--;
+ }
+ }
+ m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
+ memcpy(b, z->p, m);
+ z->n -= m;
+ z->p += m;
+ b = (char *)b + m;
+ n -= m;
+ }
+ return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
+ if (n > buff->buffsize) {
+ if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
+ luaZ_resizebuffer(L, buff, n);
+ }
+ return buff->buffer;
+}
+
+
diff --git a/lualib/lzio.h b/lualib/lzio.h
new file mode 100644
index 0000000..441f747
--- /dev/null
+++ b/lualib/lzio.h
@@ -0,0 +1,65 @@
+/*
+** $Id: lzio.h,v 1.26.1.1 2013/04/12 18:48:47 roberto Exp $
+** Buffered streams
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef lzio_h
+#define lzio_h
+
+#include "lua.h"
+
+#include "lmem.h"
+
+
+#define EOZ (-1) /* end of stream */
+
+typedef struct Zio ZIO;
+
+#define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
+
+
+typedef struct Mbuffer {
+ char *buffer;
+ size_t n;
+ size_t buffsize;
+} Mbuffer;
+
+#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_resetbuffer(buff) ((buff)->n = 0)
+
+
+#define luaZ_resizebuffer(L, buff, size) \
+ (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
+ (buff)->buffsize = size)
+
+#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
+
+
+LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
+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 */
+
+
+
+/* --------- 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) */
+};
+
+
+LUAI_FUNC int luaZ_fill (ZIO *z);
+
+#endif
From 47dbe7cfd3026d02e72aa81c826f01757ae0f4a5 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Sat, 28 Apr 2018 02:37:18 +0800
Subject: [PATCH 02/96] =?UTF-8?q?=E5=8A=A0=E5=85=A5eluna=E5=AD=90=E6=A8=A1?=
=?UTF-8?q?=E5=9D=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitmodules | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 .gitmodules
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..470fc63
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,4 @@
+[submodule "LuaEngine"]
+ path = LuaEngine
+ url = https://github.com/AyaseCore/Eluna.git
+ branch = ElunaAzerothWotlk
From 00f27756da0938a17950023b7b4af3ce26ccbe96 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Sat, 28 Apr 2018 02:43:58 +0800
Subject: [PATCH 03/96] Create README.md
---
README.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
create mode 100644 README.md
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..87cba85
--- /dev/null
+++ b/README.md
@@ -0,0 +1,81 @@
+# mod-LuaEngine
+azerothcore 的 eluna 模块
+
+
+Not sure:
+src\server\game\Maps\MapInstanced.cpp
+```
+#ifdef ELUNA
+ sEluna->FreeInstanceId(instanceId);
+#endif
+```
+Eluna API changes:
+OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
+
+
+No Settings related to eluna are added in the .
+No configuration files are added to the module.
+
+----------------------------------------------------------
+写英文老费劲了.原谅我英文水平差.没办法..天生的.
+有木有英语帝翻译一下
+
+折腾这个az+eluna,有几个地方是需要注意的,如何你要使用的话
+
+1.src\server\game\Maps\MapInstanced.cpp
+```
+#ifdef ELUNA
+ sEluna->FreeInstanceId(instanceId);
+#endif
+```
+这一句我不确定加的是不是正确的
+
+2.改了eluna的一个api
+```
+OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
+```
+为了兼容az的OnBeforeConfigLoad和OnAfterConfigLoad
+
+3.没有把这部分加到配置文件里,因为打算把这部分写到模块的配置文件里,目前没有弄.
+```
+###################################################################################################
+# ELUNA SETTINGS
+#
+# Eluna.Enabled
+# Description: Enable or disable Eluna LuaEngine
+# Default: true - (enabled)
+# false - (disabled)
+#
+# Eluna.TraceBack
+# Description: Sets whether to use debug.traceback function on a lua error or not.
+# Notice that you can redefine the function.
+# Default: false - (use default error output)
+# true - (use debug.traceback function)
+#
+# Eluna.ScriptPath
+# Description: Sets the location of the script folder to load scripts from
+# The path can be relative or absolute.
+# Default: "lua_scripts"
+#
+
+Eluna.Enabled = true
+Eluna.TraceBack = false
+Eluna.ScriptPath = "lua_scripts"
+```
+4.据说最近的eluna可以去掉单线程限制,目前我还没去掉,如果需要去掉的话
+src\server\game\Maps\MapManager.cpp
+```
+#ifdef ELUNA
+ if (num_threads > 1)
+ {
+ // Force 1 thread for Eluna as lua is single threaded. By default thread count is 1
+ // This should allow us not to use mutex locks
+ ELUNA_LOG_ERROR("MAP:Map update threads set to %i, when Eluna only allows 1, changing to 1", num_threads);
+ num_threads = 1;
+ }
+#endif
+```
+把这段去掉
+
+
+
From 0476eb8294ccba1383e088194e4ddd3465e4c551 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Sat, 28 Apr 2018 22:46:26 +0800
Subject: [PATCH 04/96] =?UTF-8?q?=E7=BB=99eluna=E6=A8=A1=E5=9D=97=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E8=AE=BE=E7=BD=AE=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CMakeLists.txt | 4 ++++
cmake/after_ws_install.cmake | 15 +++++++++++++++
conf/mod_LuaEngine.conf.dist | 25 +++++++++++++++++++++++++
3 files changed, 44 insertions(+)
create mode 100644 cmake/after_ws_install.cmake
create mode 100644 conf/mod_LuaEngine.conf.dist
diff --git a/CMakeLists.txt b/CMakeLists.txt
index db2bff1..04f922d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,10 @@
if( ELUNA )
+ CU_SET_PATH("CMAKE_MOD_ELUNA_ENGINE_DIR" "${CMAKE_CURRENT_LIST_DIR}")
add_subdirectory(lualib)
add_subdirectory(LuaEngine)
+
+ CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_CURRENT_LIST_DIR}/cmake/after_ws_install.cmake")
+ install(FILES "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" DESTINATION ${CONF_DIR})
endif()
diff --git a/cmake/after_ws_install.cmake b/cmake/after_ws_install.cmake
new file mode 100644
index 0000000..06387bd
--- /dev/null
+++ b/cmake/after_ws_install.cmake
@@ -0,0 +1,15 @@
+if( WIN32 )
+ if ( MSVC )
+ add_custom_command(TARGET worldserver
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/
+ )
+ elseif ( MINGW )
+ add_custom_command(TARGET worldserver
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" ${CMAKE_BINARY_DIR}/bin/
+ )
+ endif()
+endif()
+
+install(FILES "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" DESTINATION ${CONF_DIR})
\ No newline at end of file
diff --git a/conf/mod_LuaEngine.conf.dist b/conf/mod_LuaEngine.conf.dist
new file mode 100644
index 0000000..d3490f0
--- /dev/null
+++ b/conf/mod_LuaEngine.conf.dist
@@ -0,0 +1,25 @@
+[worldserver]
+
+###################################################################################################
+# ELUNA SETTINGS
+#
+# Eluna.Enabled
+# Description: Enable or disable Eluna LuaEngine
+# Default: true - (enabled)
+# false - (disabled)
+#
+# Eluna.TraceBack
+# Description: Sets whether to use debug.traceback function on a lua error or not.
+# Notice that you can redefine the function.
+# Default: false - (use default error output)
+# true - (use debug.traceback function)
+#
+# Eluna.ScriptPath
+# Description: Sets the location of the script folder to load scripts from
+# The path can be relative or absolute.
+# Default: "lua_scripts"
+#
+
+Eluna.Enabled = true
+Eluna.TraceBack = false
+Eluna.ScriptPath = "lua_scripts"
From 099f9f4c71c23046151f0489f311734c64631f13 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Sun, 29 Apr 2018 01:56:49 +0000
Subject: [PATCH 05/96] Update README.md
---
README.md | 81 +++++--------------------------------------------------
1 file changed, 7 insertions(+), 74 deletions(-)
diff --git a/README.md b/README.md
index 87cba85..542943b 100644
--- a/README.md
+++ b/README.md
@@ -1,81 +1,14 @@
# mod-LuaEngine
azerothcore 的 eluna 模块
-
-Not sure:
-src\server\game\Maps\MapInstanced.cpp
-```
-#ifdef ELUNA
- sEluna->FreeInstanceId(instanceId);
-#endif
-```
-Eluna API changes:
-OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
-
-
-No Settings related to eluna are added in the .
-No configuration files are added to the module.
-
-----------------------------------------------------------
-写英文老费劲了.原谅我英文水平差.没办法..天生的.
-有木有英语帝翻译一下
-
-折腾这个az+eluna,有几个地方是需要注意的,如何你要使用的话
-
-1.src\server\game\Maps\MapInstanced.cpp
-```
-#ifdef ELUNA
- sEluna->FreeInstanceId(instanceId);
-#endif
-```
-这一句我不确定加的是不是正确的
-
-2.改了eluna的一个api
+Eluna API changes:(更改了一个eluna的api)
```
OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
```
-为了兼容az的OnBeforeConfigLoad和OnAfterConfigLoad
-
-3.没有把这部分加到配置文件里,因为打算把这部分写到模块的配置文件里,目前没有弄.
-```
-###################################################################################################
-# ELUNA SETTINGS
-#
-# Eluna.Enabled
-# Description: Enable or disable Eluna LuaEngine
-# Default: true - (enabled)
-# false - (disabled)
-#
-# Eluna.TraceBack
-# Description: Sets whether to use debug.traceback function on a lua error or not.
-# Notice that you can redefine the function.
-# Default: false - (use default error output)
-# true - (use debug.traceback function)
-#
-# Eluna.ScriptPath
-# Description: Sets the location of the script folder to load scripts from
-# The path can be relative or absolute.
-# Default: "lua_scripts"
-#
-
-Eluna.Enabled = true
-Eluna.TraceBack = false
-Eluna.ScriptPath = "lua_scripts"
-```
-4.据说最近的eluna可以去掉单线程限制,目前我还没去掉,如果需要去掉的话
-src\server\game\Maps\MapManager.cpp
-```
-#ifdef ELUNA
- if (num_threads > 1)
- {
- // Force 1 thread for Eluna as lua is single threaded. By default thread count is 1
- // This should allow us not to use mutex locks
- ELUNA_LOG_ERROR("MAP:Map update threads set to %i, when Eluna only allows 1, changing to 1", num_threads);
- num_threads = 1;
- }
-#endif
-```
-把这段去掉
-
-
+azerothcore:
+https://github.com/AyaseCore/azerothcore-wotlk/tree/ElunaAzerothWotlk
+eluna:
+https://github.com/AyaseCore/Eluna/tree/ElunaAzerothWotlk
+azerothcore-module:
+https://github.com/AyaseCore/mod-LuaEngine
From 20c29ebb856bf06b0fc82051f1a08739f54a6d5b Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Sun, 29 Apr 2018 01:58:16 +0000
Subject: [PATCH 06/96] Update README.md
---
README.md | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/README.md b/README.md
index 542943b..2b685b7 100644
--- a/README.md
+++ b/README.md
@@ -7,8 +7,17 @@ OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
```
azerothcore:
+
https://github.com/AyaseCore/azerothcore-wotlk/tree/ElunaAzerothWotlk
+
+
eluna:
+
https://github.com/AyaseCore/Eluna/tree/ElunaAzerothWotlk
+
+
azerothcore-module:
+
https://github.com/AyaseCore/mod-LuaEngine
+
+
From 4162b3448e8740988968d16ec3ae44e7e42724ba Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Sun, 29 Apr 2018 21:52:59 +0800
Subject: [PATCH 07/96] Set theme jekyll-theme-slate
---
_config.yml | 1 +
1 file changed, 1 insertion(+)
create mode 100644 _config.yml
diff --git a/_config.yml b/_config.yml
new file mode 100644
index 0000000..c741881
--- /dev/null
+++ b/_config.yml
@@ -0,0 +1 @@
+theme: jekyll-theme-slate
\ No newline at end of file
From b74ad92c55e65a418e7e4d662852c0f326eb8f10 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Wed, 2 May 2018 01:59:44 +0000
Subject: [PATCH 08/96] Update README.md
---
README.md | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index 2b685b7..d24d0e3 100644
--- a/README.md
+++ b/README.md
@@ -6,18 +6,26 @@ Eluna API changes:(更改了一个eluna的api)
OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
```
-azerothcore:
+-------
+
+1. Merge my acore's ElunaAzerothwotlk branch.
https://github.com/AyaseCore/azerothcore-wotlk/tree/ElunaAzerothWotlk
-eluna:
-
-https://github.com/AyaseCore/Eluna/tree/ElunaAzerothWotlk
-
-
-azerothcore-module:
+2.Pull my lua module. Put it in the modules folder of acore.
https://github.com/AyaseCore/mod-LuaEngine
+3.Open folders:Modules /mod-LuaEngine/LuaEngine.
+
+
+4.Pull the ElunaAzerothwotlk branch of my eluna.
+
+https://github.com/AyaseCore/Eluna/tree/ElunaAzerothWotlk
+
+
+5.And then recompile.
+
+
From 0591565106777945c053cc9704cd24cc9934ebd0 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Fri, 4 May 2018 21:46:17 +0800
Subject: [PATCH 09/96] fix(test) #1 Ubuntu - Cant Link Library after Compile
---
CMakeLists.txt | 5 ++++-
LuaEngine | 2 +-
cmake/after_gs_install.cmake | 21 +++++++++++++++++++++
cmake/before_gs_install.cmake | 16 ++++++++++++++++
4 files changed, 42 insertions(+), 2 deletions(-)
create mode 100644 cmake/after_gs_install.cmake
create mode 100644 cmake/before_gs_install.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 04f922d..c3c0329 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,9 +1,12 @@
if( ELUNA )
CU_SET_PATH("CMAKE_MOD_ELUNA_ENGINE_DIR" "${CMAKE_CURRENT_LIST_DIR}")
add_subdirectory(lualib)
- add_subdirectory(LuaEngine)
+ #add_subdirectory(LuaEngine)
+ CU_ADD_HOOK(BEFORE_GAME_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/cmake/before_gs_install.cmake")
+ CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/cmake/after_gs_install.cmake")
CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_CURRENT_LIST_DIR}/cmake/after_ws_install.cmake")
+
install(FILES "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" DESTINATION ${CONF_DIR})
endif()
diff --git a/LuaEngine b/LuaEngine
index 629e503..909e514 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 629e50357f7faa85173ae1181b4e81e4f1518e73
+Subproject commit 909e51499870287c3a9bf22a4b8e379aa9ea2594
diff --git a/cmake/after_gs_install.cmake b/cmake/after_gs_install.cmake
new file mode 100644
index 0000000..d7e00af
--- /dev/null
+++ b/cmake/after_gs_install.cmake
@@ -0,0 +1,21 @@
+
+add_dependencies(game lualib)
+target_link_libraries(game lualib)
+
+if( WIN32 )
+ if ( MSVC )
+ add_custom_command(TARGET game
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/lua_scripts/extensions/"
+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/lua_scripts/extensions/"
+ )
+ elseif ( MINGW )
+ add_custom_command(TARGET game
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/lua_scripts/extensions/"
+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/lua_scripts/extensions/"
+ )
+ endif()
+endif()
+
+install(DIRECTORY extensions DESTINATION "${BIN_DIR}/lua_scripts/")
diff --git a/cmake/before_gs_install.cmake b/cmake/before_gs_install.cmake
new file mode 100644
index 0000000..d893169
--- /dev/null
+++ b/cmake/before_gs_install.cmake
@@ -0,0 +1,16 @@
+file(GLOB_RECURSE method_headers ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/*Methods.h)
+file(GLOB_RECURSE sources_ElunaFile_CPP ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/*.cpp )
+file(GLOB_RECURSE sources_ElunaFile_H ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/*.h)
+
+set(game_STAT_SRCS
+ ${game_STAT_SRCS}
+ ${sources_ElunaFile_H}
+ ${sources_ElunaFile_CPP}
+)
+
+source_group("LuaEngine\\Methods" FILES ${method_headers})
+
+source_group("LuaEngine\\Header Files" FILES ${sources_ElunaFile_H})
+
+source_group("LuaEngine\\Source Files" FILES ${sources_ElunaFile_CPP})
+
From 10df006b11a72bf40bc7149b1a3ad89c60f3fdf6 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Fri, 4 May 2018 23:37:56 +0800
Subject: [PATCH 10/96] some change
---
cmake/after_gs_install.cmake | 7 +++++++
cmake/after_ws_install.cmake | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/cmake/after_gs_install.cmake b/cmake/after_gs_install.cmake
index d7e00af..a3ce693 100644
--- a/cmake/after_gs_install.cmake
+++ b/cmake/after_gs_install.cmake
@@ -1,4 +1,11 @@
+include_directories(
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
+)
+
+
add_dependencies(game lualib)
target_link_libraries(game lualib)
diff --git a/cmake/after_ws_install.cmake b/cmake/after_ws_install.cmake
index 06387bd..91bbc6f 100644
--- a/cmake/after_ws_install.cmake
+++ b/cmake/after_ws_install.cmake
@@ -1,3 +1,10 @@
+
+include_directories(
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
+)
+
if( WIN32 )
if ( MSVC )
add_custom_command(TARGET worldserver
From d514a2032953c060440b6ee4415f867774917653 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Sun, 6 May 2018 18:24:43 +0800
Subject: [PATCH 11/96] modify the directory compatible Linux.
---
cmake/after_gs_install.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmake/after_gs_install.cmake b/cmake/after_gs_install.cmake
index a3ce693..7254cb2 100644
--- a/cmake/after_gs_install.cmake
+++ b/cmake/after_gs_install.cmake
@@ -25,4 +25,4 @@ if( WIN32 )
endif()
endif()
-install(DIRECTORY extensions DESTINATION "${BIN_DIR}/lua_scripts/")
+install(DIRECTORY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/lua_scripts/")
From 35b154c93bc65b3fab7defc7b3cea1c93f5b0622 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Sun, 6 May 2018 19:54:14 +0800
Subject: [PATCH 12/96] cmake change
---
CMakeLists.txt | 2 +-
cmake/before_script_install.cmake | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
create mode 100644 cmake/before_script_install.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c3c0329..673fa30 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,10 +1,10 @@
if( ELUNA )
CU_SET_PATH("CMAKE_MOD_ELUNA_ENGINE_DIR" "${CMAKE_CURRENT_LIST_DIR}")
add_subdirectory(lualib)
- #add_subdirectory(LuaEngine)
CU_ADD_HOOK(BEFORE_GAME_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/cmake/before_gs_install.cmake")
CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/cmake/after_gs_install.cmake")
+ CU_ADD_HOOK(BEFORE_SCRIPTS_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/cmake/before_script_install.cmake")
CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_CURRENT_LIST_DIR}/cmake/after_ws_install.cmake")
install(FILES "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" DESTINATION ${CONF_DIR})
diff --git a/cmake/before_script_install.cmake b/cmake/before_script_install.cmake
new file mode 100644
index 0000000..cce9e1d
--- /dev/null
+++ b/cmake/before_script_install.cmake
@@ -0,0 +1,5 @@
+include_directories(
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
+)
\ No newline at end of file
From 629cf03312d0901c09289c6f76f4db1c521e5bf4 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Mon, 7 May 2018 23:17:51 +0800
Subject: [PATCH 13/96] submodule update
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 909e514..7d71daa 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 909e51499870287c3a9bf22a4b8e379aa9ea2594
+Subproject commit 7d71daa8f78df69c2219379bd419b50e0dcbb37d
From 077d949206e7cb191cddb070fe54a2315ff5be7a Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Tue, 15 May 2018 23:11:32 +0800
Subject: [PATCH 14/96] Modify the eluna module installation method.
---
CMakeLists.txt | 14 +++-----------
cmake/after_load_conf.cmake | 9 +++++++++
2 files changed, 12 insertions(+), 11 deletions(-)
create mode 100644 cmake/after_load_conf.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 673fa30..1acb733 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,14 +1,6 @@
-if( ELUNA )
- CU_SET_PATH("CMAKE_MOD_ELUNA_ENGINE_DIR" "${CMAKE_CURRENT_LIST_DIR}")
- add_subdirectory(lualib)
-
- CU_ADD_HOOK(BEFORE_GAME_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/cmake/before_gs_install.cmake")
- CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/cmake/after_gs_install.cmake")
- CU_ADD_HOOK(BEFORE_SCRIPTS_LIBRARY "${CMAKE_CURRENT_LIST_DIR}/cmake/before_script_install.cmake")
- CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_CURRENT_LIST_DIR}/cmake/after_ws_install.cmake")
-
- install(FILES "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" DESTINATION ${CONF_DIR})
-endif()
+CU_SET_PATH("CMAKE_MOD_ELUNA_ENGINE_DIR" "${CMAKE_CURRENT_LIST_DIR}")
+CU_ADD_HOOK(AFTER_LOAD_CONF "${CMAKE_CURRENT_LIST_DIR}/cmake/after_load_conf.cmake")
+
diff --git a/cmake/after_load_conf.cmake b/cmake/after_load_conf.cmake
new file mode 100644
index 0000000..c7fcfba
--- /dev/null
+++ b/cmake/after_load_conf.cmake
@@ -0,0 +1,9 @@
+add_subdirectory(${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib)
+add_definitions(-DELUNA)
+CU_ADD_HOOK(BEFORE_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_gs_install.cmake")
+CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_gs_install.cmake")
+CU_ADD_HOOK(BEFORE_SCRIPTS_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_script_install.cmake")
+CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_ws_install.cmake")
+
+message("[Eluna Module] LuaEngine is enable!")
+
From 6ed6370d097b41e73906d258e440b4eb0d0fe671 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Tue, 15 May 2018 23:45:30 +0800
Subject: [PATCH 15/96] add some define in the cmake.
---
cmake/after_load_conf.cmake | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cmake/after_load_conf.cmake b/cmake/after_load_conf.cmake
index c7fcfba..2e682cb 100644
--- a/cmake/after_load_conf.cmake
+++ b/cmake/after_load_conf.cmake
@@ -1,9 +1,11 @@
add_subdirectory(${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib)
add_definitions(-DELUNA)
+add_definitions(-DAZEROTHCORE)
+add_definitions(-DWOTLK)
CU_ADD_HOOK(BEFORE_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_gs_install.cmake")
CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_gs_install.cmake")
CU_ADD_HOOK(BEFORE_SCRIPTS_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_script_install.cmake")
CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_ws_install.cmake")
-message("[Eluna Module] LuaEngine is enable!")
+message("** [Eluna Module] LuaEngine is enable!")
From 25e0e5405b52b931f3e5100dc57f80ef15d180bd Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Wed, 16 May 2018 20:01:43 +0800
Subject: [PATCH 16/96] update lua version:5.2.3 to 5.2.4
---
lualib/ldblib.c | 12 +++++++++++-
lualib/ldebug.c | 21 +++++++++++++++++++--
lualib/lgc.c | 4 ++--
lualib/llex.c | 4 ++--
lualib/lobject.h | 6 +++---
lualib/lopcodes.h | 4 ++--
lualib/ltablib.c | 10 ++++++----
lualib/lua.h | 8 ++++----
lualib/luaconf.h | 6 +++---
9 files changed, 52 insertions(+), 23 deletions(-)
diff --git a/lualib/ldblib.c b/lualib/ldblib.c
index 84fe3c7..bd8df9d 100644
--- a/lualib/ldblib.c
+++ b/lualib/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.132.1.1 2013/04/12 18:48:47 roberto Exp $
+** $Id: ldblib.c,v 1.132.1.2 2015/02/19 17:16:55 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -21,6 +21,11 @@
#define HOOKKEY "_HKEY"
+static void checkstack (lua_State *L, lua_State *L1, int n) {
+ if (L != L1 && !lua_checkstack(L1, n))
+ luaL_error(L, "stack overflow");
+}
+
static int db_getregistry (lua_State *L) {
lua_pushvalue(L, LUA_REGISTRYINDEX);
@@ -114,6 +119,7 @@ static int db_getinfo (lua_State *L) {
int arg;
lua_State *L1 = getthread(L, &arg);
const char *options = luaL_optstring(L, arg+2, "flnStu");
+ checkstack(L, L1, 3);
if (lua_isnumber(L, arg+1)) {
if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
lua_pushnil(L); /* level out of range */
@@ -173,6 +179,7 @@ static int db_getlocal (lua_State *L) {
else { /* stack-level argument */
if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
return luaL_argerror(L, arg+1, "level out of range");
+ checkstack(L, L1, 1);
name = lua_getlocal(L1, &ar, nvar);
if (name) {
lua_xmove(L1, L, 1); /* push local value */
@@ -196,6 +203,7 @@ static int db_setlocal (lua_State *L) {
return luaL_argerror(L, arg+1, "level out of range");
luaL_checkany(L, arg+3);
lua_settop(L, arg+3);
+ checkstack(L, L1, 1);
lua_xmove(L, L1, 1);
lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));
return 1;
@@ -313,6 +321,7 @@ static int db_sethook (lua_State *L) {
lua_pushvalue(L, -1);
lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
}
+ checkstack(L, L1, 1);
lua_pushthread(L1); lua_xmove(L1, L, 1);
lua_pushvalue(L, arg+1);
lua_rawset(L, -3); /* set new hook */
@@ -331,6 +340,7 @@ static int db_gethook (lua_State *L) {
lua_pushliteral(L, "external hook");
else {
gethooktable(L);
+ checkstack(L, L1, 1);
lua_pushthread(L1); lua_xmove(L1, L, 1);
lua_rawget(L, -2); /* get hook */
lua_remove(L, -2); /* remove hook table */
diff --git a/lualib/ldebug.c b/lualib/ldebug.c
index 20d663e..9611846 100644
--- a/lualib/ldebug.c
+++ b/lualib/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 2.90.1.3 2013/05/16 16:04:15 roberto Exp $
+** $Id: ldebug.c,v 2.90.1.4 2015/02/19 17:05:13 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -47,6 +47,16 @@ static int currentline (CallInfo *ci) {
}
+static void swapextra (lua_State *L) {
+ if (L->status == LUA_YIELD) {
+ CallInfo *ci = L->ci; /* get function that yielded */
+ StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
+ ci->func = restorestack(L, ci->extra);
+ ci->extra = savestack(L, temp);
+ }
+}
+
+
/*
** this function can be called asynchronous (e.g. during a signal)
*/
@@ -144,6 +154,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
const char *name;
lua_lock(L);
+ swapextra(L);
if (ar == NULL) { /* information about non-active function? */
if (!isLfunction(L->top - 1)) /* not a Lua function? */
name = NULL;
@@ -158,6 +169,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
api_incr_top(L);
}
}
+ swapextra(L);
lua_unlock(L);
return name;
}
@@ -165,11 +177,14 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
StkId pos = 0; /* to avoid warnings */
- const char *name = findlocal(L, ar->i_ci, n, &pos);
+ const char *name;
lua_lock(L);
+ swapextra(L);
+ name = findlocal(L, ar->i_ci, n, &pos);
if (name)
setobjs2s(L, pos, L->top - 1);
L->top--; /* pop value */
+ swapextra(L);
lua_unlock(L);
return name;
}
@@ -269,6 +284,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
CallInfo *ci;
StkId func;
lua_lock(L);
+ swapextra(L);
if (*what == '>') {
ci = NULL;
func = L->top - 1;
@@ -287,6 +303,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
setobjs2s(L, L->top, func);
api_incr_top(L);
}
+ swapextra(L);
if (strchr(what, 'L'))
collectvalidlines(L, cl);
lua_unlock(L);
diff --git a/lualib/lgc.c b/lualib/lgc.c
index 52460dc..553fd17 100644
--- a/lualib/lgc.c
+++ b/lualib/lgc.c
@@ -1,5 +1,5 @@
/*
-** $Id: lgc.c,v 2.140.1.2 2013/04/26 18:22:05 roberto Exp $
+** $Id: lgc.c,v 2.140.1.3 2014/09/01 16:55:08 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@@ -403,7 +403,7 @@ static int traverseephemeron (global_State *g, Table *h) {
reallymarkobject(g, gcvalue(gval(n))); /* mark it now */
}
}
- if (prop)
+ if (g->gcstate != GCSatomic || prop)
linktable(h, &g->ephemeron); /* have to propagate again */
else if (hasclears) /* does table have white keys? */
linktable(h, &g->allweak); /* may have to clean white keys */
diff --git a/lualib/llex.c b/lualib/llex.c
index c4b820e..32cdcf1 100644
--- a/lualib/llex.c
+++ b/lualib/llex.c
@@ -1,5 +1,5 @@
/*
-** $Id: llex.c,v 2.63.1.2 2013/08/30 15:49:41 roberto Exp $
+** $Id: llex.c,v 2.63.1.3 2015/02/09 17:56:34 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@@ -152,7 +152,7 @@ static void inclinenumber (LexState *ls) {
if (currIsNewline(ls) && ls->current != old)
next(ls); /* skip `\n\r' or `\r\n' */
if (++ls->linenumber >= MAX_INT)
- luaX_syntaxerror(ls, "chunk has too many lines");
+ lexerror(ls, "chunk has too many lines", 0);
}
diff --git a/lualib/lobject.h b/lualib/lobject.h
index 3a630b9..bc0bb69 100644
--- a/lualib/lobject.h
+++ b/lualib/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 2.71.1.1 2013/04/12 18:48:47 roberto Exp $
+** $Id: lobject.h,v 2.71.1.2 2014/05/07 14:14:58 roberto Exp $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -561,12 +561,12 @@ typedef struct Table {
CommonHeader;
lu_byte flags; /* 1<= R(A) + 1 */
+OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A - 1) */
OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
diff --git a/lualib/ltablib.c b/lualib/ltablib.c
index 6001224..99764d2 100644
--- a/lualib/ltablib.c
+++ b/lualib/ltablib.c
@@ -1,10 +1,11 @@
/*
-** $Id: ltablib.c,v 1.65.1.1 2013/04/12 18:48:47 roberto Exp $
+** $Id: ltablib.c,v 1.65.1.2 2014/05/07 16:32:55 roberto Exp $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/
+#include
#include
#define ltablib_c
@@ -134,13 +135,14 @@ static int pack (lua_State *L) {
static int unpack (lua_State *L) {
- int i, e, n;
+ int i, e;
+ unsigned int n;
luaL_checktype(L, 1, LUA_TTABLE);
i = luaL_optint(L, 2, 1);
e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1));
if (i > e) return 0; /* empty range */
- n = e - i + 1; /* number of elements */
- if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
+ n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */
+ if (n > (INT_MAX - 10) || !lua_checkstack(L, ++n))
return luaL_error(L, "too many results to unpack");
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
while (i++ < e) /* push arg[i + 1...e] */
diff --git a/lualib/lua.h b/lualib/lua.h
index 149a2c3..ff4a108 100644
--- a/lualib/lua.h
+++ b/lualib/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.285.1.2 2013/11/11 12:09:16 roberto Exp $
+** $Id: lua.h,v 1.285.1.4 2015/02/21 14:04:50 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@@ -19,11 +19,11 @@
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "2"
#define LUA_VERSION_NUM 502
-#define LUA_VERSION_RELEASE "3"
+#define LUA_VERSION_RELEASE "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-2013 Lua.org, PUC-Rio"
+#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2015 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
@@ -418,7 +418,7 @@ struct lua_Debug {
/******************************************************************************
-* Copyright (C) 1994-2013 Lua.org, PUC-Rio.
+* Copyright (C) 1994-2015 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
diff --git a/lualib/luaconf.h b/lualib/luaconf.h
index 18be9a9..1b0ff59 100644
--- a/lualib/luaconf.h
+++ b/lualib/luaconf.h
@@ -1,5 +1,5 @@
/*
-** $Id: luaconf.h,v 1.176.1.1 2013/04/12 18:48:47 roberto Exp $
+** $Id: luaconf.h,v 1.176.1.2 2013/11/21 17:26:16 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@@ -326,7 +326,7 @@
/*
-@@ LUA_INT32 is an signed integer with exactly 32 bits.
+@@ LUA_INT32 is a signed integer with exactly 32 bits.
@@ LUAI_UMEM is an unsigned integer big enough to count the total
@* memory used by Lua.
@@ LUAI_MEM is a signed integer big enough to count the total memory
@@ -350,7 +350,7 @@
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
-** its only purpose is to stop Lua to consume unlimited stack
+** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
*/
#if LUAI_BITSINT >= 32
From 632054a0bdf516da7b3ba511c3d93ec360fea657 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Thu, 17 May 2018 22:25:09 +0800
Subject: [PATCH 17/96] redo LuaEngine file.
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 7d71daa..6f06eca 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 7d71daa8f78df69c2219379bd419b50e0dcbb37d
+Subproject commit 6f06ecaba69ba6479e192808636d462b96b58bf1
From 4f4ad232e740221b13c1ccae67539aec3767ca22 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Wed, 23 May 2018 22:38:31 +0800
Subject: [PATCH 18/96] merge "skeleton-module"
---
.editorconfig | 8 ++++++
.gitattributes | 62 +++++++++++++++++++++++++++++++++++++++++
.gitignore | 48 +++++++++++++++++++++++++++++++
include.sh | 0
sql/auth/.gitkeep | 0
sql/characters/.gitkeep | 0
sql/world/.gitkeep | 0
7 files changed, 118 insertions(+)
create mode 100644 .editorconfig
create mode 100644 .gitattributes
create mode 100644 .gitignore
create mode 100644 include.sh
create mode 100644 sql/auth/.gitkeep
create mode 100644 sql/characters/.gitkeep
create mode 100644 sql/world/.gitkeep
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..eb64e2f
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,8 @@
+[*]
+charset = utf-8
+indent_style = space
+indent_size = 4
+tab_width = 4
+insert_final_newline = true
+trim_trailing_whitespace = true
+max_line_length = 80
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..823b0b0
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,62 @@
+## AUTO-DETECT
+## Handle line endings automatically for files detected as
+## text and leave all files detected as binary untouched.
+## This will handle all files NOT defined below.
+* text=auto eol=lf
+
+# Text
+*.conf
+*.conf.dist
+*.txt
+*.md
+*.cmake
+
+# Bash
+*.sh text
+
+# Lua if lua module?
+*.lua
+
+# SQL
+*.sql
+
+# C++
+*.c text
+*.cc text
+*.cxx text
+*.cpp text
+*.c++ text
+*.hpp text
+*.h text
+*.h++ text
+*.hh text
+
+
+## For documentation
+
+# Documents
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
+
+
+# Graphics
+*.png binary
+*.jpg binary
+*.jpeg binary
+*.gif binary
+*.tif binary
+*.tiff binary
+*.ico binary
+# SVG treated as an asset (binary) by default. If you want to treat it as text,
+# comment-out the following line and uncomment the line after.
+*.svg binary
+#*.svg text
+*.eps binary
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d011fdd
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,48 @@
+!.gitignore
+
+#
+#Generic
+#
+
+.directory
+.mailmap
+*.orig
+*.rej
+*~
+.hg/
+*.kdev*
+.DS_Store
+CMakeLists.txt.user
+*.bak
+*.patch
+*.diff
+*.REMOTE.*
+*.BACKUP.*
+*.BASE.*
+*.LOCAL.*
+
+#
+# IDE & other softwares
+#
+/.settings/
+/.externalToolBuilders/*
+# exclude in all levels
+nbproject/
+.sync.ffs_db
+*.kate-swp
+
+#
+# Eclipse
+#
+*.pydevproject
+.metadata
+.gradle
+tmp/
+*.tmp
+*.swp
+*~.nib
+local.properties
+.settings/
+.loadpath
+.project
+.cproject
diff --git a/include.sh b/include.sh
new file mode 100644
index 0000000..e69de29
diff --git a/sql/auth/.gitkeep b/sql/auth/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/sql/characters/.gitkeep b/sql/characters/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/sql/world/.gitkeep b/sql/world/.gitkeep
new file mode 100644
index 0000000..e69de29
From f9570085f4750235101b0dda9f55da45c8a249ca Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Wed, 23 May 2018 23:11:39 +0800
Subject: [PATCH 19/96] update readme.md
---
README.md | 36 +++++++++++-------------------------
README_EN.md | 17 +++++++++++++++++
2 files changed, 28 insertions(+), 25 deletions(-)
create mode 100644 README_EN.md
diff --git a/README.md b/README.md
index d24d0e3..8164476 100644
--- a/README.md
+++ b/README.md
@@ -1,31 +1,17 @@
# mod-LuaEngine
-azerothcore 的 eluna 模块
+中文|[english](README_EN.md)
-Eluna API changes:(更改了一个eluna的api)
+一个用于AzerothCore的ELUNA模块.
+
+为了兼容AzerothCore.更改了一个eluna的api
```
OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
```
--------
-
-1. Merge my acore's ElunaAzerothwotlk branch.
-
-https://github.com/AyaseCore/azerothcore-wotlk/tree/ElunaAzerothWotlk
-
-
-2.Pull my lua module. Put it in the modules folder of acore.
-
-https://github.com/AyaseCore/mod-LuaEngine
-
-
-3.Open folders:Modules /mod-LuaEngine/LuaEngine.
-
-
-4.Pull the ElunaAzerothwotlk branch of my eluna.
-
-https://github.com/AyaseCore/Eluna/tree/ElunaAzerothWotlk
-
-
-5.And then recompile.
-
-
+如何安装:
+* 下载这个模块:[download](https://github.com/AyaseCore/mod-LuaEngine/archive/master.zip)
+* 解压并放到Azerothcore源码的modules文件夹中.
+* 下载ELUNA的核心文件:[download](https://github.com/AyaseCore/Eluna/archive/ElunaAzerothWotlk.zip)
+* 解压并放置到模块的LuaEngine文件夹中:mod-LuaEngine/LuaEngine
+* 重新cmake.
+* 重新生成.
diff --git a/README_EN.md b/README_EN.md
new file mode 100644
index 0000000..d2115fd
--- /dev/null
+++ b/README_EN.md
@@ -0,0 +1,17 @@
+# mod-LuaEngine
+[chinese](README.md) | english
+
+a Eluna module for AzerothCore
+
+To make Eluna compatible with Azerothcore.one lua Api has been changed.
+```
+OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
+```
+
+How to install:
+* download this module:[download](https://github.com/AyaseCore/mod-LuaEngine/archive/master.zip)
+* unzip this module.Put it in the modules folder of the Azerothcore.
+* download ELUNA core file:[download](https://github.com/AyaseCore/Eluna/archive/ElunaAzerothWotlk.zip)
+* unzip,Put it in the lua module folder:mod-LuaEngine/LuaEngine
+* cmake again
+* rebuild.
From 13e33ecace190d85cf14beb30f73ecb3b4bbf709 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Thu, 31 May 2018 19:24:05 +0800
Subject: [PATCH 20/96] link branch :elunaAzerothwotlk.
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 6f06eca..35295a3 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 6f06ecaba69ba6479e192808636d462b96b58bf1
+Subproject commit 35295a3f9acafce9c22b871463724266205779d8
From 85792eaf6fb22696879aaaedd5913de1a8b91e75 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Thu, 7 Jun 2018 20:51:22 +0800
Subject: [PATCH 21/96] submodule change.
---
.gitmodules | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.gitmodules b/.gitmodules
index 470fc63..daac882 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,4 +1,4 @@
[submodule "LuaEngine"]
path = LuaEngine
- url = https://github.com/AyaseCore/Eluna.git
- branch = ElunaAzerothWotlk
+ url = https://github.com/ElunaLuaEngine/Eluna.git
+ branch = master
From 6e1c062b5381b08b189a6c7fef96614ea49c72e9 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Thu, 7 Jun 2018 20:52:28 +0800
Subject: [PATCH 22/96] Change the submodule to the official eluna.
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 35295a3..9b5499d 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 35295a3f9acafce9c22b871463724266205779d8
+Subproject commit 9b5499db9cf8ba05893455a276f55cc132e3bf73
From cd53cc25b1d98d397c66bb219480220c58d4da60 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Fri, 8 Jun 2018 22:41:25 +0800
Subject: [PATCH 23/96] update readme.md
---
README.md | 24 ++++++++++++++----------
README_CN.md | 21 +++++++++++++++++++++
README_EN.md | 17 -----------------
3 files changed, 35 insertions(+), 27 deletions(-)
create mode 100644 README_CN.md
delete mode 100644 README_EN.md
diff --git a/README.md b/README.md
index 8164476..a13ec10 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,21 @@
# mod-LuaEngine
-中文|[english](README_EN.md)
+ english | [chinese](README_CN.md)
-一个用于AzerothCore的ELUNA模块.
+a Eluna module for AzerothCore
-为了兼容AzerothCore.更改了一个eluna的api
+To make Eluna compatible with Azerothcore.one lua Api has been changed.
```
OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
```
-如何安装:
-* 下载这个模块:[download](https://github.com/AyaseCore/mod-LuaEngine/archive/master.zip)
-* 解压并放到Azerothcore源码的modules文件夹中.
-* 下载ELUNA的核心文件:[download](https://github.com/AyaseCore/Eluna/archive/ElunaAzerothWotlk.zip)
-* 解压并放置到模块的LuaEngine文件夹中:mod-LuaEngine/LuaEngine
-* 重新cmake.
-* 重新生成.
+How to install:
+* download or clone this module:
+> [download zip file.](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
+> clone `git clone https://github.com/azerothcore/mod-eluna-lua-engine.git`
+* Put it in the modules folder of the Azerothcore.
+* download or clone the ELUNA core file:
+> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
+> clone `git clone https://github.com/ElunaLuaEngine/Eluna.git`
+* Put it in the lua module folder:mod-LuaEngine/LuaEngine
+* cmake again
+* rebuild.
\ No newline at end of file
diff --git a/README_CN.md b/README_CN.md
new file mode 100644
index 0000000..7093e8f
--- /dev/null
+++ b/README_CN.md
@@ -0,0 +1,21 @@
+# mod-LuaEngine
+[english](README.md) | 中文
+
+一个用于AzerothCore的ELUNA模块.
+
+为了兼容AzerothCore.更改了一个eluna的api
+```
+OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
+```
+
+如何安装:
+* 下载或者克隆这个模块:
+> [下载zip压缩包](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
+> 或者克隆 `git clone https://github.com/azerothcore/mod-eluna-lua-engine.git`
+* 解压并放到Azerothcore源码的modules文件夹中.
+* 下载或者克隆ELUNA的核心文件:
+> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
+> clone `git clone https://github.com/ElunaLuaEngine/Eluna.git`
+* 解压并放置到模块的LuaEngine文件夹中:mod-LuaEngine/LuaEngine
+* 重新cmake.
+* 重新生成.
\ No newline at end of file
diff --git a/README_EN.md b/README_EN.md
deleted file mode 100644
index d2115fd..0000000
--- a/README_EN.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# mod-LuaEngine
-[chinese](README.md) | english
-
-a Eluna module for AzerothCore
-
-To make Eluna compatible with Azerothcore.one lua Api has been changed.
-```
-OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
-```
-
-How to install:
-* download this module:[download](https://github.com/AyaseCore/mod-LuaEngine/archive/master.zip)
-* unzip this module.Put it in the modules folder of the Azerothcore.
-* download ELUNA core file:[download](https://github.com/AyaseCore/Eluna/archive/ElunaAzerothWotlk.zip)
-* unzip,Put it in the lua module folder:mod-LuaEngine/LuaEngine
-* cmake again
-* rebuild.
From da01904615591f07f028fcb99bd99023c980a0cc Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Fri, 8 Jun 2018 22:59:46 +0800
Subject: [PATCH 24/96] Update README.md
---
README.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index a13ec10..b1e3fcc 100644
--- a/README.md
+++ b/README.md
@@ -11,11 +11,11 @@ OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
How to install:
* download or clone this module:
> [download zip file.](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
-> clone `git clone https://github.com/azerothcore/mod-eluna-lua-engine.git`
+> or clone `git clone https://github.com/azerothcore/mod-eluna-lua-engine.git`
* Put it in the modules folder of the Azerothcore.
* download or clone the ELUNA core file:
> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
-> clone `git clone https://github.com/ElunaLuaEngine/Eluna.git`
+> or clone `git clone https://github.com/ElunaLuaEngine/Eluna.git`
* Put it in the lua module folder:mod-LuaEngine/LuaEngine
* cmake again
-* rebuild.
\ No newline at end of file
+* rebuild.
From b49fd65a0d4e2f1fa51a8e0c56fe7c2a06f42016 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Mon, 11 Jun 2018 22:39:12 +0800
Subject: [PATCH 25/96] Eluna update version
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 9b5499d..a4ef7ee 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 9b5499db9cf8ba05893455a276f55cc132e3bf73
+Subproject commit a4ef7eeaec044548a39f3e2b9db582cd78e4eb91
From 0b12fbb05328455267137d159165b976afaa7e06 Mon Sep 17 00:00:00 2001
From: MaloW
Date: Mon, 16 Jul 2018 23:52:12 +0200
Subject: [PATCH 26/96] Update README.md
Updated installation guide to avoid an issue where LuaEngine.h would not be included properly in the project.
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index b1e3fcc..05d21ab 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ How to install:
* Put it in the modules folder of the Azerothcore.
* download or clone the ELUNA core file:
> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
-> or clone `git clone https://github.com/ElunaLuaEngine/Eluna.git`
-* Put it in the lua module folder:mod-LuaEngine/LuaEngine
+> or clone `git clone https://github.com/ElunaLuaEngine/Eluna.git .`
+* Put it in the lua module folder:mod-LuaEngine/LuaEngine. (If you downloaded the zip-file you'll want to move all the files inside the Eluna-master folder into the mod-eluna-lua-engine/LuaEngine folder. LuaEngine.h needs to be directly under mod-eluna-lua-engine/LuaEngine without any extra sub-folders.)
* cmake again
* rebuild.
From fcdee8ab330843396f613db4885ed2bd4a4b1e1c Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Thu, 15 Nov 2018 23:22:17 +0800
Subject: [PATCH 27/96] Set theme jekyll-theme-architect
---
_config.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/_config.yml b/_config.yml
index c741881..3397c9a 100644
--- a/_config.yml
+++ b/_config.yml
@@ -1 +1 @@
-theme: jekyll-theme-slate
\ No newline at end of file
+theme: jekyll-theme-architect
\ No newline at end of file
From 8e08b6a9fc2b1da484bc766de05873d12233fd5e Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Mon, 18 Feb 2019 23:31:48 +0800
Subject: [PATCH 28/96] Eluna update version.
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index a4ef7ee..e1d151b 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit a4ef7eeaec044548a39f3e2b9db582cd78e4eb91
+Subproject commit e1d151b86204e53e04e8ec3d971faf1fa944d3cc
From 12ab5ef9495cd26a301fbca23541c82e041a9466 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Mon, 18 Feb 2019 23:45:56 +0800
Subject: [PATCH 29/96] update readme.md
---
README.md | 23 +++++++++++------------
README_CN.md | 20 +++++++++-----------
2 files changed, 20 insertions(+), 23 deletions(-)
diff --git a/README.md b/README.md
index b1e3fcc..f8e312d 100644
--- a/README.md
+++ b/README.md
@@ -1,21 +1,20 @@
# mod-LuaEngine
english | [chinese](README_CN.md)
-a Eluna module for AzerothCore
-
-To make Eluna compatible with Azerothcore.one lua Api has been changed.
-```
-OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
-```
+a Eluna module for AzerothCore.
How to install:
-* download or clone this module:
+
+1. download or clone this module:
> [download zip file.](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
> or clone `git clone https://github.com/azerothcore/mod-eluna-lua-engine.git`
-* Put it in the modules folder of the Azerothcore.
-* download or clone the ELUNA core file:
+2. Put it in the modules folder of the Azerothcore.
+3. download or clone the ELUNA core file:
> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
> or clone `git clone https://github.com/ElunaLuaEngine/Eluna.git`
-* Put it in the lua module folder:mod-LuaEngine/LuaEngine
-* cmake again
-* rebuild.
+4. Put it in the lua module folder:mod-LuaEngine/LuaEngine
+5. cmake again
+6. rebuild.
+
+Eluna API : [http://www.elunaengine.com/](http://www.elunaengine.com/)
+
diff --git a/README_CN.md b/README_CN.md
index 7093e8f..de371c4 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -3,19 +3,17 @@
一个用于AzerothCore的ELUNA模块.
-为了兼容AzerothCore.更改了一个eluna的api
-```
-OnConfigLoad(bool reload) => OnConfigLoad(bool reload, bool isBefore)
-```
-
如何安装:
-* 下载或者克隆这个模块:
+
+1. 下载或者克隆这个模块:
> [下载zip压缩包](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
> 或者克隆 `git clone https://github.com/azerothcore/mod-eluna-lua-engine.git`
-* 解压并放到Azerothcore源码的modules文件夹中.
-* 下载或者克隆ELUNA的核心文件:
+2. 解压并放到Azerothcore源码的modules文件夹中.
+3. 下载或者克隆ELUNA的核心文件:
> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
> clone `git clone https://github.com/ElunaLuaEngine/Eluna.git`
-* 解压并放置到模块的LuaEngine文件夹中:mod-LuaEngine/LuaEngine
-* 重新cmake.
-* 重新生成.
\ No newline at end of file
+4. 解压并放置到模块的LuaEngine文件夹中:mod-LuaEngine/LuaEngine
+5. 重新cmake.
+6. 重新生成.
+
+Eluna API : [http://www.elunaengine.com/](http://www.elunaengine.com/)
\ No newline at end of file
From bd28c0a0455118ac98957604a843e157df3b9309 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Wed, 20 Feb 2019 20:12:49 +0800
Subject: [PATCH 30/96] merge 'skeleton-module'
---
.git_commit_template.txt | 49 ++++++++++++++++++++++
.gitattributes | 89 +++++++++++++++++++++++++++++-----------
.gitignore | 2 +-
sql/README.md | 24 +++++++++++
4 files changed, 140 insertions(+), 24 deletions(-)
create mode 100644 .git_commit_template.txt
create mode 100644 sql/README.md
diff --git a/.git_commit_template.txt b/.git_commit_template.txt
new file mode 100644
index 0000000..708b551
--- /dev/null
+++ b/.git_commit_template.txt
@@ -0,0 +1,49 @@
+### TITLE
+## Type(Scope/Subscope): Commit ultra short explanation
+## |---- Write below the examples with a maximum of 50 characters ----|
+## Example 1: fix(DB/SAI): Missing spell to NPC Hogger
+## Example 2: fix(CORE/Raid): Phase 2 of Ragnaros
+## Example 3: feat(CORE/Commands): New GM command to do something
+
+
+### DESCRIPTION
+## Explain why this change is being made, what does it fix etc...
+## |---- Write below the examples with a maximum of 72 characters per lines ----|
+## Example: Hogger (id: 492) was not charging player when being engaged.
+
+
+## Provide links to any issue, commit, pull request or other resource
+## Example 1: Closes issue #23
+## Example 2: Ported from other project's commit (link)
+## Example 3: References taken from wowpedia / wowhead / wowwiki / https://wowgaming.altervista.org/aowow/
+
+
+
+## =======================================================
+## EXTRA INFOS
+## =======================================================
+## "Type" can be:
+## feat (new feature)
+## fix (bug fix)
+## refactor (refactoring production code)
+## style (formatting, missing semi colons, etc; no code change)
+## docs (changes to documentation)
+## test (adding or refactoring tests; no production code change)
+## chore (updating bash scripts, git files etc; no production code change)
+## --------------------
+## Remember to
+## Capitalize the subject line
+## Use the imperative mood in the subject line
+## Do not end the subject line with a period
+## Separate subject from body with a blank line
+## Use the body to explain what and why rather than how
+## Can use multiple lines with "-" for bullet points in body
+## --------------------
+## More info here https://www.conventionalcommits.org/en/v1.0.0-beta.2/
+## =======================================================
+## "Scope" can be:
+## CORE (core related, c++)
+## DB (database related, sql)
+## =======================================================
+## "Subscope" is optional and depends on the nature of the commit.
+## =======================================================
diff --git a/.gitattributes b/.gitattributes
index 823b0b0..7ef9001 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -5,22 +5,19 @@
* text=auto eol=lf
# Text
-*.conf
-*.conf.dist
-*.txt
-*.md
-*.cmake
+*.conf text
+*.conf.dist text
+*.cmake text
-# Bash
+## Scripts
*.sh text
+*.fish text
+*.lua text
-# Lua if lua module?
-*.lua
+## SQL
+*.sql text
-# SQL
-*.sql
-
-# C++
+## C++
*.c text
*.cc text
*.cxx text
@@ -46,17 +43,63 @@
*.rtf diff=astextplain
*.RTF diff=astextplain
+## DOCUMENTATION
+*.markdown text
+*.md text
+*.mdwn text
+*.mdown text
+*.mkd text
+*.mkdn text
+*.mdtxt text
+*.mdtext text
+*.txt text
+AUTHORS text
+CHANGELOG text
+CHANGES text
+CONTRIBUTING text
+COPYING text
+copyright text
+*COPYRIGHT* text
+INSTALL text
+license text
+LICENSE text
+NEWS text
+readme text
+*README* text
+TODO text
-# Graphics
-*.png binary
-*.jpg binary
+## GRAPHICS
+*.ai binary
+*.bmp binary
+*.eps binary
+*.gif binary
+*.ico binary
+*.jng binary
+*.jp2 binary
+*.jpg binary
*.jpeg binary
-*.gif binary
-*.tif binary
+*.jpx binary
+*.jxr binary
+*.pdf binary
+*.png binary
+*.psb binary
+*.psd binary
+*.svg text
+*.svgz binary
+*.tif binary
*.tiff binary
-*.ico binary
-# SVG treated as an asset (binary) by default. If you want to treat it as text,
-# comment-out the following line and uncomment the line after.
-*.svg binary
-#*.svg text
-*.eps binary
+*.wbmp binary
+*.webp binary
+
+
+## ARCHIVES
+*.7z binary
+*.gz binary
+*.jar binary
+*.rar binary
+*.tar binary
+*.zip binary
+
+## EXECUTABLES
+*.exe binary
+*.pyc binary
diff --git a/.gitignore b/.gitignore
index d011fdd..c6e1299 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,7 +8,7 @@
.mailmap
*.orig
*.rej
-*~
+*.*~
.hg/
*.kdev*
.DS_Store
diff --git a/sql/README.md b/sql/README.md
new file mode 100644
index 0000000..3afd348
--- /dev/null
+++ b/sql/README.md
@@ -0,0 +1,24 @@
+# BEST PRACTICES
+
+## Create a new table
+
+**Example:**
+```
+CREATE TABLE IF NOT EXISTS `table`(
+ `id` int(11) unsigned NOT NULL,
+ `active` BOOLEAN DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+```
+
+**Boolean datatype in mysql:**
+Use "TinyInt(1)"" or "Boolean" (this is the same thing)
+
+"bit(1)" can also work, but it may require a syntax like b'(0) and b'(1) when inserting (not sure).
+
+If there are multiple booleans in the same table, bit(1) is better, otherwise it's the same result.
+
+
+## Resources
+
+https://www.w3schools.com/sql/sql_datatypes.asp
From 542c7213c384004d13e65b2777d15da26e9e8606 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Wed, 20 Feb 2019 20:17:44 +0800
Subject: [PATCH 31/96] Use the new CMAKE macro.
---
cmake/after_load_conf.cmake | 2 ++
cmake/after_ws_install.cmake | 16 ----------------
2 files changed, 2 insertions(+), 16 deletions(-)
diff --git a/cmake/after_load_conf.cmake b/cmake/after_load_conf.cmake
index 2e682cb..3ed0075 100644
--- a/cmake/after_load_conf.cmake
+++ b/cmake/after_load_conf.cmake
@@ -7,5 +7,7 @@ CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_gs_ins
CU_ADD_HOOK(BEFORE_SCRIPTS_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_script_install.cmake")
CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_ws_install.cmake")
+AC_ADD_CONFIG_FILE("${CMAKE_CURRENT_LIST_DIR}/conf/mod_LuaEngine.conf.dist")
+
message("** [Eluna Module] LuaEngine is enable!")
diff --git a/cmake/after_ws_install.cmake b/cmake/after_ws_install.cmake
index 91bbc6f..c2912ab 100644
--- a/cmake/after_ws_install.cmake
+++ b/cmake/after_ws_install.cmake
@@ -4,19 +4,3 @@ include_directories(
${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
)
-
-if( WIN32 )
- if ( MSVC )
- add_custom_command(TARGET worldserver
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/
- )
- elseif ( MINGW )
- add_custom_command(TARGET worldserver
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" ${CMAKE_BINARY_DIR}/bin/
- )
- endif()
-endif()
-
-install(FILES "${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist" DESTINATION ${CONF_DIR})
\ No newline at end of file
From e541cb22b218d58a3cbe7c6a2f21893e12365363 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Wed, 20 Feb 2019 20:31:57 +0800
Subject: [PATCH 32/96] Fix config file directory error.
---
cmake/after_load_conf.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmake/after_load_conf.cmake b/cmake/after_load_conf.cmake
index 3ed0075..2c10f00 100644
--- a/cmake/after_load_conf.cmake
+++ b/cmake/after_load_conf.cmake
@@ -7,7 +7,7 @@ CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_gs_ins
CU_ADD_HOOK(BEFORE_SCRIPTS_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_script_install.cmake")
CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_ws_install.cmake")
-AC_ADD_CONFIG_FILE("${CMAKE_CURRENT_LIST_DIR}/conf/mod_LuaEngine.conf.dist")
+AC_ADD_CONFIG_FILE("${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist")
message("** [Eluna Module] LuaEngine is enable!")
From 940ed6fa801d6c8991d932d42ad56247ce8ebc19 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Sat, 9 Mar 2019 22:45:01 +0800
Subject: [PATCH 33/96] Move files ObjectGuid.h.
---
cmake/after_gs_install.cmake | 2 +-
cmake/after_ws_install.cmake | 2 +-
cmake/before_script_install.cmake | 2 +-
ObjectGuid.h => src/ObjectGuid.h | 0
4 files changed, 3 insertions(+), 3 deletions(-)
rename ObjectGuid.h => src/ObjectGuid.h (100%)
diff --git a/cmake/after_gs_install.cmake b/cmake/after_gs_install.cmake
index 7254cb2..19722a5 100644
--- a/cmake/after_gs_install.cmake
+++ b/cmake/after_gs_install.cmake
@@ -1,8 +1,8 @@
include_directories(
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}
${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/src
)
diff --git a/cmake/after_ws_install.cmake b/cmake/after_ws_install.cmake
index c2912ab..3fbebd1 100644
--- a/cmake/after_ws_install.cmake
+++ b/cmake/after_ws_install.cmake
@@ -1,6 +1,6 @@
include_directories(
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}
${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/src
)
diff --git a/cmake/before_script_install.cmake b/cmake/before_script_install.cmake
index cce9e1d..7487800 100644
--- a/cmake/before_script_install.cmake
+++ b/cmake/before_script_install.cmake
@@ -1,5 +1,5 @@
include_directories(
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}
${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/src
)
\ No newline at end of file
diff --git a/ObjectGuid.h b/src/ObjectGuid.h
similarity index 100%
rename from ObjectGuid.h
rename to src/ObjectGuid.h
From 157d833327b7a9df53d0fc2c1d01f4f3222ae1b0 Mon Sep 17 00:00:00 2001
From: Ayase <137056643@qq.com>
Date: Sat, 9 Mar 2019 23:05:11 +0800
Subject: [PATCH 34/96] update README.md
---
README.md | 4 ++--
README_CN.md | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index b293d55..cfe8345 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# mod-LuaEngine
- english | [chinese](README_CN.md)
+ english | [中文说明](README_CN.md)
a Eluna module for AzerothCore.
@@ -12,7 +12,7 @@ How to install:
3. download or clone the ELUNA core file:
> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
> or clone `git clone https://github.com/ElunaLuaEngine/Eluna.git .`
-* Put it in the lua module folder:mod-LuaEngine/LuaEngine. (If you downloaded the zip-file you'll want to move all the files inside the Eluna-master folder into the mod-eluna-lua-engine/LuaEngine folder. LuaEngine.h needs to be directly under mod-eluna-lua-engine/LuaEngine without any extra sub-folders.)
+4. Put it in the lua module folder:mod-LuaEngine/LuaEngine. (If you downloaded the zip-file you'll want to move all the files inside the `Eluna-master` folder into the `mod-eluna-lua-engine/LuaEngine` folder. `LuaEngine.h` needs to be directly under `mod-eluna-lua-engine/LuaEngine` without any extra sub-folders.)
5. cmake again
6. rebuild.
diff --git a/README_CN.md b/README_CN.md
index de371c4..87d0f5c 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -12,7 +12,7 @@
3. 下载或者克隆ELUNA的核心文件:
> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
> clone `git clone https://github.com/ElunaLuaEngine/Eluna.git`
-4. 解压并放置到模块的LuaEngine文件夹中:mod-LuaEngine/LuaEngine
+4. 解压并放置到模块的LuaEngine文件夹中:mod-LuaEngine/LuaEngine(如果下载了zip文件,你需要将`Eluna-master`文件夹中的所有文件移动到`mod-eluna-lua-engine/LuaEngine`文件夹中。`LuaEngine.h`需要直接位于目录:`mod-eluna-lua-engine/LuaEngine`之下,不要有任何的子文件夹。)
5. 重新cmake.
6. 重新生成.
From 1c93c564950f2205ab323e3e62ad8c08307761a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefano=20Borz=C3=AC?=
Date: Wed, 27 Mar 2019 18:10:19 +0100
Subject: [PATCH 35/96] Added icon for the modules catalogue (#10)
---
icon.png | Bin 0 -> 4095 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 icon.png
diff --git a/icon.png b/icon.png
new file mode 100644
index 0000000000000000000000000000000000000000..35e9047b02d06cf73c245878dfc1ad1ef38aed04
GIT binary patch
literal 4095
zcma)9XE+;<*9~H(W@@j*D790xHj$_mTdh)?+N!ovQX@!-Ql-?a+Oca>J63EpYt|lB
zE!C?2{XV~6-gBRG&vVb`bD!tlctd?nS{e=-002O%t%WqcR;T|+MRDDI*I%1n3x$KO
zCKB-PzshSbPQ7-heYGr~0stWJeuG4{vdrob-Uwy
zm`7b}4z6ZKf`C+R%uc$$90f=)FqyHAQx|RAQLfZ8cwk<%`xd{~$38HTxd)*&CSATo
zgHF&5@+e%sTM2Z6i4`0GNd*L){)ivvT=0`Hl4?V!p&etYrI!)MK`ZUYe~8W7*+DDh
zy#E)uiE8+aoTSl!-Mf5hcZ^J9X{qDsaunwB1lf{s4Al(a*mWt;R%|%js?cX+7CE6j
zm&*2=KUCH|7IFjNU}S`39#N?fC!urr$#B;gZQlG+u+C$Qt?gyD+8#p@=~!|Aw4raIl=Q>ov4Fv)eKkd%o
z;LeM=
z23kuq7DX=*{L)eLM<72A<}JJynKY~8ohZC;QC=0pgvPUp5U__&V*SBo+E<*?-_Twq
zQmUNu&a|*xW87i*A~~a<*;3?&5-k>ify-mRlS0GeHO_h5XP%Blh`$uxreteb8~j&o
z*AsT={0R0&0~=?a)RhrJ1!jyVuPI?EJfp%9$Pyi`PF##wT)l5`MUV(a_s|b&chdUl
zg)#KHol2|x+Os3wT9G0uW01M_rKOl9EdOUPhUe3cSP#bS>x~9zLV}e_@|@hIRAJ~%
z$0jluJ63xhZVx|c)Wua?3Mi2C^kn>D)K>es4-#MJW1^p=PvL|S^?+>J2U>3!Glk}4
z+Gu7!=1FUrv7+iPpdHgnlof)1y%`+FA_8W
zMwE<{DK~K`nC6&B=`?H(&u*&joQ2_{L-<1L>>apa?eaUDUq~?rJv`y4wq}mKZ9<#?WE#|s%WDv4FXqWi&
zaP9RjaHPuU<-k;N@X41>S)6Ym1jODd7n^f3#gG}JrKH1LmUtV~**k0!X!L97?j7$%
zt$+ht!w}X&-WNRTGE|e)n4WR=6q#rl1tE>poB$l{g?Q=`Eti=N>RhgODdus8k>YI4
z$$5T~2UK2^!eIo2S+aai42VA55X&|V{t}^FEytmKpj*F$k!$4h1C8@y%F5k#-7Efz
zJEs^}2_y%9o9RL-{)>aXqt@hcwcl!?bBBsJdGaP_%(KN)x}UTOPMhLgPKQq44Bo3u
z_+}Y#JLa>ez1omwuQ5i4Aw>Wgihgg;hOC$Gn#l~iEz%^@sT!<93-hMAe}qKAY<#T8
z@Ih@!LIkqichm$FwwZjIe2R1#N-{Orrhky_qux?0i!C@-bi+e6cTPJ6LXSX`X2~}aR!mxnxf5b
zf~c?|-PE(Xc7JFJp|kKTAdj{Gf&}Q2`g-MSLDrXl&bQ4zLz&`W{Dh(8JqxtbRp3p6
z9fak9VUlBjVoaRG^1Z5eHpAT`^y37B>a%-!CvscbuijarMiN__?rw*z9#B+vNwuj&
z?x>;D$7CPvLv7LmTpbjeb#y{j&b8~2Bdl0J{}PkeBs
zp2X==g;tusvQVkRzFp-rwY|R?N*c90@~qjUZb3``CB$mj*{XE11)cVWjN>x&F{yoV
zKslLiEj<{!Y5$X~7j;Wz?aZYapTJ-I+dPqWAxThcTa8Wb1_!<|*&^G}x;)waByG9G
z29VtglgbVzLHUT9yF#6V(zG-|HYyO50zQrlHccAXq{tw2FcVRk<;m
z1hh@tuqvaZCcA*8N%VzhqL64RI}=R8-pZ|HT~I9o*i#Ny?I#3#zJcmpI+N-s5$>)R
zs&nh&(4O?=t#JB$VG$cc_TIU>G`G^7c)Ny<)xfZ=FejNVomWdvSY%-!=UDQw9U5Q}
z#G9@Tq=!=Qzt~k4s2MG2L1TWeZwXa!X$M=fx_;h%I5hl`*G3{^B5
zD0~^3bDA>pz3z73+cpEAd;vIMQjT$9(4b6Fxdrfu_s~I966;xx-^18sxWR*9N{5jE
zy&R{9XuGf57R$h;k*kT5ZDsGRJRlA^&0>tRnTL^+lvK>cf2GfpRU_pCSKBP&+uDCz
zxvv^fl|C*x4oOZ-(Cb?e5h=gtn>Y|(;^jPD=we%
zjyP|U8*-roLBm1mL7s56`R8`hJi2h*NIV7=GwreH`5syYG-yP#YayI}b~iJYdBS8{
z{`yIXdbL{3DjHCfem4V@tG%GQ2O)+pHS!hd5p8jYQQjo7y&=n-ZEiHRqLSy``ya(6
zB!-nxQkQ%~f2fSuJ}{I|U2lq4>SMd*
zo6b)y0k;d8U;|RUAI;$l5j6ouQLlVQRg7D>D<0+x7c#P=IfaY2xovAtM`y!cd=%!L
zOmu+B`G;3$*bKM%w8l)=1V%&~ABQXbl`r#%gt7(kw72TH689@J`V!YeY#l1ci^PbH
zxH@s?o@z4eu90aY*6hB06Qj|aiTSXHo|!xH4P|Rkg>%E9q2Y%!9Fk}0ZmjK1J{mMn
z6iA-9kRqZ~nP!Vjqdzz5_h)-7>}NF{Za3`I@HX8LwI*YC?aC=tDX|26(4d{O@L~u(S47g5MN=C_5
z(~+ziO)S`AS?_hkVC`U>TC>)o}qflh)V`PU?cBkF#0u8divqZ~#a1arCCyKERxZnu3&
zjQq?zR%y4U+{&rku`s|df*vqJRpZ!-Ig;2YlqVWACnU0z|i*KnCeOBNL1~3cCahqxLNJ8he_GyIOl6-<}}4+liXf1Z)WRO}R>0CBeW^
zx#PuQLVn+KUEzVJIhE(xY;iyrKI<2?(L<@njN2g@n-3uJ5NYkK`lL}&T`L#kxYUvk
zTH`=`%ws`cjA*j3bt4YfNNGOI_yPJ|Mju5gU!^>N9{J#-HN}5shDE6d@TL&_0^3bk
zkBXheh3tF~PFzWf>;%Q!QxBK4BF*@nDk)8lq*{Faq2<_8mH(P@u5^&Igo8fdX{3;E
zw*F?tF9W%js)>)Wt^uWs1-KlGko2;>WP|687pDen%C!LgQ^U-z220-RBD;a2QK-AV
z^IE=Wi0u+ce>^1hOlrR&H+9D>QiWy<%JqsW=ug$uNnVcTg76XPt-NVKslQGr8fG%4
zR6zMy_C8)H&xBp&lJzEYjD#S}GiE)={}0&B&4v2uqkqgK%JDFR$jk(f4FlFYMezNd
z#2)`VX?38JSx;?g-a0xH{)3>3n23AB<{S@skE;`F&{i$)b-Wm3WWb%d|Ip^cJh;T%wgv4UMfy_zoqm~e!Kf*qh
zkFp{w$xDHxke;lgLN9TW?X2zUV79V7qSt+yNp)I>&M%qy{flZ9A)pCGI0b-=gIZmu
zy5+6!1)icK5%3^y#y7{>>+q7wV{kjy+;mkzm2^<8;jDgTh(NWP8UG1ls@lC#dEaDU
zZ%?)j@qVX2@f#isZ7RJWuI(lnqA+##J;qcY6bYSM;_{6=HGGD
zy8T6H)_X6}vpXXDx4GEk1<4stfBF#JHI)
Date: Sun, 31 Mar 2019 00:06:24 +0800
Subject: [PATCH 36/96] Eluna update version.
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index e1d151b..adf722a 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit e1d151b86204e53e04e8ec3d971faf1fa944d3cc
+Subproject commit adf722a18111c316783ed65392d7b57934f39b07
From e27b9e0d892d1627b1bccc16f7ceeca9f9bcbe61 Mon Sep 17 00:00:00 2001
From: Kargatum
Date: Wed, 3 Apr 2019 12:32:07 +0700
Subject: [PATCH 37/96] Cmake: Rewrite build and use inherited dependencies
(#12)
---
CMakeLists.txt | 7 +--
cmake/after_gs_install.cmake | 43 ++++++++++---------
...f.cmake => after_load_cmake_modules.cmake} | 3 +-
cmake/after_ws_install.cmake | 6 ---
cmake/before_gs_install.cmake | 11 ++---
cmake/before_script_install.cmake | 5 ---
lualib/CMakeLists.txt | 31 ++++++++-----
7 files changed, 50 insertions(+), 56 deletions(-)
rename cmake/{after_load_conf.cmake => after_load_cmake_modules.cmake} (99%)
delete mode 100644 cmake/after_ws_install.cmake
delete mode 100644 cmake/before_script_install.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1acb733..54641af 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,2 @@
CU_SET_PATH("CMAKE_MOD_ELUNA_ENGINE_DIR" "${CMAKE_CURRENT_LIST_DIR}")
-CU_ADD_HOOK(AFTER_LOAD_CONF "${CMAKE_CURRENT_LIST_DIR}/cmake/after_load_conf.cmake")
-
-
-
-
-
+CU_ADD_HOOK(AFTER_LOAD_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake/after_load_cmake_modules.cmake")
diff --git a/cmake/after_gs_install.cmake b/cmake/after_gs_install.cmake
index 19722a5..9808df3 100644
--- a/cmake/after_gs_install.cmake
+++ b/cmake/after_gs_install.cmake
@@ -1,28 +1,31 @@
+CollectIncludeDirectories(
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}
+ PUBLIC_INCLUDES)
-include_directories(
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/src
-)
-
+target_include_directories(game-interface
+ INTERFACE
+ ${PUBLIC_INCLUDES})
add_dependencies(game lualib)
-target_link_libraries(game lualib)
+
+target_link_libraries(game
+ PUBLIC
+ lualib)
if( WIN32 )
- if ( MSVC )
- add_custom_command(TARGET game
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/lua_scripts/extensions/"
- COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/lua_scripts/extensions/"
- )
- elseif ( MINGW )
- add_custom_command(TARGET game
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/lua_scripts/extensions/"
- COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/lua_scripts/extensions/"
- )
- endif()
+ if ( MSVC )
+ add_custom_command(TARGET game
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/lua_scripts/extensions/"
+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/lua_scripts/extensions/"
+ )
+ elseif ( MINGW )
+ add_custom_command(TARGET game
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/lua_scripts/extensions/"
+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/lua_scripts/extensions/"
+ )
+ endif()
endif()
install(DIRECTORY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/lua_scripts/")
diff --git a/cmake/after_load_conf.cmake b/cmake/after_load_cmake_modules.cmake
similarity index 99%
rename from cmake/after_load_conf.cmake
rename to cmake/after_load_cmake_modules.cmake
index 2c10f00..9876317 100644
--- a/cmake/after_load_conf.cmake
+++ b/cmake/after_load_cmake_modules.cmake
@@ -1,7 +1,9 @@
add_subdirectory(${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib)
+
add_definitions(-DELUNA)
add_definitions(-DAZEROTHCORE)
add_definitions(-DWOTLK)
+
CU_ADD_HOOK(BEFORE_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_gs_install.cmake")
CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_gs_install.cmake")
CU_ADD_HOOK(BEFORE_SCRIPTS_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_script_install.cmake")
@@ -10,4 +12,3 @@ CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_w
AC_ADD_CONFIG_FILE("${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist")
message("** [Eluna Module] LuaEngine is enable!")
-
diff --git a/cmake/after_ws_install.cmake b/cmake/after_ws_install.cmake
deleted file mode 100644
index 3fbebd1..0000000
--- a/cmake/after_ws_install.cmake
+++ /dev/null
@@ -1,6 +0,0 @@
-
-include_directories(
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/src
-)
diff --git a/cmake/before_gs_install.cmake b/cmake/before_gs_install.cmake
index d893169..95b99b0 100644
--- a/cmake/before_gs_install.cmake
+++ b/cmake/before_gs_install.cmake
@@ -2,15 +2,12 @@ file(GLOB_RECURSE method_headers ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/*Method
file(GLOB_RECURSE sources_ElunaFile_CPP ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/*.cpp )
file(GLOB_RECURSE sources_ElunaFile_H ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/*.h)
-set(game_STAT_SRCS
- ${game_STAT_SRCS}
- ${sources_ElunaFile_H}
- ${sources_ElunaFile_CPP}
+set(ElunaLuaEngineFiles
+ ${ElunaLuaEngineFiles}
+ ${sources_ElunaFile_H}
+ ${sources_ElunaFile_CPP}
)
source_group("LuaEngine\\Methods" FILES ${method_headers})
-
source_group("LuaEngine\\Header Files" FILES ${sources_ElunaFile_H})
-
source_group("LuaEngine\\Source Files" FILES ${sources_ElunaFile_CPP})
-
diff --git a/cmake/before_script_install.cmake b/cmake/before_script_install.cmake
deleted file mode 100644
index 7487800..0000000
--- a/cmake/before_script_install.cmake
+++ /dev/null
@@ -1,5 +0,0 @@
-include_directories(
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/src
-)
\ No newline at end of file
diff --git a/lualib/CMakeLists.txt b/lualib/CMakeLists.txt
index c201500..b1bf6e4 100644
--- a/lualib/CMakeLists.txt
+++ b/lualib/CMakeLists.txt
@@ -4,16 +4,25 @@
# Please see the included DOCS/LICENSE.md for more information
#
-file(GLOB sources *.c)
-list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/lua.c)
-list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/luac.c)
-
-set(lua_STAT_SRCS
- ${sources}
-)
-
-include_directories(
+CollectSourceFiles(
${CMAKE_CURRENT_SOURCE_DIR}
-)
+ PRIVATE_SOURCES
+ # Exclude
+ ${CMAKE_CURRENT_SOURCE_DIR}/Debugging
+ ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders)
-add_library(lualib STATIC ${lua_STAT_SRCS})
+list(REMOVE_ITEM PRIVATE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lua.c)
+list(REMOVE_ITEM PRIVATE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/luac.c)
+
+add_library(lualib STATIC
+ ${PRIVATE_SOURCES})
+
+CollectIncludeDirectories(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ PUBLIC_INCLUDES)
+
+target_include_directories(lualib
+ PUBLIC
+ ${PUBLIC_INCLUDES}
+ PRIVATE
+ ${CMAKE_CURRENT_BINARY_DIR})
From 56ec11eed7552c274a93667df6313a8b1ca7ed49 Mon Sep 17 00:00:00 2001
From: Kargatum
Date: Wed, 3 Apr 2019 12:51:03 +0700
Subject: [PATCH 38/96] Cmake: Delete unused hooks (#13)
---
cmake/after_load_cmake_modules.cmake | 2 --
1 file changed, 2 deletions(-)
diff --git a/cmake/after_load_cmake_modules.cmake b/cmake/after_load_cmake_modules.cmake
index 9876317..eb7b43b 100644
--- a/cmake/after_load_cmake_modules.cmake
+++ b/cmake/after_load_cmake_modules.cmake
@@ -6,8 +6,6 @@ add_definitions(-DWOTLK)
CU_ADD_HOOK(BEFORE_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_gs_install.cmake")
CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_gs_install.cmake")
-CU_ADD_HOOK(BEFORE_SCRIPTS_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_script_install.cmake")
-CU_ADD_HOOK(AFTER_WORLDSERVER_CMAKE "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_ws_install.cmake")
AC_ADD_CONFIG_FILE("${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist")
From f92ef4bc64e2f8e2528d602a0b37e902e842365b Mon Sep 17 00:00:00 2001
From: Stoabrogga <38475780+Stoabrogga@users.noreply.github.com>
Date: Sat, 6 Apr 2019 00:14:32 +0200
Subject: [PATCH 39/96] feat(CI): Travis integration (#11)
---
.travis.yml | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++
LuaEngine | 2 +-
2 files changed, 78 insertions(+), 1 deletion(-)
create mode 100644 .travis.yml
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..c1538c7
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,77 @@
+sudo: required
+dist: xenial # (16.04)
+# bionic (18.04) is not yet available in travis
+
+language: cpp
+
+cache: ccache
+
+addons:
+ apt:
+ update: true
+
+services:
+ - mysql
+
+git:
+ depth: 10
+
+stages:
+ - prepare_cache
+ - run
+
+jobs:
+ include:
+ - stage: prepare_cache
+ env: TRAVIS_BUILD_ID="1"
+ before_install:
+ - cd ..
+ - git clone --depth=1 --branch=master https://github.com/azerothcore/azerothcore-wotlk.git azerothcore-wotlk
+ - mv "$TRAVIS_BUILD_DIR" azerothcore-wotlk/modules
+ - cd azerothcore-wotlk
+ - source ./apps/ci/ci-before_install.sh
+ install:
+ - source ./apps/ci/ci-install.sh OFF
+ script:
+ - source ./apps/ci/ci-compile.sh
+
+ - stage: run
+ env: TRAVIS_BUILD_ID="1"
+ before_install:
+ - cd ..
+ - git clone --depth=1 --branch=master https://github.com/azerothcore/azerothcore-wotlk.git azerothcore-wotlk
+ - mv "$TRAVIS_BUILD_DIR" azerothcore-wotlk/modules
+ - cd azerothcore-wotlk
+ - source ./apps/ci/ci-before_install.sh
+ install:
+ - source ./apps/ci/ci-install.sh ON
+ - source ./apps/ci/ci-import-db.sh
+ script:
+ - source ./apps/ci/ci-compile.sh
+ - source ./apps/ci/ci-worldserver-dry-run.sh
+
+ - stage: prepare_cache
+ env: TRAVIS_BUILD_ID="2"
+ before_install:
+ - cd ..
+ - git clone --depth=1 --branch=master https://github.com/azerothcore/azerothcore-wotlk.git azerothcore-wotlk
+ - mv "$TRAVIS_BUILD_DIR" azerothcore-wotlk/modules
+ - cd azerothcore-wotlk
+ - source ./apps/ci/ci-before_install.sh
+ install:
+ - source ./apps/ci/ci-install.sh OFF
+ script:
+ - source ./apps/ci/ci-compile.sh
+
+ - stage: run
+ env: TRAVIS_BUILD_ID="2"
+ before_install:
+ - cd ..
+ - git clone --depth=1 --branch=master https://github.com/azerothcore/azerothcore-wotlk.git azerothcore-wotlk
+ - mv "$TRAVIS_BUILD_DIR" azerothcore-wotlk/modules
+ - cd azerothcore-wotlk
+ - source ./apps/ci/ci-before_install.sh
+ install:
+ - source ./apps/ci/ci-install.sh ON
+ script:
+ - source ./apps/ci/ci-compile.sh
diff --git a/LuaEngine b/LuaEngine
index adf722a..c027d0b 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit adf722a18111c316783ed65392d7b57934f39b07
+Subproject commit c027d0bcb5868e87413214e9b68e99b33db41039
From 2ee4125ea64a5ee8a26f91a24b5a37aa1dd0f01c Mon Sep 17 00:00:00 2001
From: Walter Pagani
Date: Thu, 25 Jul 2019 15:32:11 -0300
Subject: [PATCH 40/96] docs: Add README spanish translation (#14)
---
README.md | 2 +-
README_CN.md | 2 +-
README_ES.md | 19 +++++++++++++++++++
3 files changed, 21 insertions(+), 2 deletions(-)
create mode 100644 README_ES.md
diff --git a/README.md b/README.md
index cfe8345..9fcccb2 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# mod-LuaEngine
- english | [中文说明](README_CN.md)
+[english](README.md) | [中文说明](README_CN.md) | [Español](README_ES.md)
a Eluna module for AzerothCore.
diff --git a/README_CN.md b/README_CN.md
index 87d0f5c..56776fd 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -1,5 +1,5 @@
# mod-LuaEngine
-[english](README.md) | 中文
+[english](README.md) | [中文说明](README_CN.md) | [Español](README_ES.md)
一个用于AzerothCore的ELUNA模块.
diff --git a/README_ES.md b/README_ES.md
new file mode 100644
index 0000000..b33b262
--- /dev/null
+++ b/README_ES.md
@@ -0,0 +1,19 @@
+# mod-LuaEngine
+ [English](README.md) | [中文说明](README_CN.md) | [Español](README_ES.md)
+
+Un módulo de Eluna para AzerothCore.
+
+Cómo instalar:
+
+1. Descargar o clonar este módulo:
+> [Descargar archivo zip](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
+> o clonar `git clone https://github.com/azerothcore/mod-eluna-lua-engine.git`
+2. Póngalo en la carpeta de módulos del Azerothcore.
+> $HOME/azerothcore/modules/
+3. Descargar o clonar el archivo central de ELUNA:
+> [Descargar archivo zip](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
+> o clonar `git clone https://github.com/ElunaLuaEngine/Eluna.git .`
+4. Dentro de la carpeta del módulo de Eluna de Azeroth, se encuentra una carpeta / directorio llamado: `LuaEngine` (mod-eluna-lua-engine/LuaEngine). Debe depositar los ficheros de lua, directamente dentro de esa carpeta. Los archivos directamente, no un directorio y luego los ficheros dentro. Por eso te utiliza el “.” cuando se está clonando, para que no genere un directorio nuevo.
+5. Una vez copiado los ficheros y descargado el modulo, debes volver a compilar. Si seguiste la guía de instalación, debiste haber generado un directorio build, dentro de azerothcore. Dirígete a él y realiza la compilación como lo menciona en la guía.
+
+Eluna API : [http://www.elunaengine.com/](http://www.elunaengine.com/)
From 0b4f92cbe160175064ba7b09b220cb2a5175ded7 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Thu, 3 Oct 2019 13:51:30 +0800
Subject: [PATCH 41/96] Eluna update version.
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index c027d0b..897d5e9 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit c027d0bcb5868e87413214e9b68e99b33db41039
+Subproject commit 897d5e915978817d948d8f2745fa977eea048c47
From 4628f0cb728b91b3e6f67526a6b354e9d0601bf9 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Thu, 3 Oct 2019 13:53:17 +0800
Subject: [PATCH 42/96] =?UTF-8?q?=E4=BF=AE=E6=AD=A3api=E5=9C=B0=E5=9D=80?=
=?UTF-8?q?=E5=A4=B1=E6=95=88.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 4 ++--
README_CN.md | 3 ++-
README_ES.md | 3 ++-
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 9fcccb2..05df3cc 100644
--- a/README.md
+++ b/README.md
@@ -16,5 +16,5 @@ How to install:
5. cmake again
6. rebuild.
-Eluna API : [http://www.elunaengine.com/](http://www.elunaengine.com/)
-
+Eluna API :
+[http://elunaluaengine.github.io/](http://elunaluaengine.github.io/)
diff --git a/README_CN.md b/README_CN.md
index 56776fd..8e21a58 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -16,4 +16,5 @@
5. 重新cmake.
6. 重新生成.
-Eluna API : [http://www.elunaengine.com/](http://www.elunaengine.com/)
\ No newline at end of file
+Eluna API :
+[http://elunaluaengine.github.io/](http://elunaluaengine.github.io/)
\ No newline at end of file
diff --git a/README_ES.md b/README_ES.md
index b33b262..39f6161 100644
--- a/README_ES.md
+++ b/README_ES.md
@@ -16,4 +16,5 @@ Cómo instalar:
4. Dentro de la carpeta del módulo de Eluna de Azeroth, se encuentra una carpeta / directorio llamado: `LuaEngine` (mod-eluna-lua-engine/LuaEngine). Debe depositar los ficheros de lua, directamente dentro de esa carpeta. Los archivos directamente, no un directorio y luego los ficheros dentro. Por eso te utiliza el “.” cuando se está clonando, para que no genere un directorio nuevo.
5. Una vez copiado los ficheros y descargado el modulo, debes volver a compilar. Si seguiste la guía de instalación, debiste haber generado un directorio build, dentro de azerothcore. Dirígete a él y realiza la compilación como lo menciona en la guía.
-Eluna API : [http://www.elunaengine.com/](http://www.elunaengine.com/)
+Eluna API :
+[http://elunaluaengine.github.io/](http://elunaluaengine.github.io/)
From fb67bdef989634b822f5dc671e20647a0581734e Mon Sep 17 00:00:00 2001
From: Kargatum
Date: Mon, 11 Nov 2019 23:16:16 +0700
Subject: [PATCH 43/96] Update LuaEngine to actual (#19)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 897d5e9..8fe15b7 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 897d5e915978817d948d8f2745fa977eea048c47
+Subproject commit 8fe15b76a8c3ab040cc61aba870b5ab92afa3d11
From d544a70792106d45b1fcd9db3781d7f427d1188c Mon Sep 17 00:00:00 2001
From: Viste
Date: Sun, 24 Nov 2019 15:01:53 +0300
Subject: [PATCH 44/96] update LuaEngine to latest (#20)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 8fe15b7..dab3724 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 8fe15b76a8c3ab040cc61aba870b5ab92afa3d11
+Subproject commit dab372408c0b7038e646fe8c3a42059163476925
From f31d3e3dfe420ceccfe0f2c3a2f8f78b94384851 Mon Sep 17 00:00:00 2001
From: VhiperDEV <39068627+vhiperdev@users.noreply.github.com>
Date: Mon, 2 Dec 2019 06:36:36 -0300
Subject: [PATCH 45/96] fix build azerothcore (#21)
---
.travis.yml | 3 +--
LuaEngine | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index c1538c7..848d188 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,5 @@
sudo: required
-dist: xenial # (16.04)
-# bionic (18.04) is not yet available in travis
+dist: bionic # (18.04)
language: cpp
diff --git a/LuaEngine b/LuaEngine
index dab3724..35e85a7 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit dab372408c0b7038e646fe8c3a42059163476925
+Subproject commit 35e85a71ae723db0b5ab915bf4bf7bad1e8f0c9f
From b6e3ed364d58f75b0961775c482e09e2f8f452e9 Mon Sep 17 00:00:00 2001
From: Rochet2
Date: Fri, 3 Jan 2020 22:11:06 +0200
Subject: [PATCH 46/96] Try fix warning
---
lualib/CMakeLists.txt | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lualib/CMakeLists.txt b/lualib/CMakeLists.txt
index b1bf6e4..3f97344 100644
--- a/lualib/CMakeLists.txt
+++ b/lualib/CMakeLists.txt
@@ -26,3 +26,9 @@ target_include_directories(lualib
${PUBLIC_INCLUDES}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
+
+if (APPLE)
+ target_compile_definitions(lualib PUBLIC LUA_USE_MACOSX)
+elseif (UNIX)
+ target_compile_definitions(lualib PUBLIC LUA_USE_LINUX)
+endif()
From 363ca13f230beacc9ce96baddfc6bd9e753f8033 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Sun, 22 Mar 2020 22:25:36 +0800
Subject: [PATCH 47/96] Eluna update version.
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 35e85a7..3d9ce19 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 35e85a71ae723db0b5ab915bf4bf7bad1e8f0c9f
+Subproject commit 3d9ce1911eb6050d8629d76f7bda2d24ee48b542
From 574c6c589df52dcbed013d5b2d5f4a1b18b28625 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Mon, 23 Mar 2020 22:19:30 +0800
Subject: [PATCH 48/96] Avoid including redundant directories.
---
cmake/after_gs_install.cmake | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/cmake/after_gs_install.cmake b/cmake/after_gs_install.cmake
index 9808df3..0ac0155 100644
--- a/cmake/after_gs_install.cmake
+++ b/cmake/after_gs_install.cmake
@@ -1,6 +1,9 @@
-CollectIncludeDirectories(
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}
- PUBLIC_INCLUDES)
+set(PUBLIC_INCLUDES
+ ${PUBLIC_INCLUDES}
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
+ ${CMAKE_MOD_ELUNA_ENGINE_DIR}/src
+)
target_include_directories(game-interface
INTERFACE
From 2e7300be214a0bba205a55e39507a0d8df2ea1c3 Mon Sep 17 00:00:00 2001
From: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
Date: Thu, 9 Apr 2020 20:52:33 +0200
Subject: [PATCH 49/96] Update LuaEngine
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 3d9ce19..c83e3a3 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 3d9ce1911eb6050d8629d76f7bda2d24ee48b542
+Subproject commit c83e3a33a01df47b63e152fa8405292e1b616a2a
From 81506786b0ee68ba632a8aa9b7cd0324c18a6496 Mon Sep 17 00:00:00 2001
From: Rochet2
Date: Fri, 10 Apr 2020 01:31:30 +0300
Subject: [PATCH 50/96] Eluna update version
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index c83e3a3..f7adf33 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit c83e3a33a01df47b63e152fa8405292e1b616a2a
+Subproject commit f7adf330284995eca84a68be538fdbe0978a107d
From 3419e76486752f9fd72fdf390b45485ab4ab9caa Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Tue, 2 Jun 2020 22:49:42 +0800
Subject: [PATCH 51/96] =?UTF-8?q?=E6=9D=82=E9=A1=B9=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
cmake/after_gs_install.cmake | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/cmake/after_gs_install.cmake b/cmake/after_gs_install.cmake
index 0ac0155..5dc331d 100644
--- a/cmake/after_gs_install.cmake
+++ b/cmake/after_gs_install.cmake
@@ -16,19 +16,14 @@ target_link_libraries(game
lualib)
if( WIN32 )
- if ( MSVC )
- add_custom_command(TARGET game
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/lua_scripts/extensions/"
- COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/lua_scripts/extensions/"
- )
- elseif ( MINGW )
- add_custom_command(TARGET game
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/lua_scripts/extensions/"
- COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/lua_scripts/extensions/"
- )
+ if (MSVC)
+ set(MSVC_CONFIGURATION_NAME $(ConfigurationName)/)
endif()
+ add_custom_command(TARGET game
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/${MSVC_CONFIGURATION_NAME}lua_scripts/extensions/"
+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/${MSVC_CONFIGURATION_NAME}lua_scripts/extensions/"
+ )
endif()
install(DIRECTORY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/lua_scripts/")
From 2aba9a4c051bf0d60547f0b41053f8ef573503f8 Mon Sep 17 00:00:00 2001
From: Rochet2
Date: Sun, 16 Aug 2020 14:42:50 +0300
Subject: [PATCH 52/96] feat(CI): move from Travis to GitHub Actions (#30)
---
.github/workflows/core_build.yml | 45 +++++++++++++++++++
.travis.yml | 76 --------------------------------
2 files changed, 45 insertions(+), 76 deletions(-)
create mode 100644 .github/workflows/core_build.yml
delete mode 100644 .travis.yml
diff --git a/.github/workflows/core_build.yml b/.github/workflows/core_build.yml
new file mode 100644
index 0000000..7e43788
--- /dev/null
+++ b/.github/workflows/core_build.yml
@@ -0,0 +1,45 @@
+name: core-build
+on:
+ push:
+ pull_request:
+
+jobs:
+ build:
+ strategy:
+ fail-fast: false
+ matrix:
+ compiler: [clang6, clang9, clang10]
+ runs-on: ubuntu-20.04
+ name: ${{ matrix.compiler }}
+ env:
+ COMPILER: ${{ matrix.compiler }}
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ repository: 'azerothcore/azerothcore-wotlk'
+ ref: 'master'
+ submodules: 'recursive'
+ - uses: actions/checkout@v2
+ with:
+ submodules: 'recursive'
+ path: 'modules/mod-eluna-lua-engine'
+ - name: Cache
+ uses: actions/cache@v1.1.2
+ with:
+ path: /home/runner/.ccache
+ key: ccache:${{ matrix.compiler }}:${{ github.ref }}:${{ github.sha }}
+ restore-keys: |
+ ccache:${{ matrix.compiler }}:${{ github.ref }}
+ ccache:${{ matrix.compiler }}
+ - name: Configure OS
+ run: source ./apps/ci/ci-install.sh
+ env:
+ CONTINUOUS_INTEGRATION: true
+ - name: Import db
+ run: source ./apps/ci/ci-import-db.sh
+ - name: Build
+ run: source ./apps/ci/ci-compile.sh
+ - name: Dry run
+ run: source ./apps/ci/ci-worldserver-dry-run.sh
+ - name: Check startup errors
+ run: source ./apps/ci/ci-error-check.sh
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 848d188..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,76 +0,0 @@
-sudo: required
-dist: bionic # (18.04)
-
-language: cpp
-
-cache: ccache
-
-addons:
- apt:
- update: true
-
-services:
- - mysql
-
-git:
- depth: 10
-
-stages:
- - prepare_cache
- - run
-
-jobs:
- include:
- - stage: prepare_cache
- env: TRAVIS_BUILD_ID="1"
- before_install:
- - cd ..
- - git clone --depth=1 --branch=master https://github.com/azerothcore/azerothcore-wotlk.git azerothcore-wotlk
- - mv "$TRAVIS_BUILD_DIR" azerothcore-wotlk/modules
- - cd azerothcore-wotlk
- - source ./apps/ci/ci-before_install.sh
- install:
- - source ./apps/ci/ci-install.sh OFF
- script:
- - source ./apps/ci/ci-compile.sh
-
- - stage: run
- env: TRAVIS_BUILD_ID="1"
- before_install:
- - cd ..
- - git clone --depth=1 --branch=master https://github.com/azerothcore/azerothcore-wotlk.git azerothcore-wotlk
- - mv "$TRAVIS_BUILD_DIR" azerothcore-wotlk/modules
- - cd azerothcore-wotlk
- - source ./apps/ci/ci-before_install.sh
- install:
- - source ./apps/ci/ci-install.sh ON
- - source ./apps/ci/ci-import-db.sh
- script:
- - source ./apps/ci/ci-compile.sh
- - source ./apps/ci/ci-worldserver-dry-run.sh
-
- - stage: prepare_cache
- env: TRAVIS_BUILD_ID="2"
- before_install:
- - cd ..
- - git clone --depth=1 --branch=master https://github.com/azerothcore/azerothcore-wotlk.git azerothcore-wotlk
- - mv "$TRAVIS_BUILD_DIR" azerothcore-wotlk/modules
- - cd azerothcore-wotlk
- - source ./apps/ci/ci-before_install.sh
- install:
- - source ./apps/ci/ci-install.sh OFF
- script:
- - source ./apps/ci/ci-compile.sh
-
- - stage: run
- env: TRAVIS_BUILD_ID="2"
- before_install:
- - cd ..
- - git clone --depth=1 --branch=master https://github.com/azerothcore/azerothcore-wotlk.git azerothcore-wotlk
- - mv "$TRAVIS_BUILD_DIR" azerothcore-wotlk/modules
- - cd azerothcore-wotlk
- - source ./apps/ci/ci-before_install.sh
- install:
- - source ./apps/ci/ci-install.sh ON
- script:
- - source ./apps/ci/ci-compile.sh
From 6a474a2e83c689e214b5f32e33ab7c9688114ea4 Mon Sep 17 00:00:00 2001
From: Patrick Lewis
Date: Sat, 21 Nov 2020 02:34:53 -0800
Subject: [PATCH 53/96] docs(readme): add AzerothCore logo and build status
badge (#33)
---
README.md | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 05df3cc..1f1fc2a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,7 @@
-# mod-LuaEngine
+#  AzerothCore
+## mod-LuaEngine
+- Latest build status with azerothcore: [](https://github.com/azerothcore/mod-eluna-lua-engine)
+
[english](README.md) | [中文说明](README_CN.md) | [Español](README_ES.md)
a Eluna module for AzerothCore.
From fcee06f26782a8ddf1d5ed85ff957e377c19047b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Mon, 23 Nov 2020 13:28:03 +0100
Subject: [PATCH 54/96] fix(build): update Eluna to latest version (#34)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index f7adf33..f117491 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit f7adf330284995eca84a68be538fdbe0978a107d
+Subproject commit f117491095ca29b55227717af84cd7d4257426c9
From e05489f61be4c18d981748a8813764f5a7550940 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Mon, 23 Nov 2020 15:40:40 +0100
Subject: [PATCH 55/96] docs: improve README.md (#35)
---
README.md | 44 ++++++++++++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 14 deletions(-)
diff --git a/README.md b/README.md
index 1f1fc2a..a9a394a 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,39 @@
-#  AzerothCore
-## mod-LuaEngine
+#  mod-eluna-lua-engine for AzerothCore
- Latest build status with azerothcore: [](https://github.com/azerothcore/mod-eluna-lua-engine)
[english](README.md) | [中文说明](README_CN.md) | [Español](README_ES.md)
-a Eluna module for AzerothCore.
+An [Eluna](https://github.com/ElunaLuaEngine/Eluna) module for AzerothCore.
-How to install:
+## How to install:
-1. download or clone this module:
-> [download zip file.](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
-> or clone `git clone https://github.com/azerothcore/mod-eluna-lua-engine.git`
-2. Put it in the modules folder of the Azerothcore.
-3. download or clone the ELUNA core file:
-> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
-> or clone `git clone https://github.com/ElunaLuaEngine/Eluna.git .`
-4. Put it in the lua module folder:mod-LuaEngine/LuaEngine. (If you downloaded the zip-file you'll want to move all the files inside the `Eluna-master` folder into the `mod-eluna-lua-engine/LuaEngine` folder. `LuaEngine.h` needs to be directly under `mod-eluna-lua-engine/LuaEngine` without any extra sub-folders.)
-5. cmake again
-6. rebuild.
+### 1) Download the sources
+
+You can get the sources either using git (recommended) or downloading them manually.
+
+#### download with git (recommended)
+
+1. open a terminal inside your `azerothcore-wotlk` folder
+2. go inside the **modules** folder: `cd modules`
+3. download the module sources using:
+```
+git clone https://github.com/azerothcore/mod-eluna-lua-engine.git
+```
+4. go inside the **mod-eluna-lua-engine** folder: `cd mod-eluna-lua-engine`
+5. download the Eluna sources using `git submodule update --init`
+
+Optional: if you need to update Eluna to the latest version, you can `cd LuaEngine` and run `git pull` from there.
+
+#### download manually
+
+1. download [mod-eluna-lua-engine](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
+2. extract it move the folder **mod-eluna-lua-engine** inside the **modules** folder of your azerothcore-wotlk sources
+3. download [Eluna](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
+4. extract it and move all the files inside the `Eluna-master` folder into the `mod-eluna-lua-engine/LuaEngine` folder. `LuaEngine.h` needs to be directly under `mod-eluna-lua-engine/LuaEngine` without any extra sub-folders.
+
+### 2) Build
+
+You need to run the cmake again and and rebuild the project.
Eluna API :
[http://elunaluaengine.github.io/](http://elunaluaengine.github.io/)
From 605f43b8adbeae16255ea659d398272805726f4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Thu, 3 Dec 2020 09:46:55 +0100
Subject: [PATCH 56/96] fix: update Eluna (#36)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index f117491..6d7ab9c 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit f117491095ca29b55227717af84cd7d4257426c9
+Subproject commit 6d7ab9c35efa323d9b432276e7f71b277ce7d139
From fce22f208500973e6696cee05e38b5097092c977 Mon Sep 17 00:00:00 2001
From: Helias
Date: Sat, 27 Mar 2021 12:41:01 +0100
Subject: [PATCH 57/96] chore: update submodule
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 6d7ab9c..8f5c469 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 6d7ab9c35efa323d9b432276e7f71b277ce7d139
+Subproject commit 8f5c4699b2531c408b615f55270541a7267c742b
From cfc557a6751c54906ce4c03457d0a79fb9fdb251 Mon Sep 17 00:00:00 2001
From: Helias
Date: Sat, 17 Apr 2021 15:21:23 +0200
Subject: [PATCH 58/96] fix: build, update LuaEngine
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 8f5c469..ca5f1bb 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 8f5c4699b2531c408b615f55270541a7267c742b
+Subproject commit ca5f1bb59dd0abc5d61a65a56415f5703eaede74
From 6aa494f4b38fd1413e5c0f297aa6fa600f519cea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Mon, 26 Apr 2021 22:02:57 +0200
Subject: [PATCH 59/96] feat: update to latest Eluna (#41)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index ca5f1bb..2962d4f 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit ca5f1bb59dd0abc5d61a65a56415f5703eaede74
+Subproject commit 2962d4fea3708cf22964d1cc750290b8980b313f
From bb18a86cee8ab9d22b09ff4cb47ecedbb5c128d5 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Wed, 12 May 2021 17:46:06 +0800
Subject: [PATCH 60/96] remove 'ObjectGuid.h', AC already supports ObjectGuid.
---
cmake/after_gs_install.cmake | 1 -
src/ObjectGuid.h | 92 ------------------------------------
2 files changed, 93 deletions(-)
delete mode 100644 src/ObjectGuid.h
diff --git a/cmake/after_gs_install.cmake b/cmake/after_gs_install.cmake
index 5dc331d..de63c48 100644
--- a/cmake/after_gs_install.cmake
+++ b/cmake/after_gs_install.cmake
@@ -2,7 +2,6 @@ set(PUBLIC_INCLUDES
${PUBLIC_INCLUDES}
${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/src
)
target_include_directories(game-interface
diff --git a/src/ObjectGuid.h b/src/ObjectGuid.h
deleted file mode 100644
index 7a6e3a3..0000000
--- a/src/ObjectGuid.h
+++ /dev/null
@@ -1,92 +0,0 @@
-#ifndef ObjectGuid_h__
-#define ObjectGuid_h__
-
-#include "ObjectDefines.h"
-
-class ObjectGuid
-{
-public:
- ObjectGuid() : _guid(0) { }
-
- ObjectGuid(uint64 guid) : _guid(guid) { }
-
- operator uint64() const { return _guid; }
-
- void Set(uint64 guid) { _guid = guid; }
- void Clear() { _guid = 0; }
-
- HighGuid GetHigh() const { return HighGuid((_guid >> 48) & 0x0000FFFF); }
- uint32 GetEntry() const { return HasEntry() ? uint32((_guid >> 24) & UI64LIT(0x0000000000FFFFFF)) : 0; }
- uint32 GetCounter() const
- {
- return HasEntry()
- ? uint32(_guid & UI64LIT(0x0000000000FFFFFF))
- : uint32(_guid & UI64LIT(0x00000000FFFFFFFF));
- }
-
- static uint32 GetMaxCounter(HighGuid high)
- {
- return HasEntry(high)
- ? uint32(0x00FFFFFF)
- : uint32(0xFFFFFFFF);
- }
-
- uint32 GetMaxCounter() const { return GetMaxCounter(GetHigh()); }
-
- bool IsEmpty() const { return _guid == 0; }
- bool IsCreature() const { return GetHigh() == HIGHGUID_UNIT; }
- bool IsPet() const { return GetHigh() == HIGHGUID_PET; }
- bool IsVehicle() const { return GetHigh() == HIGHGUID_VEHICLE; }
- bool IsCreatureOrPet() const { return IsCreature() || IsPet(); }
- bool IsCreatureOrVehicle() const { return IsCreature() || IsVehicle(); }
- bool IsAnyTypeCreature() const { return IsCreature() || IsPet() || IsVehicle(); }
- bool IsPlayer() const { return !IsEmpty() && GetHigh() == HIGHGUID_PLAYER; }
- bool IsUnit() const { return IsAnyTypeCreature() || IsPlayer(); }
- bool IsItem() const { return GetHigh() == HIGHGUID_ITEM; }
- bool IsGameObject() const { return GetHigh() == HIGHGUID_GAMEOBJECT; }
- bool IsDynamicObject() const { return GetHigh() == HIGHGUID_DYNAMICOBJECT; }
- bool IsCorpse() const { return GetHigh() == HIGHGUID_CORPSE; }
- bool IsTransport() const { return GetHigh() == HIGHGUID_TRANSPORT; }
- bool IsMOTransport() const { return GetHigh() == HIGHGUID_MO_TRANSPORT; }
- bool IsAnyTypeGameObject() const { return IsGameObject() || IsTransport() || IsMOTransport(); }
- bool IsInstance() const { return GetHigh() == HIGHGUID_INSTANCE; }
- bool IsGroup() const { return GetHigh() == HIGHGUID_GROUP; }
-
- bool operator!() const { return IsEmpty(); }
-
- char const* GetTypeName() { return GetLogNameForGuid(_guid); }
- char const* GetTypeName() const { return !IsEmpty() ? GetTypeName() : "None"; }
-
-private:
- static bool HasEntry(HighGuid high)
- {
- switch (high)
- {
- case HIGHGUID_ITEM:
- case HIGHGUID_PLAYER:
- case HIGHGUID_DYNAMICOBJECT:
- case HIGHGUID_CORPSE:
- case HIGHGUID_MO_TRANSPORT:
- case HIGHGUID_INSTANCE:
- case HIGHGUID_GROUP:
- return false;
- case HIGHGUID_GAMEOBJECT:
- case HIGHGUID_TRANSPORT:
- case HIGHGUID_UNIT:
- case HIGHGUID_PET:
- case HIGHGUID_VEHICLE:
- default:
- return true;
- }
- }
-
- bool HasEntry() const { return HasEntry(GetHigh()); }
-
- explicit ObjectGuid(uint32 const&) = delete; // no implementation, used to catch wrong type assignment
- ObjectGuid(HighGuid, uint32, uint64 counter) = delete; // no implementation, used to catch wrong type assignment
- ObjectGuid(HighGuid, uint64 counter) = delete; // no implementation, used to catch wrong type assignment
-
- uint64 _guid;
-};
-
-#endif // ObjectGuid_h__
\ No newline at end of file
From 10f5840d2fb063f9d9ca57af280b7bd2c61d8b99 Mon Sep 17 00:00:00 2001
From: Kargatum
Date: Thu, 13 May 2021 14:21:14 +0700
Subject: [PATCH 61/96] feat(CI): set only default version clang (#43)
---
.github/workflows/core_build.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/core_build.yml b/.github/workflows/core_build.yml
index 7e43788..34d5439 100644
--- a/.github/workflows/core_build.yml
+++ b/.github/workflows/core_build.yml
@@ -8,8 +8,8 @@ jobs:
strategy:
fail-fast: false
matrix:
- compiler: [clang6, clang9, clang10]
- runs-on: ubuntu-20.04
+ compiler: [clang]
+ runs-on: ubuntu-latest
name: ${{ matrix.compiler }}
env:
COMPILER: ${{ matrix.compiler }}
From 87b2426fa519d02297e2e385fa2164a40c0df90a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Mon, 31 May 2021 18:46:19 +0200
Subject: [PATCH 62/96] feat: update to latest Eluna (#46)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 2962d4f..841ddd4 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 2962d4fea3708cf22964d1cc750290b8980b313f
+Subproject commit 841ddd4db713750d52546b7b3814a992d1793319
From d3003fae9beff968d0826674d6bc59fec0f1b5bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Thu, 3 Jun 2021 14:51:42 +0200
Subject: [PATCH 63/96] feat: update to latest Eluna (#47)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 841ddd4..dbf6ed9 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 841ddd4db713750d52546b7b3814a992d1793319
+Subproject commit dbf6ed96f149420bec8f35a66e7dca31a324555f
From 81548013dc0748c1aeb15179fed6b7fe861b64bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Sat, 5 Jun 2021 13:53:24 +0200
Subject: [PATCH 64/96] feat: update to latest Eluna (#48)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index dbf6ed9..2861199 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit dbf6ed96f149420bec8f35a66e7dca31a324555f
+Subproject commit 286119950f6f1bd82cfc50886da9ebda6e0a8b0c
From 4766cec9b7d0151971b6de1e31f3e8c4c5eee365 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Mon, 21 Jun 2021 00:09:58 +0800
Subject: [PATCH 65/96] Update README_CN.md
---
README_CN.md | 50 ++++++++++++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 14 deletions(-)
diff --git a/README_CN.md b/README_CN.md
index 8e21a58..a3f0a31 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -1,20 +1,42 @@
-# mod-LuaEngine
+
+#  mod-eluna-lua-engine for AzerothCore
+- Latest build status with azerothcore: [](https://github.com/azerothcore/mod-eluna-lua-engine)
+
[english](README.md) | [中文说明](README_CN.md) | [Español](README_ES.md)
-一个用于AzerothCore的ELUNA模块.
+一个用于Azerothcore的[Eluna](https://github.com/ElunaLuaEngine/Eluna)模块.
-如何安装:
+## 如何安装:
+
+### 1) 下载源码
+
+你可以使用git(推荐)或手动下载源代码的方法安装。
+
+#### 使用git(推荐)下载
+
+1. 在你的`azerothcore-wotlk`源码文件夹中打开命令行(win的用户进入目录后shift+鼠标右键可以通过右键菜单打开)
+2. 进入 **modules** 文件夹,命令行中输入: `cd modules`
+3. 下载模块源码:
+```
+git clone https://github.com/azerothcore/mod-eluna-lua-engine.git
+```
+4. 下载模块源码后进入文件夹 **mod-eluna-lua-engine**,命令行中输入: `cd mod-eluna-lua-engine`
+5. 下载Eluna源码,命令行中输入: `git submodule update --init`
+
+可选: 模块中集成的Eluna是稳定版本,如果你要更新Eluna到最新版本,你可以进入目录**LuaEngine**(命令行输入:`cd LuaEngine`),进入后输入`git pull`获取即可更新最新版本.
+请注意,最新版本可能和稳定版的源码不匹配.视情况可能需要自行修正.
+
+#### 手动下载
+
+1. 下载 [mod-eluna-lua-engine](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
+2. 解压到你的`azerothcore-wotlk`源码中的**modules**文件夹中,请确保路径看起来是这样的`azerothcore-wotlk/modules/mod-eluna-lua-engine`
+3. 下载 [Eluna](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
+4. 把文件解压到 `mod-eluna-lua-engine/LuaEngine`. `LuaEngine.h`这个文件的路径看起来应该是这样的`mod-eluna-lua-engine/LuaEngine/LuaEngine.h`.
+
+### 2) 生成
+
+你需要重新CMake并重新生成你的项目.
-1. 下载或者克隆这个模块:
-> [下载zip压缩包](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
-> 或者克隆 `git clone https://github.com/azerothcore/mod-eluna-lua-engine.git`
-2. 解压并放到Azerothcore源码的modules文件夹中.
-3. 下载或者克隆ELUNA的核心文件:
-> [download zip file.](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
-> clone `git clone https://github.com/ElunaLuaEngine/Eluna.git`
-4. 解压并放置到模块的LuaEngine文件夹中:mod-LuaEngine/LuaEngine(如果下载了zip文件,你需要将`Eluna-master`文件夹中的所有文件移动到`mod-eluna-lua-engine/LuaEngine`文件夹中。`LuaEngine.h`需要直接位于目录:`mod-eluna-lua-engine/LuaEngine`之下,不要有任何的子文件夹。)
-5. 重新cmake.
-6. 重新生成.
Eluna API :
-[http://elunaluaengine.github.io/](http://elunaluaengine.github.io/)
\ No newline at end of file
+[http://elunaluaengine.github.io/](http://elunaluaengine.github.io/)
From 982cbfa1c36292e12c25644fc10e51d4e1df8bfb Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Mon, 21 Jun 2021 00:14:19 +0800
Subject: [PATCH 66/96] Fixed log not showing.
---
conf/mod_LuaEngine.conf.dist | 89 ++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+)
diff --git a/conf/mod_LuaEngine.conf.dist b/conf/mod_LuaEngine.conf.dist
index d3490f0..0fd798c 100644
--- a/conf/mod_LuaEngine.conf.dist
+++ b/conf/mod_LuaEngine.conf.dist
@@ -23,3 +23,92 @@
Eluna.Enabled = true
Eluna.TraceBack = false
Eluna.ScriptPath = "lua_scripts"
+
+
+###################################################################################################
+# LOGGING SYSTEM SETTINGS
+#
+# Appender config values: Given an appender "name"
+# Appender.name
+# Description: Defines 'where to log'.
+# Format: Type,LogLevel,Flags,optional1,optional2,optional3
+#
+# Type
+# 0 - (None)
+# 1 - (Console)
+# 2 - (File)
+# 3 - (DB)
+#
+# LogLevel
+# 0 - (Disabled)
+# 1 - (Fatal)
+# 2 - (Error)
+# 3 - (Warning)
+# 4 - (Info)
+# 5 - (Debug)
+# 6 - (Trace)
+#
+# Flags:
+# 0 - None
+# 1 - Prefix Timestamp to the text
+# 2 - Prefix Log Level to the text
+# 4 - Prefix Log Filter type to the text
+# 8 - Append timestamp to the log file name. Format: YYYY-MM-DD_HH-MM-SS
+# (Only used with Type = 2)
+# 16 - Make a backup of existing file before overwrite
+# (Only used with Mode = w)
+#
+# Colors (read as optional1 if Type = Console)
+# Format: "fatal error warn info debug trace"
+# 0 - BLACK
+# 1 - RED
+# 2 - GREEN
+# 3 - BROWN
+# 4 - BLUE
+# 5 - MAGENTA
+# 6 - CYAN
+# 7 - GREY
+# 8 - YELLOW
+# 9 - LRED
+# 10 - LGREEN
+# 11 - LBLUE
+# 12 - LMAGENTA
+# 13 - LCYAN
+# 14 - WHITE
+# Example: "1 9 3 6 5 8"
+#
+# File: Name of the file (read as optional1 if Type = File)
+# Allows to use one "%s" to create dynamic files
+#
+# Mode: Mode to open the file (read as optional2 if Type = File)
+# a - (Append)
+# w - (Overwrite)
+#
+# MaxFileSize: Maximum file size of the log file before creating a new log file
+# (read as optional3 if Type = File)
+# Size is measured in bytes expressed in a 64-bit unsigned integer.
+# Maximum value is 4294967295 (4 GB). Leave blank for no limit.
+# NOTE: Does not work with dynamic filenames.
+# Example: 536870912 (512 MB)
+#
+Appender.ElunaLog=2,5,0,eluna.log,w
+Appender.ElunaConsole=1,4,0,"0 9 0 3 5 0"
+
+# Logger config values: Given a logger "name"
+# Logger.name
+# Description: Defines 'What to log'
+# Format: LogLevel,AppenderList
+#
+# LogLevel
+# 0 - (Disabled)
+# 1 - (Fatal)
+# 2 - (Error)
+# 3 - (Warning)
+# 4 - (Info)
+# 5 - (Debug)
+# 6 - (Trace)
+#
+# AppenderList: List of appenders linked to logger
+# (Using spaces as separator).
+#
+Logger.eluna=6,ElunaLog ElunaConsole
From edabf159367bcd88bf6a81f39961a317c270eb55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Sat, 26 Jun 2021 01:35:59 +0200
Subject: [PATCH 67/96] feat: update to latest Eluna (#50)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 2861199..89ee3b1 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 286119950f6f1bd82cfc50886da9ebda6e0a8b0c
+Subproject commit 89ee3b166e9b3d247cd77d4128e400bbd052833d
From 888430dff40d6b8a0f7ff67b13fec0b6457d60d3 Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Fri, 2 Jul 2021 22:05:13 +0800
Subject: [PATCH 68/96] Update README_CN.md
---
README_CN.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README_CN.md b/README_CN.md
index a3f0a31..ec2b68a 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -1,6 +1,6 @@
#  mod-eluna-lua-engine for AzerothCore
-- Latest build status with azerothcore: [](https://github.com/azerothcore/mod-eluna-lua-engine)
+- 最新版本在Azerothcore的构建状态: [](https://github.com/azerothcore/mod-eluna-lua-engine)
[english](README.md) | [中文说明](README_CN.md) | [Español](README_ES.md)
From 6d13edfb5113fcd325e894cef1c97c22ca589312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Fri, 16 Jul 2021 14:41:52 +0200
Subject: [PATCH 69/96] feat: update to latest Eluna (#51)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 89ee3b1..f9aaee3 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 89ee3b166e9b3d247cd77d4128e400bbd052833d
+Subproject commit f9aaee345ba6600bd068b530bc46c3619135b4f9
From 506a1ac522ce8b6e66d60a8d897422079036d366 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Wed, 25 Aug 2021 12:40:24 +0200
Subject: [PATCH 70/96] feat: update to latest Eluna (#52)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index f9aaee3..a6a7553 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit f9aaee345ba6600bd068b530bc46c3619135b4f9
+Subproject commit a6a75531620b0d27935ecde2bcb7b54e526f1ba6
From 3b943f78c6b6e21c80c6f400a64cf5ce14919622 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Wed, 15 Sep 2021 12:52:01 +0200
Subject: [PATCH 71/96] feat: update to latest Eluna (#55)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index a6a7553..c76bc5d 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit a6a75531620b0d27935ecde2bcb7b54e526f1ba6
+Subproject commit c76bc5d0983bcab60842b8d9aef40a9ae50a2638
From e45a79958a748a5c4c9f88d43846c37e643e3a91 Mon Sep 17 00:00:00 2001
From: UltraNix
Date: Sat, 25 Sep 2021 19:23:32 +0200
Subject: [PATCH 72/96] New player event: PLAYER_EVENT_ON_PET_ADDED_TO_WORLD
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index c76bc5d..a137f30 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit c76bc5d0983bcab60842b8d9aef40a9ae50a2638
+Subproject commit a137f30e6de475ccf0dbdd9cf99ef503ba75c665
From 2e3fd3941c5955ac2e13dfb458862075a6dde2ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Mon, 4 Oct 2021 16:52:55 +0200
Subject: [PATCH 73/96] fix: restore latest Eluna master (#59)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index a137f30..b12521e 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit a137f30e6de475ccf0dbdd9cf99ef503ba75c665
+Subproject commit b12521e587f9fa382b43ea17dc75f09bc253e895
From ab11bd6569fa64f6650ca59e45f8f7a02b162100 Mon Sep 17 00:00:00 2001
From: Axel Cocat
Date: Fri, 8 Oct 2021 13:48:00 +0200
Subject: [PATCH 74/96] feat: change LuaEngine submodule to AzerothCore's fork
(#60)
---
.gitmodules | 2 +-
LuaEngine | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.gitmodules b/.gitmodules
index daac882..8e2b3f1 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,4 +1,4 @@
[submodule "LuaEngine"]
path = LuaEngine
- url = https://github.com/ElunaLuaEngine/Eluna.git
+ url = https://github.com/azerothcore/Eluna.git
branch = master
diff --git a/LuaEngine b/LuaEngine
index b12521e..63b2b84 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit b12521e587f9fa382b43ea17dc75f09bc253e895
+Subproject commit 63b2b84e8bafcc1268bdef4f31df10e53b29b725
From 2858534e35ee3aff6ff06ca62f726f463b8be4b0 Mon Sep 17 00:00:00 2001
From: Axel Cocat
Date: Fri, 8 Oct 2021 16:40:48 +0200
Subject: [PATCH 75/96] feat: update to latest Eluna (#61)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 63b2b84..a3f1218 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 63b2b84e8bafcc1268bdef4f31df10e53b29b725
+Subproject commit a3f12188b8823024f0d210ea90aa92d101c6acc4
From 9ac67c412084f877e267c08020663b01b779ce47 Mon Sep 17 00:00:00 2001
From: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
Date: Thu, 14 Oct 2021 19:28:43 +0200
Subject: [PATCH 76/96] Update eluna to LuaEngine
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index a3f1218..f18b282 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit a3f12188b8823024f0d210ea90aa92d101c6acc4
+Subproject commit f18b282a9cf957f1cc7f8aac3616709c71c70a0d
From 126f7ebf5327c472a627a579431f6c26d335e4b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Fri, 15 Oct 2021 11:48:34 +0200
Subject: [PATCH 77/96] fix: update to latest eluna (#63)
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index f18b282..c0b8e21 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit f18b282a9cf957f1cc7f8aac3616709c71c70a0d
+Subproject commit c0b8e217287dfe87a910922e1c029810509f974c
From 90e783dfc5d7d9b50a7cc92a19fc45b857003ec9 Mon Sep 17 00:00:00 2001
From: 55Honey <71938210+55Honey@users.noreply.github.com>
Date: Tue, 19 Oct 2021 13:04:00 +0200
Subject: [PATCH 78/96] docs(README): update Eluna link (#64)
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index a9a394a..89b5c91 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ Optional: if you need to update Eluna to the latest version, you can `cd LuaEngi
1. download [mod-eluna-lua-engine](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
2. extract it move the folder **mod-eluna-lua-engine** inside the **modules** folder of your azerothcore-wotlk sources
-3. download [Eluna](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
+3. download [Eluna](https://github.com/Azerothcore/Eluna/archive/master.zip)
4. extract it and move all the files inside the `Eluna-master` folder into the `mod-eluna-lua-engine/LuaEngine` folder. `LuaEngine.h` needs to be directly under `mod-eluna-lua-engine/LuaEngine` without any extra sub-folders.
### 2) Build
From de4ea7469b44d627e41d55b36fa88b4f0ff1cefe Mon Sep 17 00:00:00 2001
From: Winfidonarleyan
Date: Fri, 22 Oct 2021 22:52:08 +0700
Subject: [PATCH 79/96] feat(Misc): update LuaEngine to
cccf0623ee42107f6e9de54c9ffcf1ba12a7d259
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index c0b8e21..cccf062 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit c0b8e217287dfe87a910922e1c029810509f974c
+Subproject commit cccf0623ee42107f6e9de54c9ffcf1ba12a7d259
From 8f159c7e94241057007e1a39101d507d4553f05a Mon Sep 17 00:00:00 2001
From: ayase <137056643@qq.com>
Date: Sat, 23 Oct 2021 11:10:55 +0800
Subject: [PATCH 80/96] Update README_CN.md
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
更改下载eluna的链接,添加中文文档地址
---
README_CN.md | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/README_CN.md b/README_CN.md
index ec2b68a..36a7152 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -30,7 +30,7 @@ git clone https://github.com/azerothcore/mod-eluna-lua-engine.git
1. 下载 [mod-eluna-lua-engine](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
2. 解压到你的`azerothcore-wotlk`源码中的**modules**文件夹中,请确保路径看起来是这样的`azerothcore-wotlk/modules/mod-eluna-lua-engine`
-3. 下载 [Eluna](https://github.com/ElunaLuaEngine/Eluna/archive/master.zip)
+3. 下载 [Eluna](https://github.com/azerothcore/Eluna/archive/master.zip)
4. 把文件解压到 `mod-eluna-lua-engine/LuaEngine`. `LuaEngine.h`这个文件的路径看起来应该是这样的`mod-eluna-lua-engine/LuaEngine/LuaEngine.h`.
### 2) 生成
@@ -40,3 +40,6 @@ git clone https://github.com/azerothcore/mod-eluna-lua-engine.git
Eluna API :
[http://elunaluaengine.github.io/](http://elunaluaengine.github.io/)
+Eluna 中文文档(重构):
+[http://wiki.uiwow.com/doku.php/eluna:start](http://wiki.uiwow.com/doku.php/eluna:start)
+
From c47fedf9db0d7aed6248ca84d8591e85af08af59 Mon Sep 17 00:00:00 2001
From: fborzi
Date: Mon, 1 Nov 2021 12:33:59 +0100
Subject: [PATCH 81/96] feat(Eluna): update to latest Eluna
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index cccf062..437ab62 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit cccf0623ee42107f6e9de54c9ffcf1ba12a7d259
+Subproject commit 437ab629969ece89d8add3ac74e1e67e491370fc
From 5e7e1eec349f673d795b07ca0c3893c692dbde81 Mon Sep 17 00:00:00 2001
From: 55Honey <71938210+55Honey@users.noreply.github.com>
Date: Fri, 5 Nov 2021 09:25:34 +0100
Subject: [PATCH 82/96] feat: update to latest Eluna
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index 437ab62..df8b3ef 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit 437ab629969ece89d8add3ac74e1e67e491370fc
+Subproject commit df8b3efbbe2092fab76d86211140037839e2cba0
From 302cb7ee2606e5fe6b769726639620e4149e6cab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Sun, 14 Nov 2021 20:59:29 +0100
Subject: [PATCH 83/96] docs(README): add Eluna update procedure (#68)
---
README.md | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/README.md b/README.md
index 89b5c91..733d7e8 100644
--- a/README.md
+++ b/README.md
@@ -37,3 +37,18 @@ You need to run the cmake again and and rebuild the project.
Eluna API :
[http://elunaluaengine.github.io/](http://elunaluaengine.github.io/)
+
+## How to update the Eluna version (for project mainteners)
+
+1) `cd` into `mod-eluna-lua-engine`
+2) `git checkout master`
+3) cd `LuaEngine`
+4) `git checkout master`
+5) `git pull`
+6) `cd ..` so you get back to `mod-eluna-lua-engine`
+7) `git checkout -b some-new-unique-branch-name`
+8) `git add LuaEngine`
+9) `git commit -m "feat: update Eluna version"`
+10) `git push`
+11) The terminal will tell you something like `fatal: The current branch some-new-unique-branch-name has no upstream branch.` and suggest the command to use, for example: `git push --set-upstream origin some-new-unique-branch-name`
+12) Open [the repo on Github](https://github.com/azerothcore/mod-eluna-lua-engine) and create a new PR
From b7717d5020f75fbbcc628102c982d4ebb8cc58dc Mon Sep 17 00:00:00 2001
From: fborzi
Date: Sun, 14 Nov 2021 21:01:35 +0100
Subject: [PATCH 84/96] feat: update to latest Eluna
---
LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LuaEngine b/LuaEngine
index df8b3ef..ccf3372 160000
--- a/LuaEngine
+++ b/LuaEngine
@@ -1 +1 @@
-Subproject commit df8b3efbbe2092fab76d86211140037839e2cba0
+Subproject commit ccf337262c2573f345e54b2973678f5dbf282aa2
From 1c1e17e578b1ff7df24a4d350c4dcf261fa48094 Mon Sep 17 00:00:00 2001
From: Kargatum
Date: Thu, 2 Dec 2021 20:29:13 +0700
Subject: [PATCH 85/96] feat(Misc): add support new modules loading api (#71)
---
.gitmodules | 2 +-
CMakeLists.txt | 2 -
cmake/after_gs_install.cmake | 28 -
cmake/after_load_cmake_modules.cmake | 12 -
cmake/before_gs_install.cmake | 13 -
src/ElunaLuaEngine_SC.cpp | 943 ++++++++++++++++++++++++++
LuaEngine => src/LuaEngine | 0
src/eluna_lua_engine_loader.cpp | 25 +
{lualib => src/lualib}/CMakeLists.txt | 0
{lualib => src/lualib}/lapi.c | 0
{lualib => src/lualib}/lapi.h | 0
{lualib => src/lualib}/lauxlib.c | 0
{lualib => src/lualib}/lauxlib.h | 0
{lualib => src/lualib}/lbaselib.c | 0
{lualib => src/lualib}/lbitlib.c | 0
{lualib => src/lualib}/lcode.c | 0
{lualib => src/lualib}/lcode.h | 0
{lualib => src/lualib}/lcorolib.c | 0
{lualib => src/lualib}/lctype.c | 0
{lualib => src/lualib}/lctype.h | 0
{lualib => src/lualib}/ldblib.c | 0
{lualib => src/lualib}/ldebug.c | 0
{lualib => src/lualib}/ldebug.h | 0
{lualib => src/lualib}/ldo.c | 0
{lualib => src/lualib}/ldo.h | 0
{lualib => src/lualib}/ldump.c | 0
{lualib => src/lualib}/lfunc.c | 0
{lualib => src/lualib}/lfunc.h | 0
{lualib => src/lualib}/lgc.c | 0
{lualib => src/lualib}/lgc.h | 0
{lualib => src/lualib}/linit.c | 0
{lualib => src/lualib}/liolib.c | 0
{lualib => src/lualib}/llex.c | 0
{lualib => src/lualib}/llex.h | 0
{lualib => src/lualib}/llimits.h | 0
{lualib => src/lualib}/lmathlib.c | 0
{lualib => src/lualib}/lmem.c | 0
{lualib => src/lualib}/lmem.h | 0
{lualib => src/lualib}/loadlib.c | 0
{lualib => src/lualib}/lobject.c | 0
{lualib => src/lualib}/lobject.h | 0
{lualib => src/lualib}/lopcodes.c | 0
{lualib => src/lualib}/lopcodes.h | 0
{lualib => src/lualib}/loslib.c | 0
{lualib => src/lualib}/lparser.c | 0
{lualib => src/lualib}/lparser.h | 0
{lualib => src/lualib}/lstate.c | 0
{lualib => src/lualib}/lstate.h | 0
{lualib => src/lualib}/lstring.c | 0
{lualib => src/lualib}/lstring.h | 0
{lualib => src/lualib}/lstrlib.c | 0
{lualib => src/lualib}/ltable.c | 0
{lualib => src/lualib}/ltable.h | 0
{lualib => src/lualib}/ltablib.c | 0
{lualib => src/lualib}/ltm.c | 0
{lualib => src/lualib}/ltm.h | 0
{lualib => src/lualib}/lua.c | 0
{lualib => src/lualib}/lua.h | 0
{lualib => src/lualib}/lua.hpp | 0
{lualib => src/lualib}/luac.c | 0
{lualib => src/lualib}/luaconf.h | 0
{lualib => src/lualib}/lualib.h | 0
{lualib => src/lualib}/lundump.c | 0
{lualib => src/lualib}/lundump.h | 0
{lualib => src/lualib}/lvm.c | 0
{lualib => src/lualib}/lvm.h | 0
{lualib => src/lualib}/lzio.c | 0
{lualib => src/lualib}/lzio.h | 0
68 files changed, 969 insertions(+), 56 deletions(-)
delete mode 100644 CMakeLists.txt
delete mode 100644 cmake/after_gs_install.cmake
delete mode 100644 cmake/after_load_cmake_modules.cmake
delete mode 100644 cmake/before_gs_install.cmake
create mode 100644 src/ElunaLuaEngine_SC.cpp
rename LuaEngine => src/LuaEngine (100%)
create mode 100644 src/eluna_lua_engine_loader.cpp
rename {lualib => src/lualib}/CMakeLists.txt (100%)
rename {lualib => src/lualib}/lapi.c (100%)
rename {lualib => src/lualib}/lapi.h (100%)
rename {lualib => src/lualib}/lauxlib.c (100%)
rename {lualib => src/lualib}/lauxlib.h (100%)
rename {lualib => src/lualib}/lbaselib.c (100%)
rename {lualib => src/lualib}/lbitlib.c (100%)
rename {lualib => src/lualib}/lcode.c (100%)
rename {lualib => src/lualib}/lcode.h (100%)
rename {lualib => src/lualib}/lcorolib.c (100%)
rename {lualib => src/lualib}/lctype.c (100%)
rename {lualib => src/lualib}/lctype.h (100%)
rename {lualib => src/lualib}/ldblib.c (100%)
rename {lualib => src/lualib}/ldebug.c (100%)
rename {lualib => src/lualib}/ldebug.h (100%)
rename {lualib => src/lualib}/ldo.c (100%)
rename {lualib => src/lualib}/ldo.h (100%)
rename {lualib => src/lualib}/ldump.c (100%)
rename {lualib => src/lualib}/lfunc.c (100%)
rename {lualib => src/lualib}/lfunc.h (100%)
rename {lualib => src/lualib}/lgc.c (100%)
rename {lualib => src/lualib}/lgc.h (100%)
rename {lualib => src/lualib}/linit.c (100%)
rename {lualib => src/lualib}/liolib.c (100%)
rename {lualib => src/lualib}/llex.c (100%)
rename {lualib => src/lualib}/llex.h (100%)
rename {lualib => src/lualib}/llimits.h (100%)
rename {lualib => src/lualib}/lmathlib.c (100%)
rename {lualib => src/lualib}/lmem.c (100%)
rename {lualib => src/lualib}/lmem.h (100%)
rename {lualib => src/lualib}/loadlib.c (100%)
rename {lualib => src/lualib}/lobject.c (100%)
rename {lualib => src/lualib}/lobject.h (100%)
rename {lualib => src/lualib}/lopcodes.c (100%)
rename {lualib => src/lualib}/lopcodes.h (100%)
rename {lualib => src/lualib}/loslib.c (100%)
rename {lualib => src/lualib}/lparser.c (100%)
rename {lualib => src/lualib}/lparser.h (100%)
rename {lualib => src/lualib}/lstate.c (100%)
rename {lualib => src/lualib}/lstate.h (100%)
rename {lualib => src/lualib}/lstring.c (100%)
rename {lualib => src/lualib}/lstring.h (100%)
rename {lualib => src/lualib}/lstrlib.c (100%)
rename {lualib => src/lualib}/ltable.c (100%)
rename {lualib => src/lualib}/ltable.h (100%)
rename {lualib => src/lualib}/ltablib.c (100%)
rename {lualib => src/lualib}/ltm.c (100%)
rename {lualib => src/lualib}/ltm.h (100%)
rename {lualib => src/lualib}/lua.c (100%)
rename {lualib => src/lualib}/lua.h (100%)
rename {lualib => src/lualib}/lua.hpp (100%)
rename {lualib => src/lualib}/luac.c (100%)
rename {lualib => src/lualib}/luaconf.h (100%)
rename {lualib => src/lualib}/lualib.h (100%)
rename {lualib => src/lualib}/lundump.c (100%)
rename {lualib => src/lualib}/lundump.h (100%)
rename {lualib => src/lualib}/lvm.c (100%)
rename {lualib => src/lualib}/lvm.h (100%)
rename {lualib => src/lualib}/lzio.c (100%)
rename {lualib => src/lualib}/lzio.h (100%)
diff --git a/.gitmodules b/.gitmodules
index 8e2b3f1..1bb8b63 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,4 +1,4 @@
[submodule "LuaEngine"]
- path = LuaEngine
+ path = src/LuaEngine
url = https://github.com/azerothcore/Eluna.git
branch = master
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index 54641af..0000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-CU_SET_PATH("CMAKE_MOD_ELUNA_ENGINE_DIR" "${CMAKE_CURRENT_LIST_DIR}")
-CU_ADD_HOOK(AFTER_LOAD_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake/after_load_cmake_modules.cmake")
diff --git a/cmake/after_gs_install.cmake b/cmake/after_gs_install.cmake
deleted file mode 100644
index de63c48..0000000
--- a/cmake/after_gs_install.cmake
+++ /dev/null
@@ -1,28 +0,0 @@
-set(PUBLIC_INCLUDES
- ${PUBLIC_INCLUDES}
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine
- ${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib
-)
-
-target_include_directories(game-interface
- INTERFACE
- ${PUBLIC_INCLUDES})
-
-add_dependencies(game lualib)
-
-target_link_libraries(game
- PUBLIC
- lualib)
-
-if( WIN32 )
- if (MSVC)
- set(MSVC_CONFIGURATION_NAME $(ConfigurationName)/)
- endif()
- add_custom_command(TARGET game
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/bin/${MSVC_CONFIGURATION_NAME}lua_scripts/extensions/"
- COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" "${CMAKE_BINARY_DIR}/bin/${MSVC_CONFIGURATION_NAME}lua_scripts/extensions/"
- )
-endif()
-
-install(DIRECTORY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/extensions" DESTINATION "${CMAKE_INSTALL_PREFIX}/bin/lua_scripts/")
diff --git a/cmake/after_load_cmake_modules.cmake b/cmake/after_load_cmake_modules.cmake
deleted file mode 100644
index eb7b43b..0000000
--- a/cmake/after_load_cmake_modules.cmake
+++ /dev/null
@@ -1,12 +0,0 @@
-add_subdirectory(${CMAKE_MOD_ELUNA_ENGINE_DIR}/lualib)
-
-add_definitions(-DELUNA)
-add_definitions(-DAZEROTHCORE)
-add_definitions(-DWOTLK)
-
-CU_ADD_HOOK(BEFORE_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/before_gs_install.cmake")
-CU_ADD_HOOK(AFTER_GAME_LIBRARY "${CMAKE_MOD_ELUNA_ENGINE_DIR}/cmake/after_gs_install.cmake")
-
-AC_ADD_CONFIG_FILE("${CMAKE_MOD_ELUNA_ENGINE_DIR}/conf/mod_LuaEngine.conf.dist")
-
-message("** [Eluna Module] LuaEngine is enable!")
diff --git a/cmake/before_gs_install.cmake b/cmake/before_gs_install.cmake
deleted file mode 100644
index 95b99b0..0000000
--- a/cmake/before_gs_install.cmake
+++ /dev/null
@@ -1,13 +0,0 @@
-file(GLOB_RECURSE method_headers ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/*Methods.h)
-file(GLOB_RECURSE sources_ElunaFile_CPP ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/*.cpp )
-file(GLOB_RECURSE sources_ElunaFile_H ${CMAKE_MOD_ELUNA_ENGINE_DIR}/LuaEngine/*.h)
-
-set(ElunaLuaEngineFiles
- ${ElunaLuaEngineFiles}
- ${sources_ElunaFile_H}
- ${sources_ElunaFile_CPP}
-)
-
-source_group("LuaEngine\\Methods" FILES ${method_headers})
-source_group("LuaEngine\\Header Files" FILES ${sources_ElunaFile_H})
-source_group("LuaEngine\\Source Files" FILES ${sources_ElunaFile_CPP})
diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp
new file mode 100644
index 0000000..6ab9cfe
--- /dev/null
+++ b/src/ElunaLuaEngine_SC.cpp
@@ -0,0 +1,943 @@
+/*
+ * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+#include "Chat.h"
+#include "ElunaEventMgr.h"
+#include "Log.h"
+#include "LuaEngine.h"
+#include "Pet.h"
+#include "Player.h"
+#include "ScriptMgr.h"
+#include "ScriptedGossip.h"
+
+class Eluna_AllCreatureScript : public AllCreatureScript
+{
+public:
+ Eluna_AllCreatureScript() : AllCreatureScript("Eluna_AllCreatureScript") { }
+
+ // Creature
+ bool CanCreatureGossipHello(Player* player, Creature* creature) override
+ {
+ if (sEluna->OnGossipHello(player, creature))
+ return true;
+
+ return false;
+ }
+
+ bool CanCreatureGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action) override
+ {
+ if (sEluna->OnGossipSelect(player, creature, sender, action))
+ return true;
+
+ return false;
+ }
+
+ bool CanCreatureGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 action, const char* code) override
+ {
+ if (sEluna->OnGossipSelectCode(player, creature, sender, action, code))
+ return true;
+
+ return false;
+ }
+
+ void OnCreatureAddWorld(Creature* creature) override
+ {
+ sEluna->OnAddToWorld(creature);
+
+ if (creature->IsGuardian() && creature->ToTempSummon() && creature->ToTempSummon()->GetSummonerGUID().IsPlayer())
+ sEluna->OnPetAddedToWorld(creature->ToTempSummon()->GetSummonerUnit()->ToPlayer(), creature);
+ }
+
+ void OnCreatureRemoveWorld(Creature* creature) override
+ {
+ sEluna->OnRemoveFromWorld(creature);
+ }
+
+ bool CanCreatureQuestAccept(Player* player, Creature* creature, Quest const* quest) override
+ {
+ sEluna->OnQuestAccept(player, creature, quest);
+ return false;
+ }
+
+ bool CanCreatureQuestReward(Player* player, Creature* creature, Quest const* quest, uint32 opt) override
+ {
+ if (sEluna->OnQuestReward(player, creature, quest, opt))
+ {
+ ClearGossipMenuFor(player);
+ return true;
+ }
+
+ return false;
+ }
+
+ CreatureAI* GetCreatureAI(Creature* creature) const override
+ {
+ if (CreatureAI* luaAI = sEluna->GetAI(creature))
+ return luaAI;
+
+ return nullptr;
+ }
+};
+
+class Eluna_AllGameObjectScript : public AllGameObjectScript
+{
+public:
+ Eluna_AllGameObjectScript() : AllGameObjectScript("Eluna_AllGameObjectScript") { }
+
+ void OnGameObjectAddWorld(GameObject* go) override
+ {
+ sEluna->OnAddToWorld(go);
+ }
+
+ void OnGameObjectRemoveWorld(GameObject* go) override
+ {
+ sEluna->OnRemoveFromWorld(go);
+ }
+
+ void OnGameObjectUpdate(GameObject* go, uint32 diff) override
+ {
+ sEluna->UpdateAI(go, diff);
+ }
+
+ bool CanGameObjectGossipHello(Player* player, GameObject* go) override
+ {
+ if (sEluna->OnGossipHello(player, go))
+ return true;
+
+ if (sEluna->OnGameObjectUse(player, go))
+ return true;
+
+ return false;
+ }
+
+ void OnGameObjectDamaged(GameObject* go, Player* player) override
+ {
+ sEluna->OnDamaged(go, player);
+ }
+
+ void OnGameObjectDestroyed(GameObject* go, Player* player) override
+ {
+ sEluna->OnDestroyed(go, player);
+ }
+
+ void OnGameObjectLootStateChanged(GameObject* go, uint32 state, Unit* /*unit*/) override
+ {
+ sEluna->OnLootStateChanged(go, state);
+ }
+
+ void OnGameObjectStateChanged(GameObject* go, uint32 state) override
+ {
+ sEluna->OnGameObjectStateChanged(go, state);
+ }
+
+ bool CanGameObjectQuestAccept(Player* player, GameObject* go, Quest const* quest) override
+ {
+ sEluna->OnQuestAccept(player, go, quest);
+ return false;
+ }
+
+ bool CanGameObjectGossipSelect(Player* player, GameObject* go, uint32 sender, uint32 action) override
+ {
+ if (sEluna->OnGossipSelect(player, go, sender, action))
+ return true;
+
+ return false;
+ }
+
+ bool CanGameObjectGossipSelectCode(Player* player, GameObject* go, uint32 sender, uint32 action, const char* code) override
+ {
+ if (sEluna->OnGossipSelectCode(player, go, sender, action, code))
+ return true;
+
+ return false;
+ }
+
+ bool CanGameObjectQuestReward(Player* player, GameObject* go, Quest const* quest, uint32 opt) override
+ {
+ if (sEluna->OnQuestAccept(player, go, quest))
+ return false;
+
+ if (sEluna->OnQuestReward(player, go, quest, opt))
+ return false;
+
+ return true;
+ }
+
+ GameObjectAI* GetGameObjectAI(GameObject* go) const override
+ {
+ sEluna->OnSpawn(go);
+ return nullptr;
+ }
+};
+
+class Eluna_AllItemScript : public AllItemScript
+{
+public:
+ Eluna_AllItemScript() : AllItemScript("Eluna_AllItemScript") { }
+
+ bool CanItemQuestAccept(Player* player, Item* item, Quest const* quest) override
+ {
+ if (sEluna->OnQuestAccept(player, item, quest))
+ return false;
+
+ return true;
+ }
+
+ bool CanItemUse(Player* player, Item* item, SpellCastTargets const& targets) override
+ {
+ if (!sEluna->OnUse(player, item, targets))
+ return true;
+
+ return false;
+ }
+
+ bool CanItemExpire(Player* player, ItemTemplate const* proto) override
+ {
+ if (sEluna->OnExpire(player, proto))
+ return false;
+
+ return true;
+ }
+
+ bool CanItemRemove(Player* player, Item* item) override
+ {
+ if (sEluna->OnRemove(player, item))
+ return false;
+
+ return true;
+ }
+
+ void OnItemGossipSelect(Player* player, Item* item, uint32 sender, uint32 action) override
+ {
+ sEluna->HandleGossipSelectOption(player, item, sender, action, "");
+ }
+
+ void OnItemGossipSelectCode(Player* player, Item* item, uint32 sender, uint32 action, const char* code) override
+ {
+ sEluna->HandleGossipSelectOption(player, item, sender, action, code);
+ }
+};
+
+class Eluna_AllMapScript : public AllMapScript
+{
+public:
+ Eluna_AllMapScript() : AllMapScript("Eluna_AllMapScript") { }
+
+ void OnBeforeCreateInstanceScript(InstanceMap* instanceMap, InstanceScript* instanceData, bool /*load*/, std::string /*data*/, uint32 /*completedEncounterMask*/) override
+ {
+ instanceData = sEluna->GetInstanceData(instanceMap);
+ }
+
+ void OnDestroyInstance(MapInstanced* /*mapInstanced*/, Map* map) override
+ {
+ sEluna->FreeInstanceId(map->GetInstanceId());
+ }
+
+ void OnCreateMap(Map* map) override
+ {
+ sEluna->OnCreate(map);
+ }
+
+ void OnDestroyMap(Map* map) override
+ {
+ sEluna->OnDestroy(map);
+ }
+
+ void OnPlayerEnterAll(Map* map, Player* player) override
+ {
+ sEluna->OnPlayerEnter(map, player);
+ }
+
+ void OnPlayerLeaveAll(Map* map, Player* player) override
+ {
+ sEluna->OnPlayerLeave(map, player);
+ }
+
+ void OnMapUpdate(Map* map, uint32 diff) override
+ {
+ sEluna->OnUpdate(map, diff);
+ }
+};
+
+class Eluna_AuctionHouseScript : public AuctionHouseScript
+{
+public:
+ Eluna_AuctionHouseScript() : AuctionHouseScript("Eluna_AuctionHouseScript") { }
+
+ void OnAuctionAdd(AuctionHouseObject* ah, AuctionEntry* entry) override
+ {
+ sEluna->OnAdd(ah, entry);
+ }
+
+ void OnAuctionRemove(AuctionHouseObject* ah, AuctionEntry* entry) override
+ {
+ sEluna->OnRemove(ah, entry);
+ }
+
+ void OnAuctionSuccessful(AuctionHouseObject* ah, AuctionEntry* entry) override
+ {
+ sEluna->OnSuccessful(ah, entry);
+ }
+
+ void OnAuctionExpire(AuctionHouseObject* ah, AuctionEntry* entry) override
+ {
+ sEluna->OnExpire(ah, entry);
+ }
+};
+
+class Eluna_BGScript : public BGScript
+{
+public:
+ Eluna_BGScript() : BGScript("Eluna_BGScript") { }
+
+ void OnBattlegroundStart(Battleground* bg) override
+ {
+ sEluna->OnBGStart(bg, bg->GetBgTypeID(), bg->GetInstanceID());
+ }
+
+ void OnBattlegroundEnd(Battleground* bg, TeamId winnerTeam) override
+ {
+ sEluna->OnBGEnd(bg, bg->GetBgTypeID(), bg->GetInstanceID(), winnerTeam);
+ }
+
+ void OnBattlegroundDestroy(Battleground* bg) override
+ {
+ sEluna->OnBGDestroy(bg, bg->GetBgTypeID(), bg->GetInstanceID());
+ }
+
+ void OnBattlegroundCreate(Battleground* bg) override
+ {
+ sEluna->OnBGCreate(bg, bg->GetBgTypeID(), bg->GetInstanceID());
+ }
+};
+
+class Eluna_CommandSC : public CommandSC
+{
+public:
+ Eluna_CommandSC() : CommandSC("Eluna_CommandSC") { }
+
+ bool CanExecuteCommand(ChatHandler& handler, std::string_view cmdStr) override
+ {
+ if (!sEluna->OnCommand(handler.IsConsole() ? nullptr : handler.GetSession()->GetPlayer(), std::string(cmdStr).c_str()))
+ {
+ return false;
+ }
+
+ return true;
+ }
+};
+
+class Eluna_ElunaScript : public ElunaScript
+{
+public:
+ Eluna_ElunaScript() : ElunaScript("Eluna_ElunaScript") { }
+
+ // Weather
+ void OnWeatherChange(Weather* weather, WeatherState state, float grade) override
+ {
+ sEluna->OnChange(weather, weather->GetZone(), state, grade);
+ }
+
+ // AreaTriger
+ bool CanAreaTrigger(Player* player, AreaTrigger const* trigger) override
+ {
+ if (sEluna->OnAreaTrigger(player, trigger))
+ return false;
+
+ return true;
+ }
+};
+
+class Eluna_GameEventScript : public GameEventScript
+{
+public:
+ Eluna_GameEventScript() : GameEventScript("Eluna_GameEventScript") { }
+
+ void OnEventStart(uint16 eventID)
+ {
+ sEluna->OnGameEventStart(eventID);
+ }
+
+ void OnEventStop(uint16 eventID)
+ {
+ sEluna->OnGameEventStop(eventID);
+ }
+};
+
+class Eluna_GroupScript : public GroupScript
+{
+public:
+ Eluna_GroupScript() : GroupScript("Eluna_GroupScript") { }
+
+ void OnAddMember(Group* group, ObjectGuid guid) override
+ {
+ sEluna->OnAddMember(group, guid);
+ }
+
+ void OnInviteMember(Group* group, ObjectGuid guid) override
+ {
+ sEluna->OnInviteMember(group, guid);
+ }
+
+ void OnRemoveMember(Group* group, ObjectGuid guid, RemoveMethod method, ObjectGuid /* kicker */, const char* /* reason */) override
+ {
+ sEluna->OnRemoveMember(group, guid, method);
+ }
+
+ void OnChangeLeader(Group* group, ObjectGuid newLeaderGuid, ObjectGuid oldLeaderGuid) override
+ {
+ sEluna->OnChangeLeader(group, newLeaderGuid, oldLeaderGuid);
+ }
+
+ void OnDisband(Group* group) override
+ {
+ sEluna->OnDisband(group);
+ }
+};
+
+class Eluna_GuildScript : public GuildScript
+{
+public:
+ Eluna_GuildScript() : GuildScript("Eluna_GuildScript") { }
+
+ void OnAddMember(Guild* guild, Player* player, uint8& plRank) override
+ {
+ sEluna->OnAddMember(guild, player, plRank);
+ }
+
+ void OnRemoveMember(Guild* guild, Player* player, bool isDisbanding, bool /*isKicked*/) override
+ {
+ sEluna->OnRemoveMember(guild, player, isDisbanding);
+ }
+
+ void OnMOTDChanged(Guild* guild, const std::string& newMotd) override
+ {
+ sEluna->OnMOTDChanged(guild, newMotd);
+ }
+
+ void OnInfoChanged(Guild* guild, const std::string& newInfo) override
+ {
+ sEluna->OnInfoChanged(guild, newInfo);
+ }
+
+ void OnCreate(Guild* guild, Player* leader, const std::string& name) override
+ {
+ sEluna->OnCreate(guild, leader, name);
+ }
+
+ void OnDisband(Guild* guild) override
+ {
+ sEluna->OnDisband(guild);
+ }
+
+ void OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair) override
+ {
+ sEluna->OnMemberWitdrawMoney(guild, player, amount, isRepair);
+ }
+
+ void OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount) override
+ {
+ sEluna->OnMemberDepositMoney(guild, player, amount);
+ }
+
+ void OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId,
+ bool isDestBank, uint8 destContainer, uint8 destSlotId) override
+ {
+ sEluna->OnItemMove(guild, player, pItem, isSrcBank, srcContainer, srcSlotId, isDestBank, destContainer, destSlotId);
+ }
+
+ void OnEvent(Guild* guild, uint8 eventType, ObjectGuid::LowType playerGuid1, ObjectGuid::LowType playerGuid2, uint8 newRank) override
+ {
+ sEluna->OnEvent(guild, eventType, playerGuid1, playerGuid2, newRank);
+ }
+
+ void OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, ObjectGuid::LowType playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId) override
+ {
+ sEluna->OnBankEvent(guild, eventType, tabId, playerGuid, itemOrMoney, itemStackCount, destTabId);
+ }
+};
+
+class Eluna_LootScript : public LootScript
+{
+public:
+ Eluna_LootScript() : LootScript("Eluna_LootScript") { }
+
+ void OnLootMoney(Player* player, uint32 gold) override
+ {
+ sEluna->OnLootMoney(player, gold);
+ }
+};
+
+class Eluna_MiscScript : public MiscScript
+{
+public:
+ Eluna_MiscScript() : MiscScript("Eluna_MiscScript") { }
+
+ void GetDialogStatus(Player* player, Object* questgiver) override
+ {
+ if (questgiver->GetTypeId() == TYPEID_GAMEOBJECT)
+ sEluna->GetDialogStatus(player, questgiver->ToGameObject());
+ else if (questgiver->GetTypeId() == TYPEID_UNIT)
+ sEluna->GetDialogStatus(player, questgiver->ToCreature());
+ }
+};
+
+class Eluna_PetScript : public PetScript
+{
+public:
+ Eluna_PetScript() : PetScript("Eluna_PetScript") { }
+
+ void OnPetAddToWorld(Pet* pet) override
+ {
+ sEluna->OnPetAddedToWorld(pet->GetOwner(), pet);
+ }
+};
+
+class Eluna_PlayerScript : public PlayerScript
+{
+public:
+ Eluna_PlayerScript() : PlayerScript("Eluna_PlayerScript") { }
+
+ void OnPlayerResurrect(Player* player, float /*restore_percent*/, bool /*applySickness*/) override
+ {
+ sEluna->OnResurrect(player);
+ }
+
+ bool CanPlayerUseChat(Player* player, uint32 type, uint32 lang, std::string& msg) override
+ {
+ if (type != CHAT_MSG_SAY && type != CHAT_MSG_YELL && type != CHAT_MSG_EMOTE)
+ return true;
+
+ if (!sEluna->OnChat(player, type, lang, msg))
+ return false;
+
+ return true;
+ }
+
+ bool CanPlayerUseChat(Player* player, uint32 type, uint32 lang, std::string& msg, Player* target) override
+ {
+ if (!sEluna->OnChat(player, type, lang, msg, target))
+ return false;
+
+ return true;
+ }
+
+ bool CanPlayerUseChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group) override
+ {
+ if (!sEluna->OnChat(player, type, lang, msg, group))
+ return false;
+
+ return true;
+ }
+
+ bool CanPlayerUseChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild) override
+ {
+ if (!sEluna->OnChat(player, type, lang, msg, guild))
+ return false;
+
+ return true;
+ }
+
+ bool CanPlayerUseChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel) override
+ {
+ if (!sEluna->OnChat(player, type, lang, msg, channel))
+ return false;
+
+ return true;
+ }
+
+ void OnLootItem(Player* player, Item* item, uint32 count, ObjectGuid lootguid) override
+ {
+ sEluna->OnLootItem(player, item, count, lootguid);
+ }
+
+ void OnPlayerLearnTalents(Player* player, uint32 talentId, uint32 talentRank, uint32 spellid) override
+ {
+ sEluna->OnLearnTalents(player, talentId, talentRank, spellid);
+ }
+
+ bool CanUseItem(Player* player, ItemTemplate const* proto, InventoryResult& result) override
+ {
+ result = sEluna->OnCanUseItem(player, proto->ItemId);
+ return result != EQUIP_ERR_OK ? false : true;
+ }
+
+ void OnEquip(Player* player, Item* it, uint8 bag, uint8 slot, bool /*update*/) override
+ {
+ sEluna->OnEquip(player, it, bag, slot);
+ }
+
+ void OnPlayerEnterCombat(Player* player, Unit* enemy) override
+ {
+ sEluna->OnPlayerEnterCombat(player, enemy);
+ }
+
+ void OnPlayerLeaveCombat(Player* player) override
+ {
+ sEluna->OnPlayerLeaveCombat(player);
+ }
+
+ bool CanRepopAtGraveyard(Player* player) override
+ {
+ sEluna->OnRepop(player);
+ return true;
+ }
+
+ void OnQuestAbandon(Player* player, uint32 questId) override
+ {
+ sEluna->OnQuestAbandon(player, questId);
+ }
+
+ void OnMapChanged(Player* player) override
+ {
+ sEluna->OnMapChanged(player);
+ }
+
+ void OnGossipSelect(Player* player, uint32 menu_id, uint32 sender, uint32 action) override
+ {
+ sEluna->HandleGossipSelectOption(player, menu_id, sender, action, "");
+ }
+
+ void OnGossipSelectCode(Player* player, uint32 menu_id, uint32 sender, uint32 action, const char* code) override
+ {
+ sEluna->HandleGossipSelectOption(player, menu_id, sender, action, code);
+ }
+
+ void OnPVPKill(Player* killer, Player* killed) override
+ {
+ sEluna->OnPVPKill(killer, killed);
+ }
+
+ void OnCreatureKill(Player* killer, Creature* killed) override
+ {
+ sEluna->OnCreatureKill(killer, killed);
+ }
+
+ void OnPlayerKilledByCreature(Creature* killer, Player* killed) override
+ {
+ sEluna->OnPlayerKilledByCreature(killer, killed);
+ }
+
+ void OnLevelChanged(Player* player, uint8 oldLevel) override
+ {
+ sEluna->OnLevelChanged(player, oldLevel);
+ }
+
+ void OnFreeTalentPointsChanged(Player* player, uint32 points) override
+ {
+ sEluna->OnFreeTalentPointsChanged(player, points);
+ }
+
+ void OnTalentsReset(Player* player, bool noCost) override
+ {
+ sEluna->OnTalentsReset(player, noCost);
+ }
+
+ void OnMoneyChanged(Player* player, int32& amount) override
+ {
+ sEluna->OnMoneyChanged(player, amount);
+ }
+
+ void OnGiveXP(Player* player, uint32& amount, Unit* victim) override
+ {
+ sEluna->OnGiveXP(player, amount, victim);
+ }
+
+ void OnReputationChange(Player* player, uint32 factionID, int32& standing, bool incremental) override
+ {
+ sEluna->OnReputationChange(player, factionID, standing, incremental);
+ }
+
+ void OnDuelRequest(Player* target, Player* challenger) override
+ {
+ sEluna->OnDuelRequest(target, challenger);
+ }
+
+ void OnDuelStart(Player* player1, Player* player2) override
+ {
+ sEluna->OnDuelStart(player1, player2);
+ }
+
+ void OnDuelEnd(Player* winner, Player* loser, DuelCompleteType type) override
+ {
+ sEluna->OnDuelEnd(winner, loser, type);
+ }
+
+ void OnEmote(Player* player, uint32 emote) override
+ {
+ sEluna->OnEmote(player, emote);
+ }
+
+ void OnTextEmote(Player* player, uint32 textEmote, uint32 emoteNum, ObjectGuid guid) override
+ {
+ sEluna->OnTextEmote(player, textEmote, emoteNum, guid);
+ }
+
+ void OnSpellCast(Player* player, Spell* spell, bool skipCheck) override
+ {
+ sEluna->OnSpellCast(player, spell, skipCheck);
+ }
+
+ void OnLogin(Player* player) override
+ {
+ sEluna->OnLogin(player);
+ }
+
+ void OnLogout(Player* player) override
+ {
+ sEluna->OnLogout(player);
+ }
+
+ void OnCreate(Player* player) override
+ {
+ sEluna->OnCreate(player);
+ }
+
+ void OnSave(Player* player) override
+ {
+ sEluna->OnSave(player);
+ }
+
+ void OnDelete(ObjectGuid guid, uint32 /*accountId*/) override
+ {
+ sEluna->OnDelete(guid.GetCounter());
+ }
+
+ void OnBindToInstance(Player* player, Difficulty difficulty, uint32 mapid, bool permanent) override
+ {
+ sEluna->OnBindToInstance(player, difficulty, mapid, permanent);
+ }
+
+ void OnUpdateZone(Player* player, uint32 newZone, uint32 newArea) override
+ {
+ sEluna->OnUpdateZone(player, newZone, newArea);
+ }
+
+ void OnFirstLogin(Player* player) override
+ {
+ sEluna->OnFirstLogin(player);
+ }
+};
+
+class Eluna_ServerScript : public ServerScript
+{
+public:
+ Eluna_ServerScript() : ServerScript("Eluna_ServerScript") { }
+
+ bool CanPacketSend(WorldSession* session, WorldPacket& packet) override
+ {
+ if (!sEluna->OnPacketSend(session, packet))
+ return false;
+
+ return true;
+ }
+
+ bool CanPacketReceive(WorldSession* session, WorldPacket& packet) override
+ {
+ if (!sEluna->OnPacketReceive(session, packet))
+ return false;
+
+ return true;
+ }
+};
+
+class Eluna_SpellSC : public SpellSC
+{
+public:
+ Eluna_SpellSC() : SpellSC("Eluna_SpellSC") { }
+
+ void OnDummyEffect(WorldObject* caster, uint32 spellID, SpellEffIndex effIndex, GameObject* gameObjTarget) override
+ {
+ sEluna->OnDummyEffect(caster, spellID, effIndex, gameObjTarget);
+ }
+
+ void OnDummyEffect(WorldObject* caster, uint32 spellID, SpellEffIndex effIndex, Creature* creatureTarget) override
+ {
+ sEluna->OnDummyEffect(caster, spellID, effIndex, creatureTarget);
+ }
+
+ void OnDummyEffect(WorldObject* caster, uint32 spellID, SpellEffIndex effIndex, Item* itemTarget) override
+ {
+ sEluna->OnDummyEffect(caster, spellID, effIndex, itemTarget);
+ }
+};
+
+class Eluna_UnitScript : public UnitScript
+{
+public:
+ Eluna_UnitScript() : UnitScript("Eluna_UnitScript") { }
+
+ void OnUnitUpdate(Unit* unit, uint32 diff) override
+ {
+ unit->elunaEvents->Update(diff);
+ }
+};
+
+class Eluna_VehicleScript : public VehicleScript
+{
+public:
+ Eluna_VehicleScript() : VehicleScript("Eluna_VehicleScript") { }
+
+ void OnInstall(Vehicle* veh) override
+ {
+ sEluna->OnInstall(veh);
+ }
+
+ void OnUninstall(Vehicle* veh) override
+ {
+ sEluna->OnUninstall(veh);
+ }
+
+ void OnInstallAccessory(Vehicle* veh, Creature* accessory) override
+ {
+ sEluna->OnInstallAccessory(veh, accessory);
+ }
+
+ void OnAddPassenger(Vehicle* veh, Unit* passenger, int8 seatId) override
+ {
+ sEluna->OnAddPassenger(veh, passenger, seatId);
+ }
+
+ void OnRemovePassenger(Vehicle* veh, Unit* passenger) override
+ {
+ sEluna->OnRemovePassenger(veh, passenger);
+ }
+};
+
+class Eluna_WorldObjectScript : public WorldObjectScript
+{
+public:
+ Eluna_WorldObjectScript() : WorldObjectScript("Eluna_WorldObjectScript") { }
+
+ void OnWorldObjectDestroy(WorldObject* object) override
+ {
+ delete object->elunaEvents;
+ object->elunaEvents = nullptr;
+ }
+
+ void OnWorldObjectCreate(WorldObject* object) override
+ {
+ object->elunaEvents = nullptr;
+ }
+
+ void OnWorldObjectSetMap(WorldObject* object, Map* /*map*/) override
+ {
+ delete object->elunaEvents;
+
+ // On multithread replace this with a pointer to map's Eluna pointer stored in a map
+ object->elunaEvents = new ElunaEventProcessor(&Eluna::GEluna, object);
+ }
+
+ void OnWorldObjectResetMap(WorldObject* object) override
+ {
+ delete object->elunaEvents;
+ object->elunaEvents = nullptr;
+ }
+
+ void OnWorldObjectUpdate(WorldObject* object, uint32 diff) override
+ {
+ object->elunaEvents->Update(diff);
+ }
+};
+
+class Eluna_WorldScript : public WorldScript
+{
+public:
+ Eluna_WorldScript() : WorldScript("Eluna_WorldScript") { }
+
+ void OnOpenStateChange(bool open) override
+ {
+ sEluna->OnOpenStateChange(open);
+ }
+
+ void OnBeforeConfigLoad(bool reload) override
+ {
+ if (!reload)
+ {
+ ///- Initialize Lua Engine
+ LOG_INFO("eluna", "Initialize Eluna Lua Engine...");
+ Eluna::Initialize();
+ }
+
+ sEluna->OnConfigLoad(reload, true);
+ }
+
+ void OnAfterConfigLoad(bool reload) override
+ {
+ sEluna->OnConfigLoad(reload, false);
+ }
+
+ void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) override
+ {
+ sEluna->OnShutdownInitiate(code, mask);
+ }
+
+ void OnShutdownCancel() override
+ {
+ sEluna->OnShutdownCancel();
+ }
+
+ void OnUpdate(uint32 diff) override
+ {
+ sEluna->OnWorldUpdate(diff);
+ }
+
+ void OnStartup() override
+ {
+ sEluna->OnStartup();
+ }
+
+ void OnShutdown() override
+ {
+ sEluna->OnShutdown();
+ Eluna::Uninitialize();
+ }
+
+ void OnBeforeWorldInitialized() override
+ {
+ ///- Run eluna scripts.
+ // in multithread foreach: run scripts
+ sEluna->RunScripts();
+ sEluna->OnConfigLoad(false, false); // Must be done after Eluna is initialized and scripts have run.
+ }
+};
+
+// Group all custom scripts
+void AddSC_ElunaLuaEngine()
+{
+ new Eluna_AllCreatureScript();
+ new Eluna_AllGameObjectScript();
+ new Eluna_AllItemScript();
+ new Eluna_AllMapScript();
+ new Eluna_AuctionHouseScript();
+ new Eluna_BGScript();
+ new Eluna_CommandSC();
+ new Eluna_ElunaScript();
+ new Eluna_GameEventScript();
+ new Eluna_GroupScript();
+ new Eluna_GuildScript();
+ new Eluna_LootScript();
+ new Eluna_MiscScript();
+ new Eluna_PetScript();
+ new Eluna_PlayerScript();
+ new Eluna_ServerScript();
+ new Eluna_SpellSC();
+ new Eluna_UnitScript();
+ new Eluna_VehicleScript();
+ new Eluna_WorldObjectScript();
+ new Eluna_WorldScript();
+}
diff --git a/LuaEngine b/src/LuaEngine
similarity index 100%
rename from LuaEngine
rename to src/LuaEngine
diff --git a/src/eluna_lua_engine_loader.cpp b/src/eluna_lua_engine_loader.cpp
new file mode 100644
index 0000000..12040dc
--- /dev/null
+++ b/src/eluna_lua_engine_loader.cpp
@@ -0,0 +1,25 @@
+/*
+ * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+// From SC
+void AddSC_ElunaLuaEngine();
+
+// Add all
+void Addmod_eluna_lua_engineScripts()
+{
+ AddSC_ElunaLuaEngine();
+}
diff --git a/lualib/CMakeLists.txt b/src/lualib/CMakeLists.txt
similarity index 100%
rename from lualib/CMakeLists.txt
rename to src/lualib/CMakeLists.txt
diff --git a/lualib/lapi.c b/src/lualib/lapi.c
similarity index 100%
rename from lualib/lapi.c
rename to src/lualib/lapi.c
diff --git a/lualib/lapi.h b/src/lualib/lapi.h
similarity index 100%
rename from lualib/lapi.h
rename to src/lualib/lapi.h
diff --git a/lualib/lauxlib.c b/src/lualib/lauxlib.c
similarity index 100%
rename from lualib/lauxlib.c
rename to src/lualib/lauxlib.c
diff --git a/lualib/lauxlib.h b/src/lualib/lauxlib.h
similarity index 100%
rename from lualib/lauxlib.h
rename to src/lualib/lauxlib.h
diff --git a/lualib/lbaselib.c b/src/lualib/lbaselib.c
similarity index 100%
rename from lualib/lbaselib.c
rename to src/lualib/lbaselib.c
diff --git a/lualib/lbitlib.c b/src/lualib/lbitlib.c
similarity index 100%
rename from lualib/lbitlib.c
rename to src/lualib/lbitlib.c
diff --git a/lualib/lcode.c b/src/lualib/lcode.c
similarity index 100%
rename from lualib/lcode.c
rename to src/lualib/lcode.c
diff --git a/lualib/lcode.h b/src/lualib/lcode.h
similarity index 100%
rename from lualib/lcode.h
rename to src/lualib/lcode.h
diff --git a/lualib/lcorolib.c b/src/lualib/lcorolib.c
similarity index 100%
rename from lualib/lcorolib.c
rename to src/lualib/lcorolib.c
diff --git a/lualib/lctype.c b/src/lualib/lctype.c
similarity index 100%
rename from lualib/lctype.c
rename to src/lualib/lctype.c
diff --git a/lualib/lctype.h b/src/lualib/lctype.h
similarity index 100%
rename from lualib/lctype.h
rename to src/lualib/lctype.h
diff --git a/lualib/ldblib.c b/src/lualib/ldblib.c
similarity index 100%
rename from lualib/ldblib.c
rename to src/lualib/ldblib.c
diff --git a/lualib/ldebug.c b/src/lualib/ldebug.c
similarity index 100%
rename from lualib/ldebug.c
rename to src/lualib/ldebug.c
diff --git a/lualib/ldebug.h b/src/lualib/ldebug.h
similarity index 100%
rename from lualib/ldebug.h
rename to src/lualib/ldebug.h
diff --git a/lualib/ldo.c b/src/lualib/ldo.c
similarity index 100%
rename from lualib/ldo.c
rename to src/lualib/ldo.c
diff --git a/lualib/ldo.h b/src/lualib/ldo.h
similarity index 100%
rename from lualib/ldo.h
rename to src/lualib/ldo.h
diff --git a/lualib/ldump.c b/src/lualib/ldump.c
similarity index 100%
rename from lualib/ldump.c
rename to src/lualib/ldump.c
diff --git a/lualib/lfunc.c b/src/lualib/lfunc.c
similarity index 100%
rename from lualib/lfunc.c
rename to src/lualib/lfunc.c
diff --git a/lualib/lfunc.h b/src/lualib/lfunc.h
similarity index 100%
rename from lualib/lfunc.h
rename to src/lualib/lfunc.h
diff --git a/lualib/lgc.c b/src/lualib/lgc.c
similarity index 100%
rename from lualib/lgc.c
rename to src/lualib/lgc.c
diff --git a/lualib/lgc.h b/src/lualib/lgc.h
similarity index 100%
rename from lualib/lgc.h
rename to src/lualib/lgc.h
diff --git a/lualib/linit.c b/src/lualib/linit.c
similarity index 100%
rename from lualib/linit.c
rename to src/lualib/linit.c
diff --git a/lualib/liolib.c b/src/lualib/liolib.c
similarity index 100%
rename from lualib/liolib.c
rename to src/lualib/liolib.c
diff --git a/lualib/llex.c b/src/lualib/llex.c
similarity index 100%
rename from lualib/llex.c
rename to src/lualib/llex.c
diff --git a/lualib/llex.h b/src/lualib/llex.h
similarity index 100%
rename from lualib/llex.h
rename to src/lualib/llex.h
diff --git a/lualib/llimits.h b/src/lualib/llimits.h
similarity index 100%
rename from lualib/llimits.h
rename to src/lualib/llimits.h
diff --git a/lualib/lmathlib.c b/src/lualib/lmathlib.c
similarity index 100%
rename from lualib/lmathlib.c
rename to src/lualib/lmathlib.c
diff --git a/lualib/lmem.c b/src/lualib/lmem.c
similarity index 100%
rename from lualib/lmem.c
rename to src/lualib/lmem.c
diff --git a/lualib/lmem.h b/src/lualib/lmem.h
similarity index 100%
rename from lualib/lmem.h
rename to src/lualib/lmem.h
diff --git a/lualib/loadlib.c b/src/lualib/loadlib.c
similarity index 100%
rename from lualib/loadlib.c
rename to src/lualib/loadlib.c
diff --git a/lualib/lobject.c b/src/lualib/lobject.c
similarity index 100%
rename from lualib/lobject.c
rename to src/lualib/lobject.c
diff --git a/lualib/lobject.h b/src/lualib/lobject.h
similarity index 100%
rename from lualib/lobject.h
rename to src/lualib/lobject.h
diff --git a/lualib/lopcodes.c b/src/lualib/lopcodes.c
similarity index 100%
rename from lualib/lopcodes.c
rename to src/lualib/lopcodes.c
diff --git a/lualib/lopcodes.h b/src/lualib/lopcodes.h
similarity index 100%
rename from lualib/lopcodes.h
rename to src/lualib/lopcodes.h
diff --git a/lualib/loslib.c b/src/lualib/loslib.c
similarity index 100%
rename from lualib/loslib.c
rename to src/lualib/loslib.c
diff --git a/lualib/lparser.c b/src/lualib/lparser.c
similarity index 100%
rename from lualib/lparser.c
rename to src/lualib/lparser.c
diff --git a/lualib/lparser.h b/src/lualib/lparser.h
similarity index 100%
rename from lualib/lparser.h
rename to src/lualib/lparser.h
diff --git a/lualib/lstate.c b/src/lualib/lstate.c
similarity index 100%
rename from lualib/lstate.c
rename to src/lualib/lstate.c
diff --git a/lualib/lstate.h b/src/lualib/lstate.h
similarity index 100%
rename from lualib/lstate.h
rename to src/lualib/lstate.h
diff --git a/lualib/lstring.c b/src/lualib/lstring.c
similarity index 100%
rename from lualib/lstring.c
rename to src/lualib/lstring.c
diff --git a/lualib/lstring.h b/src/lualib/lstring.h
similarity index 100%
rename from lualib/lstring.h
rename to src/lualib/lstring.h
diff --git a/lualib/lstrlib.c b/src/lualib/lstrlib.c
similarity index 100%
rename from lualib/lstrlib.c
rename to src/lualib/lstrlib.c
diff --git a/lualib/ltable.c b/src/lualib/ltable.c
similarity index 100%
rename from lualib/ltable.c
rename to src/lualib/ltable.c
diff --git a/lualib/ltable.h b/src/lualib/ltable.h
similarity index 100%
rename from lualib/ltable.h
rename to src/lualib/ltable.h
diff --git a/lualib/ltablib.c b/src/lualib/ltablib.c
similarity index 100%
rename from lualib/ltablib.c
rename to src/lualib/ltablib.c
diff --git a/lualib/ltm.c b/src/lualib/ltm.c
similarity index 100%
rename from lualib/ltm.c
rename to src/lualib/ltm.c
diff --git a/lualib/ltm.h b/src/lualib/ltm.h
similarity index 100%
rename from lualib/ltm.h
rename to src/lualib/ltm.h
diff --git a/lualib/lua.c b/src/lualib/lua.c
similarity index 100%
rename from lualib/lua.c
rename to src/lualib/lua.c
diff --git a/lualib/lua.h b/src/lualib/lua.h
similarity index 100%
rename from lualib/lua.h
rename to src/lualib/lua.h
diff --git a/lualib/lua.hpp b/src/lualib/lua.hpp
similarity index 100%
rename from lualib/lua.hpp
rename to src/lualib/lua.hpp
diff --git a/lualib/luac.c b/src/lualib/luac.c
similarity index 100%
rename from lualib/luac.c
rename to src/lualib/luac.c
diff --git a/lualib/luaconf.h b/src/lualib/luaconf.h
similarity index 100%
rename from lualib/luaconf.h
rename to src/lualib/luaconf.h
diff --git a/lualib/lualib.h b/src/lualib/lualib.h
similarity index 100%
rename from lualib/lualib.h
rename to src/lualib/lualib.h
diff --git a/lualib/lundump.c b/src/lualib/lundump.c
similarity index 100%
rename from lualib/lundump.c
rename to src/lualib/lundump.c
diff --git a/lualib/lundump.h b/src/lualib/lundump.h
similarity index 100%
rename from lualib/lundump.h
rename to src/lualib/lundump.h
diff --git a/lualib/lvm.c b/src/lualib/lvm.c
similarity index 100%
rename from lualib/lvm.c
rename to src/lualib/lvm.c
diff --git a/lualib/lvm.h b/src/lualib/lvm.h
similarity index 100%
rename from lualib/lvm.h
rename to src/lualib/lvm.h
diff --git a/lualib/lzio.c b/src/lualib/lzio.c
similarity index 100%
rename from lualib/lzio.c
rename to src/lualib/lzio.c
diff --git a/lualib/lzio.h b/src/lualib/lzio.h
similarity index 100%
rename from lualib/lzio.h
rename to src/lualib/lzio.h
From f68d83e8c6ecf64844a42aaa8ad25cb8aa0a3a17 Mon Sep 17 00:00:00 2001
From: Kargatum
Date: Sat, 4 Dec 2021 18:28:12 +0700
Subject: [PATCH 86/96] fix(AreaTrigger): correct condition (#72)
---
src/ElunaLuaEngine_SC.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp
index 6ab9cfe..0d5ac75 100644
--- a/src/ElunaLuaEngine_SC.cpp
+++ b/src/ElunaLuaEngine_SC.cpp
@@ -356,9 +356,9 @@ public:
bool CanAreaTrigger(Player* player, AreaTrigger const* trigger) override
{
if (sEluna->OnAreaTrigger(player, trigger))
- return false;
+ return true;
- return true;
+ return false;
}
};
From 36a0fe51556b809a3468b781e4162a1307183b72 Mon Sep 17 00:00:00 2001
From: anzz1
Date: Wed, 5 Jan 2022 17:10:06 +0200
Subject: [PATCH 87/96] Update README.md
Change manual instructions to reflect the change that LuaEngine folder needs to be at `mod-eluna-lua-engine/src/LuaEngine` instead of `mod-eluna-lua-engine/LuaEngine`
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 733d7e8..7d9e2f2 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ Optional: if you need to update Eluna to the latest version, you can `cd LuaEngi
1. download [mod-eluna-lua-engine](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
2. extract it move the folder **mod-eluna-lua-engine** inside the **modules** folder of your azerothcore-wotlk sources
3. download [Eluna](https://github.com/Azerothcore/Eluna/archive/master.zip)
-4. extract it and move all the files inside the `Eluna-master` folder into the `mod-eluna-lua-engine/LuaEngine` folder. `LuaEngine.h` needs to be directly under `mod-eluna-lua-engine/LuaEngine` without any extra sub-folders.
+4. extract it and move all the files inside the `Eluna-master` folder into the `mod-eluna-lua-engine/src/LuaEngine` folder. `LuaEngine.h` needs to be directly under `mod-eluna-lua-engine/src/LuaEngine` without any extra sub-folders.
### 2) Build
From 474b9c565bab3a346c91b9b0eb7ef6a54e516811 Mon Sep 17 00:00:00 2001
From: Nefertumm
Date: Sat, 15 Jan 2022 20:20:44 -0300
Subject: [PATCH 88/96] Fix(build): update Eluna version
---
src/LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/LuaEngine b/src/LuaEngine
index ccf3372..9fbfec1 160000
--- a/src/LuaEngine
+++ b/src/LuaEngine
@@ -1 +1 @@
-Subproject commit ccf337262c2573f345e54b2973678f5dbf282aa2
+Subproject commit 9fbfec18df9430808417edeb926f644a317e6b3a
From 8302a0d383a8255fc0885219c4dbc39ab358a9a5 Mon Sep 17 00:00:00 2001
From: Kargatum
Date: Fri, 21 Jan 2022 22:21:50 +0700
Subject: [PATCH 89/96] fix(Misc): correct `Eluna::Uninitialize` (#84)
---
src/ElunaLuaEngine_SC.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp
index 0d5ac75..868b246 100644
--- a/src/ElunaLuaEngine_SC.cpp
+++ b/src/ElunaLuaEngine_SC.cpp
@@ -904,6 +904,10 @@ public:
void OnShutdown() override
{
sEluna->OnShutdown();
+ }
+
+ void OnAfterUnloadAllMaps() override
+ {
Eluna::Uninitialize();
}
From c35f531f812bdf75972dc197d168d337c094e080 Mon Sep 17 00:00:00 2001
From: Kargatum
Date: Mon, 24 Jan 2022 18:00:09 +0700
Subject: [PATCH 90/96] feat(Misc): update LuaEngine (#85)
---
src/LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/LuaEngine b/src/LuaEngine
index 9fbfec1..5ead47b 160000
--- a/src/LuaEngine
+++ b/src/LuaEngine
@@ -1 +1 @@
-Subproject commit 9fbfec18df9430808417edeb926f644a317e6b3a
+Subproject commit 5ead47b73310e936444ffbf005fb894a902cf67c
From 82b66879aa4671a519fa79a3ba4fc390251a77e2 Mon Sep 17 00:00:00 2001
From: Nefertumm
Date: Wed, 2 Feb 2022 13:07:54 -0300
Subject: [PATCH 91/96] feat: Update Eluna version + ReputationHook (#87)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* Fix(build): OnReputationChange from void to bool
* feat: Update Eluna version + Reputation hook
* Update src/ElunaLuaEngine_SC.cpp
Co-authored-by: Stefano Borzì
Co-authored-by: Stefano Borzì
---
src/ElunaLuaEngine_SC.cpp | 4 ++--
src/LuaEngine | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp
index 868b246..7a1d70e 100644
--- a/src/ElunaLuaEngine_SC.cpp
+++ b/src/ElunaLuaEngine_SC.cpp
@@ -657,9 +657,9 @@ public:
sEluna->OnGiveXP(player, amount, victim);
}
- void OnReputationChange(Player* player, uint32 factionID, int32& standing, bool incremental) override
+ bool OnReputationChange(Player* player, uint32 factionID, int32& standing, bool incremental) override
{
- sEluna->OnReputationChange(player, factionID, standing, incremental);
+ return sEluna->OnReputationChange(player, factionID, standing, incremental);
}
void OnDuelRequest(Player* target, Player* challenger) override
diff --git a/src/LuaEngine b/src/LuaEngine
index 5ead47b..51230f7 160000
--- a/src/LuaEngine
+++ b/src/LuaEngine
@@ -1 +1 @@
-Subproject commit 5ead47b73310e936444ffbf005fb894a902cf67c
+Subproject commit 51230f73eab720fb8e570d7791758a821cd154e1
From 84f2edc6dfeb251714bece0f0874be8dde005620 Mon Sep 17 00:00:00 2001
From: Kargatum
Date: Sat, 5 Feb 2022 07:21:31 +0700
Subject: [PATCH 92/96] feat(DB): add support new db api (#88)
---
src/LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/LuaEngine b/src/LuaEngine
index 51230f7..61d13b7 160000
--- a/src/LuaEngine
+++ b/src/LuaEngine
@@ -1 +1 @@
-Subproject commit 51230f73eab720fb8e570d7791758a821cd154e1
+Subproject commit 61d13b7ffc69bbb3564f2d2677a495a5df54ad1e
From 19e0f03b2d562ac67b07fc3cbce59e409ad1cb78 Mon Sep 17 00:00:00 2001
From: Axel Cocat
Date: Tue, 15 Feb 2022 10:38:12 +0100
Subject: [PATCH 93/96] feat: pass ChatHandler to OnCommand call
---
src/ElunaLuaEngine_SC.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp
index 7a1d70e..89907bd 100644
--- a/src/ElunaLuaEngine_SC.cpp
+++ b/src/ElunaLuaEngine_SC.cpp
@@ -332,7 +332,7 @@ public:
bool CanExecuteCommand(ChatHandler& handler, std::string_view cmdStr) override
{
- if (!sEluna->OnCommand(handler.IsConsole() ? nullptr : handler.GetSession()->GetPlayer(), std::string(cmdStr).c_str()))
+ if (!sEluna->OnCommand(handler, std::string(cmdStr).c_str()))
{
return false;
}
From e6a69a70e266dddc81546f0bccf63406dc16de04 Mon Sep 17 00:00:00 2001
From: Axel Cocat
Date: Sun, 20 Feb 2022 18:35:57 +0100
Subject: [PATCH 94/96] feat: update submodule
---
src/LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/LuaEngine b/src/LuaEngine
index 61d13b7..796dff5 160000
--- a/src/LuaEngine
+++ b/src/LuaEngine
@@ -1 +1 @@
-Subproject commit 61d13b7ffc69bbb3564f2d2677a495a5df54ad1e
+Subproject commit 796dff57b50b1bbf98adfc9ee4ccd1de65f752be
From 59a71445caafff0c0ac07f520544bb6bb201a13a Mon Sep 17 00:00:00 2001
From: 55Honey <71938210+55Honey@users.noreply.github.com>
Date: Thu, 24 Mar 2022 20:54:19 +0100
Subject: [PATCH 95/96] chore: update readme
---
README.md | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index 7d9e2f2..dbb23e4 100644
--- a/README.md
+++ b/README.md
@@ -9,9 +9,9 @@ An [Eluna](https://github.com/ElunaLuaEngine/Eluna) module for AzerothCore.
### 1) Download the sources
-You can get the sources either using git (recommended) or downloading them manually.
+You can get the sources using git.
-#### download with git (recommended)
+#### download with git
1. open a terminal inside your `azerothcore-wotlk` folder
2. go inside the **modules** folder: `cd modules`
@@ -22,21 +22,15 @@ git clone https://github.com/azerothcore/mod-eluna-lua-engine.git
4. go inside the **mod-eluna-lua-engine** folder: `cd mod-eluna-lua-engine`
5. download the Eluna sources using `git submodule update --init`
-Optional: if you need to update Eluna to the latest version, you can `cd LuaEngine` and run `git pull` from there.
+Optional: if you need to update Eluna to the latest version, you can `cd src` and `cd LuaEngine` and run `git pull` from there.
-#### download manually
-
-1. download [mod-eluna-lua-engine](https://github.com/azerothcore/mod-eluna-lua-engine/archive/master.zip)
-2. extract it move the folder **mod-eluna-lua-engine** inside the **modules** folder of your azerothcore-wotlk sources
-3. download [Eluna](https://github.com/Azerothcore/Eluna/archive/master.zip)
-4. extract it and move all the files inside the `Eluna-master` folder into the `mod-eluna-lua-engine/src/LuaEngine` folder. `LuaEngine.h` needs to be directly under `mod-eluna-lua-engine/src/LuaEngine` without any extra sub-folders.
### 2) Build
You need to run the cmake again and and rebuild the project.
-Eluna API :
-[http://elunaluaengine.github.io/](http://elunaluaengine.github.io/)
+Eluna API for AC:
+[https://www.azerothcore.org/pages/eluna/index.html](https://www.azerothcore.org/pages/eluna/index.html)
## How to update the Eluna version (for project mainteners)
From 35da9552aeedd436345faece5699bbd9e9fc9466 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Francesco=20Borz=C3=AC?=
Date: Fri, 25 Mar 2022 12:42:15 +0100
Subject: [PATCH 96/96] fix: submodule (#93)
---
src/LuaEngine | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/LuaEngine b/src/LuaEngine
index 796dff5..6fb5300 160000
--- a/src/LuaEngine
+++ b/src/LuaEngine
@@ -1 +1 @@
-Subproject commit 796dff57b50b1bbf98adfc9ee4ccd1de65f752be
+Subproject commit 6fb5300b4eee16a7a3f9c9000edcfca5e504b842