[
  {
    "path": ".gitattributes",
    "content": "# Auto detect text files and perform LF normalization\n* text=auto\n\n# Custom for Visual Studio\n*.cs     diff=csharp\n*.sln    merge=union\n*.csproj merge=union\n*.vbproj merge=union\n*.fsproj merge=union\n*.dbproj merge=union\n\n# Standard to msysgit\n*.doc\t diff=astextplain\n*.DOC\t diff=astextplain\n*.docx diff=astextplain\n*.DOCX diff=astextplain\n*.dot  diff=astextplain\n*.DOT  diff=astextplain\n*.pdf  diff=astextplain\n*.PDF\t diff=astextplain\n*.rtf\t diff=astextplain\n*.RTF\t diff=astextplain\n"
  },
  {
    "path": ".gitignore",
    "content": "#################\n## Eclipse\n#################\n\n*.pydevproject\n.project\n.metadata\nbin/\ntmp/\n*.tmp\n*.bak\n*.swp\n*~.nib\nlocal.properties\n.classpath\n.settings/\n.loadpath\n\n# External tool builders\n.externalToolBuilders/\n\n# Locally stored \"Eclipse launch configurations\"\n*.launch\n\n# CDT-specific\n.cproject\n\n# PDT-specific\n.buildpath\n\n\n#################\n## Visual Studio\n#################\n\n## Ignore Visual Studio temporary files, build results, and\n## files generated by popular Visual Studio add-ons.\n\n# User-specific files\n*.suo\n*.user\n*.sln.docstates\n\n# Build results\n[Dd]ebug/\n[Rr]elease/\n*_i.c\n*_p.c\n*.ilk\n*.meta\n*.obj\n*.pch\n*.pdb\n*.pgc\n*.pgd\n*.rsp\n*.sbr\n*.tlb\n*.tli\n*.tlh\n*.tmp\n*.vspscc\n.builds\n*.dotCover\n\n## TODO: If you have NuGet Package Restore enabled, uncomment this\n#packages/\n\n# Visual C++ cache files\nipch/\n*.aps\n*.ncb\n*.opensdf\n*.sdf\n\n# Visual Studio profiler\n*.psess\n*.vsp\n\n# ReSharper is a .NET coding add-in\n_ReSharper*\n\n# Installshield output folder\n[Ee]xpress\n\n# DocProject is a documentation generator add-in\nDocProject/buildhelp/\nDocProject/Help/*.HxT\nDocProject/Help/*.HxC\nDocProject/Help/*.hhc\nDocProject/Help/*.hhk\nDocProject/Help/*.hhp\nDocProject/Help/Html2\nDocProject/Help/html\n\n# Click-Once directory\npublish\n\n# Others\n[Bb]in\n[Oo]bj\nsql\nTestResults\n*.Cache\nClientBin\nstylecop.*\n~$*\n*.dbmdl\nGenerated_Code #added for RIA/Silverlight projects\n\n# Backup & report files from converting an old project file to a newer\n# Visual Studio version. Backup files are not needed, because we have git ;-)\n_UpgradeReport_Files/\nBackup*/\nUpgradeLog*.XML\n\n\n\n############\n## Windows\n############\n\n# Windows image file caches\nThumbs.db\n\n# Folder config file\nDesktop.ini\n\n\n#############\n## Python\n#############\n\n*.py[co]\n\n# Packages\n*.egg\n*.egg-info\ndist\nbuild\neggs\nparts\nbin\nvar\nsdist\ndevelop-eggs\n.installed.cfg\n\n# Installer logs\npip-log.txt\n\n# Unit test / coverage reports\n.coverage\n.tox\n\n#Translations\n*.mo\n\n#Mr Developer\n.mr.developer.cfg\n\n# Mac crap\n.DS_Store\n"
  },
  {
    "path": "lauxlib.h",
    "content": "/*\n** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $\n** Auxiliary functions for building Lua libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lauxlib_h\n#define lauxlib_h\n\n\n#include <stddef.h>\n#include <stdio.h>\n\n#include \"lua.h\"\n\n\n#if defined(LUA_COMPAT_GETN)\nLUALIB_API int (luaL_getn) (lua_State *L, int t);\nLUALIB_API void (luaL_setn) (lua_State *L, int t, int n);\n#else\n#define luaL_getn(L,i)          ((int)lua_objlen(L, i))\n#define luaL_setn(L,i,j)        ((void)0)  /* no op! */\n#endif\n\n#if defined(LUA_COMPAT_OPENLIB)\n#define luaI_openlib\tluaL_openlib\n#endif\n\n\n/* extra error code for `luaL_load' */\n#define LUA_ERRFILE     (LUA_ERRERR+1)\n\n\ntypedef struct luaL_Reg {\n  const char *name;\n  lua_CFunction func;\n} luaL_Reg;\n\n\n\nLUALIB_API void (luaI_openlib) (lua_State *L, const char *libname,\n                                const luaL_Reg *l, int nup);\nLUALIB_API void (luaL_register) (lua_State *L, const char *libname,\n                                const luaL_Reg *l);\nLUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\nLUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);\nLUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);\nLUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,\n                                                          size_t *l);\nLUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,\n                                          const char *def, size_t *l);\nLUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);\nLUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);\n\nLUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);\nLUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,\n                                          lua_Integer def);\n\nLUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\nLUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);\nLUALIB_API void (luaL_checkany) (lua_State *L, int narg);\n\nLUALIB_API int   (luaL_newmetatable) (lua_State *L, const char *tname);\nLUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\n\nLUALIB_API void (luaL_where) (lua_State *L, int lvl);\nLUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\n\nLUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,\n                                   const char *const lst[]);\n\nLUALIB_API int (luaL_ref) (lua_State *L, int t);\nLUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\n\nLUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);\nLUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,\n                                  const char *name);\nLUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\n\nLUALIB_API lua_State *(luaL_newstate) (void);\n\n\nLUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\n                                                  const char *r);\n\nLUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,\n                                         const char *fname, int szhint);\n\n\n\n\n/*\n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define luaL_argcheck(L, cond,numarg,extramsg)\t\\\n\t\t((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))\n#define luaL_checkstring(L,n)\t(luaL_checklstring(L, (n), NULL))\n#define luaL_optstring(L,n,d)\t(luaL_optlstring(L, (n), (d), NULL))\n#define luaL_checkint(L,n)\t((int)luaL_checkinteger(L, (n)))\n#define luaL_optint(L,n,d)\t((int)luaL_optinteger(L, (n), (d)))\n#define luaL_checklong(L,n)\t((long)luaL_checkinteger(L, (n)))\n#define luaL_optlong(L,n,d)\t((long)luaL_optinteger(L, (n), (d)))\n\n#define luaL_typename(L,i)\tlua_typename(L, lua_type(L,(i)))\n\n#define luaL_dofile(L, fn) \\\n\t(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_dostring(L, s) \\\n\t(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\n\n#define luaL_getmetatable(L,n)\t(lua_getfield(L, LUA_REGISTRYINDEX, (n)))\n\n#define luaL_opt(L,f,n,d)\t(lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\n\n/*\n** {======================================================\n** Generic Buffer manipulation\n** =======================================================\n*/\n\n\n\ntypedef struct luaL_Buffer {\n  char *p;\t\t\t/* current position in buffer */\n  int lvl;  /* number of strings in the stack (level) */\n  lua_State *L;\n  char buffer[LUAL_BUFFERSIZE];\n} luaL_Buffer;\n\n#define luaL_addchar(B,c) \\\n  ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \\\n   (*(B)->p++ = (char)(c)))\n\n/* compatibility only */\n#define luaL_putchar(B,c)\tluaL_addchar(B,c)\n\n#define luaL_addsize(B,n)\t((B)->p += (n))\n\nLUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\nLUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);\nLUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\nLUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\nLUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\nLUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\n\n\n/* }====================================================== */\n\n\n/* compatibility with ref system */\n\n/* pre-defined references */\n#define LUA_NOREF       (-2)\n#define LUA_REFNIL      (-1)\n\n#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \\\n      (lua_pushstring(L, \"unlocked references are obsolete\"), lua_error(L), 0))\n\n#define lua_unref(L,ref)        luaL_unref(L, LUA_REGISTRYINDEX, (ref))\n\n#define lua_getref(L,ref)       lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))\n\n\n#define luaL_reg\tluaL_Reg\n\n#endif\n\n\n"
  },
  {
    "path": "lua.h",
    "content": "/*\n** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $\n** Lua - An Extensible Extension Language\n** Lua.org, PUC-Rio, Brazil (http://www.lua.org)\n** See Copyright Notice at the end of this file\n*/\n\n\n#ifndef lua_h\n#define lua_h\n\n#include <stdarg.h>\n#include <stddef.h>\n\n\n#include \"luaconf.h\"\n\n\n#define LUA_VERSION\t\"Lua 5.1\"\n#define LUA_RELEASE\t\"Lua 5.1.4\"\n#define LUA_VERSION_NUM\t501\n#define LUA_COPYRIGHT\t\"Copyright (C) 1994-2008 Lua.org, PUC-Rio\"\n#define LUA_AUTHORS \t\"R. Ierusalimschy, L. H. de Figueiredo & W. Celes\"\n\n\n/* mark for precompiled code (`<esc>Lua') */\n#define\tLUA_SIGNATURE\t\"\\033Lua\"\n\n/* option for multiple returns in `lua_pcall' and `lua_call' */\n#define LUA_MULTRET\t(-1)\n\n\n/*\n** pseudo-indices\n*/\n#define LUA_REGISTRYINDEX\t(-10000)\n#define LUA_ENVIRONINDEX\t(-10001)\n#define LUA_GLOBALSINDEX\t(-10002)\n#define lua_upvalueindex(i)\t(LUA_GLOBALSINDEX-(i))\n\n\n/* thread status; 0 is OK */\n#define LUA_YIELD\t1\n#define LUA_ERRRUN\t2\n#define LUA_ERRSYNTAX\t3\n#define LUA_ERRMEM\t4\n#define LUA_ERRERR\t5\n\n\ntypedef struct lua_State lua_State;\n\ntypedef int (*lua_CFunction) (lua_State *L);\n\n\n/*\n** functions that read/write blocks when loading/dumping Lua chunks\n*/\ntypedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);\n\ntypedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);\n\n\n/*\n** prototype for memory-allocation functions\n*/\ntypedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);\n\n\n/*\n** basic types\n*/\n#define LUA_TNONE\t\t(-1)\n\n#define LUA_TNIL\t\t0\n#define LUA_TBOOLEAN\t\t1\n#define LUA_TLIGHTUSERDATA\t2\n#define LUA_TNUMBER\t\t3\n#define LUA_TSTRING\t\t4\n#define LUA_TTABLE\t\t5\n#define LUA_TFUNCTION\t\t6\n#define LUA_TUSERDATA\t\t7\n#define LUA_TTHREAD\t\t8\n\n\n\n/* minimum Lua stack available to a C function */\n#define LUA_MINSTACK\t20\n\n\n/*\n** generic extra include file\n*/\n#if defined(LUA_USER_H)\n#include LUA_USER_H\n#endif\n\n\n/* type of numbers in Lua */\ntypedef LUA_NUMBER lua_Number;\n\n\n/* type for integer functions */\ntypedef LUA_INTEGER lua_Integer;\n\n\n\n/*\n** state manipulation\n*/\nLUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);\nLUA_API void       (lua_close) (lua_State *L);\nLUA_API lua_State *(lua_newthread) (lua_State *L);\n\nLUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);\n\n\n/*\n** basic stack manipulation\n*/\nLUA_API int   (lua_gettop) (lua_State *L);\nLUA_API void  (lua_settop) (lua_State *L, int idx);\nLUA_API void  (lua_pushvalue) (lua_State *L, int idx);\nLUA_API void  (lua_remove) (lua_State *L, int idx);\nLUA_API void  (lua_insert) (lua_State *L, int idx);\nLUA_API void  (lua_replace) (lua_State *L, int idx);\nLUA_API int   (lua_checkstack) (lua_State *L, int sz);\n\nLUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);\n\n\n/*\n** access functions (stack -> C)\n*/\n\nLUA_API int             (lua_isnumber) (lua_State *L, int idx);\nLUA_API int             (lua_isstring) (lua_State *L, int idx);\nLUA_API int             (lua_iscfunction) (lua_State *L, int idx);\nLUA_API int             (lua_isuserdata) (lua_State *L, int idx);\nLUA_API int             (lua_type) (lua_State *L, int idx);\nLUA_API const char     *(lua_typename) (lua_State *L, int tp);\n\nLUA_API int            (lua_equal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_rawequal) (lua_State *L, int idx1, int idx2);\nLUA_API int            (lua_lessthan) (lua_State *L, int idx1, int idx2);\n\nLUA_API lua_Number      (lua_tonumber) (lua_State *L, int idx);\nLUA_API lua_Integer     (lua_tointeger) (lua_State *L, int idx);\nLUA_API int             (lua_toboolean) (lua_State *L, int idx);\nLUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);\nLUA_API size_t          (lua_objlen) (lua_State *L, int idx);\nLUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);\nLUA_API void\t       *(lua_touserdata) (lua_State *L, int idx);\nLUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);\nLUA_API const void     *(lua_topointer) (lua_State *L, int idx);\n\n\n/*\n** push functions (C -> stack)\n*/\nLUA_API void  (lua_pushnil) (lua_State *L);\nLUA_API void  (lua_pushnumber) (lua_State *L, lua_Number n);\nLUA_API void  (lua_pushinteger) (lua_State *L, lua_Integer n);\nLUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);\nLUA_API void  (lua_pushstring) (lua_State *L, const char *s);\nLUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,\n                                                      va_list argp);\nLUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);\nLUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);\nLUA_API void  (lua_pushboolean) (lua_State *L, int b);\nLUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);\nLUA_API int   (lua_pushthread) (lua_State *L);\n\n\n/*\n** get functions (Lua -> stack)\n*/\nLUA_API void  (lua_gettable) (lua_State *L, int idx);\nLUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawget) (lua_State *L, int idx);\nLUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);\nLUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);\nLUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);\nLUA_API int   (lua_getmetatable) (lua_State *L, int objindex);\nLUA_API void  (lua_getfenv) (lua_State *L, int idx);\n\n\n/*\n** set functions (stack -> Lua)\n*/\nLUA_API void  (lua_settable) (lua_State *L, int idx);\nLUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);\nLUA_API void  (lua_rawset) (lua_State *L, int idx);\nLUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);\nLUA_API int   (lua_setmetatable) (lua_State *L, int objindex);\nLUA_API int   (lua_setfenv) (lua_State *L, int idx);\n\n\n/*\n** `load' and `call' functions (load and run Lua code)\n*/\nLUA_API void  (lua_call) (lua_State *L, int nargs, int nresults);\nLUA_API int   (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);\nLUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);\nLUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,\n                                        const char *chunkname);\n\nLUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);\n\n\n/*\n** coroutine functions\n*/\nLUA_API int  (lua_yield) (lua_State *L, int nresults);\nLUA_API int  (lua_resume) (lua_State *L, int narg);\nLUA_API int  (lua_status) (lua_State *L);\n\n/*\n** garbage-collection function and options\n*/\n\n#define LUA_GCSTOP\t\t0\n#define LUA_GCRESTART\t\t1\n#define LUA_GCCOLLECT\t\t2\n#define LUA_GCCOUNT\t\t3\n#define LUA_GCCOUNTB\t\t4\n#define LUA_GCSTEP\t\t5\n#define LUA_GCSETPAUSE\t\t6\n#define LUA_GCSETSTEPMUL\t7\n\nLUA_API int (lua_gc) (lua_State *L, int what, int data);\n\n\n/*\n** miscellaneous functions\n*/\n\nLUA_API int   (lua_error) (lua_State *L);\n\nLUA_API int   (lua_next) (lua_State *L, int idx);\n\nLUA_API void  (lua_concat) (lua_State *L, int n);\n\nLUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);\nLUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);\n\n\n\n/* \n** ===============================================================\n** some useful macros\n** ===============================================================\n*/\n\n#define lua_pop(L,n)\t\tlua_settop(L, -(n)-1)\n\n#define lua_newtable(L)\t\tlua_createtable(L, 0, 0)\n\n#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))\n\n#define lua_pushcfunction(L,f)\tlua_pushcclosure(L, (f), 0)\n\n#define lua_strlen(L,i)\t\tlua_objlen(L, (i))\n\n#define lua_isfunction(L,n)\t(lua_type(L, (n)) == LUA_TFUNCTION)\n#define lua_istable(L,n)\t(lua_type(L, (n)) == LUA_TTABLE)\n#define lua_islightuserdata(L,n)\t(lua_type(L, (n)) == LUA_TLIGHTUSERDATA)\n#define lua_isnil(L,n)\t\t(lua_type(L, (n)) == LUA_TNIL)\n#define lua_isboolean(L,n)\t(lua_type(L, (n)) == LUA_TBOOLEAN)\n#define lua_isthread(L,n)\t(lua_type(L, (n)) == LUA_TTHREAD)\n#define lua_isnone(L,n)\t\t(lua_type(L, (n)) == LUA_TNONE)\n#define lua_isnoneornil(L, n)\t(lua_type(L, (n)) <= 0)\n\n#define lua_pushliteral(L, s)\t\\\n\tlua_pushlstring(L, \"\" s, (sizeof(s)/sizeof(char))-1)\n\n#define lua_setglobal(L,s)\tlua_setfield(L, LUA_GLOBALSINDEX, (s))\n#define lua_getglobal(L,s)\tlua_getfield(L, LUA_GLOBALSINDEX, (s))\n\n#define lua_tostring(L,i)\tlua_tolstring(L, (i), NULL)\n\n\n\n/*\n** compatibility macros and functions\n*/\n\n#define lua_open()\tluaL_newstate()\n\n#define lua_getregistry(L)\tlua_pushvalue(L, LUA_REGISTRYINDEX)\n\n#define lua_getgccount(L)\tlua_gc(L, LUA_GCCOUNT, 0)\n\n#define lua_Chunkreader\t\tlua_Reader\n#define lua_Chunkwriter\t\tlua_Writer\n\n\n/* hack */\nLUA_API void lua_setlevel\t(lua_State *from, lua_State *to);\n\n\n/*\n** {======================================================================\n** Debug API\n** =======================================================================\n*/\n\n\n/*\n** Event codes\n*/\n#define LUA_HOOKCALL\t0\n#define LUA_HOOKRET\t1\n#define LUA_HOOKLINE\t2\n#define LUA_HOOKCOUNT\t3\n#define LUA_HOOKTAILRET 4\n\n\n/*\n** Event masks\n*/\n#define LUA_MASKCALL\t(1 << LUA_HOOKCALL)\n#define LUA_MASKRET\t(1 << LUA_HOOKRET)\n#define LUA_MASKLINE\t(1 << LUA_HOOKLINE)\n#define LUA_MASKCOUNT\t(1 << LUA_HOOKCOUNT)\n\ntypedef struct lua_Debug lua_Debug;  /* activation record */\n\n\n/* Functions to be called by the debuger in specific events */\ntypedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);\n\n\nLUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);\nLUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);\nLUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);\nLUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);\nLUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);\n\nLUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);\nLUA_API lua_Hook lua_gethook (lua_State *L);\nLUA_API int lua_gethookmask (lua_State *L);\nLUA_API int lua_gethookcount (lua_State *L);\n\n\nstruct lua_Debug {\n  int event;\n  const char *name;\t/* (n) */\n  const char *namewhat;\t/* (n) `global', `local', `field', `method' */\n  const char *what;\t/* (S) `Lua', `C', `main', `tail' */\n  const char *source;\t/* (S) */\n  int currentline;\t/* (l) */\n  int nups;\t\t/* (u) number of upvalues */\n  int linedefined;\t/* (S) */\n  int lastlinedefined;\t/* (S) */\n  char short_src[LUA_IDSIZE]; /* (S) */\n  /* private part */\n  int i_ci;  /* active function */\n};\n\n/* }====================================================================== */\n\n\n/******************************************************************************\n* Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.\n*\n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the\n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject to\n* the following conditions:\n*\n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n******************************************************************************/\n\n\n#endif\n"
  },
  {
    "path": "lua_tinker.cpp",
    "content": "// lua_tinker.cpp\n//\n// LuaTinker - Simple and light C++ wrapper for Lua.\n//\n// Copyright (c) 2005-2007 Kwon-il Lee (zupet@hitel.net)\n// \n// please check Licence.txt file for licence and legal issues. \n\n#include <iostream>\n\nextern \"C\" \n{\n\t#include \"lua.h\"\n\t#include \"lualib.h\"\n\t#include \"lauxlib.h\"\n};\n\n#include \"lua_tinker.h\"\n\n\n/*---------------------------------------------------------------------------*/ \n/* init                                                                      */ \n/*---------------------------------------------------------------------------*/ \nvoid lua_tinker::init(lua_State *L)\n{\n\tinit_s64(L);\n\tinit_u64(L);\n}\n\n/*---------------------------------------------------------------------------*/ \n/* __s64                                                                     */ \n/*---------------------------------------------------------------------------*/ \nstatic int tostring_s64(lua_State *L)\n{\n\tchar temp[64];\n\tsprintf_s(temp, \"%I64d\", *(long long*)lua_topointer(L, 1));\n\tlua_pushstring(L, temp);\n\treturn 1;\n}\n\n/*---------------------------------------------------------------------------*/ \nstatic int eq_s64(lua_State *L)\n{\n\tlua_pushboolean(L, memcmp(lua_topointer(L, 1), lua_topointer(L, 2), sizeof(long long)) == 0);\n\treturn 1;\n}\n\n/*---------------------------------------------------------------------------*/ \nstatic int lt_s64(lua_State *L)\n{\n\tlua_pushboolean(L, memcmp(lua_topointer(L, 1), lua_topointer(L, 2), sizeof(long long)) < 0);\n\treturn 1;\n}\n\n/*---------------------------------------------------------------------------*/ \nstatic int le_s64(lua_State *L)\n{\n\tlua_pushboolean(L, memcmp(lua_topointer(L, 1), lua_topointer(L, 2), sizeof(long long)) <= 0);\n\treturn 1;\n}\n\n/*---------------------------------------------------------------------------*/ \nvoid lua_tinker::init_s64(lua_State *L)\n{\n\tconst char* name = \"__s64\";\n\tlua_pushstring(L, name);\n\tlua_newtable(L);\n\n\tlua_pushstring(L, \"__name\");\n\tlua_pushstring(L, name);\n\tlua_rawset(L, -3);\n\n\tlua_pushstring(L, \"__tostring\");\n\tlua_pushcclosure(L, tostring_s64, 0);\n\tlua_rawset(L, -3);\n\n\tlua_pushstring(L, \"__eq\");\n\tlua_pushcclosure(L, eq_s64, 0);\n\tlua_rawset(L, -3);\t\n\n\tlua_pushstring(L, \"__lt\");\n\tlua_pushcclosure(L, lt_s64, 0);\n\tlua_rawset(L, -3);\t\n\n\tlua_pushstring(L, \"__le\");\n\tlua_pushcclosure(L, le_s64, 0);\n\tlua_rawset(L, -3);\t\n\n\tlua_settable(L, LUA_GLOBALSINDEX);\n}\n\n/*---------------------------------------------------------------------------*/ \n/* __u64                                                                     */ \n/*---------------------------------------------------------------------------*/ \nstatic int tostring_u64(lua_State *L)\n{\n\tchar temp[64];\n\tsprintf_s(temp, \"%I64u\", *(unsigned long long*)lua_topointer(L, 1));\n\tlua_pushstring(L, temp);\n\treturn 1;\n}\n\n/*---------------------------------------------------------------------------*/ \nstatic int eq_u64(lua_State *L)\n{\n\tlua_pushboolean(L, memcmp(lua_topointer(L, 1), lua_topointer(L, 2), sizeof(unsigned long long)) == 0);\n\treturn 1;\n}\n\n/*---------------------------------------------------------------------------*/ \nstatic int lt_u64(lua_State *L)\n{\n\tlua_pushboolean(L, memcmp(lua_topointer(L, 1), lua_topointer(L, 2), sizeof(unsigned long long)) < 0);\n\treturn 1;\n}\n\n/*---------------------------------------------------------------------------*/ \nstatic int le_u64(lua_State *L)\n{\n\tlua_pushboolean(L, memcmp(lua_topointer(L, 1), lua_topointer(L, 2), sizeof(unsigned long long)) <= 0);\n\treturn 1;\n}\n\n/*---------------------------------------------------------------------------*/ \nvoid lua_tinker::init_u64(lua_State *L)\n{\n\tconst char* name = \"__u64\";\n\tlua_pushstring(L, name);\n\tlua_newtable(L);\n\n\tlua_pushstring(L, \"__name\");\n\tlua_pushstring(L, name);\n\tlua_rawset(L, -3);\n\n\tlua_pushstring(L, \"__tostring\");\n\tlua_pushcclosure(L, tostring_u64, 0);\n\tlua_rawset(L, -3);\n\n\tlua_pushstring(L, \"__eq\");\n\tlua_pushcclosure(L, eq_u64, 0);\n\tlua_rawset(L, -3);\t\n\n\tlua_pushstring(L, \"__lt\");\n\tlua_pushcclosure(L, lt_u64, 0);\n\tlua_rawset(L, -3);\t\n\n\tlua_pushstring(L, \"__le\");\n\tlua_pushcclosure(L, le_u64, 0);\n\tlua_rawset(L, -3);\t\n\n\tlua_settable(L, LUA_GLOBALSINDEX);\n}\n\n/*---------------------------------------------------------------------------*/ \n/* excution                                                                  */ \n/*---------------------------------------------------------------------------*/ \nvoid lua_tinker::dofile(lua_State *L, const char *filename)\n{\n\tlua_pushcclosure(L, on_error, 0);\n\tint errfunc = lua_gettop(L);\n\n    if(luaL_loadfile(L, filename) == 0)\n\t{\n\t\tlua_pcall(L, 0, 1, errfunc);\n\t}\n\telse\n\t{\n\t\tprint_error(L, \"%s\", lua_tostring(L, -1));\n\t}\n\n\tlua_remove(L, errfunc);\n\tlua_pop(L, 1);\n}\n\n/*---------------------------------------------------------------------------*/ \nvoid lua_tinker::dostring(lua_State *L, const char* buff)\n{\n\tlua_tinker::dobuffer(L, buff, strlen(buff));\n}\n\n/*---------------------------------------------------------------------------*/ \nvoid lua_tinker::dobuffer(lua_State *L, const char* buff, size_t len)\n{\n\tlua_pushcclosure(L, on_error, 0);\n\tint errfunc = lua_gettop(L);\n\n    if(luaL_loadbuffer(L, buff, len, \"lua_tinker::dobuffer()\") == 0)\n\t{\n\t\tlua_pcall(L, 0, 1, errfunc);\n\t}\n\telse\n\t{\n\t\tprint_error(L, \"%s\", lua_tostring(L, -1));\n\t}\n\n\tlua_remove(L, errfunc);\n\tlua_pop(L, 1);\n}\n\n/*---------------------------------------------------------------------------*/ \n/* debug helpers                                                             */ \n/*---------------------------------------------------------------------------*/ \nstatic void call_stack(lua_State* L, int n)\n{\n    lua_Debug ar;\n    if(lua_getstack(L, n, &ar) == 1)\n\t{\n\t\tlua_getinfo(L, \"nSlu\", &ar);\n\n\t\tconst char* indent;\n\t\tif(n == 0)\n\t\t{\n\t\t\tindent = \"->\\t\";\n\t\t\tlua_tinker::print_error(L, \"\\t<call stack>\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tindent = \"\\t\";\n\t\t}\n\n\t\tif(ar.name)\n\t\t\tlua_tinker::print_error(L, \"%s%s() : line %d [%s : line %d]\", indent, ar.name, ar.currentline, ar.source, ar.linedefined);\n\t\telse\n\t\t\tlua_tinker::print_error(L, \"%sunknown : line %d [%s : line %d]\", indent, ar.currentline, ar.source, ar.linedefined);\n\n\t\tcall_stack(L, n+1);\n\t}\n}\n\n/*---------------------------------------------------------------------------*/ \nint lua_tinker::on_error(lua_State *L)\n{\n\tprint_error(L, \"%s\", lua_tostring(L, -1));\n\n\tcall_stack(L, 0);\n\n\treturn 0;\n}\n\n/*---------------------------------------------------------------------------*/ \nvoid lua_tinker::print_error(lua_State *L, const char* fmt, ...)\n{\n\tchar text[4096];\n\n\tva_list args;\n\tva_start(args, fmt);\n\tvsprintf_s(text, fmt, args);\n\tva_end(args);\n\n\tlua_pushstring(L, \"_ALERT\");\n\tlua_gettable(L, LUA_GLOBALSINDEX);\n\tif(lua_isfunction(L, -1))\n\t{\n\t\tlua_pushstring(L, text);\n\t\tlua_call(L, 1, 0);\n\t}\n\telse\n\t{\n\t\tprintf(\"%s\\n\", text);\n\t\tlua_pop(L, 1);\n\t}\n}\n\n/*---------------------------------------------------------------------------*/ \nvoid lua_tinker::enum_stack(lua_State *L)\n{\n\tint top = lua_gettop(L);\n\tprint_error(L, \"Type:%d\", top);\n\tfor(int i=1; i<=lua_gettop(L); ++i)\n\t{\n\t\tswitch(lua_type(L, i))\n\t\t{\n\t\tcase LUA_TNIL:\n\t\t\tprint_error(L, \"\\t%s\", lua_typename(L, lua_type(L, i)));\n\t\t\tbreak;\n\t\tcase LUA_TBOOLEAN:\n\t\t\tprint_error(L, \"\\t%s\t%s\", lua_typename(L, lua_type(L, i)), lua_toboolean(L, i)?\"true\":\"false\");\n\t\t\tbreak;\n\t\tcase LUA_TLIGHTUSERDATA:\n\t\t\tprint_error(L, \"\\t%s\t0x%08p\", lua_typename(L, lua_type(L, i)), lua_topointer(L, i));\n\t\t\tbreak;\n\t\tcase LUA_TNUMBER:\n\t\t\tprint_error(L, \"\\t%s\t%f\", lua_typename(L, lua_type(L, i)), lua_tonumber(L, i));\n\t\t\tbreak;\n\t\tcase LUA_TSTRING:\n\t\t\tprint_error(L, \"\\t%s\t%s\", lua_typename(L, lua_type(L, i)), lua_tostring(L, i));\n\t\t\tbreak;\n\t\tcase LUA_TTABLE:\n\t\t\tprint_error(L, \"\\t%s\t0x%08p\", lua_typename(L, lua_type(L, i)), lua_topointer(L, i));\n\t\t\tbreak;\n\t\tcase LUA_TFUNCTION:\n\t\t\tprint_error(L, \"\\t%s()\t0x%08p\", lua_typename(L, lua_type(L, i)), lua_topointer(L, i));\n\t\t\tbreak;\n\t\tcase LUA_TUSERDATA:\n\t\t\tprint_error(L, \"\\t%s\t0x%08p\", lua_typename(L, lua_type(L, i)), lua_topointer(L, i));\n\t\t\tbreak;\n\t\tcase LUA_TTHREAD:\n\t\t\tprint_error(L, \"\\t%s\", lua_typename(L, lua_type(L, i)));\n\t\t\tbreak;\n\t\t}\n\t}\n}\n \n/*---------------------------------------------------------------------------*/ \n/* read                                                                      */ \n/*---------------------------------------------------------------------------*/ \ntemplate<>\nchar* lua_tinker::read(lua_State *L, int index)\n{\n\treturn (char*)lua_tostring(L, index);\t\t\t\t\n}\n\ntemplate<>\nconst char* lua_tinker::read(lua_State *L, int index)\n{\n\treturn (const char*)lua_tostring(L, index);\t\t\n}\n\ntemplate<>\nchar lua_tinker::read(lua_State *L, int index)\n{\n\treturn (char)lua_tonumber(L, index);\t\t\t\t\n}\n\ntemplate<>\nunsigned char lua_tinker::read(lua_State *L, int index)\n{\n\treturn (unsigned char)lua_tonumber(L, index);\t\t\n}\n\ntemplate<>\nshort lua_tinker::read(lua_State *L, int index)\n{\n\treturn (short)lua_tonumber(L, index);\t\t\t\t\n}\n\ntemplate<>\nunsigned short lua_tinker::read(lua_State *L, int index)\n{\n\treturn (unsigned short)lua_tonumber(L, index);\t\n}\n\ntemplate<>\nlong lua_tinker::read(lua_State *L, int index)\n{\n\treturn (long)lua_tonumber(L, index);\t\t\t\t\n}\n\ntemplate<>\nunsigned long lua_tinker::read(lua_State *L, int index)\n{\n\treturn (unsigned long)lua_tonumber(L, index);\t\t\n}\n\ntemplate<>\nint lua_tinker::read(lua_State *L, int index)\n{\n\treturn (int)lua_tonumber(L, index);\t\t\t\t\n}\n\ntemplate<>\nunsigned int lua_tinker::read(lua_State *L, int index)\n{\n\treturn (unsigned int)lua_tonumber(L, index);\t\t\n}\n\ntemplate<>\nfloat lua_tinker::read(lua_State *L, int index)\n{\n\treturn (float)lua_tonumber(L, index);\t\t\t\t\n}\n\ntemplate<>\ndouble lua_tinker::read(lua_State *L, int index)\n{\n\treturn (double)lua_tonumber(L, index);\t\t\t\n}\n\ntemplate<>\nbool lua_tinker::read(lua_State *L, int index)\n{\n\tif(lua_isboolean(L, index))\n\t\treturn lua_toboolean(L, index) != 0;\t\t\t\t\n\telse\n\t\treturn lua_tonumber(L, index) != 0;\n}\n\ntemplate<>\nvoid lua_tinker::read(lua_State *L, int index)\n{\n\treturn;\t\t\t\t\t\t\t\t\t\t\t\n}\n\ntemplate<>\nlong long lua_tinker::read(lua_State *L, int index)\n{\n\tif(lua_isnumber(L,index))\n\t\treturn (long long)lua_tonumber(L, index);\n\telse\n\t\treturn *(long long*)lua_touserdata(L, index);\n}\ntemplate<>\nunsigned long long lua_tinker::read(lua_State *L, int index)\n{\n\tif(lua_isnumber(L,index))\n\t\treturn (unsigned long long)lua_tonumber(L, index);\n\telse\n\t\treturn *(unsigned long long*)lua_touserdata(L, index);\n}\n\ntemplate<>\nlua_tinker::table lua_tinker::read(lua_State *L, int index)\n{\n\treturn table(L, index);\n}\n\n/*---------------------------------------------------------------------------*/ \n/* push                                                                      */ \n/*---------------------------------------------------------------------------*/ \ntemplate<>\nvoid lua_tinker::push(lua_State *L, char ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, unsigned char ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, short ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, unsigned short ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, long ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, unsigned long ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, int ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, unsigned int ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, float ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, double ret)\n{\n\tlua_pushnumber(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, char* ret)\n{\n\tlua_pushstring(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, const char* ret)\n{\n\tlua_pushstring(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, bool ret)\n{\n\tlua_pushboolean(L, ret);\t\t\t\t\t\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, lua_value* ret)\n{\n\tif(ret) ret->to_lua(L); else lua_pushnil(L);\t\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, long long ret)\t\t\t\n{ \n\t*(long long*)lua_newuserdata(L, sizeof(long long)) = ret;\n\tlua_pushstring(L, \"__s64\");\n\tlua_gettable(L, LUA_GLOBALSINDEX);\n\tlua_setmetatable(L, -2);\n}\ntemplate<>\nvoid lua_tinker::push(lua_State *L, unsigned long long ret)\n{\n\t*(unsigned long long*)lua_newuserdata(L, sizeof(unsigned long long)) = ret;\n\tlua_pushstring(L, \"__u64\");\n\tlua_gettable(L, LUA_GLOBALSINDEX);\n\tlua_setmetatable(L, -2);\n}\n\ntemplate<>\nvoid lua_tinker::push(lua_State *L, lua_tinker::table ret)\n{\n\tlua_pushvalue(L, ret.m_obj->m_index);\n}\n\n/*---------------------------------------------------------------------------*/ \n/* pop                                                                       */ \n/*---------------------------------------------------------------------------*/ \ntemplate<>\nvoid lua_tinker::pop(lua_State *L)\n{\n\tlua_pop(L, 1);\n}\n\ntemplate<>\t\nlua_tinker::table lua_tinker::pop(lua_State *L)\n{\n\treturn table(L, lua_gettop(L));\n}\n\n/*---------------------------------------------------------------------------*/ \n/* Tinker Class Helper                                                       */ \n/*---------------------------------------------------------------------------*/ \nstatic void invoke_parent(lua_State *L)\n{\n\tlua_pushstring(L, \"__parent\");\n\tlua_rawget(L, -2);\n\tif(lua_istable(L,-1))\n\t{\n\t\tlua_pushvalue(L,2);\n\t\tlua_rawget(L, -2);\n\t\tif(!lua_isnil(L,-1))\n\t\t{\n\t\t\tlua_remove(L,-2);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlua_remove(L, -1);\n\t\t\tinvoke_parent(L);\n\t\t\tlua_remove(L,-2);\n\t\t}\n\t}\n}\n\n/*---------------------------------------------------------------------------*/ \nint lua_tinker::meta_get(lua_State *L)\n{\n\tlua_getmetatable(L,1);\n\tlua_pushvalue(L,2);\n\tlua_rawget(L,-2);\n\n\tif(lua_isuserdata(L,-1))\n\t{\n\t\tuser2type<var_base*>::invoke(L,-1)->get(L);\n\t\tlua_remove(L, -2);\n\t}\n\telse if(lua_isnil(L,-1))\n\t{\n\t\tlua_remove(L,-1);\n\t\tinvoke_parent(L);\n\t\tif(lua_isnil(L,-1))\n\t\t{\n\t\t\tlua_pushfstring(L, \"can't find '%s' class variable. (forgot registering class variable ?)\", lua_tostring(L, 2));\n\t\t\tlua_error(L);\n\t\t}\n\t} \n\n\tlua_remove(L,-2);\n\n\treturn 1;\n}\n\n/*---------------------------------------------------------------------------*/ \nint lua_tinker::meta_set(lua_State *L)\n{\n\tlua_getmetatable(L,1);\n\tlua_pushvalue(L,2);\n\tlua_rawget(L,-2);\n\n\tif(lua_isuserdata(L,-1))\n\t{\n\t\tuser2type<var_base*>::invoke(L,-1)->set(L);\n\t}\n\telse if(lua_isnil(L, -1))\n\t{\n\t\tlua_pushvalue(L,2);\n\t\tlua_pushvalue(L,3);\n\t\tlua_rawset(L, -4);\n\t}\n\tlua_settop(L, 3);\n\treturn 0;\n}\n\n/*---------------------------------------------------------------------------*/ \nvoid lua_tinker::push_meta(lua_State *L, const char* name)\n{\n\tlua_pushstring(L, name);\n\tlua_gettable(L, LUA_GLOBALSINDEX);\n}\n\n/*---------------------------------------------------------------------------*/ \n/* table object on stack                                                     */ \n/*---------------------------------------------------------------------------*/ \nlua_tinker::table_obj::table_obj(lua_State* L, int index)\n\t:m_L(L)\n\t,m_index(index)\n\t,m_ref(0)\n{\n\tif(lua_isnil(m_L, m_index))\n\t{\n\t\tm_pointer = NULL;\n\t\tlua_remove(m_L, m_index);\n\t}\n\telse\n\t{\n\t\tm_pointer = lua_topointer(m_L, m_index);\n\t}\n}\n\nlua_tinker::table_obj::~table_obj()\n{\n\tif(validate())\n\t{\n\t\tlua_remove(m_L, m_index);\n\t}\n}\n\nvoid lua_tinker::table_obj::inc_ref()\n{\n\t++m_ref;\n}\n\nvoid lua_tinker::table_obj::dec_ref()\n{\n\tif(--m_ref == 0)\n\t\tdelete this;\n}\n\nbool lua_tinker::table_obj::validate()\n{\n\tif(m_pointer != NULL)\n\t{\n\t\tif(m_pointer == lua_topointer(m_L, m_index))\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint top = lua_gettop(m_L);\n\n\t\t\tfor(int i=1; i<=top; ++i)\n\t\t\t{\n\t\t\t\tif(m_pointer == lua_topointer(m_L, i))\n\t\t\t\t{\n\t\t\t\t\tm_index = i;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tm_pointer = NULL;\n\t\t\treturn false;\n\t\t}\n\t}\n\telse\n\t{\n        return false;\n\t}\n}\n\n/*---------------------------------------------------------------------------*/ \n/* Table Object Holder                                                       */ \n/*---------------------------------------------------------------------------*/ \nlua_tinker::table::table(lua_State* L)\n{\n\tlua_newtable(L);\n\n\tm_obj = new table_obj(L, lua_gettop(L));\n\n\tm_obj->inc_ref();\n}\n\nlua_tinker::table::table(lua_State* L, const char* name)\n{\n\tlua_pushstring(L, name);\n\tlua_gettable(L, LUA_GLOBALSINDEX);\n\n\tif(lua_istable(L, -1) == 0)\n\t{\n\t\tlua_pop(L, 1);\n\n\t\tlua_newtable(L);\n\t\tlua_pushstring(L, name);\n\t\tlua_pushvalue(L, -2);\n\t\tlua_settable(L, LUA_GLOBALSINDEX);\n\t}\n\n\tm_obj = new table_obj(L, lua_gettop(L));\n}\n\nlua_tinker::table::table(lua_State* L, int index)\n{\n\tif(index < 0)\n\t{\n\t\tindex = lua_gettop(L) + index + 1;\n\t}\n\n\tm_obj = new table_obj(L, index);\n\n\tm_obj->inc_ref();\n}\n\nlua_tinker::table::table(const table& input)\n{\n\tm_obj = input.m_obj;\n\n\tm_obj->inc_ref();\n}\n\nlua_tinker::table::~table()\n{\n\tm_obj->dec_ref();\n}\n\n/*---------------------------------------------------------------------------*/ \n"
  },
  {
    "path": "lua_tinker.h",
    "content": "// lua_tinker.h\n//\n// LuaTinker - Simple and light C++ wrapper for Lua.\n//\n// Copyright (c) 2005-2007 Kwon-il Lee (zupet@hitel.net)\n// \n// please check Licence.txt file for licence and legal issues. \n\n#if !defined(_LUA_TINKER_H_)\n#define _LUA_TINKER_H_\n\n#include <new>\n#include <string.h>\n\nnamespace lua_tinker\n{\n\t// init LuaTinker\n\tvoid\tinit(lua_State *L);\n\n\tvoid\tinit_s64(lua_State *L);\n\tvoid\tinit_u64(lua_State *L);\n\n\t// string-buffer excution\n\tvoid\tdofile(lua_State *L, const char *filename);\n\tvoid\tdostring(lua_State *L, const char* buff);\n\tvoid\tdobuffer(lua_State *L, const char* buff, size_t sz);\n\t\n\t// debug helpers\n\tvoid\tenum_stack(lua_State *L);\n\tint\t\ton_error(lua_State *L);\n\tvoid\tprint_error(lua_State *L, const char* fmt, ...);\n\n\t// dynamic type extention\n\tstruct lua_value\n\t{\n\t\tvirtual void to_lua(lua_State *L) = 0;\n\t};\n\n\t// type trait\n\ttemplate<typename T> struct class_name;\n\tstruct table;\n\n\ttemplate<bool C, typename A, typename B> struct if_ {};\n\ttemplate<typename A, typename B>\t\tstruct if_<true, A, B> { typedef A type; };\n\ttemplate<typename A, typename B>\t\tstruct if_<false, A, B> { typedef B type; };\n\n\ttemplate<typename A>\n\tstruct is_ptr { static const bool value = false; };\n\ttemplate<typename A>\n\tstruct is_ptr<A*> { static const bool value = true; };\n\n\ttemplate<typename A>\n\tstruct is_ref { static const bool value = false; };\n\ttemplate<typename A>\n\tstruct is_ref<A&> { static const bool value = true; };\n\n\ttemplate<typename A>\n\tstruct remove_const { typedef A type; };\n\ttemplate<typename A>\n\tstruct remove_const<const A> { typedef A type; };\n\n\ttemplate<typename A>\n\tstruct base_type { typedef A type; };\n\ttemplate<typename A>\n\tstruct base_type<A*> { typedef A type; };\n\ttemplate<typename A>\n\tstruct base_type<A&> { typedef A type; };\n\n\ttemplate<typename A>\n\tstruct class_type { typedef typename remove_const<typename base_type<A>::type>::type type; };\n\t\n\ttemplate<typename A>\n\tstruct is_obj { static const bool value = true; };\n\ttemplate<> struct is_obj<char>\t\t\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<unsigned char>\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<short>\t\t\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<unsigned short>\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<long>\t\t\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<unsigned long>\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<int>\t\t\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<unsigned int>\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<float>\t\t\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<double>\t\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<char*>\t\t\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<const char*>\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<bool>\t\t\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<lua_value*>\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<long long>\t\t\t\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<unsigned long long>\t{ static const bool value = false; };\n\ttemplate<> struct is_obj<table>\t\t\t\t\t{ static const bool value = false; };\n\n\t/////////////////////////////////\n\tenum { no = 1, yes = 2 }; \n\ttypedef char (& no_type )[no]; \n\ttypedef char (& yes_type)[yes]; \n\n\tstruct int_conv_type { int_conv_type(int); }; \n\n\tno_type int_conv_tester (...); \n\tyes_type int_conv_tester (int_conv_type); \n\n\tno_type vfnd_ptr_tester (const volatile char *); \n\tno_type vfnd_ptr_tester (const volatile short *); \n\tno_type vfnd_ptr_tester (const volatile int *); \n\tno_type vfnd_ptr_tester (const volatile long *); \n\tno_type vfnd_ptr_tester (const volatile double *); \n\tno_type vfnd_ptr_tester (const volatile float *); \n\tno_type vfnd_ptr_tester (const volatile bool *); \n\tyes_type vfnd_ptr_tester (const volatile void *); \n\n\ttemplate <typename T> T* add_ptr(T&); \n\n\ttemplate <bool C> struct bool_to_yesno { typedef no_type type; }; \n\ttemplate <> struct bool_to_yesno<true> { typedef yes_type type; }; \n\n\ttemplate <typename T> \n\tstruct is_enum \n\t{ \n\t\tstatic T arg; \n\t\tstatic const bool value = ( (sizeof(int_conv_tester(arg)) == sizeof(yes_type)) && (sizeof(vfnd_ptr_tester(add_ptr(arg))) == sizeof(yes_type)) ); \n\t}; \n\t/////////////////////////////////\n\n\t// from lua\n\ttemplate<typename T>\n\tstruct void2val { static T invoke(void* input){ return *(T*)input; } };\n\ttemplate<typename T>\n\tstruct void2ptr { static T* invoke(void* input){ return (T*)input; } };\n\ttemplate<typename T>\n\tstruct void2ref { static T& invoke(void* input){ return *(T*)input; } };\n\n\ttemplate<typename T>  \n\tstruct void2type\n\t{\n\t\tstatic T invoke(void* ptr)\n\t\t{\n\t\t\treturn\tif_<is_ptr<T>::value\n\t\t\t\t\t\t,void2ptr<typename base_type<T>::type>\n\t\t\t\t\t\t,typename if_<is_ref<T>::value\n\t\t\t\t\t\t\t,void2ref<typename base_type<T>::type>\n\t\t\t\t\t\t\t,void2val<typename base_type<T>::type>\n\t\t\t\t\t\t>::type\n\t\t\t\t\t>::type::invoke(ptr);\n\t\t}\n\t};\n\n\tstruct user\n\t{\n\t\tuser(void* p) : m_p(p) {}\n\t\tvirtual ~user() {}\n\t\tvoid* m_p;\n\t};\n\n\ttemplate<typename T>  \n\tstruct user2type { static T invoke(lua_State *L, int index) { return void2type<T>::invoke(lua_touserdata(L, index)); } };\n\n\ttemplate<typename T>\n\tstruct lua2enum { static T invoke(lua_State *L, int index) { return (T)(int)lua_tonumber(L, index); } };\n\n\ttemplate<typename T>\n\tstruct lua2object\n\t{ \n\t\tstatic T invoke(lua_State *L, int index) \n\t\t{ \n\t\t\tif(!lua_isuserdata(L,index))\n\t\t\t{\n\t\t\t\tlua_pushstring(L, \"no class at first argument. (forgot ':' expression ?)\");\n\t\t\t\tlua_error(L);\n\t\t\t}\n\t\t\treturn void2type<T>::invoke(user2type<user*>::invoke(L,index)->m_p); \n\t\t} \n\t};\n\n\ttemplate<typename T>\n\tT lua2type(lua_State *L, int index)\n\t{\n\t\treturn\tif_<is_enum<T>::value\n\t\t\t\t\t,lua2enum<T>\n\t\t\t\t\t,lua2object<T> \n\t\t\t\t>::type::invoke(L, index);\n\t}\n\n\ttemplate<typename T>\n\tstruct val2user : user\n\t{\n\t\tval2user() : user(new T) {}\n\n\t\ttemplate<typename T1>\n\t\tval2user(T1 t1) : user(new T(t1)) {}\n\n\t\ttemplate<typename T1, typename T2>\n\t\tval2user(T1 t1, T2 t2) : user(new T(t1, t2)) {}\n\n\t\ttemplate<typename T1, typename T2, typename T3>\n\t\tval2user(T1 t1, T2 t2, T3 t3) : user(new T(t1, t2, t3)) {}\n\n\t\ttemplate<typename T1, typename T2, typename T3, typename T4>\n\t\tval2user(T1 t1, T2 t2, T3 t3, T4 t4) : user(new T(t1, t2, t3,t4)) {}\n\n\t\ttemplate<typename T1, typename T2, typename T3, typename T4, typename T5>\n\t\tval2user(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) : user(new T(t1, t2, t3,t4,t5)) {}\n\n\t\t~val2user() { delete ((T*)m_p); }\n\t};\n\n\ttemplate<typename T>\n\tstruct ptr2user : user\n\t{\n\t\tptr2user(T* t) : user((void*)t) {}\n\t};\n\n\ttemplate<typename T>\n\tstruct ref2user : user\n\t{\n\t\tref2user(T& t) : user(&t) {}\n\t};\n\n\t// to lua\n\ttemplate<typename T>\n\tstruct val2lua { static void invoke(lua_State *L, T& input){ new(lua_newuserdata(L, sizeof(val2user<T>))) val2user<T>(input); } };\n\ttemplate<typename T>\n\tstruct ptr2lua { static void invoke(lua_State *L, T* input){ if(input) new(lua_newuserdata(L, sizeof(ptr2user<T>))) ptr2user<T>(input); else lua_pushnil(L); } };\n\ttemplate<typename T>\n\tstruct ref2lua { static void invoke(lua_State *L, T& input){ new(lua_newuserdata(L, sizeof(ref2user<T>))) ref2user<T>(input); } };\n\n\ttemplate<typename T>\n\tstruct enum2lua { static void invoke(lua_State *L, T val) { lua_pushnumber(L, (int)val); } };\n\n\ttemplate<typename T>\n\tstruct object2lua \n\t{ \n\t\tstatic void invoke(lua_State *L, T val) \n\t\t{ \n\t\t\tif_<is_ptr<T>::value\n\t\t\t\t,ptr2lua<typename base_type<T>::type>\n\t\t\t\t,typename if_<is_ref<T>::value\n\t\t\t\t\t,ref2lua<typename base_type<T>::type>\n\t\t\t\t\t,val2lua<typename base_type<T>::type>\n\t\t\t\t>::type\n\t\t\t>::type::invoke(L, val);\n\n\t\t\tpush_meta(L, class_name<typename class_type<T>::type>::name());\n\t\t\tlua_setmetatable(L, -2);\n\t\t} \n\t};\n\n\ttemplate<typename T>\n\tvoid type2lua(lua_State *L, T val)\n\t{\n\t\tif_<is_enum<T>::value\n\t\t\t,enum2lua<T>\n\t\t\t,object2lua<T>\n\t\t>::type::invoke(L, val);\n\t}\n\n\t// get value from cclosure\n\ttemplate<typename T>  \n\tT upvalue_(lua_State *L)\n\t{\n\t\treturn user2type<T>::invoke(L, lua_upvalueindex(1));\n\t}\n\n\t// read a value from lua stack \n\ttemplate<typename T>  \n\tT read(lua_State *L, int index)\t\t\t\t{ return lua2type<T>(L, index); }\n\n\ttemplate<>\tchar*\t\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tconst char*\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tchar\t\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tunsigned char\t\tread(lua_State *L, int index);\n\ttemplate<>\tshort\t\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tunsigned short\t\tread(lua_State *L, int index);\n\ttemplate<>\tlong\t\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tunsigned long\t\tread(lua_State *L, int index);\n\ttemplate<>\tint\t\t\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tunsigned int\t\tread(lua_State *L, int index);\n\ttemplate<>\tfloat\t\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tdouble\t\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tbool\t\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tvoid\t\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tlong long\t\t\tread(lua_State *L, int index);\n\ttemplate<>\tunsigned long long\tread(lua_State *L, int index);\n\ttemplate<>\ttable\t\t\t\tread(lua_State *L, int index);\n\n\t// push a value to lua stack \n\ttemplate<typename T>  \n\tvoid push(lua_State *L, T ret)\t\t\t\t\t{ type2lua<T>(L, ret); }\n\t\n\ttemplate<>\tvoid push(lua_State *L, char ret);\n\ttemplate<>\tvoid push(lua_State *L, unsigned char ret);\n\ttemplate<>\tvoid push(lua_State *L, short ret);\n\ttemplate<>\tvoid push(lua_State *L, unsigned short ret);\n\ttemplate<>\tvoid push(lua_State *L, long ret);\n\ttemplate<>\tvoid push(lua_State *L, unsigned long ret);\n\ttemplate<>\tvoid push(lua_State *L, int ret);\n\ttemplate<>\tvoid push(lua_State *L, unsigned int ret);\n\ttemplate<>\tvoid push(lua_State *L, float ret);\n\ttemplate<>\tvoid push(lua_State *L, double ret);\n\ttemplate<>\tvoid push(lua_State *L, char* ret);\n\ttemplate<>\tvoid push(lua_State *L, const char* ret);\n\ttemplate<>\tvoid push(lua_State *L, bool ret);\n\ttemplate<>\tvoid push(lua_State *L, lua_value* ret);\n\ttemplate<>\tvoid push(lua_State *L, long long ret);\n\ttemplate<>\tvoid push(lua_State *L, unsigned long long ret);\n\ttemplate<>\tvoid push(lua_State *L, table ret);\n\n\t// pop a value from lua stack\n\ttemplate<typename T>  \n\tT pop(lua_State *L) { T t = read<T>(L, -1); lua_pop(L, 1); return t; }\n\t\n\ttemplate<>\tvoid\tpop(lua_State *L);\n\ttemplate<>\ttable\tpop(lua_State *L);\n\n\t// functor (with return value)\n\ttemplate<typename RVal, typename T1=void, typename T2=void, typename T3=void, typename T4=void, typename T5=void>\n\tstruct functor\n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,upvalue_<RVal(*)(T1,T2,T3,T4,T5)>(L)(read<T1>(L,1),read<T2>(L,2),read<T3>(L,3),read<T4>(L,4),read<T5>(L,5))); return 1; }\n\t};\n\n\ttemplate<typename RVal, typename T1, typename T2, typename T3, typename T4>\n\tstruct functor<RVal,T1,T2,T3,T4> \n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,upvalue_<RVal(*)(T1,T2,T3,T4)>(L)(read<T1>(L,1),read<T2>(L,2),read<T3>(L,3),read<T4>(L,4))); return 1; }\n\t};\n\n\ttemplate<typename RVal, typename T1, typename T2, typename T3>\n\tstruct functor<RVal,T1,T2,T3> \n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,upvalue_<RVal(*)(T1,T2,T3)>(L)(read<T1>(L,1),read<T2>(L,2),read<T3>(L,3))); return 1; }\n\t};\n\n\ttemplate<typename RVal, typename T1, typename T2>\n\tstruct functor<RVal,T1,T2> \n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,upvalue_<RVal(*)(T1,T2)>(L)(read<T1>(L,1),read<T2>(L,2))); return 1; }\n\t};\n\n\ttemplate<typename RVal, typename T1>\n\tstruct functor<RVal,T1> \n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,upvalue_<RVal(*)(T1)>(L)(read<T1>(L,1))); return 1; }\n\t};\n\n\ttemplate<typename RVal>\n\tstruct functor<RVal>\n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,upvalue_<RVal(*)()>(L)()); return 1; }\n\t};\n\n\t// functor (without return value)\n\ttemplate<typename T1, typename T2, typename T3, typename T4, typename T5>\n\tstruct functor<void, T1, T2, T3, T4, T5>\n\t{\n\t\tstatic int invoke(lua_State *L) { upvalue_<void(*)(T1,T2,T3,T4,T5)>(L)(read<T1>(L,1),read<T2>(L,2),read<T3>(L,3),read<T4>(L,4),read<T5>(L,5)); return 0; }\n\t};\n\n\ttemplate<typename T1, typename T2, typename T3, typename T4>\n\tstruct functor<void, T1, T2, T3, T4>\n\t{\n\t\tstatic int invoke(lua_State *L) { upvalue_<void(*)(T1,T2,T3,T4)>(L)(read<T1>(L,1),read<T2>(L,2),read<T3>(L,3),read<T4>(L,4)); return 0; }\n\t};\n\n\ttemplate<typename T1, typename T2, typename T3>\n\tstruct functor<void, T1, T2, T3>\n\t{\n\t\tstatic int invoke(lua_State *L) { upvalue_<void(*)(T1,T2,T3)>(L)(read<T1>(L,1),read<T2>(L,2),read<T3>(L,3)); return 0; }\n\t};\n\n\ttemplate<typename T1, typename T2>\n\tstruct functor<void, T1, T2>\n\t{\n\t\tstatic int invoke(lua_State *L) { upvalue_<void(*)(T1,T2)>(L)(read<T1>(L,1),read<T2>(L,2)); return 0; }\n\t};\n\n\ttemplate<typename T1>\n\tstruct functor<void, T1>\n\t{\n\t\tstatic int invoke(lua_State *L) { upvalue_<void(*)(T1)>(L)(read<T1>(L,1)); return 0; }\n\t};\n\n\ttemplate<>\n\tstruct functor<void>\n\t{\n\t\tstatic int invoke(lua_State *L) { upvalue_<void(*)()>(L)(); return 0; }\n\t};\n\n\t// functor (non-managed)\n\ttemplate<typename T1>\n\tstruct functor<int, lua_State*, T1>\n\t{\n\t\tstatic int invoke(lua_State *L) { return upvalue_<int(*)(lua_State*,T1)>(L)(L,read<T1>(L,1)); }\n\t};\n\n\ttemplate<>\n\tstruct functor<int,lua_State*>\n\t{\n\t\tstatic int invoke(lua_State *L) { return upvalue_<int(*)(lua_State*)>(L)(L); }\n\t};\n\n\t// push_functor\n\ttemplate<typename RVal> \n\tvoid push_functor(lua_State *L, RVal (*func)())\n\t{\n\t\tlua_pushcclosure(L, functor<RVal>::invoke, 1);\n\t}\n\n\ttemplate<typename RVal, typename T1> \n\tvoid push_functor(lua_State *L, RVal (*func)(T1))\n\t{ \n\t\tlua_pushcclosure(L, functor<RVal,T1>::invoke, 1);\n\t}\n\n\ttemplate<typename RVal, typename T1, typename T2> \n\tvoid push_functor(lua_State *L, RVal (*func)(T1,T2))\n\t{ \n\t\tlua_pushcclosure(L, functor<RVal,T1,T2>::invoke, 1);\n\t}\n\n\ttemplate<typename RVal, typename T1, typename T2, typename T3> \n\tvoid push_functor(lua_State *L, RVal (*func)(T1,T2,T3))\n\t{ \n\t\tlua_pushcclosure(L, functor<RVal,T1,T2,T3>::invoke, 1);\n\t}\n\n\ttemplate<typename RVal, typename T1, typename T2, typename T3, typename T4> \n\tvoid push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4))\n\t{ \n\t\tlua_pushcclosure(L, functor<RVal,T1,T2,T3,T4>::invoke, 1);\n\t}\n\n\ttemplate<typename RVal, typename T1, typename T2, typename T3, typename T4, typename T5> \n\tvoid push_functor(lua_State *L, RVal (*func)(T1,T2,T3,T4,T5))\n\t{ \n\t\tlua_pushcclosure(L, functor<RVal,T1,T2,T3,T4,T5>::invoke, 1);\n\t}\n\n\t// member variable\n\tstruct var_base\n\t{\n\t\tvirtual void get(lua_State *L) = 0;\n\t\tvirtual void set(lua_State *L) = 0;\n\t};\n\n\ttemplate<typename T, typename V>\n\tstruct mem_var : var_base\n\t{\n\t\tV T::*_var;\n\t\tmem_var(V T::*val) : _var(val) {}\n\t\tvoid get(lua_State *L)\t{ push<if_<is_obj<V>::value,V&,V>::type>(L, read<T*>(L,1)->*(_var));\t}\n\t\tvoid set(lua_State *L)\t{ read<T*>(L,1)->*(_var) = read<V>(L, 3);\t}\n\t};\n\n\t// class member functor (with return value)\n\ttemplate<typename RVal, typename T, typename T1=void, typename T2=void, typename T3=void, typename T4=void, typename T5=void>\n\tstruct mem_functor\n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,(read<T*>(L,1)->*upvalue_<RVal(T::*)(T1,T2,T3,T4,T5)>(L))(read<T1>(L,2),read<T2>(L,3),read<T3>(L,4),read<T4>(L,5),read<T5>(L,6)));; return 1; }\n\t};\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2, typename T3, typename T4> \n\tstruct mem_functor<RVal,T,T1,T2,T3,T4>\n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,(read<T*>(L,1)->*upvalue_<RVal(T::*)(T1,T2,T3,T4)>(L))(read<T1>(L,2),read<T2>(L,3),read<T3>(L,4),read<T4>(L,5))); return 1; }\n\t};\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2, typename T3> \n\tstruct mem_functor<RVal,T,T1,T2,T3>\n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,(read<T*>(L,1)->*upvalue_<RVal(T::*)(T1,T2,T3)>(L))(read<T1>(L,2),read<T2>(L,3),read<T3>(L,4))); return 1; }\n\t};\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2> \n\tstruct mem_functor<RVal,T,T1, T2>\n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,(read<T*>(L,1)->*upvalue_<RVal(T::*)(T1,T2)>(L))(read<T1>(L,2),read<T2>(L,3))); return 1; }\n\t};\n\n\ttemplate<typename RVal, typename T, typename T1> \n\tstruct mem_functor<RVal,T,T1>\n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,(read<T*>(L,1)->*upvalue_<RVal(T::*)(T1)>(L))(read<T1>(L,2))); return 1; }\n\t};\n\n\ttemplate<typename RVal, typename T> \n\tstruct mem_functor<RVal,T>\n\t{\n\t\tstatic int invoke(lua_State *L) { push(L,(read<T*>(L,1)->*upvalue_<RVal(T::*)()>(L))()); return 1; }\n\t};\n\n\t// class member functor (without return value)\n\ttemplate<typename T, typename T1, typename T2, typename T3, typename T4, typename T5>\n\tstruct mem_functor<void,T,T1,T2,T3,T4,T5>\n\t{\n\t\tstatic int invoke(lua_State *L)  { (read<T*>(L,1)->*upvalue_<void(T::*)(T1,T2,T3,T4,T5)>(L))(read<T1>(L,2),read<T2>(L,3),read<T3>(L,4),read<T4>(L,5),read<T5>(L,6)); return 0; }\n\t};\n\n\ttemplate<typename T, typename T1, typename T2, typename T3, typename T4>\n\tstruct mem_functor<void,T,T1,T2,T3,T4>\n\t{\n\t\tstatic int invoke(lua_State *L)  { (read<T*>(L,1)->*upvalue_<void(T::*)(T1,T2,T3,T4)>(L))(read<T1>(L,2),read<T2>(L,3),read<T3>(L,4),read<T4>(L,5)); return 0; }\n\t};\n\n\ttemplate<typename T, typename T1, typename T2, typename T3>\n\tstruct mem_functor<void,T,T1,T2,T3>\n\t{\n\t\tstatic int invoke(lua_State *L)  { (read<T*>(L,1)->*upvalue_<void(T::*)(T1,T2,T3)>(L))(read<T1>(L,2),read<T2>(L,3),read<T3>(L,4)); return 0; }\n\t};\n\n\ttemplate<typename T, typename T1, typename T2>\n\tstruct mem_functor<void,T,T1,T2>\n\t{\n\t\tstatic int invoke(lua_State *L)  { (read<T*>(L,1)->*upvalue_<void(T::*)(T1,T2)>(L))(read<T1>(L,2),read<T2>(L,3)); return 0; }\n\t};\n\n\ttemplate<typename T, typename T1>\n\tstruct mem_functor<void,T,T1>\n\t{\n\t\tstatic int invoke(lua_State *L)  { (read<T*>(L,1)->*upvalue_<void(T::*)(T1)>(L))(read<T1>(L,2)); return 0; }\n\t};\n\n\ttemplate<typename T>\n\tstruct mem_functor<void,T>\n\t{\n\t\tstatic int invoke(lua_State *L)  { (read<T*>(L,1)->*upvalue_<void(T::*)()>(L))(); return 0; }\n\t};\n\n\t// class member functor (non-managed)\n\ttemplate<typename T, typename T1> \n\tstruct mem_functor<int,T,lua_State*,T1>\n\t{\n\t\tstatic int invoke(lua_State *L) { return (read<T*>(L,1)->*upvalue_<int(T::*)(lua_State*,T1)>(L))(L, read<T1>(L,2)); }\n\t};\n\n\ttemplate<typename T> \n\tstruct mem_functor<int,T,lua_State*>\n\t{\n\t\tstatic int invoke(lua_State *L) { return (read<T*>(L,1)->*upvalue_<int(T::*)(lua_State*)>(L))(L); }\n\t};\n\n\t// push_functor\n\ttemplate<typename RVal, typename T>\n\tvoid push_functor(lua_State *L, RVal (T::*func)()) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T>\n\tvoid push_functor(lua_State *L, RVal (T::*func)() const) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1)) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1) const) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1,T2)) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1,T2>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1,T2) const) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1,T2>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2, typename T3>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3)) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1,T2,T3>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2, typename T3>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3) const) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1,T2,T3>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2, typename T3, typename T4>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4)) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1,T2,T3,T4>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2, typename T3, typename T4>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4) const) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1,T2,T3,T4>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2, typename T3, typename T4, typename T5>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5)) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1,T2,T3,T4,T5>::invoke, 1); \n\t}\n\n\ttemplate<typename RVal, typename T, typename T1, typename T2, typename T3, typename T4, typename T5>\n\tvoid push_functor(lua_State *L, RVal (T::*func)(T1,T2,T3,T4,T5) const) \n\t{ \n\t\tlua_pushcclosure(L, mem_functor<RVal,T,T1,T2,T3,T4,T5>::invoke, 1); \n\t}\n\n\t// constructor\n\ttemplate<typename T, typename T1, typename T2, typename T3, typename T4, typename T5>\n\tint constructor(lua_State *L) \n\t{ \n\t\tnew(lua_newuserdata(L, sizeof(val2user<T>))) val2user<T>(read<T1>(L,2),read<T2>(L,3),read<T3>(L,4),read<T4>(L,5),read<T5>(L,6));\n\t\tpush_meta(L, class_name<typename class_type<T>::type>::name());\n\t\tlua_setmetatable(L, -2);\n\n\t\treturn 1; \n\t}\n\n\ttemplate<typename T, typename T1, typename T2, typename T3, typename T4>\n\tint constructor(lua_State *L) \n\t{ \n\t\tnew(lua_newuserdata(L, sizeof(val2user<T>))) val2user<T>(read<T1>(L,2),read<T2>(L,3),read<T3>(L,4),read<T4>(L,5));\n\t\tpush_meta(L, class_name<typename class_type<T>::type>::name());\n\t\tlua_setmetatable(L, -2);\n\n\t\treturn 1; \n\t}\n\n\ttemplate<typename T, typename T1, typename T2, typename T3>\n\tint constructor(lua_State *L) \n\t{ \n\t\tnew(lua_newuserdata(L, sizeof(val2user<T>))) val2user<T>(read<T1>(L,2),read<T2>(L,3),read<T3>(L,4));\n\t\tpush_meta(L, class_name<typename class_type<T>::type>::name());\n\t\tlua_setmetatable(L, -2);\n\n\t\treturn 1; \n\t}\n\n\ttemplate<typename T, typename T1, typename T2>\n\tint constructor(lua_State *L) \n\t{ \n\t\tnew(lua_newuserdata(L, sizeof(val2user<T>))) val2user<T>(read<T1>(L,2),read<T2>(L,3));\n\t\tpush_meta(L, class_name<typename class_type<T>::type>::name());\n\t\tlua_setmetatable(L, -2);\n\n\t\treturn 1; \n\t}\n\n\ttemplate<typename T, typename T1>\n\tint constructor(lua_State *L) \n\t{ \n\t\tnew(lua_newuserdata(L, sizeof(val2user<T>))) val2user<T>(read<T1>(L,2));\n\t\tpush_meta(L, class_name<typename class_type<T>::type>::name());\n\t\tlua_setmetatable(L, -2);\n\n\t\treturn 1; \n\t}\n\n\ttemplate<typename T>\n\tint constructor(lua_State *L) \n\t{ \n\t\tnew(lua_newuserdata(L, sizeof(val2user<T>))) val2user<T>();\n\t\tpush_meta(L, class_name<typename class_type<T>::type>::name());\n\t\tlua_setmetatable(L, -2);\n\n\t\treturn 1; \n\t}\n\n\t// destroyer\n\ttemplate<typename T>\n\tint destroyer(lua_State *L) \n\t{ \n\t\t((user*)lua_touserdata(L, 1))->~user();\n\t\treturn 0;\n\t}\n\n\t// global function\n\ttemplate<typename F> \n\tvoid def(lua_State* L, const char* name, F func)\n\t{ \n\t\tlua_pushstring(L, name);\n\t\tlua_pushlightuserdata(L, (void*)func);\n\t\tpush_functor(L, func);\n\t\tlua_settable(L, LUA_GLOBALSINDEX);\n\t}\n\n\t// global variable\n\ttemplate<typename T>\n\tvoid set(lua_State* L, const char* name, T object)\n\t{\n\t\tlua_pushstring(L, name);\n\t\tpush(L, object);\n\t\tlua_settable(L, LUA_GLOBALSINDEX);\n\t}\n\n\ttemplate<typename T>\n\tT get(lua_State* L, const char* name)\n\t{\n\t\tlua_pushstring(L, name);\n\t\tlua_gettable(L, LUA_GLOBALSINDEX);\n\t\treturn pop<T>(L);\n\t}\n\n\ttemplate<typename T>\n\tvoid decl(lua_State* L, const char* name, T object)\n\t{\n\t\tset(L, name, object);\n\t}\n\n\t// call\n\ttemplate<typename RVal>\n\tRVal call(lua_State* L, const char* name)\n\t{\n\t\tlua_pushcclosure(L, on_error, 0);\n\t\tint errfunc = lua_gettop(L);\n\n\t\tlua_pushstring(L, name);\n\t\tlua_gettable(L, LUA_GLOBALSINDEX);\n\n\t\tif(lua_isfunction(L,-1))\n\t\t{\n\t\t\tlua_pcall(L, 0, 1, errfunc);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprint_error(L, \"lua_tinker::call() attempt to call global `%s' (not a function)\", name);\n\t\t}\n\n\t\tlua_remove(L, errfunc);\n\t\treturn pop<RVal>(L);\n\t}\n\n\ttemplate<typename RVal, typename T1>\n\tRVal call(lua_State* L, const char* name, T1 arg)\n\t{\n\t\tlua_pushcclosure(L, on_error, 0);\n\t\tint errfunc = lua_gettop(L);\n\n\t\tlua_pushstring(L, name);\n\t\tlua_gettable(L, LUA_GLOBALSINDEX);\n\t\tif(lua_isfunction(L,-1))\n\t\t{\n\t\t\tpush(L, arg);\n\t\t\tlua_pcall(L, 1, 1, errfunc);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprint_error(L, \"lua_tinker::call() attempt to call global `%s' (not a function)\", name);\n\t\t}\n\n\t\tlua_remove(L, errfunc);\n\t\treturn pop<RVal>(L);\n\t}\n\n\ttemplate<typename RVal, typename T1, typename T2>\n\tRVal call(lua_State* L, const char* name, T1 arg1, T2 arg2)\n\t{\n\t\tlua_pushcclosure(L, on_error, 0);\n\t\tint errfunc = lua_gettop(L);\n\n\t\tlua_pushstring(L, name);\n\t\tlua_gettable(L, LUA_GLOBALSINDEX);\n\t\tif(lua_isfunction(L,-1))\n\t\t{\n\t\t\tpush(L, arg1);\n\t\t\tpush(L, arg2);\n\t\t\tlua_pcall(L, 2, 1, errfunc);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprint_error(L, \"lua_tinker::call() attempt to call global `%s' (not a function)\", name);\n\t\t}\n\n\t\tlua_remove(L, errfunc);\n\t\treturn pop<RVal>(L);\n\t}\n\n\ttemplate<typename RVal, typename T1, typename T2, typename T3>\n\tRVal call(lua_State* L, const char* name, T1 arg1, T2 arg2, T3 arg3)\n\t{\n\t\tlua_pushcclosure(L, on_error, 0);\n\t\tint errfunc = lua_gettop(L);\n\n\t\tlua_pushstring(L, name);\n\t\tlua_gettable(L, LUA_GLOBALSINDEX);\n\t\tif(lua_isfunction(L,-1))\n\t\t{\n\t\t\tpush(L, arg1);\n\t\t\tpush(L, arg2);\n\t\t\tpush(L, arg3);\n\t\t\tlua_pcall(L, 3, 1, errfunc);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprint_error(L, \"lua_tinker::call() attempt to call global `%s' (not a function)\", name);\n\t\t}\n\n\t\tlua_remove(L, errfunc);\n\t\treturn pop<RVal>(L);\n\t}\n\n\t// class helper\n\tint meta_get(lua_State *L);\n\tint meta_set(lua_State *L);\n\tvoid push_meta(lua_State *L, const char* name);\n\n\t// class init\n\ttemplate<typename T>\n\tvoid class_add(lua_State* L, const char* name) \n\t{ \n\t\tclass_name<T>::name(name);\n\n\t\tlua_pushstring(L, name);\n\t\tlua_newtable(L);\n\n\t\tlua_pushstring(L, \"__name\");\n\t\tlua_pushstring(L, name);\n\t\tlua_rawset(L, -3);\n\n\t\tlua_pushstring(L, \"__index\");\n\t\tlua_pushcclosure(L, meta_get, 0);\n\t\tlua_rawset(L, -3);\n\n\t\tlua_pushstring(L, \"__newindex\");\n\t\tlua_pushcclosure(L, meta_set, 0);\n\t\tlua_rawset(L, -3);\n\n\t\tlua_pushstring(L, \"__gc\");\n\t\tlua_pushcclosure(L, destroyer<T>, 0);\n\t\tlua_rawset(L, -3);\n\n\t\tlua_settable(L, LUA_GLOBALSINDEX);\n\t}\n\n\t// Tinker Class Inheritence\n\ttemplate<typename T, typename P>\n\tvoid class_inh(lua_State* L)\n\t{\n\t\tpush_meta(L, class_name<T>::name());\n\t\tif(lua_istable(L, -1))\n\t\t{\n\t\t\tlua_pushstring(L, \"__parent\");\n\t\t\tpush_meta(L, class_name<P>::name());\n\t\t\tlua_rawset(L, -3);\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\n\t// Tinker Class Constructor\n\ttemplate<typename T, typename F>\n\tvoid class_con(lua_State* L,F func)\n\t{\n\t\tpush_meta(L, class_name<T>::name());\n\t\tif(lua_istable(L, -1))\n\t\t{\n\t\t\tlua_newtable(L);\n\t\t\tlua_pushstring(L, \"__call\");\n\t\t\tlua_pushcclosure(L, func, 0);\n\t\t\tlua_rawset(L, -3);\n\t\t\tlua_setmetatable(L, -2);\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\n\t// Tinker Class Functions\n\ttemplate<typename T, typename F>\n\tvoid class_def(lua_State* L, const char* name, F func) \n\t{ \n\t\tpush_meta(L, class_name<T>::name());\n\t\tif(lua_istable(L, -1))\n\t\t{\n\t\t\tlua_pushstring(L, name);\n\t\t\tnew(lua_newuserdata(L,sizeof(F))) F(func);\n\t\t\tpush_functor(L, func);\n\t\t\tlua_rawset(L, -3);\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\n\t// Tinker Class Variables\n\ttemplate<typename T, typename BASE, typename VAR>\n\tvoid class_mem(lua_State* L, const char* name, VAR BASE::*val) \n\t{ \n\t\tpush_meta(L, class_name<T>::name());\n\t\tif(lua_istable(L, -1))\n\t\t{\n\t\t\tlua_pushstring(L, name);\n\t\t\tnew(lua_newuserdata(L,sizeof(mem_var<BASE,VAR>))) mem_var<BASE,VAR>(val);\n\t\t\tlua_rawset(L, -3);\n\t\t}\n\t\tlua_pop(L, 1);\n\t}\n\n\ttemplate<typename T>\n\tstruct class_name\n\t{\n\t\t// global name\n\t\tstatic const char* name(const char* name = NULL)\n\t\t{\n\t\t\tstatic char temp[256] = \"\";\n\t\t\tif(name) strcpy_s(temp, name);\n\t\t\treturn temp;\n\t\t}\n\t};\n\n\t// Table Object on Stack\n\tstruct table_obj\n\t{\n\t\ttable_obj(lua_State* L, int index);\n\t\t~table_obj();\n\n\t\tvoid inc_ref();\n\t\tvoid dec_ref();\n\n\t\tbool validate();\n\n\t\ttemplate<typename T>\n\t\tvoid set(const char* name, T object)\n\t\t{\n\t\t\tif(validate())\n\t\t\t{\n\t\t\t\tlua_pushstring(m_L, name);\n\t\t\t\tpush(m_L, object);\n\t\t\t\tlua_settable(m_L, m_index);\n\t\t\t}\n\t\t}\n\n\t\ttemplate<typename T>\n\t\tT get(const char* name)\n\t\t{\n\t\t\tif(validate())\n\t\t\t{\n\t\t\t\tlua_pushstring(m_L, name);\n\t\t\t\tlua_gettable(m_L, m_index);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlua_pushnil(m_L);\n\t\t\t}\n\n\t\t\treturn pop<T>(m_L);\n\t\t}\n\n\t\tlua_State*\t\tm_L;\n\t\tint\t\t\t\tm_index;\n\t\tconst void*\t\tm_pointer;\n\t\tint\t\t\t\tm_ref;\n\t};\n\n\t// Table Object Holder\n\tstruct table\n\t{\n\t\ttable(lua_State* L);\n\t\ttable(lua_State* L, int index);\n\t\ttable(lua_State* L, const char* name);\n\t\ttable(const table& input);\n\t\t~table();\n\n\t\ttemplate<typename T>\n\t\tvoid set(const char* name, T object)\n\t\t{\n\t\t\tm_obj->set(name, object);\n\t\t}\n\n\t\ttemplate<typename T>\n\t\tT get(const char* name)\n\t\t{\n\t\t\treturn m_obj->get<T>(name);\n\t\t}\n\n\t\ttable_obj*\t\tm_obj;\n\t};\n\n} // namespace lua_tinker\n\n#endif //_LUA_TINKER_H_\n"
  },
  {
    "path": "luaconf.h",
    "content": "/*\n** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $\n** Configuration file for Lua\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lconfig_h\n#define lconfig_h\n\n#include <limits.h>\n#include <stddef.h>\n\n\n/*\n** ==================================================================\n** Search for \"@@\" to find all configurable definitions.\n** ===================================================================\n*/\n\n\n/*\n@@ LUA_ANSI controls the use of non-ansi features.\n** CHANGE it (define it) if you want Lua to avoid the use of any\n** non-ansi feature or library.\n*/\n#if defined(__STRICT_ANSI__)\n#define LUA_ANSI\n#endif\n\n\n#if !defined(LUA_ANSI) && defined(_WIN32)\n#define LUA_WIN\n#endif\n\n#if defined(LUA_USE_LINUX)\n#define LUA_USE_POSIX\n#define LUA_USE_DLOPEN\t\t/* needs an extra library: -ldl */\n#define LUA_USE_READLINE\t/* needs some extra libraries */\n#endif\n\n#if defined(LUA_USE_MACOSX)\n#define LUA_USE_POSIX\n#define LUA_DL_DYLD\t\t/* does not need extra library */\n#endif\n\n\n\n/*\n@@ LUA_USE_POSIX includes all functionallity listed as X/Open System\n@* Interfaces Extension (XSI).\n** CHANGE it (define it) if your system is XSI compatible.\n*/\n#if defined(LUA_USE_POSIX)\n#define LUA_USE_MKSTEMP\n#define LUA_USE_ISATTY\n#define LUA_USE_POPEN\n#define LUA_USE_ULONGJMP\n#endif\n\n\n/*\n@@ LUA_PATH and LUA_CPATH are the names of the environment variables that\n@* Lua check to set its paths.\n@@ LUA_INIT is the name of the environment variable that Lua\n@* checks for initialization code.\n** CHANGE them if you want different names.\n*/\n#define LUA_PATH        \"LUA_PATH\"\n#define LUA_CPATH       \"LUA_CPATH\"\n#define LUA_INIT\t\"LUA_INIT\"\n\n\n/*\n@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for\n@* Lua libraries.\n@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for\n@* C libraries.\n** CHANGE them if your machine has a non-conventional directory\n** hierarchy or if you want to install your libraries in\n** non-conventional directories.\n*/\n#if defined(_WIN32)\n/*\n** In Windows, any exclamation mark ('!') in the path is replaced by the\n** path of the directory of the executable file of the current process.\n*/\n#define LUA_LDIR\t\"!\\\\lua\\\\\"\n#define LUA_CDIR\t\"!\\\\\"\n#define LUA_PATH_DEFAULT  \\\n\t\t\".\\\\?.lua;\"  LUA_LDIR\"?.lua;\"  LUA_LDIR\"?\\\\init.lua;\" \\\n\t\t             LUA_CDIR\"?.lua;\"  LUA_CDIR\"?\\\\init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\".\\\\?.dll;\"  LUA_CDIR\"?.dll;\" LUA_CDIR\"loadall.dll\"\n\n#else\n#define LUA_ROOT\t\"/usr/local/\"\n#define LUA_LDIR\tLUA_ROOT \"share/lua/5.1/\"\n#define LUA_CDIR\tLUA_ROOT \"lib/lua/5.1/\"\n#define LUA_PATH_DEFAULT  \\\n\t\t\"./?.lua;\"  LUA_LDIR\"?.lua;\"  LUA_LDIR\"?/init.lua;\" \\\n\t\t            LUA_CDIR\"?.lua;\"  LUA_CDIR\"?/init.lua\"\n#define LUA_CPATH_DEFAULT \\\n\t\"./?.so;\"  LUA_CDIR\"?.so;\" LUA_CDIR\"loadall.so\"\n#endif\n\n\n/*\n@@ LUA_DIRSEP is the directory separator (for submodules).\n** CHANGE it if your machine does not use \"/\" as the directory separator\n** and is not Windows. (On Windows Lua automatically uses \"\\\".)\n*/\n#if defined(_WIN32)\n#define LUA_DIRSEP\t\"\\\\\"\n#else\n#define LUA_DIRSEP\t\"/\"\n#endif\n\n\n/*\n@@ LUA_PATHSEP is the character that separates templates in a path.\n@@ LUA_PATH_MARK is the string that marks the substitution points in a\n@* template.\n@@ LUA_EXECDIR in a Windows path is replaced by the executable's\n@* directory.\n@@ LUA_IGMARK is a mark to ignore all before it when bulding the\n@* luaopen_ function name.\n** CHANGE them if for some reason your system cannot use those\n** characters. (E.g., if one of those characters is a common character\n** in file/directory names.) Probably you do not need to change them.\n*/\n#define LUA_PATHSEP\t\";\"\n#define LUA_PATH_MARK\t\"?\"\n#define LUA_EXECDIR\t\"!\"\n#define LUA_IGMARK\t\"-\"\n\n\n/*\n@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.\n** CHANGE that if ptrdiff_t is not adequate on your machine. (On most\n** machines, ptrdiff_t gives a good choice between int or long.)\n*/\n#define LUA_INTEGER\tptrdiff_t\n\n\n/*\n@@ LUA_API is a mark for all core API functions.\n@@ LUALIB_API is a mark for all standard library functions.\n** CHANGE them if you need to define those functions in some special way.\n** For instance, if you want to create one Windows DLL with the core and\n** the libraries, you may want to use the following definition (define\n** LUA_BUILD_AS_DLL to get it).\n*/\n#if defined(LUA_BUILD_AS_DLL)\n\n#if defined(LUA_CORE) || defined(LUA_LIB)\n#define LUA_API __declspec(dllexport)\n#else\n#define LUA_API __declspec(dllimport)\n#endif\n\n#else\n\n#define LUA_API\t\textern\n\n#endif\n\n/* more often than not the libs go together with the core */\n#define LUALIB_API\tLUA_API\n\n\n/*\n@@ LUAI_FUNC is a mark for all extern functions that are not to be\n@* exported to outside modules.\n@@ LUAI_DATA is a mark for all extern (const) variables that are not to\n@* be exported to outside modules.\n** CHANGE them if you need to mark them in some special way. Elf/gcc\n** (versions 3.2 and later) mark them as \"hidden\" to optimize access\n** when Lua is compiled as a shared library.\n*/\n#if defined(luaall_c)\n#define LUAI_FUNC\tstatic\n#define LUAI_DATA\t/* empty */\n\n#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \\\n      defined(__ELF__)\n#define LUAI_FUNC\t__attribute__((visibility(\"hidden\"))) extern\n#define LUAI_DATA\tLUAI_FUNC\n\n#else\n#define LUAI_FUNC\textern\n#define LUAI_DATA\textern\n#endif\n\n\n\n/*\n@@ LUA_QL describes how error messages quote program elements.\n** CHANGE it if you want a different appearance.\n*/\n#define LUA_QL(x)\t\"'\" x \"'\"\n#define LUA_QS\t\tLUA_QL(\"%s\")\n\n\n/*\n@@ LUA_IDSIZE gives the maximum size for the description of the source\n@* of a function in debug information.\n** CHANGE it if you want a different size.\n*/\n#define LUA_IDSIZE\t60\n\n\n/*\n** {==================================================================\n** Stand-alone configuration\n** ===================================================================\n*/\n\n#if defined(lua_c) || defined(luaall_c)\n\n/*\n@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that\n@* is, whether we're running lua interactively).\n** CHANGE it if you have a better definition for non-POSIX/non-Windows\n** systems.\n*/\n#if defined(LUA_USE_ISATTY)\n#include <unistd.h>\n#define lua_stdin_is_tty()\tisatty(0)\n#elif defined(LUA_WIN)\n#include <io.h>\n#include <stdio.h>\n#define lua_stdin_is_tty()\t_isatty(_fileno(stdin))\n#else\n#define lua_stdin_is_tty()\t1  /* assume stdin is a tty */\n#endif\n\n\n/*\n@@ LUA_PROMPT is the default prompt used by stand-alone Lua.\n@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.\n** CHANGE them if you want different prompts. (You can also change the\n** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)\n*/\n#define LUA_PROMPT\t\t\"> \"\n#define LUA_PROMPT2\t\t\">> \"\n\n\n/*\n@@ LUA_PROGNAME is the default name for the stand-alone Lua program.\n** CHANGE it if your stand-alone interpreter has a different name and\n** your system is not able to detect that name automatically.\n*/\n#define LUA_PROGNAME\t\t\"lua\"\n\n\n/*\n@@ LUA_MAXINPUT is the maximum length for an input line in the\n@* stand-alone interpreter.\n** CHANGE it if you need longer lines.\n*/\n#define LUA_MAXINPUT\t512\n\n\n/*\n@@ lua_readline defines how to show a prompt and then read a line from\n@* the standard input.\n@@ lua_saveline defines how to \"save\" a read line in a \"history\".\n@@ lua_freeline defines how to free a line read by lua_readline.\n** CHANGE them if you want to improve this functionality (e.g., by using\n** GNU readline and history facilities).\n*/\n#if defined(LUA_USE_READLINE)\n#include <stdio.h>\n#include <readline/readline.h>\n#include <readline/history.h>\n#define lua_readline(L,b,p)\t((void)L, ((b)=readline(p)) != NULL)\n#define lua_saveline(L,idx) \\\n\tif (lua_strlen(L,idx) > 0)  /* non-empty line? */ \\\n\t  add_history(lua_tostring(L, idx));  /* add it to history */\n#define lua_freeline(L,b)\t((void)L, free(b))\n#else\n#define lua_readline(L,b,p)\t\\\n\t((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \\\n\tfgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */\n#define lua_saveline(L,idx)\t{ (void)L; (void)idx; }\n#define lua_freeline(L,b)\t{ (void)L; (void)b; }\n#endif\n\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles\n@* as a percentage.\n** CHANGE it if you want the GC to run faster or slower (higher values\n** mean larger pauses which mean slower collection.) You can also change\n** this value dynamically.\n*/\n#define LUAI_GCPAUSE\t200  /* 200% (wait memory to double before next GC) */\n\n\n/*\n@@ LUAI_GCMUL defines the default speed of garbage collection relative to\n@* memory allocation as a percentage.\n** CHANGE it if you want to change the granularity of the garbage\n** collection. (Higher values mean coarser collections. 0 represents\n** infinity, where each step performs a full collection.) You can also\n** change this value dynamically.\n*/\n#define LUAI_GCMUL\t200 /* GC runs 'twice the speed' of memory allocation */\n\n\n\n/*\n@@ LUA_COMPAT_GETN controls compatibility with old getn behavior.\n** CHANGE it (define it) if you want exact compatibility with the\n** behavior of setn/getn in Lua 5.0.\n*/\n#undef LUA_COMPAT_GETN\n\n/*\n@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.\n** CHANGE it to undefined as soon as you do not need a global 'loadlib'\n** function (the function is still available as 'package.loadlib').\n*/\n#undef LUA_COMPAT_LOADLIB\n\n/*\n@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.\n** CHANGE it to undefined as soon as your programs use only '...' to\n** access vararg parameters (instead of the old 'arg' table).\n*/\n#define LUA_COMPAT_VARARG\n\n/*\n@@ LUA_COMPAT_MOD controls compatibility with old math.mod function.\n** CHANGE it to undefined as soon as your programs use 'math.fmod' or\n** the new '%' operator instead of 'math.mod'.\n*/\n#define LUA_COMPAT_MOD\n\n/*\n@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting\n@* facility.\n** CHANGE it to 2 if you want the old behaviour, or undefine it to turn\n** off the advisory error when nesting [[...]].\n*/\n#define LUA_COMPAT_LSTR\t\t1\n\n/*\n@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.\n** CHANGE it to undefined as soon as you rename 'string.gfind' to\n** 'string.gmatch'.\n*/\n#define LUA_COMPAT_GFIND\n\n/*\n@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'\n@* behavior.\n** CHANGE it to undefined as soon as you replace to 'luaL_register'\n** your uses of 'luaL_openlib'\n*/\n#define LUA_COMPAT_OPENLIB\n\n\n\n/*\n@@ luai_apicheck is the assert macro used by the Lua-C API.\n** CHANGE luai_apicheck if you want Lua to perform some checks in the\n** parameters it gets from API calls. This may slow down the interpreter\n** a bit, but may be quite useful when debugging C code that interfaces\n** with Lua. A useful redefinition is to use assert.h.\n*/\n#if defined(LUA_USE_APICHECK)\n#include <assert.h>\n#define luai_apicheck(L,o)\t{ (void)L; assert(o); }\n#else\n#define luai_apicheck(L,o)\t{ (void)L; }\n#endif\n\n\n/*\n@@ LUAI_BITSINT defines the number of bits in an int.\n** CHANGE here if Lua cannot automatically detect the number of bits of\n** your machine. Probably you do not need to change this.\n*/\n/* avoid overflows in comparison */\n#if INT_MAX-20 < 32760\n#define LUAI_BITSINT\t16\n#elif INT_MAX > 2147483640L\n/* int has at least 32 bits */\n#define LUAI_BITSINT\t32\n#else\n#error \"you must define LUA_BITSINT with number of bits in an integer\"\n#endif\n\n\n/*\n@@ LUAI_UINT32 is an unsigned integer with at least 32 bits.\n@@ LUAI_INT32 is an signed integer with at least 32 bits.\n@@ LUAI_UMEM is an unsigned integer big enough to count the total\n@* memory used by Lua.\n@@ LUAI_MEM is a signed integer big enough to count the total memory\n@* used by Lua.\n** CHANGE here if for some weird reason the default definitions are not\n** good enough for your machine. (The definitions in the 'else'\n** part always works, but may waste space on machines with 64-bit\n** longs.) Probably you do not need to change this.\n*/\n#if LUAI_BITSINT >= 32\n#define LUAI_UINT32\tunsigned int\n#define LUAI_INT32\tint\n#define LUAI_MAXINT32\tINT_MAX\n#define LUAI_UMEM\tsize_t\n#define LUAI_MEM\tptrdiff_t\n#else\n/* 16-bit ints */\n#define LUAI_UINT32\tunsigned long\n#define LUAI_INT32\tlong\n#define LUAI_MAXINT32\tLONG_MAX\n#define LUAI_UMEM\tunsigned long\n#define LUAI_MEM\tlong\n#endif\n\n\n/*\n@@ LUAI_MAXCALLS limits the number of nested calls.\n** CHANGE it if you need really deep recursive calls. This limit is\n** arbitrary; its only purpose is to stop infinite recursion before\n** exhausting memory.\n*/\n#define LUAI_MAXCALLS\t20000\n\n\n/*\n@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function\n@* can use.\n** CHANGE it if you need lots of (Lua) stack space for your C\n** functions. This limit is arbitrary; its only purpose is to stop C\n** functions to consume unlimited stack space. (must be smaller than\n** -LUA_REGISTRYINDEX)\n*/\n#define LUAI_MAXCSTACK\t8000\n\n\n\n/*\n** {==================================================================\n** CHANGE (to smaller values) the following definitions if your system\n** has a small C stack. (Or you may want to change them to larger\n** values if your system has a large C stack and these limits are\n** too rigid for you.) Some of these constants control the size of\n** stack-allocated arrays used by the compiler or the interpreter, while\n** others limit the maximum number of recursive calls that the compiler\n** or the interpreter can perform. Values too large may cause a C stack\n** overflow for some forms of deep constructs.\n** ===================================================================\n*/\n\n\n/*\n@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and\n@* syntactical nested non-terminals in a program.\n*/\n#define LUAI_MAXCCALLS\t\t200\n\n\n/*\n@@ LUAI_MAXVARS is the maximum number of local variables per function\n@* (must be smaller than 250).\n*/\n#define LUAI_MAXVARS\t\t200\n\n\n/*\n@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function\n@* (must be smaller than 250).\n*/\n#define LUAI_MAXUPVALUES\t60\n\n\n/*\n@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.\n*/\n#define LUAL_BUFFERSIZE\t\tBUFSIZ\n\n/* }================================================================== */\n\n\n\n\n/*\n** {==================================================================\n@@ LUA_NUMBER is the type of numbers in Lua.\n** CHANGE the following definitions only if you want to build Lua\n** with a number type different from double. You may also need to\n** change lua_number2int & lua_number2integer.\n** ===================================================================\n*/\n\n#define LUA_NUMBER_DOUBLE\n#define LUA_NUMBER\tdouble\n\n/*\n@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'\n@* over a number.\n*/\n#define LUAI_UACNUMBER\tdouble\n\n\n/*\n@@ LUA_NUMBER_SCAN is the format for reading numbers.\n@@ LUA_NUMBER_FMT is the format for writing numbers.\n@@ lua_number2str converts a number to a string.\n@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.\n@@ lua_str2number converts a string to a number.\n*/\n#define LUA_NUMBER_SCAN\t\t\"%lf\"\n#define LUA_NUMBER_FMT\t\t\"%.14g\"\n#define lua_number2str(s,n)\tsprintf((s), LUA_NUMBER_FMT, (n))\n#define LUAI_MAXNUMBER2STR\t32 /* 16 digits, sign, point, and \\0 */\n#define lua_str2number(s,p)\tstrtod((s), (p))\n\n\n/*\n@@ The luai_num* macros define the primitive operations over numbers.\n*/\n#if defined(LUA_CORE)\n#include <math.h>\n#define luai_numadd(a,b)\t((a)+(b))\n#define luai_numsub(a,b)\t((a)-(b))\n#define luai_nummul(a,b)\t((a)*(b))\n#define luai_numdiv(a,b)\t((a)/(b))\n#define luai_nummod(a,b)\t((a) - floor((a)/(b))*(b))\n#define luai_numpow(a,b)\t(pow(a,b))\n#define luai_numunm(a)\t\t(-(a))\n#define luai_numeq(a,b)\t\t((a)==(b))\n#define luai_numlt(a,b)\t\t((a)<(b))\n#define luai_numle(a,b)\t\t((a)<=(b))\n#define luai_numisnan(a)\t(!luai_numeq((a), (a)))\n#endif\n\n\n/*\n@@ lua_number2int is a macro to convert lua_Number to int.\n@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.\n** CHANGE them if you know a faster way to convert a lua_Number to\n** int (with any rounding method and without throwing errors) in your\n** system. In Pentium machines, a naive typecast from double to int\n** in C is extremely slow, so any alternative is worth trying.\n*/\n\n/* On a Pentium, resort to a trick */\n#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \\\n    (defined(__i386) || defined (_M_IX86) || defined(__i386__))\n\n/* On a Microsoft compiler, use assembler */\n#if defined(_MSC_VER)\n\n#define lua_number2int(i,d)   __asm fld d   __asm fistp i\n#define lua_number2integer(i,n)\t\tlua_number2int(i, n)\n\n/* the next trick should work on any Pentium, but sometimes clashes\n   with a DirectX idiosyncrasy */\n#else\n\nunion luai_Cast { double l_d; long l_l; };\n#define lua_number2int(i,d) \\\n  { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }\n#define lua_number2integer(i,n)\t\tlua_number2int(i, n)\n\n#endif\n\n\n/* this option always works, but may be slow */\n#else\n#define lua_number2int(i,d)\t((i)=(int)(d))\n#define lua_number2integer(i,d)\t((i)=(lua_Integer)(d))\n\n#endif\n\n/* }================================================================== */\n\n\n/*\n@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.\n** CHANGE it if your system requires alignments larger than double. (For\n** instance, if your system supports long doubles and they must be\n** aligned in 16-byte boundaries, then you should add long double in the\n** union.) Probably you do not need to change this.\n*/\n#define LUAI_USER_ALIGNMENT_T\tunion { double u; void *s; long l; }\n\n\n/*\n@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.\n** CHANGE them if you prefer to use longjmp/setjmp even with C++\n** or if want/don't to use _longjmp/_setjmp instead of regular\n** longjmp/setjmp. By default, Lua handles errors with exceptions when\n** compiling as C++ code, with _longjmp/_setjmp when asked to use them,\n** and with longjmp/setjmp otherwise.\n*/\n#if defined(__cplusplus)\n/* C++ exceptions */\n#define LUAI_THROW(L,c)\tthrow(c)\n#define LUAI_TRY(L,c,a)\ttry { a } catch(...) \\\n\t{ if ((c)->status == 0) (c)->status = -1; }\n#define luai_jmpbuf\tint  /* dummy variable */\n\n#elif defined(LUA_USE_ULONGJMP)\n/* in Unix, try _longjmp/_setjmp (more efficient) */\n#define LUAI_THROW(L,c)\t_longjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\tif (_setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\tjmp_buf\n\n#else\n/* default handling with long jumps */\n#define LUAI_THROW(L,c)\tlongjmp((c)->b, 1)\n#define LUAI_TRY(L,c,a)\tif (setjmp((c)->b) == 0) { a }\n#define luai_jmpbuf\tjmp_buf\n\n#endif\n\n\n/*\n@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern\n@* can do during pattern-matching.\n** CHANGE it if you need more captures. This limit is arbitrary.\n*/\n#define LUA_MAXCAPTURES\t\t32\n\n\n/*\n@@ lua_tmpnam is the function that the OS library uses to create a\n@* temporary name.\n@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.\n** CHANGE them if you have an alternative to tmpnam (which is considered\n** insecure) or if you want the original tmpnam anyway.  By default, Lua\n** uses tmpnam except when POSIX is available, where it uses mkstemp.\n*/\n#if defined(loslib_c) || defined(luaall_c)\n\n#if defined(LUA_USE_MKSTEMP)\n#include <unistd.h>\n#define LUA_TMPNAMBUFSIZE\t32\n#define lua_tmpnam(b,e)\t{ \\\n\tstrcpy(b, \"/tmp/lua_XXXXXX\"); \\\n\te = mkstemp(b); \\\n\tif (e != -1) close(e); \\\n\te = (e == -1); }\n\n#else\n#define LUA_TMPNAMBUFSIZE\tL_tmpnam\n#define lua_tmpnam(b,e)\t\t{ e = (tmpnam(b) == NULL); }\n#endif\n\n#endif\n\n\n/*\n@@ lua_popen spawns a new process connected to the current one through\n@* the file streams.\n** CHANGE it if you have a way to implement it in your system.\n*/\n#if defined(LUA_USE_POPEN)\n\n#define lua_popen(L,c,m)\t((void)L, fflush(NULL), popen(c,m))\n#define lua_pclose(L,file)\t((void)L, (pclose(file) != -1))\n\n#elif defined(LUA_WIN)\n\n#define lua_popen(L,c,m)\t((void)L, _popen(c,m))\n#define lua_pclose(L,file)\t((void)L, (_pclose(file) != -1))\n\n#else\n\n#define lua_popen(L,c,m)\t((void)((void)c, m),  \\\n\t\tluaL_error(L, LUA_QL(\"popen\") \" not supported\"), (FILE*)0)\n#define lua_pclose(L,file)\t\t((void)((void)L, file), 0)\n\n#endif\n\n/*\n@@ LUA_DL_* define which dynamic-library system Lua should use.\n** CHANGE here if Lua has problems choosing the appropriate\n** dynamic-library system for your platform (either Windows' DLL, Mac's\n** dyld, or Unix's dlopen). If your system is some kind of Unix, there\n** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for\n** it.  To use dlopen you also need to adapt the src/Makefile (probably\n** adding -ldl to the linker options), so Lua does not select it\n** automatically.  (When you change the makefile to add -ldl, you must\n** also add -DLUA_USE_DLOPEN.)\n** If you do not want any kind of dynamic library, undefine all these\n** options.\n** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.\n*/\n#if defined(LUA_USE_DLOPEN)\n#define LUA_DL_DLOPEN\n#endif\n\n#if defined(LUA_WIN)\n#define LUA_DL_DLL\n#endif\n\n\n/*\n@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State\n@* (the data goes just *before* the lua_State pointer).\n** CHANGE (define) this if you really need that. This value must be\n** a multiple of the maximum alignment required for your machine.\n*/\n#define LUAI_EXTRASPACE\t\t0\n\n\n/*\n@@ luai_userstate* allow user-specific actions on threads.\n** CHANGE them if you defined LUAI_EXTRASPACE and need to do something\n** extra when a thread is created/deleted/resumed/yielded.\n*/\n#define luai_userstateopen(L)\t\t((void)L)\n#define luai_userstateclose(L)\t\t((void)L)\n#define luai_userstatethread(L,L1)\t((void)L)\n#define luai_userstatefree(L)\t\t((void)L)\n#define luai_userstateresume(L,n)\t((void)L)\n#define luai_userstateyield(L,n)\t((void)L)\n\n\n/*\n@@ LUA_INTFRMLEN is the length modifier for integer conversions\n@* in 'string.format'.\n@@ LUA_INTFRM_T is the integer type correspoding to the previous length\n@* modifier.\n** CHANGE them if your system supports long long or does not support long.\n*/\n\n#if defined(LUA_USELONGLONG)\n\n#define LUA_INTFRMLEN\t\t\"ll\"\n#define LUA_INTFRM_T\t\tlong long\n\n#else\n\n#define LUA_INTFRMLEN\t\t\"l\"\n#define LUA_INTFRM_T\t\tlong\n\n#endif\n\n\n\n/* =================================================================== */\n\n/*\n** Local configuration. You can use this space to add your redefinitions\n** without modifying the main part of the file.\n*/\n\n\n\n#endif\n\n"
  },
  {
    "path": "lualib.h",
    "content": "/*\n** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $\n** Lua standard libraries\n** See Copyright Notice in lua.h\n*/\n\n\n#ifndef lualib_h\n#define lualib_h\n\n#include \"lua.h\"\n\n\n/* Key to file-handle type */\n#define LUA_FILEHANDLE\t\t\"FILE*\"\n\n\n#define LUA_COLIBNAME\t\"coroutine\"\nLUALIB_API int (luaopen_base) (lua_State *L);\n\n#define LUA_TABLIBNAME\t\"table\"\nLUALIB_API int (luaopen_table) (lua_State *L);\n\n#define LUA_IOLIBNAME\t\"io\"\nLUALIB_API int (luaopen_io) (lua_State *L);\n\n#define LUA_OSLIBNAME\t\"os\"\nLUALIB_API int (luaopen_os) (lua_State *L);\n\n#define LUA_STRLIBNAME\t\"string\"\nLUALIB_API int (luaopen_string) (lua_State *L);\n\n#define LUA_MATHLIBNAME\t\"math\"\nLUALIB_API int (luaopen_math) (lua_State *L);\n\n#define LUA_DBLIBNAME\t\"debug\"\nLUALIB_API int (luaopen_debug) (lua_State *L);\n\n#define LUA_LOADLIBNAME\t\"package\"\nLUALIB_API int (luaopen_package) (lua_State *L);\n\n\n/* open all previous libraries */\nLUALIB_API void (luaL_openlibs) (lua_State *L); \n\n\n\n#ifndef lua_assert\n#define lua_assert(x)\t((void)0)\n#endif\n\n\n#endif\n"
  },
  {
    "path": "sample1.cpp",
    "content": "// sample1.cpp : C++  Lua ȣ Լ  ˾ƺ.\n//\n\n#include <iostream>\n\nextern \"C\" \n{\n\t#include \"lua.h\"\n\t#include \"lualib.h\"\n\t#include \"lauxlib.h\"\n};\n\n#include \"lua_tinker.h\"\n\nint cpp_func(int arg1, int arg2)\n{\n\treturn arg1 + arg2;\n}\n\nint main()\n{\n\t// Lua  ʱȭ Ѵ.\n\tlua_State* L = lua_open();\n\n\t// Lua ⺻ Լ εѴ.- print() \n\tluaopen_base(L);\n\n\t// LuaTinker  ̿ؼ Լ Ѵ.\n\tlua_tinker::def(L, \"cpp_func\", cpp_func);\n\n\t// sample1.lua  ε/Ѵ.\n\tlua_tinker::dofile(L, \"sample1.lua\");\n\n\t// sample1.lua  Լ ȣѴ.\n\tint result = lua_tinker::call<int>(L, \"lua_func\", 3, 4);\n\n\t// lua_func(3,4)   \n\tprintf(\"lua_func(3,4) = %d\\n\", result);\n\n\t// α׷ \n\tlua_close(L);\n\n\treturn 0;\n}\n"
  },
  {
    "path": "sample1.lua",
    "content": "-- C++   Լ ȣѴ.\nresult = cpp_func(1, 2)\n\nprint(\"cpp_func(1,2) = \"..result)\n\n\n-- Ϲ lua Լ Ѵ.\nfunction lua_func(arg1, arg2)\n\treturn arg1 + arg2\nend\n\n\n\n"
  },
  {
    "path": "sample2.cpp",
    "content": "// sample2.cpp : C++  Lua ȣ   ˾ƺ.\n//\n\nextern \"C\" \n{\n\t#include \"lua.h\"\n\t#include \"lualib.h\"\n\t#include \"lauxlib.h\"\n};\n\n#include \"lua_tinker.h\"\n\nstatic int cpp_int = 100;\n\nint main()\n{\n\t// Lua  ʱȭ Ѵ.\n\tlua_State* L = lua_open();\n\n\t// Lua ⺻ Լ εѴ.- print() \n\tluaopen_base(L);\n\n\t// LuaTinker  ̿ؼ cpp_int  Lua \n\tlua_tinker::set(L, \"cpp_int\", cpp_int);\n\n\t// sample1.lua  ε/Ѵ.\n\tlua_tinker::dofile(L, \"sample2.lua\");\n\n\t// sample1.lua  Լ ȣѴ.\n\tint lua_int = lua_tinker::get<int>(L, \"lua_int\");\n\n\t// lua_int  \n\tprintf(\"lua_int = %d\\n\", lua_int);\n\n\t// α׷ \n\tlua_close(L);\n\n\treturn 0;\n}\n"
  },
  {
    "path": "sample2.lua",
    "content": "-- C++    Ѵ.\nprint(\"cpp_int = \"..cpp_int)\n\n\n-- Lua    ҴѴ.\nlua_int = 200\n"
  },
  {
    "path": "sample3.cpp",
    "content": "// sample3.cpp : LuaTinker  Ŭ  ˾ƺ.\n//\n\nextern \"C\" \n{\n\t#include \"lua.h\"\n\t#include \"lualib.h\"\n\t#include \"lauxlib.h\"\n};\n\n#include \"lua_tinker.h\"\n\nstruct A\n{\n\tA(int v) : value(v) {}\n\tint value;\n};\n\nstruct base\n{\n\tbase() {}\n\n\tconst char* is_base(){ return \"this is base\"; }\n};\n\nclass test : public base\n{\npublic:\n\ttest(int val) : _test(val) {}\n\t~test() {}\n\n\tconst char* is_test(){ return \"this is test\"; }\n\n\tvoid ret_void() {}\n\tint ret_int()\t\t\t\t{ return _test;\t\t\t}\n\tint ret_mul(int m) const\t{ return _test * m;\t\t}\n\tA get()\t\t\t\t\t\t{ return A(_test);\t\t}\n\tvoid set(A a)\t\t\t\t{ _test = a.value;\t\t}\n\n\tint _test;\n};\n\ntest g_test(11);\n\nint main()\n{\n\t// Lua  ʱȭ Ѵ.\n\tlua_State* L = lua_open();\n\n\t// Lua ⺻ Լ εѴ.- print() \n\tluaopen_base(L);\n\t// Lua ڿ Լ εѴ.- string \n\tluaopen_string(L);\n\n\t// base Ŭ Lua  ߰Ѵ.\n\tlua_tinker::class_add<base>(L, \"base\");\n\t// base  Լ Ѵ.\n\tlua_tinker::class_def<base>(L, \"is_base\", &base::is_base);\n\n\t// test Ŭ Lua  ߰Ѵ.\n\tlua_tinker::class_add<test>(L, \"test\");\n\t// test  base   ޾ ˷ش.\n\tlua_tinker::class_inh<test, base>(L);\n\t// test Ŭ ڸ Ѵ.\n\tlua_tinker::class_con<test>(L, lua_tinker::constructor<test,int>);\n\t// test  Լ Ѵ.\n\tlua_tinker::class_def<test>(L, \"is_test\", &test::is_test);\n\tlua_tinker::class_def<test>(L, \"ret_void\", &test::ret_void);\n\tlua_tinker::class_def<test>(L, \"ret_int\", &test::ret_int);\n\tlua_tinker::class_def<test>(L, \"ret_mul\", &test::ret_mul);\n\tlua_tinker::class_def<test>(L, \"get\", &test::get);\n\tlua_tinker::class_def<test>(L, \"set\", &test::set);\n\tlua_tinker::class_mem<test>(L, \"_test\", &test::_test);\n\t\n\t// Lua  ȣ g_test  ͸ Ѵ.\n\tlua_tinker::set(L, \"g_test\", &g_test);\n\n\t// sample3.lua  ε/Ѵ.\n\tlua_tinker::dofile(L, \"sample3.lua\");\n\n\t// α׷ \n\tlua_close(L);\n\n\treturn 0;\n}\n\n"
  },
  {
    "path": "sample3.lua",
    "content": "--  g_test    _test   Ѵ.\nprint(g_test._test)\n\n-- const char* test::is_test() Լ  Ѵ.\nprint(g_test:is_test())\n\n-- test::ret_int() Լ  Ѵ.\nprint(g_test:ret_int())\n\n-- temp   test ü  ִ´.\ntemp = test(4)\n\n-- test    _test  Ѵ.\nprint(temp._test)\n\n-- Lua  ߰  A ü a  ִ´.\na = g_test:get()\n\n--  ü a Lua->C++ Ѵ.\ntemp:set(a)\n\n-- test::set(A a) Լ ȣ _test   ȭ ȮѴ.\nprint(temp._test)\n\n-- ӹ θ Լ ȣ\nprint(temp:is_base())\n\n-- ڱ ڽ Լ ȣ\nprint(temp:is_test())\n\n--  ü metatable  ϵ Ŭ  Լ 캸 Լ\n-------------------------------------------------------------------------------\nfunction objinfo(obj)\n\n\tlocal meta = getmetatable(obj)\n\tif meta ~= nil then\n\t\tmetainfo(meta)\n\telse\n\t\tprint(\"no object infomation !!\")\n\tend\nend\n\nfunction metainfo(meta)\n\n\tif meta ~= nil then\n\t\tlocal name = meta[\"__name\"]\n\t\tif name ~= nil then\n\t\t\tmetainfo(meta[\"__parent\"])\n\t\t\tprint(\"<\"..name..\">\")\n\t\t\tfor key,value in pairs(meta) do \n\t\t\t\tif not string.find(key, \"__..\") then \n\t\t\t\t\tif type(value) == \"function\" then\n\t\t\t\t\t\tprint(\"\\t[f] \"..name..\":\"..key..\"()\") \n\t\t\t\t\telseif type(value) == \"userdata\" then\n\t\t\t\t\t\tprint(\"\\t[v] \"..name..\":\"..key)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\nend\n-------------------------------------------------------------------------------\n\n-- Lua  ü userdata νĵȴ.\nprint(\"g_test\t-> \", g_test)\nprint(\"temp\t-> \", temp)\nprint(\"a\t-> \", a)\n\n-- C++   g_test  ü  캻.\nprint(\"objinfo(g_test)\")\nobjinfo(g_test)\n\n-- constructor    temp ü  캻.\nprint(\"objinfo(temp)\")\nobjinfo(temp)\n\n--   A ü  a ü  캻.\nprint(\"objinfo(a)\")\nobjinfo(a)\n\n"
  },
  {
    "path": "sample4.cpp",
    "content": "// sample4.cpp : table   ˾ƺ.\n// table    ؼ stack  table ؼ  ȴ. \n// Lua  ̺   ͸ ö󰡰  ü ο ȴ.\n//  ߸    ԰ų Lua   鿡  ų  ִ.\n\nextern \"C\" \n{\n\t#include \"lua.h\"\n\t#include \"lualib.h\"\n\t#include \"lauxlib.h\"\n};\n\n#include \"lua_tinker.h\"\n\nint main()\n{\n\t// Lua  ʱȭ Ѵ.\n\tlua_State* L = lua_open();\n\n\t// Lua ⺻ Լ εѴ.- print() \n\tluaopen_base(L);\n\n\t// Lua ̺ ϰ ÿ ǪѴ.\n\tlua_tinker::table haha(L, \"haha\");\n\n\t// haha.value = 1  ִ´.\n\thaha.set(\"value\", 1);\n\n\t// table  table  ִ´.\n\thaha.set(\"inside\", lua_tinker::table(L));\n\n\t// haha.inside  ͸  Ѵ.\n\tlua_tinker::table inside = haha.get<lua_tinker::table>(\"inside\");\n\n\t// inside.value = 2  ִ´.\n\tinside.set(\"value\", 2);\n\n\t// sample4.lua  ε/Ѵ.\n\tlua_tinker::dofile(L, \"sample4.lua\");\n\n\t// Lua   haha.test  д´.\n\tconst char* test = haha.get<const char*>(\"test\");\n\tprintf(\"haha.test = %s\\n\", test);\n\n\t//   ʰ Lua ÿ  ̺ Ѵ.()\n\tlua_tinker::table temp(L);\n\n\t//  ̺.name   ִ´.\n\ttemp.set(\"name\", \"local table !!\");\n\n\t// table  ڷ Ͽ print_table  ȣѴ.\n\tlua_tinker::call<void>(L, \"print_table\", temp);\n\n\t// Լ ϴ table ޴´.\n\tlua_tinker::table ret = lua_tinker::call<lua_tinker::table>(L, \"return_table\", \"give me a table !!\");\n\tprintf(\"ret.name =\\t%s\\n\", ret.get<const char*>(\"name\"));\n\n\t// α׷ \n\tlua_close(L);\n\n\treturn 0;\n}\n\n"
  },
  {
    "path": "sample4.lua",
    "content": "--  haha ̺ ȮѴ.\nprint(haha)\n\n--  haha.value Ѵ.\nprint(haha.value)\n\n--  haha.inside ̺ ȮѴ.\nprint(haha.inside)\n\n--  haha.inside.value Ѵ.\nprint(haha.inside.value)\n\n-- haha.test  ִ´.\nhaha.test = \"input from lua\"\n\n-- LuaTinker  Է ̺ ѱ.\nfunction print_table(arg)\n\tprint(\"arg = \", arg)\n\tprint(\"arg.name = \", arg.name)\nend\n\n-- LuaTinker  ̺ ѱ.\nfunction return_table(arg)\n\tlocal ret = {}\n\tret.name = arg\n\treturn ret\nend"
  },
  {
    "path": "sample5.cpp",
    "content": "// sample5.cpp : Defines the entry point for the console application.\n//\n\nextern \"C\" \n{\n\t#include \"lua.h\"\n\t#include \"lualib.h\"\n\t#include \"lauxlib.h\"\n};\n\n#include \"lua_tinker.h\"\n\nvoid show_error(const char* error)\n{\n\tprintf(\"_ALERT -> %s\\n\", error);\n}\n\nint main()\n{\n\t// Lua  ʱȭ Ѵ.\n\tlua_State* L = lua_open();\n\n\t// Lua ⺻ Լ εѴ.- print() \n\tluaopen_base(L);\n\n\n\t// lua_State*  ִ   ش.\n\tprintf(\"%s\\n\",\"-------------------------- current stack\");\n\tlua_tinker::enum_stack(L);\n\n\t// ÿ 1 оִ´.\n\tlua_pushnumber(L, 1);\n\n\t//    ٽ Ѵ.\n\tprintf(\"%s\\n\",\"-------------------------- stack after push '1'\");\n\tlua_tinker::enum_stack(L);\n\n\n\t// sample5.lua  ε/Ѵ.\n\tlua_tinker::dofile(L, \"sample5.lua\");\n\n\t// test_error() Լ ȣѴ.\n\t// test_error()   test_error_3() ȣ õϴ  ߻Ų.\n\t// Լ ȣ ߻  printf() ؼ µȴ.\n\tprintf(\"%s\\n\",\"-------------------------- calling test_error()\");\n\tlua_tinker::call<void>(L, \"test_error\");\n\n\t// test_error_3()  ʴ Լ̴. ȣ ü Ѵ.\n\tprintf(\"%s\\n\",\"-------------------------- calling test_error_3()\");\n\tlua_tinker::call<void>(L, \"test_error_3\");\n\n\t// printf()   ϴ   ƾ   ִ.\n\t//  ó Լ1  ڿ ߻  ϰ ȴ.\n\t// C++    void function(const char*) ° ϴ.\n\tlua_tinker::def(L, \"_ALERT\", show_error);\n\n\tlua_tinker::call<void>(L, \"_ALERT\", \"test !!!\");\n\n\t// test_error() Լ ȣѴ.\n\t// Լ ȣ ߻  Lua ϵ _ALERT() ؼ µȴ.\n\tprintf(\"%s\\n\",\"-------------------------- calling test_error()\");\n\tlua_tinker::call<void>(L, \"test_error\");\n\n\n\t// α׷ \n\tlua_close(L);\n\n\treturn 0;\n}\n\n"
  },
  {
    "path": "sample5.lua",
    "content": "-- ׽Ʈ Լ\nfunction test_error()\n\t\n\tprint(\"test_error() called !!\")\n\t\n\ttest_error_1()\nend\n\n-- ׽Ʈ Լ\nfunction test_error_1()\n\n\tprint(\"test_error_1() called !!\")\n\t\n\ttest_error_2()\nend\n\n-- ׽Ʈ Լ\nfunction test_error_2()\n\n\tprint(\"test_error_2() called !!\")\n\t\n\t--  ʴ Լ ȣ õѴ.\n\ttest_error_3()\nend"
  },
  {
    "path": "sample6.cpp",
    "content": "// sample3.cpp : LuaTinker  Ŭ  ˾ƺ.\n//\n\nextern \"C\" \n{\n\t#include \"lua.h\"\n\t#include \"lualib.h\"\n\t#include \"lauxlib.h\"\n};\n\n#include \"lua_tinker.h\"\n\n// Լ ° int(*)(lua_State*) Ǵ int(*)(lua_State*,T1)  츸 lua_yield()    ִ.\n// Լ ڰ  ʿ  lua_tinker.h  \"functor (non-managed)\" ڸƮ κ ؼ  ߰ \nint TestFunc(lua_State* L)\n{\n\tprintf(\"# TestFunc \\n\");\n\treturn lua_yield(L, 0);\n}\n\nint TestFunc2(lua_State* L, float a)\n{\n\tprintf(\"# TestFunc2(L,%f) \\n\", a);\n\treturn lua_yield(L, 0);\n}\n\nclass TestClass\n{\npublic:\n\n\t// Լ ° int(T::*)(lua_State*) Ǵ int(T::*)(lua_State*,T1)  츸 lua_yield()    ִ.\n\t// Լ ڰ  ʿ  lua_tinker.h  \"class member functor (non-managed)\" ڸƮ κ ؼ  ߰ \n\tint TestFunc(lua_State* L)\n\t{\n\t\tprintf(\"# TestClass::TestFunc \\n\");\n\t\treturn lua_yield(L, 0);\n\t}\n\n\tint TestFunc2(lua_State* L, float a)\n\t{\n\t\tprintf(\"# TestClass::TestFunc2(L,%f) \\n\", a);\n\t\treturn lua_yield(L, 0);\n\t}\n};\n\nint main()\n{\n\t// Lua  ʱȭ Ѵ.\n\tlua_State* L = lua_open();\n\n\t// Lua ⺻ Լ εѴ.- print() \n\tluaopen_base(L);\n\t// Lua ڿ Լ εѴ.- string \n\tluaopen_string(L);\n\n\t// TestFunc Լ Lua  Ѵ.\n\tlua_tinker::def(L, \"TestFunc\", &TestFunc);\n\tlua_tinker::def(L, \"TestFunc2\", &TestFunc2);\n\n\t// TestClass Ŭ Lua  ߰Ѵ.\n\tlua_tinker::class_add<TestClass>(L, \"TestClass\");\n\t// TestClass  Լ Ѵ.\n\tlua_tinker::class_def<TestClass>(L, \"TestFunc\", &TestClass::TestFunc);\n\tlua_tinker::class_def<TestClass>(L, \"TestFunc2\", &TestClass::TestFunc2);\n\n\t// TestClass    Ѵ.\n\tTestClass g_test;\n\tlua_tinker::set(L, \"g_test\", &g_test);\n\n\t// sample3.lua  εѴ.\n\tlua_tinker::dofile(L, \"sample6.lua\");\n\n\t// Thread  Ѵ.\n\tlua_newthread(L);\n\tlua_pushstring(L, \"ThreadTest\");\n\tlua_gettable(L, LUA_GLOBALSINDEX);\n\n\t// Thread  Ѵ.\n\tprintf(\"* lua_resume() ȣ\\n\");\n\tlua_resume(L, 0);\n\n\t// Thread  ٽ Ѵ.\n\tprintf(\"* lua_resume() ȣ\\n\");\n\tlua_resume(L, 0);\n\n\t// Thread  ٽ Ѵ.\n\tprintf(\"* lua_resume() ȣ\\n\");\n\tlua_resume(L, 0);\n\n\t// Thread  ٽ Ѵ.\n\tprintf(\"* lua_resume() ȣ\\n\");\n\tlua_resume(L, 0);\n\n\t// Thread  ٽ Ѵ.\n\tprintf(\"* lua_resume() ȣ\\n\");\n\tlua_resume(L, 0);\n\n\t// α׷ \n\tlua_close(L);\n\n\treturn 0;\n}\n\n"
  },
  {
    "path": "sample6.lua",
    "content": "-- lua coroutine ׽Ʈ Լ\nfunction ThreadTest()\n\tprint(\"ThreadTest \")\n\t\n\tprint(\"TestFunc ȣ\")\n\t-- ο lua_yield()  ȣȴ.\n\tTestFunc()\n\tTestFunc2(1.2)\n\tprint(\"TestFunc \")\n\t\n\tprint(\"g_test::TestFunc() ȣ\")\n\t-- ο lua_yield()  ȣȴ.\n\tg_test:TestFunc()\n\tg_test:TestFunc2(2.3)\n\tprint(\"g_test::TestFunc() \")\n\t\n\tprint(\"ThreadTest \")\nend\n"
  }
]