diff options
author | Mattes D <github@xoft.cz> | 2013-11-27 09:23:17 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2013-11-27 09:23:17 +0100 |
commit | 49760db89d94ede5d123d927141a6cd60dbaaf07 (patch) | |
tree | 6c6cf99e4cf3128311a93cd187947b502f3732a0 /lib/lua | |
parent | cWorld::SpawnExperienceOrb() now returns the entity ID of the spawned orb. (diff) | |
parent | Fixed VC2008 compilation, normalized include paths. (diff) | |
download | cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.gz cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.bz2 cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.lz cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.xz cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.zst cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.zip |
Diffstat (limited to '')
-rw-r--r-- | lib/lua/COPYRIGHT (renamed from lua-5.1.4/COPYRIGHT) | 0 | ||||
-rw-r--r-- | lib/lua/HISTORY (renamed from lua-5.1.4/HISTORY) | 0 | ||||
-rw-r--r-- | lib/lua/INSTALL (renamed from lua-5.1.4/INSTALL) | 0 | ||||
-rw-r--r-- | lib/lua/Makefile (renamed from lua-5.1.4/Makefile) | 0 | ||||
-rw-r--r-- | lib/lua/README (renamed from lua-5.1.4/README) | 0 | ||||
-rw-r--r-- | lib/lua/src/Makefile (renamed from lua-5.1.4/src/Makefile) | 0 | ||||
-rw-r--r-- | lib/lua/src/lapi.c (renamed from lua-5.1.4/src/lapi.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lapi.h (renamed from lua-5.1.4/src/lapi.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lauxlib.c (renamed from lua-5.1.4/src/lauxlib.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lauxlib.h (renamed from lua-5.1.4/src/lauxlib.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lbaselib.c (renamed from lua-5.1.4/src/lbaselib.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lcode.c (renamed from lua-5.1.4/src/lcode.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lcode.h (renamed from lua-5.1.4/src/lcode.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/ldblib.c (renamed from lua-5.1.4/src/ldblib.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/ldebug.c (renamed from lua-5.1.4/src/ldebug.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/ldebug.h (renamed from lua-5.1.4/src/ldebug.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/ldo.c (renamed from lua-5.1.4/src/ldo.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/ldo.h (renamed from lua-5.1.4/src/ldo.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/ldump.c (renamed from lua-5.1.4/src/ldump.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lfunc.c (renamed from lua-5.1.4/src/lfunc.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lfunc.h (renamed from lua-5.1.4/src/lfunc.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lgc.c (renamed from lua-5.1.4/src/lgc.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lgc.h (renamed from lua-5.1.4/src/lgc.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/linit.c (renamed from lua-5.1.4/src/linit.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/liolib.c (renamed from lua-5.1.4/src/liolib.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/llex.c (renamed from lua-5.1.4/src/llex.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/llex.h (renamed from lua-5.1.4/src/llex.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/llimits.h (renamed from lua-5.1.4/src/llimits.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lmathlib.c (renamed from lua-5.1.4/src/lmathlib.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lmem.c (renamed from lua-5.1.4/src/lmem.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lmem.h (renamed from lua-5.1.4/src/lmem.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/loadlib.c (renamed from lua-5.1.4/src/loadlib.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lobject.c (renamed from lua-5.1.4/src/lobject.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lobject.h (renamed from lua-5.1.4/src/lobject.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lopcodes.c (renamed from lua-5.1.4/src/lopcodes.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lopcodes.h (renamed from lua-5.1.4/src/lopcodes.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/loslib.c (renamed from lua-5.1.4/src/loslib.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lparser.c (renamed from lua-5.1.4/src/lparser.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lparser.h (renamed from lua-5.1.4/src/lparser.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lstate.c (renamed from lua-5.1.4/src/lstate.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lstate.h (renamed from lua-5.1.4/src/lstate.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lstring.c (renamed from lua-5.1.4/src/lstring.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lstring.h (renamed from lua-5.1.4/src/lstring.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lstrlib.c (renamed from lua-5.1.4/src/lstrlib.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/ltable.c (renamed from lua-5.1.4/src/ltable.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/ltable.h (renamed from lua-5.1.4/src/ltable.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/ltablib.c (renamed from lua-5.1.4/src/ltablib.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/ltm.c (renamed from lua-5.1.4/src/ltm.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/ltm.h (renamed from lua-5.1.4/src/ltm.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lua.c (renamed from lua-5.1.4/src/lua.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lua.h (renamed from lua-5.1.4/src/lua.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/luac.c (renamed from lua-5.1.4/src/luac.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/luaconf.h (renamed from lua-5.1.4/src/luaconf.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lualib.h (renamed from lua-5.1.4/src/lualib.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lundump.c (renamed from lua-5.1.4/src/lundump.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lundump.h (renamed from lua-5.1.4/src/lundump.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lvm.c (renamed from lua-5.1.4/src/lvm.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lvm.h (renamed from lua-5.1.4/src/lvm.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/lzio.c (renamed from lua-5.1.4/src/lzio.c) | 0 | ||||
-rw-r--r-- | lib/lua/src/lzio.h (renamed from lua-5.1.4/src/lzio.h) | 0 | ||||
-rw-r--r-- | lib/lua/src/print.c (renamed from lua-5.1.4/src/print.c) | 0 | ||||
-rw-r--r-- | lib/luaexpat/lxplib.c | 599 | ||||
-rw-r--r-- | lib/luaexpat/lxplib.h (renamed from source/LuaExpat/lxplib.h) | 0 |
63 files changed, 599 insertions, 0 deletions
diff --git a/lua-5.1.4/COPYRIGHT b/lib/lua/COPYRIGHT index 3a53e741e..3a53e741e 100644 --- a/lua-5.1.4/COPYRIGHT +++ b/lib/lua/COPYRIGHT diff --git a/lua-5.1.4/HISTORY b/lib/lua/HISTORY index ce0c95bc6..ce0c95bc6 100644 --- a/lua-5.1.4/HISTORY +++ b/lib/lua/HISTORY diff --git a/lua-5.1.4/INSTALL b/lib/lua/INSTALL index 17eb8aee8..17eb8aee8 100644 --- a/lua-5.1.4/INSTALL +++ b/lib/lua/INSTALL diff --git a/lua-5.1.4/Makefile b/lib/lua/Makefile index 6e78f66fa..6e78f66fa 100644 --- a/lua-5.1.4/Makefile +++ b/lib/lua/Makefile diff --git a/lua-5.1.4/README b/lib/lua/README index 11b4dff70..11b4dff70 100644 --- a/lua-5.1.4/README +++ b/lib/lua/README diff --git a/lua-5.1.4/src/Makefile b/lib/lua/src/Makefile index e4a3cd610..e4a3cd610 100644 --- a/lua-5.1.4/src/Makefile +++ b/lib/lua/src/Makefile diff --git a/lua-5.1.4/src/lapi.c b/lib/lua/src/lapi.c index 5d5145d2e..5d5145d2e 100644 --- a/lua-5.1.4/src/lapi.c +++ b/lib/lua/src/lapi.c diff --git a/lua-5.1.4/src/lapi.h b/lib/lua/src/lapi.h index 2c3fab244..2c3fab244 100644 --- a/lua-5.1.4/src/lapi.h +++ b/lib/lua/src/lapi.h diff --git a/lua-5.1.4/src/lauxlib.c b/lib/lua/src/lauxlib.c index 10f14e2c0..10f14e2c0 100644 --- a/lua-5.1.4/src/lauxlib.c +++ b/lib/lua/src/lauxlib.c diff --git a/lua-5.1.4/src/lauxlib.h b/lib/lua/src/lauxlib.h index 34258235d..34258235d 100644 --- a/lua-5.1.4/src/lauxlib.h +++ b/lib/lua/src/lauxlib.h diff --git a/lua-5.1.4/src/lbaselib.c b/lib/lua/src/lbaselib.c index 2a4c079d3..2a4c079d3 100644 --- a/lua-5.1.4/src/lbaselib.c +++ b/lib/lua/src/lbaselib.c diff --git a/lua-5.1.4/src/lcode.c b/lib/lua/src/lcode.c index cff626b7f..cff626b7f 100644 --- a/lua-5.1.4/src/lcode.c +++ b/lib/lua/src/lcode.c diff --git a/lua-5.1.4/src/lcode.h b/lib/lua/src/lcode.h index b941c6072..b941c6072 100644 --- a/lua-5.1.4/src/lcode.h +++ b/lib/lua/src/lcode.h diff --git a/lua-5.1.4/src/ldblib.c b/lib/lua/src/ldblib.c index 67de1222a..67de1222a 100644 --- a/lua-5.1.4/src/ldblib.c +++ b/lib/lua/src/ldblib.c diff --git a/lua-5.1.4/src/ldebug.c b/lib/lua/src/ldebug.c index 50ad3d380..50ad3d380 100644 --- a/lua-5.1.4/src/ldebug.c +++ b/lib/lua/src/ldebug.c diff --git a/lua-5.1.4/src/ldebug.h b/lib/lua/src/ldebug.h index ba28a9724..ba28a9724 100644 --- a/lua-5.1.4/src/ldebug.h +++ b/lib/lua/src/ldebug.h diff --git a/lua-5.1.4/src/ldo.c b/lib/lua/src/ldo.c index 8de05f728..8de05f728 100644 --- a/lua-5.1.4/src/ldo.c +++ b/lib/lua/src/ldo.c diff --git a/lua-5.1.4/src/ldo.h b/lib/lua/src/ldo.h index 98fddac59..98fddac59 100644 --- a/lua-5.1.4/src/ldo.h +++ b/lib/lua/src/ldo.h diff --git a/lua-5.1.4/src/ldump.c b/lib/lua/src/ldump.c index c9d3d4870..c9d3d4870 100644 --- a/lua-5.1.4/src/ldump.c +++ b/lib/lua/src/ldump.c diff --git a/lua-5.1.4/src/lfunc.c b/lib/lua/src/lfunc.c index 813e88f58..813e88f58 100644 --- a/lua-5.1.4/src/lfunc.c +++ b/lib/lua/src/lfunc.c diff --git a/lua-5.1.4/src/lfunc.h b/lib/lua/src/lfunc.h index a68cf5151..a68cf5151 100644 --- a/lua-5.1.4/src/lfunc.h +++ b/lib/lua/src/lfunc.h diff --git a/lua-5.1.4/src/lgc.c b/lib/lua/src/lgc.c index d9e0b7829..d9e0b7829 100644 --- a/lua-5.1.4/src/lgc.c +++ b/lib/lua/src/lgc.c diff --git a/lua-5.1.4/src/lgc.h b/lib/lua/src/lgc.h index 5a8dc605b..5a8dc605b 100644 --- a/lua-5.1.4/src/lgc.h +++ b/lib/lua/src/lgc.h diff --git a/lua-5.1.4/src/linit.c b/lib/lua/src/linit.c index c1f90dfab..c1f90dfab 100644 --- a/lua-5.1.4/src/linit.c +++ b/lib/lua/src/linit.c diff --git a/lua-5.1.4/src/liolib.c b/lib/lua/src/liolib.c index e79ed1cb2..e79ed1cb2 100644 --- a/lua-5.1.4/src/liolib.c +++ b/lib/lua/src/liolib.c diff --git a/lua-5.1.4/src/llex.c b/lib/lua/src/llex.c index 02849fa8f..02849fa8f 100644 --- a/lua-5.1.4/src/llex.c +++ b/lib/lua/src/llex.c diff --git a/lua-5.1.4/src/llex.h b/lib/lua/src/llex.h index a9201cee4..a9201cee4 100644 --- a/lua-5.1.4/src/llex.h +++ b/lib/lua/src/llex.h diff --git a/lua-5.1.4/src/llimits.h b/lib/lua/src/llimits.h index ca8dcb722..ca8dcb722 100644 --- a/lua-5.1.4/src/llimits.h +++ b/lib/lua/src/llimits.h diff --git a/lua-5.1.4/src/lmathlib.c b/lib/lua/src/lmathlib.c index 441fbf736..441fbf736 100644 --- a/lua-5.1.4/src/lmathlib.c +++ b/lib/lua/src/lmathlib.c diff --git a/lua-5.1.4/src/lmem.c b/lib/lua/src/lmem.c index ae7d8c965..ae7d8c965 100644 --- a/lua-5.1.4/src/lmem.c +++ b/lib/lua/src/lmem.c diff --git a/lua-5.1.4/src/lmem.h b/lib/lua/src/lmem.h index 7c2dcb322..7c2dcb322 100644 --- a/lua-5.1.4/src/lmem.h +++ b/lib/lua/src/lmem.h diff --git a/lua-5.1.4/src/loadlib.c b/lib/lua/src/loadlib.c index 0d401eba1..0d401eba1 100644 --- a/lua-5.1.4/src/loadlib.c +++ b/lib/lua/src/loadlib.c diff --git a/lua-5.1.4/src/lobject.c b/lib/lua/src/lobject.c index 4ff50732a..4ff50732a 100644 --- a/lua-5.1.4/src/lobject.c +++ b/lib/lua/src/lobject.c diff --git a/lua-5.1.4/src/lobject.h b/lib/lua/src/lobject.h index f1e447ef3..f1e447ef3 100644 --- a/lua-5.1.4/src/lobject.h +++ b/lib/lua/src/lobject.h diff --git a/lua-5.1.4/src/lopcodes.c b/lib/lua/src/lopcodes.c index 4cc745230..4cc745230 100644 --- a/lua-5.1.4/src/lopcodes.c +++ b/lib/lua/src/lopcodes.c diff --git a/lua-5.1.4/src/lopcodes.h b/lib/lua/src/lopcodes.h index 41224d6ee..41224d6ee 100644 --- a/lua-5.1.4/src/lopcodes.h +++ b/lib/lua/src/lopcodes.h diff --git a/lua-5.1.4/src/loslib.c b/lib/lua/src/loslib.c index da06a572a..da06a572a 100644 --- a/lua-5.1.4/src/loslib.c +++ b/lib/lua/src/loslib.c diff --git a/lua-5.1.4/src/lparser.c b/lib/lua/src/lparser.c index 1e2a9a88b..1e2a9a88b 100644 --- a/lua-5.1.4/src/lparser.c +++ b/lib/lua/src/lparser.c diff --git a/lua-5.1.4/src/lparser.h b/lib/lua/src/lparser.h index 18836afd1..18836afd1 100644 --- a/lua-5.1.4/src/lparser.h +++ b/lib/lua/src/lparser.h diff --git a/lua-5.1.4/src/lstate.c b/lib/lua/src/lstate.c index 4313b83a0..4313b83a0 100644 --- a/lua-5.1.4/src/lstate.c +++ b/lib/lua/src/lstate.c diff --git a/lua-5.1.4/src/lstate.h b/lib/lua/src/lstate.h index 3bc575b6b..3bc575b6b 100644 --- a/lua-5.1.4/src/lstate.h +++ b/lib/lua/src/lstate.h diff --git a/lua-5.1.4/src/lstring.c b/lib/lua/src/lstring.c index 49113151c..49113151c 100644 --- a/lua-5.1.4/src/lstring.c +++ b/lib/lua/src/lstring.c diff --git a/lua-5.1.4/src/lstring.h b/lib/lua/src/lstring.h index 73a2ff8b3..73a2ff8b3 100644 --- a/lua-5.1.4/src/lstring.h +++ b/lib/lua/src/lstring.h diff --git a/lua-5.1.4/src/lstrlib.c b/lib/lua/src/lstrlib.c index 1b4763d4e..1b4763d4e 100644 --- a/lua-5.1.4/src/lstrlib.c +++ b/lib/lua/src/lstrlib.c diff --git a/lua-5.1.4/src/ltable.c b/lib/lua/src/ltable.c index ec84f4fab..ec84f4fab 100644 --- a/lua-5.1.4/src/ltable.c +++ b/lib/lua/src/ltable.c diff --git a/lua-5.1.4/src/ltable.h b/lib/lua/src/ltable.h index f5b9d5ead..f5b9d5ead 100644 --- a/lua-5.1.4/src/ltable.h +++ b/lib/lua/src/ltable.h diff --git a/lua-5.1.4/src/ltablib.c b/lib/lua/src/ltablib.c index b6d9cb4ac..b6d9cb4ac 100644 --- a/lua-5.1.4/src/ltablib.c +++ b/lib/lua/src/ltablib.c diff --git a/lua-5.1.4/src/ltm.c b/lib/lua/src/ltm.c index c27f0f6fa..c27f0f6fa 100644 --- a/lua-5.1.4/src/ltm.c +++ b/lib/lua/src/ltm.c diff --git a/lua-5.1.4/src/ltm.h b/lib/lua/src/ltm.h index 64343b781..64343b781 100644 --- a/lua-5.1.4/src/ltm.h +++ b/lib/lua/src/ltm.h diff --git a/lua-5.1.4/src/lua.c b/lib/lua/src/lua.c index 3a4660932..3a4660932 100644 --- a/lua-5.1.4/src/lua.c +++ b/lib/lua/src/lua.c diff --git a/lua-5.1.4/src/lua.h b/lib/lua/src/lua.h index 1f8513667..1f8513667 100644 --- a/lua-5.1.4/src/lua.h +++ b/lib/lua/src/lua.h diff --git a/lua-5.1.4/src/luac.c b/lib/lua/src/luac.c index 487715433..487715433 100644 --- a/lua-5.1.4/src/luac.c +++ b/lib/lua/src/luac.c diff --git a/lua-5.1.4/src/luaconf.h b/lib/lua/src/luaconf.h index e2cb26163..e2cb26163 100644 --- a/lua-5.1.4/src/luaconf.h +++ b/lib/lua/src/luaconf.h diff --git a/lua-5.1.4/src/lualib.h b/lib/lua/src/lualib.h index 469417f67..469417f67 100644 --- a/lua-5.1.4/src/lualib.h +++ b/lib/lua/src/lualib.h diff --git a/lua-5.1.4/src/lundump.c b/lib/lua/src/lundump.c index 8010a4579..8010a4579 100644 --- a/lua-5.1.4/src/lundump.c +++ b/lib/lua/src/lundump.c diff --git a/lua-5.1.4/src/lundump.h b/lib/lua/src/lundump.h index c80189dbf..c80189dbf 100644 --- a/lua-5.1.4/src/lundump.h +++ b/lib/lua/src/lundump.h diff --git a/lua-5.1.4/src/lvm.c b/lib/lua/src/lvm.c index ee3256ab9..ee3256ab9 100644 --- a/lua-5.1.4/src/lvm.c +++ b/lib/lua/src/lvm.c diff --git a/lua-5.1.4/src/lvm.h b/lib/lua/src/lvm.h index bfe4f5678..bfe4f5678 100644 --- a/lua-5.1.4/src/lvm.h +++ b/lib/lua/src/lvm.h diff --git a/lua-5.1.4/src/lzio.c b/lib/lua/src/lzio.c index 293edd59b..293edd59b 100644 --- a/lua-5.1.4/src/lzio.c +++ b/lib/lua/src/lzio.c diff --git a/lua-5.1.4/src/lzio.h b/lib/lua/src/lzio.h index 51d695d8c..51d695d8c 100644 --- a/lua-5.1.4/src/lzio.h +++ b/lib/lua/src/lzio.h diff --git a/lua-5.1.4/src/print.c b/lib/lua/src/print.c index e240cfc3c..e240cfc3c 100644 --- a/lua-5.1.4/src/print.c +++ b/lib/lua/src/print.c diff --git a/lib/luaexpat/lxplib.c b/lib/luaexpat/lxplib.c new file mode 100644 index 000000000..1a36104a8 --- /dev/null +++ b/lib/luaexpat/lxplib.c @@ -0,0 +1,599 @@ +/* +** $Id: lxplib.c,v 1.16 2007/06/05 20:03:12 carregal Exp $ +** LuaExpat: Lua bind for Expat library +** See Copyright Notice in license.html +*/ + + +#include <assert.h> +#include <stdlib.h> +#include <string.h> + +#include "expat/expat.h" + +#include "lua/src/lua.h" +#include "lua/src/lauxlib.h" + + +#include "lxplib.h" + + +#if !defined(lua_pushliteral) +#define lua_pushliteral(L, s) \ + lua_pushstring(L, "" s, (sizeof(s)/sizeof(char))-1) +#endif + + +enum XPState { + XPSpre, /* parser just initialized */ + XPSok, /* state while parsing */ + XPSfinished, /* state after finished parsing */ + XPSerror, + XPSstring /* state while reading a string */ +}; + +struct lxp_userdata { + lua_State *L; + XML_Parser parser; /* associated expat parser */ + int tableref; /* table with callbacks for this parser */ + enum XPState state; + luaL_Buffer *b; /* to concatenate sequences of cdata pieces */ +}; + +typedef struct lxp_userdata lxp_userdata; + + +static int reporterror (lxp_userdata *xpu) { + lua_State *L = xpu->L; + XML_Parser p = xpu->parser; + lua_pushnil(L); + lua_pushstring(L, XML_ErrorString(XML_GetErrorCode(p))); + lua_pushnumber(L, XML_GetCurrentLineNumber(p)); + lua_pushnumber(L, XML_GetCurrentColumnNumber(p) + 1); + lua_pushnumber(L, XML_GetCurrentByteIndex(p) + 1); + return 5; +} + + +static lxp_userdata *createlxp (lua_State *L) { + lxp_userdata *xpu = (lxp_userdata *)lua_newuserdata(L, sizeof(lxp_userdata)); + xpu->tableref = LUA_REFNIL; /* in case of errors... */ + xpu->parser = NULL; + xpu->L = NULL; + xpu->state = XPSpre; + luaL_getmetatable(L, ParserType); + lua_setmetatable(L, -2); + return xpu; +} + + +static void lxpclose (lua_State *L, lxp_userdata *xpu) { + luaL_unref(L, LUA_REGISTRYINDEX, xpu->tableref); + xpu->tableref = LUA_REFNIL; + if (xpu->parser) + XML_ParserFree(xpu->parser); + xpu->parser = NULL; +} + + + + +/* +** Auxiliary function to call a Lua handle +*/ +static void docall (lxp_userdata *xpu, int nargs, int nres) { + lua_State *L = xpu->L; + assert(xpu->state == XPSok); + if (lua_pcall(L, nargs + 1, nres, 0) != 0) { + xpu->state = XPSerror; + luaL_unref(L, LUA_REGISTRYINDEX, xpu->tableref); + xpu->tableref = luaL_ref(L, LUA_REGISTRYINDEX); /* error message */ + } +} + + +/* +** Check whether there is pending Cdata, and call its handle if necessary +*/ +static void dischargestring (lxp_userdata *xpu) { + assert(xpu->state == XPSstring); + xpu->state = XPSok; + luaL_pushresult(xpu->b); + docall(xpu, 1, 0); +} + + +/* +** Check whether there is a Lua handle for a given event: If so, +** put it on the stack (to be called later), and also push `self' +*/ +static int getHandle (lxp_userdata *xpu, const char *handle) { + lua_State *L = xpu->L; + if (xpu->state == XPSstring) dischargestring(xpu); + if (xpu->state == XPSerror) + return 0; /* some error happened before; skip all handles */ + lua_pushstring(L, handle); + lua_gettable(L, 3); + if (lua_toboolean(L, -1) == 0) { + lua_pop(L, 1); + return 0; + } + if (!lua_isfunction(L, -1)) { + luaL_error(L, "lxp `%s' callback is not a function", handle); + } + lua_pushvalue(L, 1); /* first argument in every call (self) */ + return 1; +} + + + +/* +** {====================================================== +** Handles +** ======================================================= +*/ + + +static void f_StartCdata (void *ud) { + lxp_userdata *xpu = (lxp_userdata *)ud; + if (getHandle(xpu, StartCdataKey) == 0) return; /* no handle */ + docall(xpu, 0, 0); +} + + +static void f_EndCdataKey (void *ud) { + lxp_userdata *xpu = (lxp_userdata *)ud; + if (getHandle(xpu, EndCdataKey) == 0) return; /* no handle */ + docall(xpu, 0, 0); +} + + +static void f_CharData (void *ud, const char *s, int len) { + lxp_userdata *xpu = (lxp_userdata *)ud; + if (xpu->state == XPSok) { + if (getHandle(xpu, CharDataKey) == 0) return; /* no handle */ + xpu->state = XPSstring; + luaL_buffinit(xpu->L, xpu->b); + } + if (xpu->state == XPSstring) + luaL_addlstring(xpu->b, s, len); +} + + +static void f_Comment (void *ud, const char *data) { + lxp_userdata *xpu = (lxp_userdata *)ud; + if (getHandle(xpu, CommentKey) == 0) return; /* no handle */ + lua_pushstring(xpu->L, data); + docall(xpu, 1, 0); +} + + +static void f_Default (void *ud, const char *data, int len) { + lxp_userdata *xpu = (lxp_userdata *)ud; + if (getHandle(xpu, DefaultKey) == 0) return; /* no handle */ + lua_pushlstring(xpu->L, data, len); + docall(xpu, 1, 0); +} + + +static void f_DefaultExpand (void *ud, const char *data, int len) { + lxp_userdata *xpu = (lxp_userdata *)ud; + if (getHandle(xpu, DefaultExpandKey) == 0) return; /* no handle */ + lua_pushlstring(xpu->L, data, len); + docall(xpu, 1, 0); +} + + +static void f_StartElement (void *ud, const char *name, const char **attrs) { + lxp_userdata *xpu = (lxp_userdata *)ud; + lua_State *L = xpu->L; + int lastspec = XML_GetSpecifiedAttributeCount(xpu->parser) / 2; + int i = 1; + if (getHandle(xpu, StartElementKey) == 0) return; /* no handle */ + lua_pushstring(L, name); + lua_newtable(L); + while (*attrs) { + if (i <= lastspec) { + lua_pushnumber(L, i++); + lua_pushstring(L, *attrs); + lua_settable(L, -3); + } + lua_pushstring(L, *attrs++); + lua_pushstring(L, *attrs++); + lua_settable(L, -3); + } + docall(xpu, 2, 0); /* call function with self, name, and attributes */ +} + + +static void f_EndElement (void *ud, const char *name) { + lxp_userdata *xpu = (lxp_userdata *)ud; + if (getHandle(xpu, EndElementKey) == 0) return; /* no handle */ + lua_pushstring(xpu->L, name); + docall(xpu, 1, 0); +} + + +static int f_ExternaEntity (XML_Parser p, const char *context, + const char *base, + const char *systemId, + const char *publicId) { + lxp_userdata *xpu = (lxp_userdata *)XML_GetUserData(p); + lua_State *L = xpu->L; + lxp_userdata *child; + int status; + if (getHandle(xpu, ExternalEntityKey) == 0) return 1; /* no handle */ + child = createlxp(L); + child->parser = XML_ExternalEntityParserCreate(p, context, NULL); + if (!child->parser) + luaL_error(L, "XML_ParserCreate failed"); + lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /*lua_getref(L, xpu->tableref); */ /* child uses the same table of its father */ + child->tableref = luaL_ref(L, LUA_REGISTRYINDEX); + lua_pushstring(L, base); + lua_pushstring(L, systemId); + lua_pushstring(L, publicId); + docall(xpu, 4, 1); + status = lua_toboolean(L, -1); + lua_pop(L, 1); + lxpclose(L, child); + return status; +} + + +static void f_StartNamespaceDecl (void *ud, const char *prefix, + const char *uri) { + lxp_userdata *xpu = (lxp_userdata *)ud; + lua_State *L = xpu->L; + if (getHandle(xpu, StartNamespaceDeclKey) == 0) return; /* no handle */ + lua_pushstring(L, prefix); + lua_pushstring(L, uri); + docall(xpu, 2, 0); +} + + +static void f_EndNamespaceDecl (void *ud, const char *prefix) { + lxp_userdata *xpu = (lxp_userdata *)ud; + if (getHandle(xpu, EndNamespaceDeclKey) == 0) return; /* no handle */ + lua_pushstring(xpu->L, prefix); + docall(xpu, 1, 0); +} + + +static void f_NotationDecl (void *ud, const char *notationName, + const char *base, + const char *systemId, + const char *publicId) { + lxp_userdata *xpu = (lxp_userdata *)ud; + lua_State *L = xpu->L; + if (getHandle(xpu, NotationDeclKey) == 0) return; /* no handle */ + lua_pushstring(L, notationName); + lua_pushstring(L, base); + lua_pushstring(L, systemId); + lua_pushstring(L, publicId); + docall(xpu, 4, 0); +} + + +static int f_NotStandalone (void *ud) { + int status; + lxp_userdata *xpu = (lxp_userdata *)ud; + lua_State *L = xpu->L; + if (getHandle(xpu, NotStandaloneKey) == 0) return 1; /* no handle */ + docall(xpu, 0, 1); + status = lua_toboolean(L, -1); + lua_pop(L, 1); + return status; +} + + +static void f_ProcessingInstruction (void *ud, const char *target, + const char *data) { + lxp_userdata *xpu = (lxp_userdata *)ud; + lua_State *L = xpu->L; + if (getHandle(xpu, ProcessingInstructionKey) == 0) return; /* no handle */ + lua_pushstring(L, target); + lua_pushstring(L, data); + docall(xpu, 2, 0); +} + + +static void f_UnparsedEntityDecl (void *ud, const char *entityName, + const char *base, + const char *systemId, + const char *publicId, + const char *notationName) { + lxp_userdata *xpu = (lxp_userdata *)ud; + lua_State *L = xpu->L; + if (getHandle(xpu, UnparsedEntityDeclKey) == 0) return; /* no handle */ + lua_pushstring(L, entityName); + lua_pushstring(L, base); + lua_pushstring(L, systemId); + lua_pushstring(L, publicId); + lua_pushstring(L, notationName); + docall(xpu, 5, 0); +} + +static void f_StartDoctypeDecl (void *ud, const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid, + int has_internal_subset) { + lxp_userdata *xpu = (lxp_userdata *)ud; + if (getHandle(xpu, StartDoctypeDeclKey) == 0) return; /* no handle */ + lua_pushstring(xpu->L, doctypeName); + lua_pushstring(xpu->L, sysid); + lua_pushstring(xpu->L, pubid); + lua_pushboolean(xpu->L, has_internal_subset); + docall(xpu, 4, 0); +} + +/* }====================================================== */ + + + +static int hasfield (lua_State *L, const char *fname) { + int res; + lua_pushstring(L, fname); + lua_gettable(L, 1); + res = !lua_isnil(L, -1); + lua_pop(L, 1); + return res; +} + + +static void checkcallbacks (lua_State *L) { + static const char *const validkeys[] = { + "StartCdataSection", "EndCdataSection", "CharacterData", "Comment", + "Default", "DefaultExpand", "StartElement", "EndElement", + "ExternalEntityRef", "StartNamespaceDecl", "EndNamespaceDecl", + "NotationDecl", "NotStandalone", "ProcessingInstruction", + "UnparsedEntityDecl", "StartDoctypeDecl", NULL}; + if (hasfield(L, "_nonstrict")) return; + lua_pushnil(L); + while (lua_next(L, 1)) { + lua_pop(L, 1); /* remove value */ +#if ! defined (LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 + if (lua_type(L, -1) != LUA_TSTRING || + luaL_findstring(lua_tostring(L, -1), validkeys) < 0) + luaL_error(L, "invalid key `%s' in callback table", lua_tostring(L, -1)); +#else + luaL_checkoption(L, -1, NULL, validkeys); +#endif + } +} + + +static int lxp_make_parser (lua_State *L) { + XML_Parser p; + char sep = *luaL_optstring(L, 2, ""); + lxp_userdata *xpu = createlxp(L); + p = xpu->parser = (sep == '\0') ? XML_ParserCreate(NULL) : + XML_ParserCreateNS(NULL, sep); + if (!p) + luaL_error(L, "XML_ParserCreate failed"); + luaL_checktype(L, 1, LUA_TTABLE); + checkcallbacks(L); + lua_pushvalue(L, 1); + xpu->tableref = luaL_ref(L, LUA_REGISTRYINDEX); + XML_SetUserData(p, xpu); + if (hasfield(L, StartCdataKey) || hasfield(L, EndCdataKey)) + XML_SetCdataSectionHandler(p, f_StartCdata, f_EndCdataKey); + if (hasfield(L, CharDataKey)) + XML_SetCharacterDataHandler(p, f_CharData); + if (hasfield(L, CommentKey)) + XML_SetCommentHandler(p, f_Comment); + if (hasfield(L, DefaultKey)) + XML_SetDefaultHandler(p, f_Default); + if (hasfield(L, DefaultExpandKey)) + XML_SetDefaultHandlerExpand(p, f_DefaultExpand); + if (hasfield(L, StartElementKey) || hasfield(L, EndElementKey)) + XML_SetElementHandler(p, f_StartElement, f_EndElement); + if (hasfield(L, ExternalEntityKey)) + XML_SetExternalEntityRefHandler(p, f_ExternaEntity); + if (hasfield(L, StartNamespaceDeclKey) || hasfield(L, EndNamespaceDeclKey)) + XML_SetNamespaceDeclHandler(p, f_StartNamespaceDecl, f_EndNamespaceDecl); + if (hasfield(L, NotationDeclKey)) + XML_SetNotationDeclHandler(p, f_NotationDecl); + if (hasfield(L, NotStandaloneKey)) + XML_SetNotStandaloneHandler(p, f_NotStandalone); + if (hasfield(L, ProcessingInstructionKey)) + XML_SetProcessingInstructionHandler(p, f_ProcessingInstruction); + if (hasfield(L, UnparsedEntityDeclKey)) + XML_SetUnparsedEntityDeclHandler(p, f_UnparsedEntityDecl); + if (hasfield(L, StartDoctypeDeclKey)) + XML_SetStartDoctypeDeclHandler(p, f_StartDoctypeDecl); + return 1; +} + + +static lxp_userdata *checkparser (lua_State *L, int idx) { + lxp_userdata *xpu = (lxp_userdata *)luaL_checkudata(L, idx, ParserType); + luaL_argcheck(L, xpu, idx, "expat parser expected"); + luaL_argcheck(L, xpu->parser, idx, "parser is closed"); + return xpu; +} + + +static int parser_gc (lua_State *L) { + lxp_userdata *xpu = (lxp_userdata *)luaL_checkudata(L, 1, ParserType); + luaL_argcheck(L, xpu, 1, "expat parser expected"); + lxpclose(L, xpu); + return 0; +} + + +static int setbase (lua_State *L) { + lxp_userdata *xpu = checkparser(L, 1); + if (XML_SetBase(xpu->parser, luaL_checkstring(L, 2)) == 0) + luaL_error(L, "no memory to store base"); + return 0; +} + + +static int getbase (lua_State *L) { + lxp_userdata *xpu = checkparser(L, 1); + lua_pushstring(L, XML_GetBase(xpu->parser)); + return 1; +} + + +static int getcallbacks (lua_State *L) { + lxp_userdata *xpu = checkparser(L, 1); + lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); + return 1; +} + + +static int parse_aux (lua_State *L, lxp_userdata *xpu, const char *s, + size_t len) { + luaL_Buffer b; + int status; + xpu->L = L; + xpu->state = XPSok; + xpu->b = &b; + lua_settop(L, 2); + lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /*lua_getref(L, xpu->tableref);*/ /* to be used by handlers */ + status = XML_Parse(xpu->parser, s, (int)len, s == NULL); + if (xpu->state == XPSstring) dischargestring(xpu); + if (xpu->state == XPSerror) { /* callback error? */ + lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /* get original msg. */ + lua_error(L); + } + if (s == NULL) xpu->state = XPSfinished; + if (status) { + lua_pushboolean(L, 1); + return 1; + } + else { /* error */ + return reporterror(xpu); + } +} + + +static int lxp_parse (lua_State *L) { + lxp_userdata *xpu = checkparser(L, 1); + size_t len; + const char *s = luaL_optlstring(L, 2, NULL, &len); + if (xpu->state == XPSfinished && s != NULL) { + lua_pushnil(L); + lua_pushliteral(L, "cannot parse - document is finished"); + return 2; + } + return parse_aux(L, xpu, s, len); +} + + +static int lxp_close (lua_State *L) { + int status = 1; + lxp_userdata *xpu = (lxp_userdata *)luaL_checkudata(L, 1, ParserType); + luaL_argcheck(L, xpu, 1, "expat parser expected"); + if (xpu->state != XPSfinished) + status = parse_aux(L, xpu, NULL, 0); + lxpclose(L, xpu); + if (status > 1) luaL_error(L, "error closing parser: %s", + lua_tostring(L, -status+1)); + return 0; +} + + +static int lxp_pos (lua_State *L) { + lxp_userdata *xpu = checkparser(L, 1); + XML_Parser p = xpu->parser; + lua_pushnumber(L, XML_GetCurrentLineNumber(p)); + lua_pushnumber(L, XML_GetCurrentColumnNumber(p) + 1); + lua_pushnumber(L, XML_GetCurrentByteIndex(p) + 1); + return 3; +} + + +static int lxp_setencoding (lua_State *L) { + lxp_userdata *xpu = checkparser(L, 1); + const char *encoding = luaL_checkstring(L, 2); + luaL_argcheck(L, xpu->state == XPSpre, 1, "invalid parser state"); + XML_SetEncoding(xpu->parser, encoding); + return 0; +} + +static int lxp_stop (lua_State *L) { + lxp_userdata *xpu = checkparser(L, 1); + lua_pushboolean(L, XML_StopParser(xpu->parser, XML_FALSE) == XML_STATUS_OK); + return 1; +} + +#if !defined LUA_VERSION_NUM +/* Lua 5.0 */ +#define luaL_Reg luaL_reg +#endif + +static const struct luaL_Reg lxp_meths[] = { + {"parse", lxp_parse}, + {"close", lxp_close}, + {"__gc", parser_gc}, + {"pos", lxp_pos}, + {"setencoding", lxp_setencoding}, + {"getcallbacks", getcallbacks}, + {"getbase", getbase}, + {"setbase", setbase}, + {"stop", lxp_stop}, + {NULL, NULL} +}; + +static const struct luaL_Reg lxp_funcs[] = { + {"new", lxp_make_parser}, + {NULL, NULL} +}; + + +/* +** Assumes the table is on top of the stack. +*/ +static void set_info (lua_State *L) { + lua_pushliteral (L, "_COPYRIGHT"); + lua_pushliteral (L, "Copyright (C) 2003-2012 Kepler Project"); + lua_settable (L, -3); + lua_pushliteral (L, "_DESCRIPTION"); + lua_pushliteral (L, "LuaExpat is a SAX XML parser based on the Expat library"); + lua_settable (L, -3); + lua_pushliteral (L, "_VERSION"); + lua_pushliteral (L, "LuaExpat 1.3.0"); + lua_settable (L, -3); +} + + +#if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501 +/* +** Adapted from Lua 5.2.0 +*/ +static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { + luaL_checkstack(L, nup, "too many upvalues"); + for (; l->name != NULL; l++) { /* fill the table with given functions */ + int i; + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -nup); + lua_pushstring(L, l->name); + lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + lua_settable(L, -(nup + 3)); + } + lua_pop(L, nup); /* remove upvalues */ +} +#endif + + +int luaopen_lxp (lua_State *L) { + luaL_newmetatable(L, ParserType); + + lua_pushliteral(L, "__index"); + lua_pushvalue(L, -2); + lua_rawset(L, -3); + + luaL_setfuncs (L, lxp_meths, 0); + lua_pop (L, 1); /* remove metatable */ + + // _X 2013_04_09: Modified to allow embedding + luaL_openlib (L, "lxp", lxp_funcs, 0); + /* + lua_newtable (L); + luaL_setfuncs (L, lxp_funcs, 0); + */ + set_info (L); + return 1; +} diff --git a/source/LuaExpat/lxplib.h b/lib/luaexpat/lxplib.h index 9c0be4f78..9c0be4f78 100644 --- a/source/LuaExpat/lxplib.h +++ b/lib/luaexpat/lxplib.h |