diff -Naru lua-5.1.1/README.WOW lua511wow/README.WOW
--- lua-5.1.1/README.WOW 1969-12-31 16:00:00.000000000 -0800
+++ lua511wow/README.WOW 2007-12-05 09:00:15.046077000 -0800
@@ -0,0 +1,166 @@
+World of Warcraft version by Matthew Orlando
+
+This version of Lua is configured to match (more or less) the lua environment
+of World of Warcraft.
+
+* All 5.0-5.1 compatability options have been disabled except openlib
+* The bitlib library is included
+* WoW-specific, non-API functions are implemented (see below)
+* Global aliases to Lua functions are provided (see below)
+* string.format can use argument selection from Lua 4.0. E.g:
+ string.format("%2$d, %1$d, %d", 1, 2) == "2, 1, 2"
+* Ignores the UTF-8 Byte Order Mark at the beginning of a file
+* Max stack size increased to 4096
+
+Note: the Windows binaries included in this download are statically linked for
+performance and file size. They may not function as expected when used with
+certain third-party packages. Please compile it from source. See INSTALL for
+more information.
+
+For questions or comments, please visit
+http://sf.net/projects/lua511wow
+
+Version History
+
+v1.9
+- Added PI
+- Global versions of trigonometric functions now correctly use degrees
+- strsplit will print an appropriate error message if it overflows the stack
+- It should no longer be practically possible to overflow the stack with strjoin
+
+v1.8
+- Re-enabled 5.0 openlib compatibility since WoW does not use libs anyway
+
+v1.7
+- Changed GCPAUSE to 110 per WoW 2.1
+- Eliminated a few miscellaneous compiler warnings
+
+v1.6.1
+- Added #define LUA_LIB to lwowlib & lbitlib to fix compilation problems
+
+v1.6
+- Updated bitlib to the latest version
+- Bitlib now correctly uses 32-bit integers as does WoW
+- The global aliases to bitlib functions and table.setn have been removed since
+they do not exist in WoW
+
+v1.5.1
+- Ignores UTF-8 Byte Order Mark
+
+v1.5
+- Added debugstack() (not fully implemented--see below)
+- Made some slight optimizations/code simplifications
+
+v1.4
+- Added argument selection to string.format
+
+v1.3.1
+- Fixed Makefile problem
+
+v1.3
+- Added blizzard-specific functions & global aliases (see below)
+
+v1.2
+- This package can now be used as a drop-in replacement for the standard lua
+source distribution: The MSVC project (including precompiled windows binaries)
+is now found in the msvc subdirectory; the rest of the directory structure is
+untouched.
+
+v1.1
+- Added BitLib. Optimized file size of Luac.exe. Includes test Lua programs that
+come with standard Lua distribution.
+
+1.0 - Initial Release
+
+
+
+WoW-specific functions
+
+All WoW-specific functions are implemented in the 'wow' package for simplicity's
+sake:
+
+wow.strtrim
+wow.strsplit
+wow.strjoin
+wow.strconcat
+wow.getglobal
+wow.setglobal
+wow.debugstack (currently ignores top and bottom counts)
+
+The global versions (and the few that are added to the string table) are aliased
+below.
+
+
+
+*** Aliases ***
+
+os
+
+date = os.date
+time = os.time
+difftime = os.difftime
+
+math
+
+abs = math.abs
+acos = function (x) return math.deg(math.acos(x)) end
+asin = function (x) return math.deg(math.asin(x)) end
+atan = function (x) return math.deg(math.atan(x)) end
+atan2 = function (x,y) return math.deg(math.atan2(x,y)) end
+ceil = math.ceil
+cos = function (x) return math.cos(math.rad(x)) end
+deg = math.deg
+exp = math.exp
+floor = math.floor
+frexp = math.frexp
+ldexp = math.ldexp
+log = math.log
+log10 = math.log10
+max = math.max
+min = math.min
+mod = math.fmod
+PI = math.pi
+rad = math.rad
+random = math.random
+randomseed = math.randomseed
+sin = function (x) return math.sin(math.rad(x)) end
+sqrt = math.sqrt
+tan = function (x) return math.tan(math.rad(x)) end
+
+string
+
+format = string.format
+gmatch = string.gmatch
+gsub = string.gsub
+strbyte = string.byte
+strchar = string.char
+strfind = string.find
+strlen = string.len
+strlower = string.lower
+strmatch = string.match
+strrep = string.rep
+strrev = string.reverse
+strsub = string.sub
+strupper = string.upper
+
+table
+
+foreach = table.foreach
+foreachi = table.foreachi
+getn = table.getn
+sort = table.sort
+tinsert = table.insert
+tremove = table.remove
+
+wow
+
+strtrim = wow.strtrim
+strsplit = wow.strsplit
+strjoin = wow.strjoin
+strconcat = wow.strconcat
+getglobal = wow.getglobal
+setglobal = wow.setglobal
+debugstack = wow.debugstack
+string.trim = wow.strtrim
+string.split = wow.strsplit
+string.join = wow.strjoin
diff -Naru lua-5.1.1/msvc/Lua/Lua.vcproj lua511wow/msvc/Lua/Lua.vcproj
--- lua-5.1.1/msvc/Lua/Lua.vcproj 1969-12-31 16:00:00.000000000 -0800
+++ lua511wow/msvc/Lua/Lua.vcproj 2007-02-13 09:14:42.958005000 -0800
@@ -0,0 +1,419 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -Naru lua-5.1.1/msvc/Luac/Luac.vcproj lua511wow/msvc/Luac/Luac.vcproj
--- lua-5.1.1/msvc/Luac/Luac.vcproj 1969-12-31 16:00:00.000000000 -0800
+++ lua511wow/msvc/Luac/Luac.vcproj 2007-02-13 09:14:42.958005000 -0800
@@ -0,0 +1,343 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -Naru lua-5.1.1/msvc/msvc.sln lua511wow/msvc/msvc.sln
--- lua-5.1.1/msvc/msvc.sln 1969-12-31 16:00:00.000000000 -0800
+++ lua511wow/msvc/msvc.sln 2006-12-05 20:03:25.660087000 -0800
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lua", "Lua\Lua.vcproj", "{6A9AEE1C-ADA6-43FE-B066-46DB3FC133E5}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Luac", "Luac\Luac.vcproj", "{1BFE5A7C-DD64-409B-8002-BEFF18CCA179}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6A9AEE1C-ADA6-43FE-B066-46DB3FC133E5}.Debug|Win32.ActiveCfg = Debug|Win32
+ {6A9AEE1C-ADA6-43FE-B066-46DB3FC133E5}.Debug|Win32.Build.0 = Debug|Win32
+ {6A9AEE1C-ADA6-43FE-B066-46DB3FC133E5}.Release|Win32.ActiveCfg = Release|Win32
+ {6A9AEE1C-ADA6-43FE-B066-46DB3FC133E5}.Release|Win32.Build.0 = Release|Win32
+ {1BFE5A7C-DD64-409B-8002-BEFF18CCA179}.Debug|Win32.ActiveCfg = Debug|Win32
+ {1BFE5A7C-DD64-409B-8002-BEFF18CCA179}.Debug|Win32.Build.0 = Debug|Win32
+ {1BFE5A7C-DD64-409B-8002-BEFF18CCA179}.Release|Win32.ActiveCfg = Release|Win32
+ {1BFE5A7C-DD64-409B-8002-BEFF18CCA179}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff -Naru lua-5.1.1/src/Makefile lua511wow/src/Makefile
--- lua-5.1.1/src/Makefile 2006-03-21 17:41:49.000000000 -0700
+++ lua511wow/src/Makefile 2006-12-05 20:03:25.660087000 -0800
@@ -27,7 +27,7 @@
lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
lundump.o lvm.o lzio.o
LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \
- lstrlib.o loadlib.o linit.o
+ lstrlib.o loadlib.o lbitlib.o lwowlib.o linit.o
LUA_T= lua
LUA_O= lua.o
@@ -120,6 +120,7 @@
lundump.h lvm.h
lauxlib.o: lauxlib.c lua.h luaconf.h lauxlib.h
lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h
+lbitlib.o: lbitlib.c lua.h luaconf.h lauxlib.h lualib.h
lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \
lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \
ltable.h
@@ -170,6 +171,7 @@
llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h lundump.h
lvm.o: lvm.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
+lwowlib.o: lwowlib.c lua.h luaconf.h lauxlib.h lualib.h
lzio.o: lzio.c lua.h luaconf.h llimits.h lmem.h lstate.h lobject.h ltm.h \
lzio.h
print.o: print.c ldebug.h lstate.h lua.h luaconf.h lobject.h llimits.h \
diff -Naru lua-5.1.1/src/lauxlib.c lua511wow/src/lauxlib.c
--- lua-5.1.1/src/lauxlib.c 2006-03-21 12:31:09.000000000 -0700
+++ lua511wow/src/lauxlib.c 2006-12-05 20:03:25.660087000 -0800
@@ -548,6 +548,20 @@
return LUA_ERRFILE;
}
+static const int BOM_CHARS[] = {0xEF, 0xBB, 0xBF, -1};
+static void _consume_bom(FILE* file, int depth)
+{
+ int in = getc(file);
+
+ if (in != BOM_CHARS[depth])
+ ungetc(in, file);
+ else if (BOM_CHARS[++depth] >= 0)
+ _consume_bom(file, depth);
+}
+
+
+#define consume_bom(file) _consume_bom((file), 0)
+
LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
LoadF lf;
@@ -564,6 +578,7 @@
lf.f = fopen(filename, "r");
if (lf.f == NULL) return errfile(L, "open", fnameindex);
}
+ consume_bom(lf.f);
c = getc(lf.f);
if (c == '#') { /* Unix exec. file? */
lf.extraline = 1;
diff -Naru lua-5.1.1/src/lbitlib.c lua511wow/src/lbitlib.c
--- lua-5.1.1/src/lbitlib.c 1969-12-31 16:00:00.000000000 -0800
+++ lua511wow/src/lbitlib.c 2006-12-28 06:53:50.179672000 -0800
@@ -0,0 +1,76 @@
+/* Bitwise operations library */
+/* Reuben Thomas nov00-08dec06 */
+
+#define LUA_LIB
+
+#include "lauxlib.h"
+#include "lualib.h"
+#include "lua.h"
+
+#include
+
+#define BIT_WIDTH 32 /* Guarantee specific bit width */
+#define MAX_BIT (1 << BIT_WIDTH) - 1
+#if USHRT_MAX == MAX_BIT
+# define BIT_TYPE short
+#elif UINT_MAX == MAX_BIT
+# define BIT_TYPE int
+#elif ULONG_MAX == MAX_BIT
+# define BIT_TYPE long
+#elif ULLONG_MAX == MAX_BIT
+# define BIT_TYPE long long
+#else
+# error "No integer type found with correct bit width"
+#endif
+
+typedef BIT_TYPE Integer;
+typedef unsigned BIT_TYPE UInteger;
+
+#define TDYADIC(name, op, type1, type2) \
+ static int bit_ ## name(lua_State* L) { \
+ lua_pushnumber(L, \
+ (type1)(long long)luaL_checknumber(L, 1) op (type2)(long long)luaL_checknumber(L, 2)); \
+ return 1; \
+ }
+
+#define MONADIC(name, op, type) \
+ static int bit_ ## name(lua_State* L) { \
+ lua_pushnumber(L, op (type)(long long)luaL_checknumber(L, 1)); \
+ return 1; \
+ }
+
+#define VARIADIC(name, op, type) \
+ static int bit_ ## name(lua_State *L) { \
+ int n = lua_gettop(L), i; \
+ Integer w = (type)(long long)luaL_checknumber(L, 1); \
+ for (i = 2; i <= n; i++) \
+ w op (type)(long long)luaL_checknumber(L, i); \
+ lua_pushnumber(L, w); \
+ return 1; \
+ }
+
+MONADIC(bnot, ~, Integer)
+VARIADIC(band, &=, Integer)
+VARIADIC(bor, |=, Integer)
+VARIADIC(bxor, ^=, Integer)
+TDYADIC(lshift, <<, Integer, UInteger)
+TDYADIC(rshift, >>, UInteger, UInteger)
+TDYADIC(arshift, >>, Integer, UInteger)
+TDYADIC(mod, %, Integer, Integer)
+
+static const struct luaL_reg bitlib[] = {
+ {"bnot", bit_bnot},
+ {"band", bit_band},
+ {"bor", bit_bor},
+ {"bxor", bit_bxor},
+ {"lshift", bit_lshift},
+ {"rshift", bit_rshift},
+ {"arshift", bit_arshift},
+ {"mod", bit_mod},
+ {NULL, NULL}
+};
+
+LUALIB_API int luaopen_bit (lua_State *L) {
+ luaL_register(L, LUA_BITLIBNAME, bitlib);
+ return 1;
+}
diff -Naru lua-5.1.1/src/linit.c lua511wow/src/linit.c
--- lua-5.1.1/src/linit.c 2005-12-29 07:32:11.000000000 -0800
+++ lua511wow/src/linit.c 2006-12-05 20:03:25.660087000 -0800
@@ -23,6 +23,8 @@
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
+ {LUA_BITLIBNAME, luaopen_bit},
+ {LUA_WOWLIBNAME, luaopen_wow},
{NULL, NULL}
};
diff -Naru lua-5.1.1/src/lstrlib.c lua511wow/src/lstrlib.c
--- lua-5.1.1/src/lstrlib.c 2006-04-26 13:41:19.000000000 -0700
+++ lua511wow/src/lstrlib.c 2006-12-05 20:03:25.660087000 -0800
@@ -179,6 +179,7 @@
#define L_ESC '%'
+#define L_POS '$'
#define SPECIALS "^$*+?.([%-"
@@ -767,8 +768,14 @@
else { /* format item */
char form[MAX_FORMAT]; /* to store the format (`%...') */
char buff[MAX_ITEM]; /* to store the formatted item */
+ /* Added back the lua 4.0 feature to choose which argument to format */
+ const char *initf = strfrmt;
+ if (isdigit((unsigned char)*initf) && *(initf+1) == L_POS) {
+ arg = *initf - '0';
+ initf += 2;
+ }
arg++;
- strfrmt = scanformat(L, strfrmt, form);
+ strfrmt = scanformat(L, initf, form);
switch (*strfrmt++) {
case 'c': {
sprintf(buff, form, (int)luaL_checknumber(L, arg));
diff -Naru lua-5.1.1/src/luaconf.h lua511wow/src/luaconf.h
--- lua-5.1.1/src/luaconf.h 2006-04-10 11:27:23.000000000 -0700
+++ lua511wow/src/luaconf.h 2007-12-05 09:00:15.046077000 -0800
@@ -299,7 +299,7 @@
** mean larger pauses which mean slower collection.) You can also change
** this value dynamically.
*/
-#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */
+#define LUAI_GCPAUSE 110 /* 110% per WoW 2.1 */
/*
@@ -333,14 +333,14 @@
** CHANGE it to undefined as soon as your programs use only '...' to
** access vararg parameters (instead of the old 'arg' table).
*/
-#define LUA_COMPAT_VARARG
+#undef LUA_COMPAT_VARARG
/*
@@ LUA_COMPAT_MOD controls compatibility with old math.mod function.
** CHANGE it to undefined as soon as your programs use 'math.fmod' or
** the new '%' operator instead of 'math.mod'.
*/
-#define LUA_COMPAT_MOD
+#undef LUA_COMPAT_MOD
/*
@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
@@ -348,14 +348,14 @@
** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
** off the advisory error when nesting [[...]].
*/
-#define LUA_COMPAT_LSTR 1
+#undef LUA_COMPAT_LSTR
/*
@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
** CHANGE it to undefined as soon as you rename 'string.gfind' to
** 'string.gmatch'.
*/
-#define LUA_COMPAT_GFIND
+#undef LUA_COMPAT_GFIND
/*
@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
@@ -363,7 +363,7 @@
** CHANGE it to undefined as soon as you replace to 'luaL_registry'
** your uses of 'luaL_openlib'
*/
-#define LUA_COMPAT_OPENLIB
+#define LUA_COMPAT_OPENLIB /* Leaving this one enabled since WoW doesn't have lib capabilities anyway */
@@ -442,7 +442,7 @@
** functions. This limit is arbitrary; its only purpose is to stop C
** functions to consume unlimited stack space.
*/
-#define LUAI_MAXCSTACK 2048
+#define LUAI_MAXCSTACK 4096
diff -Naru lua-5.1.1/src/lualib.h lua511wow/src/lualib.h
--- lua-5.1.1/src/lualib.h 2005-12-27 09:12:00.000000000 -0800
+++ lua511wow/src/lualib.h 2006-12-05 20:03:25.660087000 -0800
@@ -39,6 +39,11 @@
#define LUA_LOADLIBNAME "package"
LUALIB_API int (luaopen_package) (lua_State *L);
+#define LUA_BITLIBNAME "bit"
+LUALIB_API int (luaopen_bit) (lua_State *L);
+
+#define LUA_WOWLIBNAME "wow"
+LUALIB_API int (luaopen_wow) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
diff -Naru lua-5.1.1/src/lwowlib.c lua511wow/src/lwowlib.c
--- lua-5.1.1/src/lwowlib.c 1969-12-31 16:00:00.000000000 -0800
+++ lua511wow/src/lwowlib.c 2008-01-07 07:00:33.727818000 -0800
@@ -0,0 +1,249 @@
+/*
+** This file implements lua API aliases (and a few specialized functions)
+** specific to WoW.
+*/
+
+#define LUA_LIB
+
+#include
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+static int wow_strtrim(lua_State *L)
+{
+ int front = 0, back;
+ const char *str = luaL_checklstring(L, 1, (size_t *)(&back));
+ const char *del = luaL_optstring(L, 2, "\t\n\r ");
+ --back;
+
+ while (front <= back && strchr(del, str[front]))
+ ++front;
+ while (back > front && strchr(del, str[back]))
+ --back;
+
+ lua_pushlstring(L, &str[front], back - front + 1);
+ return 1;
+}
+
+/* strsplit & strjoin adapted from code by Norganna */
+static int wow_strsplit(lua_State *L)
+{
+ const char *sep = luaL_checkstring(L, 1);
+ const char *str = luaL_checkstring(L, 2);
+ int limit = luaL_optint(L, 3, 0);
+ int count = 0;
+ /* Set the stack to a predictable size */
+ lua_settop(L, 0);
+ /* Initialize the result count */
+ /* Tokenize the string */
+ if(!limit || limit > 1) {
+ const char *end = str;
+ while(*end) {
+ int issep = 0;
+ const char *s = sep;
+ for(; *s; ++s) {
+ if(*s == *end) {
+ issep = 1;
+ break;
+ }
+ }
+ if(issep) {
+ luaL_checkstack(L, count+1, "too many results");
+ lua_pushlstring(L, str, (end-str));
+ ++count;
+ str = end+1;
+ if(count == (limit-1)) {
+ break;
+ }
+ }
+ ++end;
+ }
+ }
+ /* Add the remainder */
+ luaL_checkstack(L, count+1, "too many results");
+ lua_pushstring(L, str);
+ ++count;
+ /* Return with the number of values found */
+ return count;
+}
+
+static int wow_strjoin(lua_State *L)
+{
+ size_t seplen;
+ int entries;
+ const char *sep = luaL_checklstring(L, 1, &seplen);
+
+ /* Guarantee we have 1 stack slot free */
+ lua_remove(L, 1);
+
+ entries = lua_gettop(L);
+
+ if (seplen == 0) /* If there's no seperator, then this is the same as a concat */
+ lua_concat(L, entries);
+ else if (entries == 0) /* If there are no entries then we can't concatenate anything */
+ lua_pushstring(L, "");
+ else if (entries == 1) /* If there's only one entry, just return it */
+ ;
+ else {
+ luaL_Buffer b;
+ int i;
+
+ /* Set up buffer to store resulting string */
+ luaL_buffinit(L, &b);
+ for(i = 1; i <= entries; ++i) {
+ /* Push the current entry and add it to the buffer */
+ lua_pushvalue(L, i);
+ luaL_addvalue(&b);
+ /* Add the separator to the buffer */
+ if (i < entries) {
+ luaL_addlstring(&b, sep, seplen);
+ }
+ }
+ luaL_pushresult(&b);
+ }
+
+ return 1;
+}
+
+static int wow_strconcat(lua_State *L)
+{
+ lua_concat(L, lua_gettop(L));
+ return 1;
+}
+
+static int wow_getglobal(lua_State *L)
+{
+ lua_getglobal(L, luaL_checkstring(L, 1));
+ return 1;
+}
+
+static int wow_setglobal(lua_State *L)
+{
+ lua_settop(L, 2);
+ lua_setglobal(L, luaL_checkstring(L, 1));
+ return 0;
+}
+
+static int wow_debugstack(lua_State *L)
+{
+ int start = luaL_optint(L, 1, 1);
+ /*int ntop = luaL_optint(L, 2, 12); Ignored for now... May implement more accurate version in the future
+ int nbot = luaL_optint(L, 3, 10);*/
+ const char *trace;
+ size_t tracelen;
+
+ lua_getglobal(L, "debug");
+ lua_pushstring(L, "traceback");
+ lua_gettable(L, -2);
+ lua_pushstring(L, "");
+ lua_pushnumber(L, start);
+
+ if (lua_pcall(L, 2, 1, 0) != 0)
+ luaL_error(L, "error running `debug.traceback': %s", lua_tostring(L, -1));
+
+ if (!lua_isstring(L, -1))
+ luaL_error(L, "function `debug.traceback' did not return a string");
+
+ trace = lua_tolstring(L, -1, &tracelen);
+
+ /* TODO: Implement head/tail code here
+
+ lua_checkstack(L, 1);
+ lua_pushstring(L, ret); */
+
+ return 1;
+}
+
+static const struct luaL_reg wowlib[] = {
+ {"strtrim", wow_strtrim},
+ {"strsplit", wow_strsplit},
+ {"strjoin", wow_strjoin},
+ {"strconcat", wow_strconcat},
+ {"getglobal", wow_getglobal},
+ {"setglobal", wow_setglobal},
+ {"debugstack", wow_debugstack},
+ {NULL, NULL}
+};
+
+/* This is a lua chunk that sets up the global aliases to library functions */
+static const char *aliases =
+ "---------------- os ----------------\n"
+ "date = os.date\n"
+ "time = os.time\n"
+ "difftime = os.difftime\n"
+
+ "---------------- math ----------------\n"
+ "abs = math.abs\n"
+ "acos = function (x) return math.deg(math.acos(x)) end\n"
+ "asin = function (x) return math.deg(math.asin(x)) end\n"
+ "atan = function (x) return math.deg(math.atan(x)) end\n"
+ "atan2 = function (x,y) return math.deg(math.atan2(x,y)) end\n"
+ "ceil = math.ceil\n"
+ "cos = function (x) return math.cos(math.rad(x)) end\n"
+ "deg = math.deg\n"
+ "exp = math.exp\n"
+ "floor = math.floor\n"
+ "frexp = math.frexp\n"
+ "ldexp = math.ldexp\n"
+ "log = math.log\n"
+ "log10 = math.log10\n"
+ "max = math.max\n"
+ "min = math.min\n"
+ "mod = math.fmod\n"
+ "PI = math.pi\n"
+ "rad = math.rad\n"
+ "random = math.random\n"
+ "randomseed = math.randomseed\n"
+ "sin = function (x) return math.sin(math.rad(x)) end\n"
+ "sqrt = math.sqrt\n"
+ "tan = function (x) return math.tan(math.rad(x)) end\n"
+
+ "---------------- string ----------------\n"
+ "format = string.format\n"
+ "gmatch = string.gmatch\n"
+ "gsub = string.gsub\n"
+ "strbyte = string.byte\n"
+ "strchar = string.char\n"
+ "strfind = string.find\n"
+ "strlen = string.len\n"
+ "strlower = string.lower\n"
+ "strmatch = string.match\n"
+ "strrep = string.rep\n"
+ "strrev = string.reverse\n"
+ "strsub = string.sub\n"
+ "strupper = string.upper\n"
+
+ "---------------- table ----------------\n"
+ "foreach = table.foreach\n"
+ "foreachi = table.foreachi\n"
+ "getn = table.getn\n"
+ "sort = table.sort\n"
+ "tinsert = table.insert\n"
+ "tremove = table.remove\n"
+
+ "---------------- wow ----------------\n"
+ "strtrim = wow.strtrim\n"
+ "strsplit = wow.strsplit\n"
+ "strjoin = wow.strjoin\n"
+ "strconcat = wow.strconcat\n"
+ "getglobal = wow.getglobal\n"
+ "setglobal = wow.setglobal\n"
+ "debugstack = wow.debugstack\n"
+ "string.trim = wow.strtrim\n"
+ "string.split = wow.strsplit\n"
+ "string.join = wow.strjoin\n";
+
+
+LUALIB_API int luaopen_wow(lua_State *L)
+{
+ /* Set up new functions */
+ luaL_register(L, LUA_WOWLIBNAME, wowlib);
+
+ /* Set up aliases */
+ luaL_loadstring(L, aliases);
+ lua_call(L, 0, 0);
+
+ return 0;
+}