diff options
Diffstat (limited to '')
-rw-r--r-- | lib/cryptopp/Doxyfile (renamed from CryptoPP/Doxyfile) | 0 | ||||
-rw-r--r-- | lib/cryptopp/License.txt (renamed from CryptoPP/License.txt) | 0 | ||||
-rw-r--r-- | lib/cryptopp/Readme.txt (renamed from CryptoPP/Readme.txt) | 0 | ||||
-rw-r--r-- | lib/cryptopp/adler32.cpp (renamed from CryptoPP/adler32.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/adler32.h (renamed from CryptoPP/adler32.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/aes.h (renamed from CryptoPP/aes.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/algebra.cpp (renamed from CryptoPP/algebra.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/algebra.h (renamed from CryptoPP/algebra.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/algparam.cpp (renamed from CryptoPP/algparam.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/algparam.h (renamed from CryptoPP/algparam.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/argnames.h (renamed from CryptoPP/argnames.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/asn.cpp (renamed from CryptoPP/asn.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/asn.h (renamed from CryptoPP/asn.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/authenc.cpp (renamed from CryptoPP/authenc.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/authenc.h (renamed from CryptoPP/authenc.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/base32.cpp (renamed from CryptoPP/base32.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/base32.h (renamed from CryptoPP/base32.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/base64.cpp (renamed from CryptoPP/base64.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/base64.h (renamed from CryptoPP/base64.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/basecode.cpp (renamed from CryptoPP/basecode.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/basecode.h (renamed from CryptoPP/basecode.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/cbcmac.cpp (renamed from CryptoPP/cbcmac.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/cbcmac.h (renamed from CryptoPP/cbcmac.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/ccm.cpp (renamed from CryptoPP/ccm.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/ccm.h (renamed from CryptoPP/ccm.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/channels.cpp (renamed from CryptoPP/channels.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/channels.h (renamed from CryptoPP/channels.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/cmac.cpp (renamed from CryptoPP/cmac.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/cmac.h (renamed from CryptoPP/cmac.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/config.h (renamed from CryptoPP/config.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/cpu.cpp (renamed from CryptoPP/cpu.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/cpu.h (renamed from CryptoPP/cpu.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/crc.cpp (renamed from CryptoPP/crc.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/crc.h (renamed from CryptoPP/crc.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/cryptlib.cpp (renamed from CryptoPP/cryptlib.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/cryptlib.h (renamed from CryptoPP/cryptlib.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/default.cpp (renamed from CryptoPP/default.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/default.h (renamed from CryptoPP/default.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/des.cpp (renamed from CryptoPP/des.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/des.h (renamed from CryptoPP/des.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dessp.cpp (renamed from CryptoPP/dessp.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dh.cpp (renamed from CryptoPP/dh.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dh.h (renamed from CryptoPP/dh.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dh2.cpp (renamed from CryptoPP/dh2.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dh2.h (renamed from CryptoPP/dh2.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dll.cpp (renamed from CryptoPP/dll.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dll.h (renamed from CryptoPP/dll.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dmac.h (renamed from CryptoPP/dmac.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dsa.cpp (renamed from CryptoPP/dsa.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/dsa.h (renamed from CryptoPP/dsa.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/eax.cpp (renamed from CryptoPP/eax.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/eax.h (renamed from CryptoPP/eax.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/ec2n.cpp (renamed from CryptoPP/ec2n.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/ec2n.h (renamed from CryptoPP/ec2n.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/eccrypto.cpp (renamed from CryptoPP/eccrypto.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/eccrypto.h (renamed from CryptoPP/eccrypto.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/ecp.cpp (renamed from CryptoPP/ecp.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/ecp.h (renamed from CryptoPP/ecp.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/elgamal.cpp (renamed from CryptoPP/elgamal.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/elgamal.h (renamed from CryptoPP/elgamal.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/emsa2.cpp (renamed from CryptoPP/emsa2.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/emsa2.h (renamed from CryptoPP/emsa2.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/eprecomp.cpp (renamed from CryptoPP/eprecomp.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/eprecomp.h (renamed from CryptoPP/eprecomp.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/esign.cpp (renamed from CryptoPP/esign.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/esign.h (renamed from CryptoPP/esign.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/factory.h (renamed from CryptoPP/factory.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/files.cpp (renamed from CryptoPP/files.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/files.h (renamed from CryptoPP/files.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/filters.cpp (renamed from CryptoPP/filters.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/filters.h (renamed from CryptoPP/filters.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/fips140.cpp (renamed from CryptoPP/fips140.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/fips140.h (renamed from CryptoPP/fips140.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/fltrimpl.h (renamed from CryptoPP/fltrimpl.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gcm.cpp (renamed from CryptoPP/gcm.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gcm.h (renamed from CryptoPP/gcm.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gf256.cpp (renamed from CryptoPP/gf256.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gf256.h (renamed from CryptoPP/gf256.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gf2_32.cpp (renamed from CryptoPP/gf2_32.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gf2_32.h (renamed from CryptoPP/gf2_32.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gf2n.cpp (renamed from CryptoPP/gf2n.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gf2n.h (renamed from CryptoPP/gf2n.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gfpcrypt.cpp (renamed from CryptoPP/gfpcrypt.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gfpcrypt.h (renamed from CryptoPP/gfpcrypt.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/gzip.h (renamed from CryptoPP/gzip.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/hex.cpp (renamed from CryptoPP/hex.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/hex.h (renamed from CryptoPP/hex.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/hmac.cpp (renamed from CryptoPP/hmac.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/hmac.h (renamed from CryptoPP/hmac.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/hrtimer.cpp (renamed from CryptoPP/hrtimer.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/hrtimer.h (renamed from CryptoPP/hrtimer.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/integer.cpp (renamed from CryptoPP/integer.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/integer.h (renamed from CryptoPP/integer.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/iterhash.cpp (renamed from CryptoPP/iterhash.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/iterhash.h (renamed from CryptoPP/iterhash.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/lubyrack.h (renamed from CryptoPP/lubyrack.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/luc.cpp (renamed from CryptoPP/luc.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/luc.h (renamed from CryptoPP/luc.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/md2.cpp (renamed from CryptoPP/md2.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/md2.h (renamed from CryptoPP/md2.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/md4.cpp (renamed from CryptoPP/md4.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/md4.h (renamed from CryptoPP/md4.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/md5.cpp (renamed from CryptoPP/md5.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/md5.h (renamed from CryptoPP/md5.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/mdc.h (renamed from CryptoPP/mdc.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/misc.cpp (renamed from CryptoPP/misc.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/misc.h (renamed from CryptoPP/misc.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/modarith.h (renamed from CryptoPP/modarith.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/modes.cpp (renamed from CryptoPP/modes.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/modes.h (renamed from CryptoPP/modes.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/modexppc.h (renamed from CryptoPP/modexppc.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/mqueue.cpp (renamed from CryptoPP/mqueue.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/mqueue.h (renamed from CryptoPP/mqueue.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/mqv.cpp (renamed from CryptoPP/mqv.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/mqv.h (renamed from CryptoPP/mqv.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/nbtheory.cpp (renamed from CryptoPP/nbtheory.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/nbtheory.h (renamed from CryptoPP/nbtheory.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/network.cpp (renamed from CryptoPP/network.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/network.h (renamed from CryptoPP/network.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/nr.h (renamed from CryptoPP/nr.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/oaep.cpp (renamed from CryptoPP/oaep.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/oaep.h (renamed from CryptoPP/oaep.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/oids.h (renamed from CryptoPP/oids.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/osrng.cpp (renamed from CryptoPP/osrng.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/osrng.h (renamed from CryptoPP/osrng.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/pch.cpp (renamed from CryptoPP/pch.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/pch.h (renamed from CryptoPP/pch.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/pkcspad.cpp (renamed from CryptoPP/pkcspad.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/pkcspad.h (renamed from CryptoPP/pkcspad.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/polynomi.cpp (renamed from CryptoPP/polynomi.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/polynomi.h (renamed from CryptoPP/polynomi.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/pssr.cpp (renamed from CryptoPP/pssr.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/pssr.h (renamed from CryptoPP/pssr.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/pubkey.cpp (renamed from CryptoPP/pubkey.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/pubkey.h (renamed from CryptoPP/pubkey.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/pwdbased.h (renamed from CryptoPP/pwdbased.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/queue.cpp (renamed from CryptoPP/queue.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/queue.h (renamed from CryptoPP/queue.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rabin.cpp (renamed from CryptoPP/rabin.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rabin.h (renamed from CryptoPP/rabin.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/randpool.cpp (renamed from CryptoPP/randpool.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/randpool.h (renamed from CryptoPP/randpool.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rdtables.cpp (renamed from CryptoPP/rdtables.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/resource.h (renamed from CryptoPP/resource.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rijndael.cpp (renamed from CryptoPP/rijndael.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rijndael.h (renamed from CryptoPP/rijndael.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rng.cpp (renamed from CryptoPP/rng.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rng.h (renamed from CryptoPP/rng.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rsa.cpp (renamed from CryptoPP/rsa.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rsa.h (renamed from CryptoPP/rsa.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rw.cpp (renamed from CryptoPP/rw.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/rw.h (renamed from CryptoPP/rw.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/safer.cpp (renamed from CryptoPP/safer.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/safer.h (renamed from CryptoPP/safer.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/seal.cpp (renamed from CryptoPP/seal.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/seal.h (renamed from CryptoPP/seal.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/secblock.h (renamed from CryptoPP/secblock.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/seckey.h (renamed from CryptoPP/seckey.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/seed.cpp (renamed from CryptoPP/seed.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/seed.h (renamed from CryptoPP/seed.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/sha.cpp (renamed from CryptoPP/sha.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/sha.h (renamed from CryptoPP/sha.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/shacal2.cpp (renamed from CryptoPP/shacal2.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/shacal2.h (renamed from CryptoPP/shacal2.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/simple.cpp (renamed from CryptoPP/simple.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/simple.h (renamed from CryptoPP/simple.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/smartptr.h (renamed from CryptoPP/smartptr.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/socketft.cpp (renamed from CryptoPP/socketft.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/socketft.h (renamed from CryptoPP/socketft.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/square.cpp (renamed from CryptoPP/square.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/square.h (renamed from CryptoPP/square.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/squaretb.cpp (renamed from CryptoPP/squaretb.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/stdcpp.h (renamed from CryptoPP/stdcpp.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/strciphr.cpp (renamed from CryptoPP/strciphr.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/strciphr.h (renamed from CryptoPP/strciphr.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/tea.cpp (renamed from CryptoPP/tea.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/tea.h (renamed from CryptoPP/tea.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/tiger.cpp (renamed from CryptoPP/tiger.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/tiger.h (renamed from CryptoPP/tiger.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/tigertab.cpp (renamed from CryptoPP/tigertab.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/trdlocal.cpp (renamed from CryptoPP/trdlocal.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/trdlocal.h (renamed from CryptoPP/trdlocal.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/trunhash.h (renamed from CryptoPP/trunhash.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/ttmac.cpp (renamed from CryptoPP/ttmac.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/ttmac.h (renamed from CryptoPP/ttmac.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/validate.h (renamed from CryptoPP/validate.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/vmac.cpp (renamed from CryptoPP/vmac.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/vmac.h (renamed from CryptoPP/vmac.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/wait.cpp (renamed from CryptoPP/wait.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/wait.h (renamed from CryptoPP/wait.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/winpipes.cpp (renamed from CryptoPP/winpipes.cpp) | 0 | ||||
-rw-r--r-- | lib/cryptopp/winpipes.h (renamed from CryptoPP/winpipes.h) | 0 | ||||
-rw-r--r-- | lib/cryptopp/words.h (renamed from CryptoPP/words.h) | 0 | ||||
-rw-r--r-- | lib/expat/ascii.h (renamed from expat/ascii.h) | 0 | ||||
-rw-r--r-- | lib/expat/asciitab.h (renamed from expat/asciitab.h) | 0 | ||||
-rw-r--r-- | lib/expat/expat.h (renamed from expat/expat.h) | 0 | ||||
-rw-r--r-- | lib/expat/expat_external.h (renamed from expat/expat_external.h) | 0 | ||||
-rw-r--r-- | lib/expat/iasciitab.h (renamed from expat/iasciitab.h) | 0 | ||||
-rw-r--r-- | lib/expat/internal.h (renamed from expat/internal.h) | 0 | ||||
-rw-r--r-- | lib/expat/latin1tab.h (renamed from expat/latin1tab.h) | 0 | ||||
-rw-r--r-- | lib/expat/nametab.h (renamed from expat/nametab.h) | 0 | ||||
-rw-r--r-- | lib/expat/utf8tab.h (renamed from expat/utf8tab.h) | 0 | ||||
-rw-r--r-- | lib/expat/winconfig.h (renamed from expat/winconfig.h) | 0 | ||||
-rw-r--r-- | lib/expat/xmlparse.c (renamed from expat/xmlparse.c) | 0 | ||||
-rw-r--r-- | lib/expat/xmlrole.c (renamed from expat/xmlrole.c) | 0 | ||||
-rw-r--r-- | lib/expat/xmlrole.h (renamed from expat/xmlrole.h) | 0 | ||||
-rw-r--r-- | lib/expat/xmltok.c (renamed from expat/xmltok.c) | 0 | ||||
-rw-r--r-- | lib/expat/xmltok.h (renamed from expat/xmltok.h) | 0 | ||||
-rw-r--r-- | lib/expat/xmltok_impl.c (renamed from expat/xmltok_impl.c) | 0 | ||||
-rw-r--r-- | lib/expat/xmltok_impl.h (renamed from expat/xmltok_impl.h) | 0 | ||||
-rw-r--r-- | lib/expat/xmltok_ns.c (renamed from expat/xmltok_ns.c) | 0 | ||||
-rw-r--r-- | lib/inifile/iniFile.cpp (renamed from iniFile/iniFile.cpp) | 0 | ||||
-rw-r--r-- | lib/inifile/iniFile.h (renamed from iniFile/iniFile.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/include/json/autolink.h (renamed from jsoncpp-src-0.5.0/include/json/autolink.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/include/json/config.h (renamed from jsoncpp-src-0.5.0/include/json/config.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/include/json/features.h (renamed from jsoncpp-src-0.5.0/include/json/features.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/include/json/forwards.h (renamed from jsoncpp-src-0.5.0/include/json/forwards.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/include/json/json.h (renamed from jsoncpp-src-0.5.0/include/json/json.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/include/json/reader.h (renamed from jsoncpp-src-0.5.0/include/json/reader.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/include/json/value.h (renamed from jsoncpp-src-0.5.0/include/json/value.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/include/json/writer.h (renamed from jsoncpp-src-0.5.0/include/json/writer.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/src/lib_json/json_batchallocator.h (renamed from jsoncpp-src-0.5.0/src/lib_json/json_batchallocator.h) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/src/lib_json/json_internalarray.inl (renamed from jsoncpp-src-0.5.0/src/lib_json/json_internalarray.inl) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/src/lib_json/json_internalmap.inl (renamed from jsoncpp-src-0.5.0/src/lib_json/json_internalmap.inl) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/src/lib_json/json_reader.cpp | 885 | ||||
-rw-r--r-- | lib/jsoncpp/src/lib_json/json_value.cpp | 1727 | ||||
-rw-r--r-- | lib/jsoncpp/src/lib_json/json_valueiterator.inl (renamed from jsoncpp-src-0.5.0/src/lib_json/json_valueiterator.inl) | 0 | ||||
-rw-r--r-- | lib/jsoncpp/src/lib_json/json_writer.cpp | 829 | ||||
-rw-r--r-- | lib/jsoncpp/src/lib_json/sconscript (renamed from jsoncpp-src-0.5.0/src/lib_json/sconscript) | 0 | ||||
-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 | ||||
-rw-r--r-- | lib/md5/md5.cpp (renamed from source/md5/md5.cpp) | 0 | ||||
-rw-r--r-- | lib/md5/md5.h (renamed from source/md5/md5.h) | 0 | ||||
-rw-r--r-- | lib/sqlite/lsqlite3.c | 2175 | ||||
-rw-r--r-- | lib/sqlite/sqlite3.c (renamed from source/SQLite/sqlite3.c) | 0 | ||||
-rw-r--r-- | lib/sqlite/sqlite3.h (renamed from source/SQLite/sqlite3.h) | 0 | ||||
-rw-r--r-- | lib/sqlite/urls.txt (renamed from source/SQLite/urls.txt) | 0 | ||||
-rw-r--r-- | lib/tolua++/COPYRIGHT (renamed from tolua++-1.0.93/COPYRIGHT) | 0 | ||||
-rw-r--r-- | lib/tolua++/INSTALL (renamed from tolua++-1.0.93/INSTALL) | 0 | ||||
-rw-r--r-- | lib/tolua++/Makefile (renamed from tolua++-1.0.93/Makefile) | 0 | ||||
-rw-r--r-- | lib/tolua++/README (renamed from tolua++-1.0.93/README) | 0 | ||||
-rw-r--r-- | lib/tolua++/README-5.1 (renamed from tolua++-1.0.93/README-5.1) | 0 | ||||
-rw-r--r-- | lib/tolua++/SConstruct (renamed from tolua++-1.0.93/SConstruct) | 0 | ||||
-rw-r--r-- | lib/tolua++/include/tolua++.h | 186 | ||||
-rw-r--r-- | lib/tolua++/src/bin/SCsub (renamed from tolua++-1.0.93/src/bin/SCsub) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/all.lua (renamed from tolua++-1.0.93/src/bin/lua/all.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/array.lua (renamed from tolua++-1.0.93/src/bin/lua/array.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/basic.lua (renamed from tolua++-1.0.93/src/bin/lua/basic.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/class.lua (renamed from tolua++-1.0.93/src/bin/lua/class.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/clean.lua (renamed from tolua++-1.0.93/src/bin/lua/clean.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/code.lua (renamed from tolua++-1.0.93/src/bin/lua/code.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/compat-5.1.lua (renamed from tolua++-1.0.93/src/bin/lua/compat-5.1.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/compat.lua (renamed from tolua++-1.0.93/src/bin/lua/compat.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/container.lua (renamed from tolua++-1.0.93/src/bin/lua/container.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/custom.lua (renamed from tolua++-1.0.93/src/bin/lua/custom.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/declaration.lua (renamed from tolua++-1.0.93/src/bin/lua/declaration.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/define.lua (renamed from tolua++-1.0.93/src/bin/lua/define.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/doit.lua (renamed from tolua++-1.0.93/src/bin/lua/doit.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/enumerate.lua (renamed from tolua++-1.0.93/src/bin/lua/enumerate.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/feature.lua (renamed from tolua++-1.0.93/src/bin/lua/feature.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/function.lua (renamed from tolua++-1.0.93/src/bin/lua/function.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/module.lua (renamed from tolua++-1.0.93/src/bin/lua/module.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/namespace.lua (renamed from tolua++-1.0.93/src/bin/lua/namespace.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/operator.lua (renamed from tolua++-1.0.93/src/bin/lua/operator.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/package.lua (renamed from tolua++-1.0.93/src/bin/lua/package.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/template_class.lua (renamed from tolua++-1.0.93/src/bin/lua/template_class.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/typedef.lua (renamed from tolua++-1.0.93/src/bin/lua/typedef.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/variable.lua (renamed from tolua++-1.0.93/src/bin/lua/variable.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/lua/verbatim.lua (renamed from tolua++-1.0.93/src/bin/lua/verbatim.lua) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/tolua.c | 169 | ||||
-rw-r--r-- | lib/tolua++/src/bin/tolua_scons.pkg (renamed from tolua++-1.0.93/src/bin/tolua_scons.pkg) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/toluabind.c (renamed from tolua++-1.0.93/src/bin/toluabind.c) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/toluabind.h (renamed from tolua++-1.0.93/src/bin/toluabind.h) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/toluabind_default.c (renamed from tolua++-1.0.93/src/bin/toluabind_default.c) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/bin/toluabind_default.h (renamed from tolua++-1.0.93/src/bin/toluabind_default.h) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/lib/SCsub (renamed from tolua++-1.0.93/src/lib/SCsub) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/lib/tolua_event.c | 536 | ||||
-rw-r--r-- | lib/tolua++/src/lib/tolua_event.h (renamed from tolua++-1.0.93/src/lib/tolua_event.h) | 0 | ||||
-rw-r--r-- | lib/tolua++/src/lib/tolua_is.c | 621 | ||||
-rw-r--r-- | lib/tolua++/src/lib/tolua_map.c | 704 | ||||
-rw-r--r-- | lib/tolua++/src/lib/tolua_push.c | 171 | ||||
-rw-r--r-- | lib/tolua++/src/lib/tolua_to.c | 133 | ||||
-rw-r--r-- | lib/tolua++/win32/tolualib/tolualib.vcproj (renamed from tolua++-1.0.93/win32/tolualib/tolualib.vcproj) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/tolualib/tolualib.vcproj.LAPTOPF.Kevin.user (renamed from tolua++-1.0.93/win32/tolualib/tolualib.vcproj.LAPTOPF.Kevin.user) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/tolualib/tolualib.vcxproj (renamed from tolua++-1.0.93/win32/tolualib/tolualib.vcxproj) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/tolualib/tolualib.vcxproj.filters (renamed from tolua++-1.0.93/win32/tolualib/tolualib.vcxproj.filters) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/tolualib/tolualib.vcxproj.user (renamed from tolua++-1.0.93/win32/tolualib/tolualib.vcxproj.user) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/vc7/clean.bat (renamed from tolua++-1.0.93/win32/vc7/clean.bat) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/vc7/toluapp.sln (renamed from tolua++-1.0.93/win32/vc7/toluapp.sln) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/vc7/toluapp.vcproj (renamed from tolua++-1.0.93/win32/vc7/toluapp.vcproj) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/vc7/toluapp.vcproj.LAPTOPF.Kevin.user (renamed from tolua++-1.0.93/win32/vc7/toluapp.vcproj.LAPTOPF.Kevin.user) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/vc7/toluapp.vcxproj (renamed from tolua++-1.0.93/win32/vc7/toluapp.vcxproj) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/vc7/toluapp.vcxproj.filters (renamed from tolua++-1.0.93/win32/vc7/toluapp.vcxproj.filters) | 0 | ||||
-rw-r--r-- | lib/tolua++/win32/vc7/toluapp.vcxproj.user (renamed from tolua++-1.0.93/win32/vc7/toluapp.vcxproj.user) | 0 | ||||
-rw-r--r-- | lib/zlib/adler32.c (renamed from zlib-1.2.7/adler32.c) | 0 | ||||
-rw-r--r-- | lib/zlib/compress.c (renamed from zlib-1.2.7/compress.c) | 0 | ||||
-rw-r--r-- | lib/zlib/crc32.c (renamed from zlib-1.2.7/crc32.c) | 0 | ||||
-rw-r--r-- | lib/zlib/crc32.h (renamed from zlib-1.2.7/crc32.h) | 0 | ||||
-rw-r--r-- | lib/zlib/deflate.c (renamed from zlib-1.2.7/deflate.c) | 0 | ||||
-rw-r--r-- | lib/zlib/deflate.h (renamed from zlib-1.2.7/deflate.h) | 0 | ||||
-rw-r--r-- | lib/zlib/example.c (renamed from zlib-1.2.7/example.c) | 0 | ||||
-rw-r--r-- | lib/zlib/gzclose.c (renamed from zlib-1.2.7/gzclose.c) | 0 | ||||
-rw-r--r-- | lib/zlib/gzguts.h (renamed from zlib-1.2.7/gzguts.h) | 0 | ||||
-rw-r--r-- | lib/zlib/gzlib.c (renamed from zlib-1.2.7/gzlib.c) | 0 | ||||
-rw-r--r-- | lib/zlib/gzread.c (renamed from zlib-1.2.7/gzread.c) | 0 | ||||
-rw-r--r-- | lib/zlib/gzwrite.c (renamed from zlib-1.2.7/gzwrite.c) | 0 | ||||
-rw-r--r-- | lib/zlib/infback.c (renamed from zlib-1.2.7/infback.c) | 0 | ||||
-rw-r--r-- | lib/zlib/inffast.c (renamed from zlib-1.2.7/inffast.c) | 0 | ||||
-rw-r--r-- | lib/zlib/inffast.h (renamed from zlib-1.2.7/inffast.h) | 0 | ||||
-rw-r--r-- | lib/zlib/inffixed.h (renamed from zlib-1.2.7/inffixed.h) | 0 | ||||
-rw-r--r-- | lib/zlib/inflate.c (renamed from zlib-1.2.7/inflate.c) | 0 | ||||
-rw-r--r-- | lib/zlib/inflate.h (renamed from zlib-1.2.7/inflate.h) | 0 | ||||
-rw-r--r-- | lib/zlib/inftrees.c (renamed from zlib-1.2.7/inftrees.c) | 0 | ||||
-rw-r--r-- | lib/zlib/inftrees.h (renamed from zlib-1.2.7/inftrees.h) | 0 | ||||
-rw-r--r-- | lib/zlib/minigzip.c (renamed from zlib-1.2.7/minigzip.c) | 0 | ||||
-rw-r--r-- | lib/zlib/trees.c (renamed from zlib-1.2.7/trees.c) | 0 | ||||
-rw-r--r-- | lib/zlib/trees.h (renamed from zlib-1.2.7/trees.h) | 0 | ||||
-rw-r--r-- | lib/zlib/uncompr.c (renamed from zlib-1.2.7/uncompr.c) | 0 | ||||
-rw-r--r-- | lib/zlib/zconf.h (renamed from zlib-1.2.7/zconf.h) | 0 | ||||
-rw-r--r-- | lib/zlib/zlib.h (renamed from zlib-1.2.7/zlib.h) | 0 | ||||
-rw-r--r-- | lib/zlib/zutil.c (renamed from zlib-1.2.7/zutil.c) | 0 | ||||
-rw-r--r-- | lib/zlib/zutil.h (renamed from zlib-1.2.7/zutil.h) | 0 |
383 files changed, 8735 insertions, 0 deletions
diff --git a/CryptoPP/Doxyfile b/lib/cryptopp/Doxyfile index c221fdf56..c221fdf56 100644 --- a/CryptoPP/Doxyfile +++ b/lib/cryptopp/Doxyfile diff --git a/CryptoPP/License.txt b/lib/cryptopp/License.txt index c5d3f34b1..c5d3f34b1 100644 --- a/CryptoPP/License.txt +++ b/lib/cryptopp/License.txt diff --git a/CryptoPP/Readme.txt b/lib/cryptopp/Readme.txt index 5f3b4525d..5f3b4525d 100644 --- a/CryptoPP/Readme.txt +++ b/lib/cryptopp/Readme.txt diff --git a/CryptoPP/adler32.cpp b/lib/cryptopp/adler32.cpp index 0d52c0838..0d52c0838 100644 --- a/CryptoPP/adler32.cpp +++ b/lib/cryptopp/adler32.cpp diff --git a/CryptoPP/adler32.h b/lib/cryptopp/adler32.h index 0ed803da9..0ed803da9 100644 --- a/CryptoPP/adler32.h +++ b/lib/cryptopp/adler32.h diff --git a/CryptoPP/aes.h b/lib/cryptopp/aes.h index 008754256..008754256 100644 --- a/CryptoPP/aes.h +++ b/lib/cryptopp/aes.h diff --git a/CryptoPP/algebra.cpp b/lib/cryptopp/algebra.cpp index 958e63701..958e63701 100644 --- a/CryptoPP/algebra.cpp +++ b/lib/cryptopp/algebra.cpp diff --git a/CryptoPP/algebra.h b/lib/cryptopp/algebra.h index 13038bd80..13038bd80 100644 --- a/CryptoPP/algebra.h +++ b/lib/cryptopp/algebra.h diff --git a/CryptoPP/algparam.cpp b/lib/cryptopp/algparam.cpp index a70d5dd95..a70d5dd95 100644 --- a/CryptoPP/algparam.cpp +++ b/lib/cryptopp/algparam.cpp diff --git a/CryptoPP/algparam.h b/lib/cryptopp/algparam.h index ea5129c22..ea5129c22 100644 --- a/CryptoPP/algparam.h +++ b/lib/cryptopp/algparam.h diff --git a/CryptoPP/argnames.h b/lib/cryptopp/argnames.h index e96172521..e96172521 100644 --- a/CryptoPP/argnames.h +++ b/lib/cryptopp/argnames.h diff --git a/CryptoPP/asn.cpp b/lib/cryptopp/asn.cpp index 8ae1ad65a..8ae1ad65a 100644 --- a/CryptoPP/asn.cpp +++ b/lib/cryptopp/asn.cpp diff --git a/CryptoPP/asn.h b/lib/cryptopp/asn.h index c35126bc3..c35126bc3 100644 --- a/CryptoPP/asn.h +++ b/lib/cryptopp/asn.h diff --git a/CryptoPP/authenc.cpp b/lib/cryptopp/authenc.cpp index f93662efb..f93662efb 100644 --- a/CryptoPP/authenc.cpp +++ b/lib/cryptopp/authenc.cpp diff --git a/CryptoPP/authenc.h b/lib/cryptopp/authenc.h index 5bb2a51c8..5bb2a51c8 100644 --- a/CryptoPP/authenc.h +++ b/lib/cryptopp/authenc.h diff --git a/CryptoPP/base32.cpp b/lib/cryptopp/base32.cpp index 0568f0729..0568f0729 100644 --- a/CryptoPP/base32.cpp +++ b/lib/cryptopp/base32.cpp diff --git a/CryptoPP/base32.h b/lib/cryptopp/base32.h index cb1e1af8d..cb1e1af8d 100644 --- a/CryptoPP/base32.h +++ b/lib/cryptopp/base32.h diff --git a/CryptoPP/base64.cpp b/lib/cryptopp/base64.cpp index 7571f2b8c..7571f2b8c 100644 --- a/CryptoPP/base64.cpp +++ b/lib/cryptopp/base64.cpp diff --git a/CryptoPP/base64.h b/lib/cryptopp/base64.h index 5a9e184b2..5a9e184b2 100644 --- a/CryptoPP/base64.h +++ b/lib/cryptopp/base64.h diff --git a/CryptoPP/basecode.cpp b/lib/cryptopp/basecode.cpp index 0c98b2271..0c98b2271 100644 --- a/CryptoPP/basecode.cpp +++ b/lib/cryptopp/basecode.cpp diff --git a/CryptoPP/basecode.h b/lib/cryptopp/basecode.h index cc44c4342..cc44c4342 100644 --- a/CryptoPP/basecode.h +++ b/lib/cryptopp/basecode.h diff --git a/CryptoPP/cbcmac.cpp b/lib/cryptopp/cbcmac.cpp index 6b0e8858e..6b0e8858e 100644 --- a/CryptoPP/cbcmac.cpp +++ b/lib/cryptopp/cbcmac.cpp diff --git a/CryptoPP/cbcmac.h b/lib/cryptopp/cbcmac.h index 4675dcb3d..4675dcb3d 100644 --- a/CryptoPP/cbcmac.h +++ b/lib/cryptopp/cbcmac.h diff --git a/CryptoPP/ccm.cpp b/lib/cryptopp/ccm.cpp index 030828ad8..030828ad8 100644 --- a/CryptoPP/ccm.cpp +++ b/lib/cryptopp/ccm.cpp diff --git a/CryptoPP/ccm.h b/lib/cryptopp/ccm.h index b1e5f00b9..b1e5f00b9 100644 --- a/CryptoPP/ccm.h +++ b/lib/cryptopp/ccm.h diff --git a/CryptoPP/channels.cpp b/lib/cryptopp/channels.cpp index 7359f54f7..7359f54f7 100644 --- a/CryptoPP/channels.cpp +++ b/lib/cryptopp/channels.cpp diff --git a/CryptoPP/channels.h b/lib/cryptopp/channels.h index 837415615..837415615 100644 --- a/CryptoPP/channels.h +++ b/lib/cryptopp/channels.h diff --git a/CryptoPP/cmac.cpp b/lib/cryptopp/cmac.cpp index a31d5f8b0..a31d5f8b0 100644 --- a/CryptoPP/cmac.cpp +++ b/lib/cryptopp/cmac.cpp diff --git a/CryptoPP/cmac.h b/lib/cryptopp/cmac.h index d8a1b391d..d8a1b391d 100644 --- a/CryptoPP/cmac.h +++ b/lib/cryptopp/cmac.h diff --git a/CryptoPP/config.h b/lib/cryptopp/config.h index edbfd00ef..edbfd00ef 100644 --- a/CryptoPP/config.h +++ b/lib/cryptopp/config.h diff --git a/CryptoPP/cpu.cpp b/lib/cryptopp/cpu.cpp index 3610a7c8e..3610a7c8e 100644 --- a/CryptoPP/cpu.cpp +++ b/lib/cryptopp/cpu.cpp diff --git a/CryptoPP/cpu.h b/lib/cryptopp/cpu.h index 65029d338..65029d338 100644 --- a/CryptoPP/cpu.h +++ b/lib/cryptopp/cpu.h diff --git a/CryptoPP/crc.cpp b/lib/cryptopp/crc.cpp index 10c25c257..10c25c257 100644 --- a/CryptoPP/crc.cpp +++ b/lib/cryptopp/crc.cpp diff --git a/CryptoPP/crc.h b/lib/cryptopp/crc.h index f75ea384c..f75ea384c 100644 --- a/CryptoPP/crc.h +++ b/lib/cryptopp/crc.h diff --git a/CryptoPP/cryptlib.cpp b/lib/cryptopp/cryptlib.cpp index df138ddb0..df138ddb0 100644 --- a/CryptoPP/cryptlib.cpp +++ b/lib/cryptopp/cryptlib.cpp diff --git a/CryptoPP/cryptlib.h b/lib/cryptopp/cryptlib.h index 406872232..406872232 100644 --- a/CryptoPP/cryptlib.h +++ b/lib/cryptopp/cryptlib.h diff --git a/CryptoPP/default.cpp b/lib/cryptopp/default.cpp index 72940784d..72940784d 100644 --- a/CryptoPP/default.cpp +++ b/lib/cryptopp/default.cpp diff --git a/CryptoPP/default.h b/lib/cryptopp/default.h index fb5364152..fb5364152 100644 --- a/CryptoPP/default.h +++ b/lib/cryptopp/default.h diff --git a/CryptoPP/des.cpp b/lib/cryptopp/des.cpp index a6e0c514d..a6e0c514d 100644 --- a/CryptoPP/des.cpp +++ b/lib/cryptopp/des.cpp diff --git a/CryptoPP/des.h b/lib/cryptopp/des.h index 62f628824..62f628824 100644 --- a/CryptoPP/des.h +++ b/lib/cryptopp/des.h diff --git a/CryptoPP/dessp.cpp b/lib/cryptopp/dessp.cpp index 49ed1d26d..49ed1d26d 100644 --- a/CryptoPP/dessp.cpp +++ b/lib/cryptopp/dessp.cpp diff --git a/CryptoPP/dh.cpp b/lib/cryptopp/dh.cpp index 22097a051..22097a051 100644 --- a/CryptoPP/dh.cpp +++ b/lib/cryptopp/dh.cpp diff --git a/CryptoPP/dh.h b/lib/cryptopp/dh.h index 10e8d142e..10e8d142e 100644 --- a/CryptoPP/dh.h +++ b/lib/cryptopp/dh.h diff --git a/CryptoPP/dh2.cpp b/lib/cryptopp/dh2.cpp index 98175ee28..98175ee28 100644 --- a/CryptoPP/dh2.cpp +++ b/lib/cryptopp/dh2.cpp diff --git a/CryptoPP/dh2.h b/lib/cryptopp/dh2.h index af9d342d6..af9d342d6 100644 --- a/CryptoPP/dh2.h +++ b/lib/cryptopp/dh2.h diff --git a/CryptoPP/dll.cpp b/lib/cryptopp/dll.cpp index 2b4ef7ade..2b4ef7ade 100644 --- a/CryptoPP/dll.cpp +++ b/lib/cryptopp/dll.cpp diff --git a/CryptoPP/dll.h b/lib/cryptopp/dll.h index 50775e98b..50775e98b 100644 --- a/CryptoPP/dll.h +++ b/lib/cryptopp/dll.h diff --git a/CryptoPP/dmac.h b/lib/cryptopp/dmac.h index 80b54ac2f..80b54ac2f 100644 --- a/CryptoPP/dmac.h +++ b/lib/cryptopp/dmac.h diff --git a/CryptoPP/dsa.cpp b/lib/cryptopp/dsa.cpp index 5aace4857..5aace4857 100644 --- a/CryptoPP/dsa.cpp +++ b/lib/cryptopp/dsa.cpp diff --git a/CryptoPP/dsa.h b/lib/cryptopp/dsa.h index 6ae03877c..6ae03877c 100644 --- a/CryptoPP/dsa.h +++ b/lib/cryptopp/dsa.h diff --git a/CryptoPP/eax.cpp b/lib/cryptopp/eax.cpp index 2728c9bcd..2728c9bcd 100644 --- a/CryptoPP/eax.cpp +++ b/lib/cryptopp/eax.cpp diff --git a/CryptoPP/eax.h b/lib/cryptopp/eax.h index e48ee92b5..e48ee92b5 100644 --- a/CryptoPP/eax.h +++ b/lib/cryptopp/eax.h diff --git a/CryptoPP/ec2n.cpp b/lib/cryptopp/ec2n.cpp index b513b2cb8..b513b2cb8 100644 --- a/CryptoPP/ec2n.cpp +++ b/lib/cryptopp/ec2n.cpp diff --git a/CryptoPP/ec2n.h b/lib/cryptopp/ec2n.h index ae4007cd6..ae4007cd6 100644 --- a/CryptoPP/ec2n.h +++ b/lib/cryptopp/ec2n.h diff --git a/CryptoPP/eccrypto.cpp b/lib/cryptopp/eccrypto.cpp index 922104c4d..922104c4d 100644 --- a/CryptoPP/eccrypto.cpp +++ b/lib/cryptopp/eccrypto.cpp diff --git a/CryptoPP/eccrypto.h b/lib/cryptopp/eccrypto.h index 3530455a3..3530455a3 100644 --- a/CryptoPP/eccrypto.h +++ b/lib/cryptopp/eccrypto.h diff --git a/CryptoPP/ecp.cpp b/lib/cryptopp/ecp.cpp index 55a7cc15b..55a7cc15b 100644 --- a/CryptoPP/ecp.cpp +++ b/lib/cryptopp/ecp.cpp diff --git a/CryptoPP/ecp.h b/lib/cryptopp/ecp.h index d946be63a..d946be63a 100644 --- a/CryptoPP/ecp.h +++ b/lib/cryptopp/ecp.h diff --git a/CryptoPP/elgamal.cpp b/lib/cryptopp/elgamal.cpp index b58fe7c06..b58fe7c06 100644 --- a/CryptoPP/elgamal.cpp +++ b/lib/cryptopp/elgamal.cpp diff --git a/CryptoPP/elgamal.h b/lib/cryptopp/elgamal.h index 9afc30eee..9afc30eee 100644 --- a/CryptoPP/elgamal.h +++ b/lib/cryptopp/elgamal.h diff --git a/CryptoPP/emsa2.cpp b/lib/cryptopp/emsa2.cpp index 3dbb7e8c0..3dbb7e8c0 100644 --- a/CryptoPP/emsa2.cpp +++ b/lib/cryptopp/emsa2.cpp diff --git a/CryptoPP/emsa2.h b/lib/cryptopp/emsa2.h index 49109e6db..49109e6db 100644 --- a/CryptoPP/emsa2.h +++ b/lib/cryptopp/emsa2.h diff --git a/CryptoPP/eprecomp.cpp b/lib/cryptopp/eprecomp.cpp index a061cf6cd..a061cf6cd 100644 --- a/CryptoPP/eprecomp.cpp +++ b/lib/cryptopp/eprecomp.cpp diff --git a/CryptoPP/eprecomp.h b/lib/cryptopp/eprecomp.h index 1f3256766..1f3256766 100644 --- a/CryptoPP/eprecomp.h +++ b/lib/cryptopp/eprecomp.h diff --git a/CryptoPP/esign.cpp b/lib/cryptopp/esign.cpp index 8b42c1fa4..8b42c1fa4 100644 --- a/CryptoPP/esign.cpp +++ b/lib/cryptopp/esign.cpp diff --git a/CryptoPP/esign.h b/lib/cryptopp/esign.h index 8eecbc5a1..8eecbc5a1 100644 --- a/CryptoPP/esign.h +++ b/lib/cryptopp/esign.h diff --git a/CryptoPP/factory.h b/lib/cryptopp/factory.h index 5b65db3da..5b65db3da 100644 --- a/CryptoPP/factory.h +++ b/lib/cryptopp/factory.h diff --git a/CryptoPP/files.cpp b/lib/cryptopp/files.cpp index 453b56248..453b56248 100644 --- a/CryptoPP/files.cpp +++ b/lib/cryptopp/files.cpp diff --git a/CryptoPP/files.h b/lib/cryptopp/files.h index a47e856bf..a47e856bf 100644 --- a/CryptoPP/files.h +++ b/lib/cryptopp/files.h diff --git a/CryptoPP/filters.cpp b/lib/cryptopp/filters.cpp index 083dfd361..083dfd361 100644 --- a/CryptoPP/filters.cpp +++ b/lib/cryptopp/filters.cpp diff --git a/CryptoPP/filters.h b/lib/cryptopp/filters.h index c72a4ece3..c72a4ece3 100644 --- a/CryptoPP/filters.h +++ b/lib/cryptopp/filters.h diff --git a/CryptoPP/fips140.cpp b/lib/cryptopp/fips140.cpp index 1fcf59014..1fcf59014 100644 --- a/CryptoPP/fips140.cpp +++ b/lib/cryptopp/fips140.cpp diff --git a/CryptoPP/fips140.h b/lib/cryptopp/fips140.h index a3e538613..a3e538613 100644 --- a/CryptoPP/fips140.h +++ b/lib/cryptopp/fips140.h diff --git a/CryptoPP/fltrimpl.h b/lib/cryptopp/fltrimpl.h index 4087d7d9f..4087d7d9f 100644 --- a/CryptoPP/fltrimpl.h +++ b/lib/cryptopp/fltrimpl.h diff --git a/CryptoPP/gcm.cpp b/lib/cryptopp/gcm.cpp index 2304f96d8..2304f96d8 100644 --- a/CryptoPP/gcm.cpp +++ b/lib/cryptopp/gcm.cpp diff --git a/CryptoPP/gcm.h b/lib/cryptopp/gcm.h index 272a51c9c..272a51c9c 100644 --- a/CryptoPP/gcm.h +++ b/lib/cryptopp/gcm.h diff --git a/CryptoPP/gf256.cpp b/lib/cryptopp/gf256.cpp index 72026d1e1..72026d1e1 100644 --- a/CryptoPP/gf256.cpp +++ b/lib/cryptopp/gf256.cpp diff --git a/CryptoPP/gf256.h b/lib/cryptopp/gf256.h index e0ea74826..e0ea74826 100644 --- a/CryptoPP/gf256.h +++ b/lib/cryptopp/gf256.h diff --git a/CryptoPP/gf2_32.cpp b/lib/cryptopp/gf2_32.cpp index ae4874a40..ae4874a40 100644 --- a/CryptoPP/gf2_32.cpp +++ b/lib/cryptopp/gf2_32.cpp diff --git a/CryptoPP/gf2_32.h b/lib/cryptopp/gf2_32.h index 31713f4c0..31713f4c0 100644 --- a/CryptoPP/gf2_32.h +++ b/lib/cryptopp/gf2_32.h diff --git a/CryptoPP/gf2n.cpp b/lib/cryptopp/gf2n.cpp index bcc56071a..bcc56071a 100644 --- a/CryptoPP/gf2n.cpp +++ b/lib/cryptopp/gf2n.cpp diff --git a/CryptoPP/gf2n.h b/lib/cryptopp/gf2n.h index 67ade641e..67ade641e 100644 --- a/CryptoPP/gf2n.h +++ b/lib/cryptopp/gf2n.h diff --git a/CryptoPP/gfpcrypt.cpp b/lib/cryptopp/gfpcrypt.cpp index e293fc598..e293fc598 100644 --- a/CryptoPP/gfpcrypt.cpp +++ b/lib/cryptopp/gfpcrypt.cpp diff --git a/CryptoPP/gfpcrypt.h b/lib/cryptopp/gfpcrypt.h index 7af993fb3..7af993fb3 100644 --- a/CryptoPP/gfpcrypt.h +++ b/lib/cryptopp/gfpcrypt.h diff --git a/CryptoPP/gzip.h b/lib/cryptopp/gzip.h index f3148ad71..f3148ad71 100644 --- a/CryptoPP/gzip.h +++ b/lib/cryptopp/gzip.h diff --git a/CryptoPP/hex.cpp b/lib/cryptopp/hex.cpp index 5731df550..5731df550 100644 --- a/CryptoPP/hex.cpp +++ b/lib/cryptopp/hex.cpp diff --git a/CryptoPP/hex.h b/lib/cryptopp/hex.h index 006914c5a..006914c5a 100644 --- a/CryptoPP/hex.h +++ b/lib/cryptopp/hex.h diff --git a/CryptoPP/hmac.cpp b/lib/cryptopp/hmac.cpp index d4a649c08..d4a649c08 100644 --- a/CryptoPP/hmac.cpp +++ b/lib/cryptopp/hmac.cpp diff --git a/CryptoPP/hmac.h b/lib/cryptopp/hmac.h index 62db5ef33..62db5ef33 100644 --- a/CryptoPP/hmac.h +++ b/lib/cryptopp/hmac.h diff --git a/CryptoPP/hrtimer.cpp b/lib/cryptopp/hrtimer.cpp index 6871a15dc..6871a15dc 100644 --- a/CryptoPP/hrtimer.cpp +++ b/lib/cryptopp/hrtimer.cpp diff --git a/CryptoPP/hrtimer.h b/lib/cryptopp/hrtimer.h index 858dbd226..858dbd226 100644 --- a/CryptoPP/hrtimer.h +++ b/lib/cryptopp/hrtimer.h diff --git a/CryptoPP/integer.cpp b/lib/cryptopp/integer.cpp index f07cce873..f07cce873 100644 --- a/CryptoPP/integer.cpp +++ b/lib/cryptopp/integer.cpp diff --git a/CryptoPP/integer.h b/lib/cryptopp/integer.h index 6d844fa57..6d844fa57 100644 --- a/CryptoPP/integer.h +++ b/lib/cryptopp/integer.h diff --git a/CryptoPP/iterhash.cpp b/lib/cryptopp/iterhash.cpp index 1e31e9fb3..1e31e9fb3 100644 --- a/CryptoPP/iterhash.cpp +++ b/lib/cryptopp/iterhash.cpp diff --git a/CryptoPP/iterhash.h b/lib/cryptopp/iterhash.h index cce9e8211..cce9e8211 100644 --- a/CryptoPP/iterhash.h +++ b/lib/cryptopp/iterhash.h diff --git a/CryptoPP/lubyrack.h b/lib/cryptopp/lubyrack.h index e8fd2f748..e8fd2f748 100644 --- a/CryptoPP/lubyrack.h +++ b/lib/cryptopp/lubyrack.h diff --git a/CryptoPP/luc.cpp b/lib/cryptopp/luc.cpp index 43cd2ed21..43cd2ed21 100644 --- a/CryptoPP/luc.cpp +++ b/lib/cryptopp/luc.cpp diff --git a/CryptoPP/luc.h b/lib/cryptopp/luc.h index 730776d57..730776d57 100644 --- a/CryptoPP/luc.h +++ b/lib/cryptopp/luc.h diff --git a/CryptoPP/md2.cpp b/lib/cryptopp/md2.cpp index 41f714b59..41f714b59 100644 --- a/CryptoPP/md2.cpp +++ b/lib/cryptopp/md2.cpp diff --git a/CryptoPP/md2.h b/lib/cryptopp/md2.h index b0837c882..b0837c882 100644 --- a/CryptoPP/md2.h +++ b/lib/cryptopp/md2.h diff --git a/CryptoPP/md4.cpp b/lib/cryptopp/md4.cpp index 9ed639cb9..9ed639cb9 100644 --- a/CryptoPP/md4.cpp +++ b/lib/cryptopp/md4.cpp diff --git a/CryptoPP/md4.h b/lib/cryptopp/md4.h index 53387003c..53387003c 100644 --- a/CryptoPP/md4.h +++ b/lib/cryptopp/md4.h diff --git a/CryptoPP/md5.cpp b/lib/cryptopp/md5.cpp index a52297816..a52297816 100644 --- a/CryptoPP/md5.cpp +++ b/lib/cryptopp/md5.cpp diff --git a/CryptoPP/md5.h b/lib/cryptopp/md5.h index 73ec5326c..73ec5326c 100644 --- a/CryptoPP/md5.h +++ b/lib/cryptopp/md5.h diff --git a/CryptoPP/mdc.h b/lib/cryptopp/mdc.h index cc90cdc45..cc90cdc45 100644 --- a/CryptoPP/mdc.h +++ b/lib/cryptopp/mdc.h diff --git a/CryptoPP/misc.cpp b/lib/cryptopp/misc.cpp index 93760e3a3..93760e3a3 100644 --- a/CryptoPP/misc.cpp +++ b/lib/cryptopp/misc.cpp diff --git a/CryptoPP/misc.h b/lib/cryptopp/misc.h index 2b326dd60..2b326dd60 100644 --- a/CryptoPP/misc.h +++ b/lib/cryptopp/misc.h diff --git a/CryptoPP/modarith.h b/lib/cryptopp/modarith.h index c0368e3fb..c0368e3fb 100644 --- a/CryptoPP/modarith.h +++ b/lib/cryptopp/modarith.h diff --git a/CryptoPP/modes.cpp b/lib/cryptopp/modes.cpp index 46332284b..46332284b 100644 --- a/CryptoPP/modes.cpp +++ b/lib/cryptopp/modes.cpp diff --git a/CryptoPP/modes.h b/lib/cryptopp/modes.h index c0c30c476..c0c30c476 100644 --- a/CryptoPP/modes.h +++ b/lib/cryptopp/modes.h diff --git a/CryptoPP/modexppc.h b/lib/cryptopp/modexppc.h index fbe701279..fbe701279 100644 --- a/CryptoPP/modexppc.h +++ b/lib/cryptopp/modexppc.h diff --git a/CryptoPP/mqueue.cpp b/lib/cryptopp/mqueue.cpp index 1d645d83d..1d645d83d 100644 --- a/CryptoPP/mqueue.cpp +++ b/lib/cryptopp/mqueue.cpp diff --git a/CryptoPP/mqueue.h b/lib/cryptopp/mqueue.h index efa57a7cf..efa57a7cf 100644 --- a/CryptoPP/mqueue.h +++ b/lib/cryptopp/mqueue.h diff --git a/CryptoPP/mqv.cpp b/lib/cryptopp/mqv.cpp index c427561b2..c427561b2 100644 --- a/CryptoPP/mqv.cpp +++ b/lib/cryptopp/mqv.cpp diff --git a/CryptoPP/mqv.h b/lib/cryptopp/mqv.h index 2683817b0..2683817b0 100644 --- a/CryptoPP/mqv.h +++ b/lib/cryptopp/mqv.h diff --git a/CryptoPP/nbtheory.cpp b/lib/cryptopp/nbtheory.cpp index 3fdea4e69..3fdea4e69 100644 --- a/CryptoPP/nbtheory.cpp +++ b/lib/cryptopp/nbtheory.cpp diff --git a/CryptoPP/nbtheory.h b/lib/cryptopp/nbtheory.h index 636479269..636479269 100644 --- a/CryptoPP/nbtheory.h +++ b/lib/cryptopp/nbtheory.h diff --git a/CryptoPP/network.cpp b/lib/cryptopp/network.cpp index 9b7198d16..9b7198d16 100644 --- a/CryptoPP/network.cpp +++ b/lib/cryptopp/network.cpp diff --git a/CryptoPP/network.h b/lib/cryptopp/network.h index 96cd4567e..96cd4567e 100644 --- a/CryptoPP/network.h +++ b/lib/cryptopp/network.h diff --git a/CryptoPP/nr.h b/lib/cryptopp/nr.h index c398e3550..c398e3550 100644 --- a/CryptoPP/nr.h +++ b/lib/cryptopp/nr.h diff --git a/CryptoPP/oaep.cpp b/lib/cryptopp/oaep.cpp index 1d474be52..1d474be52 100644 --- a/CryptoPP/oaep.cpp +++ b/lib/cryptopp/oaep.cpp diff --git a/CryptoPP/oaep.h b/lib/cryptopp/oaep.h index 4bf6b0d83..4bf6b0d83 100644 --- a/CryptoPP/oaep.h +++ b/lib/cryptopp/oaep.h diff --git a/CryptoPP/oids.h b/lib/cryptopp/oids.h index 8b1030150..8b1030150 100644 --- a/CryptoPP/oids.h +++ b/lib/cryptopp/oids.h diff --git a/CryptoPP/osrng.cpp b/lib/cryptopp/osrng.cpp index 76e486b4e..76e486b4e 100644 --- a/CryptoPP/osrng.cpp +++ b/lib/cryptopp/osrng.cpp diff --git a/CryptoPP/osrng.h b/lib/cryptopp/osrng.h index ae07d057b..ae07d057b 100644 --- a/CryptoPP/osrng.h +++ b/lib/cryptopp/osrng.h diff --git a/CryptoPP/pch.cpp b/lib/cryptopp/pch.cpp index 1d9f38c57..1d9f38c57 100644 --- a/CryptoPP/pch.cpp +++ b/lib/cryptopp/pch.cpp diff --git a/CryptoPP/pch.h b/lib/cryptopp/pch.h index 418c39076..418c39076 100644 --- a/CryptoPP/pch.h +++ b/lib/cryptopp/pch.h diff --git a/CryptoPP/pkcspad.cpp b/lib/cryptopp/pkcspad.cpp index e1f1d1e23..e1f1d1e23 100644 --- a/CryptoPP/pkcspad.cpp +++ b/lib/cryptopp/pkcspad.cpp diff --git a/CryptoPP/pkcspad.h b/lib/cryptopp/pkcspad.h index 6371c7698..6371c7698 100644 --- a/CryptoPP/pkcspad.h +++ b/lib/cryptopp/pkcspad.h diff --git a/CryptoPP/polynomi.cpp b/lib/cryptopp/polynomi.cpp index 734cae926..734cae926 100644 --- a/CryptoPP/polynomi.cpp +++ b/lib/cryptopp/polynomi.cpp diff --git a/CryptoPP/polynomi.h b/lib/cryptopp/polynomi.h index cddadaeaf..cddadaeaf 100644 --- a/CryptoPP/polynomi.h +++ b/lib/cryptopp/polynomi.h diff --git a/CryptoPP/pssr.cpp b/lib/cryptopp/pssr.cpp index ccbe4ee27..ccbe4ee27 100644 --- a/CryptoPP/pssr.cpp +++ b/lib/cryptopp/pssr.cpp diff --git a/CryptoPP/pssr.h b/lib/cryptopp/pssr.h index 6ec6936e5..6ec6936e5 100644 --- a/CryptoPP/pssr.h +++ b/lib/cryptopp/pssr.h diff --git a/CryptoPP/pubkey.cpp b/lib/cryptopp/pubkey.cpp index 1159e5343..1159e5343 100644 --- a/CryptoPP/pubkey.cpp +++ b/lib/cryptopp/pubkey.cpp diff --git a/CryptoPP/pubkey.h b/lib/cryptopp/pubkey.h index 3a3f3bcde..3a3f3bcde 100644 --- a/CryptoPP/pubkey.h +++ b/lib/cryptopp/pubkey.h diff --git a/CryptoPP/pwdbased.h b/lib/cryptopp/pwdbased.h index f755724b1..f755724b1 100644 --- a/CryptoPP/pwdbased.h +++ b/lib/cryptopp/pwdbased.h diff --git a/CryptoPP/queue.cpp b/lib/cryptopp/queue.cpp index ff2f0d316..ff2f0d316 100644 --- a/CryptoPP/queue.cpp +++ b/lib/cryptopp/queue.cpp diff --git a/CryptoPP/queue.h b/lib/cryptopp/queue.h index ab89dbdf1..ab89dbdf1 100644 --- a/CryptoPP/queue.h +++ b/lib/cryptopp/queue.h diff --git a/CryptoPP/rabin.cpp b/lib/cryptopp/rabin.cpp index d496333b5..d496333b5 100644 --- a/CryptoPP/rabin.cpp +++ b/lib/cryptopp/rabin.cpp diff --git a/CryptoPP/rabin.h b/lib/cryptopp/rabin.h index 1c9bcbb49..1c9bcbb49 100644 --- a/CryptoPP/rabin.h +++ b/lib/cryptopp/rabin.h diff --git a/CryptoPP/randpool.cpp b/lib/cryptopp/randpool.cpp index a063c8996..a063c8996 100644 --- a/CryptoPP/randpool.cpp +++ b/lib/cryptopp/randpool.cpp diff --git a/CryptoPP/randpool.h b/lib/cryptopp/randpool.h index c25bc9bb1..c25bc9bb1 100644 --- a/CryptoPP/randpool.h +++ b/lib/cryptopp/randpool.h diff --git a/CryptoPP/rdtables.cpp b/lib/cryptopp/rdtables.cpp index 493793252..493793252 100644 --- a/CryptoPP/rdtables.cpp +++ b/lib/cryptopp/rdtables.cpp diff --git a/CryptoPP/resource.h b/lib/cryptopp/resource.h index 861e22ba3..861e22ba3 100644 --- a/CryptoPP/resource.h +++ b/lib/cryptopp/resource.h diff --git a/CryptoPP/rijndael.cpp b/lib/cryptopp/rijndael.cpp index c185032cf..c185032cf 100644 --- a/CryptoPP/rijndael.cpp +++ b/lib/cryptopp/rijndael.cpp diff --git a/CryptoPP/rijndael.h b/lib/cryptopp/rijndael.h index 64c784b07..64c784b07 100644 --- a/CryptoPP/rijndael.h +++ b/lib/cryptopp/rijndael.h diff --git a/CryptoPP/rng.cpp b/lib/cryptopp/rng.cpp index 9866cd831..9866cd831 100644 --- a/CryptoPP/rng.cpp +++ b/lib/cryptopp/rng.cpp diff --git a/CryptoPP/rng.h b/lib/cryptopp/rng.h index 2439dee69..2439dee69 100644 --- a/CryptoPP/rng.h +++ b/lib/cryptopp/rng.h diff --git a/CryptoPP/rsa.cpp b/lib/cryptopp/rsa.cpp index 59449c40e..59449c40e 100644 --- a/CryptoPP/rsa.cpp +++ b/lib/cryptopp/rsa.cpp diff --git a/CryptoPP/rsa.h b/lib/cryptopp/rsa.h index 6a8b18525..6a8b18525 100644 --- a/CryptoPP/rsa.h +++ b/lib/cryptopp/rsa.h diff --git a/CryptoPP/rw.cpp b/lib/cryptopp/rw.cpp index cdd9f2d22..cdd9f2d22 100644 --- a/CryptoPP/rw.cpp +++ b/lib/cryptopp/rw.cpp diff --git a/CryptoPP/rw.h b/lib/cryptopp/rw.h index 6820251e8..6820251e8 100644 --- a/CryptoPP/rw.h +++ b/lib/cryptopp/rw.h diff --git a/CryptoPP/safer.cpp b/lib/cryptopp/safer.cpp index d46ca6417..d46ca6417 100644 --- a/CryptoPP/safer.cpp +++ b/lib/cryptopp/safer.cpp diff --git a/CryptoPP/safer.h b/lib/cryptopp/safer.h index f9a3c9e1f..f9a3c9e1f 100644 --- a/CryptoPP/safer.h +++ b/lib/cryptopp/safer.h diff --git a/CryptoPP/seal.cpp b/lib/cryptopp/seal.cpp index f49b52203..f49b52203 100644 --- a/CryptoPP/seal.cpp +++ b/lib/cryptopp/seal.cpp diff --git a/CryptoPP/seal.h b/lib/cryptopp/seal.h index e14ae1caf..e14ae1caf 100644 --- a/CryptoPP/seal.h +++ b/lib/cryptopp/seal.h diff --git a/CryptoPP/secblock.h b/lib/cryptopp/secblock.h index 40cce3341..40cce3341 100644 --- a/CryptoPP/secblock.h +++ b/lib/cryptopp/secblock.h diff --git a/CryptoPP/seckey.h b/lib/cryptopp/seckey.h index 35046a61b..35046a61b 100644 --- a/CryptoPP/seckey.h +++ b/lib/cryptopp/seckey.h diff --git a/CryptoPP/seed.cpp b/lib/cryptopp/seed.cpp index 101902dce..101902dce 100644 --- a/CryptoPP/seed.cpp +++ b/lib/cryptopp/seed.cpp diff --git a/CryptoPP/seed.h b/lib/cryptopp/seed.h index 871284de7..871284de7 100644 --- a/CryptoPP/seed.h +++ b/lib/cryptopp/seed.h diff --git a/CryptoPP/sha.cpp b/lib/cryptopp/sha.cpp index df947ad16..df947ad16 100644 --- a/CryptoPP/sha.cpp +++ b/lib/cryptopp/sha.cpp diff --git a/CryptoPP/sha.h b/lib/cryptopp/sha.h index 679081e8f..679081e8f 100644 --- a/CryptoPP/sha.h +++ b/lib/cryptopp/sha.h diff --git a/CryptoPP/shacal2.cpp b/lib/cryptopp/shacal2.cpp index b0360e404..b0360e404 100644 --- a/CryptoPP/shacal2.cpp +++ b/lib/cryptopp/shacal2.cpp diff --git a/CryptoPP/shacal2.h b/lib/cryptopp/shacal2.h index 66c987fd7..66c987fd7 100644 --- a/CryptoPP/shacal2.h +++ b/lib/cryptopp/shacal2.h diff --git a/CryptoPP/simple.cpp b/lib/cryptopp/simple.cpp index 96f256b40..96f256b40 100644 --- a/CryptoPP/simple.cpp +++ b/lib/cryptopp/simple.cpp diff --git a/CryptoPP/simple.h b/lib/cryptopp/simple.h index 35fd65ae4..35fd65ae4 100644 --- a/CryptoPP/simple.h +++ b/lib/cryptopp/simple.h diff --git a/CryptoPP/smartptr.h b/lib/cryptopp/smartptr.h index a0a727edc..a0a727edc 100644 --- a/CryptoPP/smartptr.h +++ b/lib/cryptopp/smartptr.h diff --git a/CryptoPP/socketft.cpp b/lib/cryptopp/socketft.cpp index 6c5a8ff9d..6c5a8ff9d 100644 --- a/CryptoPP/socketft.cpp +++ b/lib/cryptopp/socketft.cpp diff --git a/CryptoPP/socketft.h b/lib/cryptopp/socketft.h index e414aa68f..e414aa68f 100644 --- a/CryptoPP/socketft.h +++ b/lib/cryptopp/socketft.h diff --git a/CryptoPP/square.cpp b/lib/cryptopp/square.cpp index 00e6bddbe..00e6bddbe 100644 --- a/CryptoPP/square.cpp +++ b/lib/cryptopp/square.cpp diff --git a/CryptoPP/square.h b/lib/cryptopp/square.h index d7e23c284..d7e23c284 100644 --- a/CryptoPP/square.h +++ b/lib/cryptopp/square.h diff --git a/CryptoPP/squaretb.cpp b/lib/cryptopp/squaretb.cpp index bc3bee7df..bc3bee7df 100644 --- a/CryptoPP/squaretb.cpp +++ b/lib/cryptopp/squaretb.cpp diff --git a/CryptoPP/stdcpp.h b/lib/cryptopp/stdcpp.h index 6511c4fa2..6511c4fa2 100644 --- a/CryptoPP/stdcpp.h +++ b/lib/cryptopp/stdcpp.h diff --git a/CryptoPP/strciphr.cpp b/lib/cryptopp/strciphr.cpp index 53e007376..53e007376 100644 --- a/CryptoPP/strciphr.cpp +++ b/lib/cryptopp/strciphr.cpp diff --git a/CryptoPP/strciphr.h b/lib/cryptopp/strciphr.h index d1d11a17b..d1d11a17b 100644 --- a/CryptoPP/strciphr.h +++ b/lib/cryptopp/strciphr.h diff --git a/CryptoPP/tea.cpp b/lib/cryptopp/tea.cpp index b1fb6f140..b1fb6f140 100644 --- a/CryptoPP/tea.cpp +++ b/lib/cryptopp/tea.cpp diff --git a/CryptoPP/tea.h b/lib/cryptopp/tea.h index d8ddded86..d8ddded86 100644 --- a/CryptoPP/tea.h +++ b/lib/cryptopp/tea.h diff --git a/CryptoPP/tiger.cpp b/lib/cryptopp/tiger.cpp index c6c05caed..c6c05caed 100644 --- a/CryptoPP/tiger.cpp +++ b/lib/cryptopp/tiger.cpp diff --git a/CryptoPP/tiger.h b/lib/cryptopp/tiger.h index 5f6e941ac..5f6e941ac 100644 --- a/CryptoPP/tiger.h +++ b/lib/cryptopp/tiger.h diff --git a/CryptoPP/tigertab.cpp b/lib/cryptopp/tigertab.cpp index 5c1595b5b..5c1595b5b 100644 --- a/CryptoPP/tigertab.cpp +++ b/lib/cryptopp/tigertab.cpp diff --git a/CryptoPP/trdlocal.cpp b/lib/cryptopp/trdlocal.cpp index 6d6b822c0..6d6b822c0 100644 --- a/CryptoPP/trdlocal.cpp +++ b/lib/cryptopp/trdlocal.cpp diff --git a/CryptoPP/trdlocal.h b/lib/cryptopp/trdlocal.h index 92d244a0a..92d244a0a 100644 --- a/CryptoPP/trdlocal.h +++ b/lib/cryptopp/trdlocal.h diff --git a/CryptoPP/trunhash.h b/lib/cryptopp/trunhash.h index c1c4e9b64..c1c4e9b64 100644 --- a/CryptoPP/trunhash.h +++ b/lib/cryptopp/trunhash.h diff --git a/CryptoPP/ttmac.cpp b/lib/cryptopp/ttmac.cpp index d4ff38104..d4ff38104 100644 --- a/CryptoPP/ttmac.cpp +++ b/lib/cryptopp/ttmac.cpp diff --git a/CryptoPP/ttmac.h b/lib/cryptopp/ttmac.h index b4bf86e26..b4bf86e26 100644 --- a/CryptoPP/ttmac.h +++ b/lib/cryptopp/ttmac.h diff --git a/CryptoPP/validate.h b/lib/cryptopp/validate.h index 0ab23cba3..0ab23cba3 100644 --- a/CryptoPP/validate.h +++ b/lib/cryptopp/validate.h diff --git a/CryptoPP/vmac.cpp b/lib/cryptopp/vmac.cpp index 6b490f904..6b490f904 100644 --- a/CryptoPP/vmac.cpp +++ b/lib/cryptopp/vmac.cpp diff --git a/CryptoPP/vmac.h b/lib/cryptopp/vmac.h index 07240173c..07240173c 100644 --- a/CryptoPP/vmac.h +++ b/lib/cryptopp/vmac.h diff --git a/CryptoPP/wait.cpp b/lib/cryptopp/wait.cpp index 198785838..198785838 100644 --- a/CryptoPP/wait.cpp +++ b/lib/cryptopp/wait.cpp diff --git a/CryptoPP/wait.h b/lib/cryptopp/wait.h index 045afbc18..045afbc18 100644 --- a/CryptoPP/wait.h +++ b/lib/cryptopp/wait.h diff --git a/CryptoPP/winpipes.cpp b/lib/cryptopp/winpipes.cpp index 1c2e047b0..1c2e047b0 100644 --- a/CryptoPP/winpipes.cpp +++ b/lib/cryptopp/winpipes.cpp diff --git a/CryptoPP/winpipes.h b/lib/cryptopp/winpipes.h index 07225f9f1..07225f9f1 100644 --- a/CryptoPP/winpipes.h +++ b/lib/cryptopp/winpipes.h diff --git a/CryptoPP/words.h b/lib/cryptopp/words.h index d5fda71da..d5fda71da 100644 --- a/CryptoPP/words.h +++ b/lib/cryptopp/words.h diff --git a/expat/ascii.h b/lib/expat/ascii.h index d10530b09..d10530b09 100644 --- a/expat/ascii.h +++ b/lib/expat/ascii.h diff --git a/expat/asciitab.h b/lib/expat/asciitab.h index 79a15c28c..79a15c28c 100644 --- a/expat/asciitab.h +++ b/lib/expat/asciitab.h diff --git a/expat/expat.h b/lib/expat/expat.h index 20a8278f7..20a8278f7 100644 --- a/expat/expat.h +++ b/lib/expat/expat.h diff --git a/expat/expat_external.h b/lib/expat/expat_external.h index 2c03284ea..2c03284ea 100644 --- a/expat/expat_external.h +++ b/lib/expat/expat_external.h diff --git a/expat/iasciitab.h b/lib/expat/iasciitab.h index 24a1d5ccc..24a1d5ccc 100644 --- a/expat/iasciitab.h +++ b/lib/expat/iasciitab.h diff --git a/expat/internal.h b/lib/expat/internal.h index dd5454831..dd5454831 100644 --- a/expat/internal.h +++ b/lib/expat/internal.h diff --git a/expat/latin1tab.h b/lib/expat/latin1tab.h index 53c25d76b..53c25d76b 100644 --- a/expat/latin1tab.h +++ b/lib/expat/latin1tab.h diff --git a/expat/nametab.h b/lib/expat/nametab.h index b05e62c77..b05e62c77 100644 --- a/expat/nametab.h +++ b/lib/expat/nametab.h diff --git a/expat/utf8tab.h b/lib/expat/utf8tab.h index 7bb3e7760..7bb3e7760 100644 --- a/expat/utf8tab.h +++ b/lib/expat/utf8tab.h diff --git a/expat/winconfig.h b/lib/expat/winconfig.h index c1b791d62..c1b791d62 100644 --- a/expat/winconfig.h +++ b/lib/expat/winconfig.h diff --git a/expat/xmlparse.c b/lib/expat/xmlparse.c index 115b42127..115b42127 100644 --- a/expat/xmlparse.c +++ b/lib/expat/xmlparse.c diff --git a/expat/xmlrole.c b/lib/expat/xmlrole.c index 55cba6429..55cba6429 100644 --- a/expat/xmlrole.c +++ b/lib/expat/xmlrole.c diff --git a/expat/xmlrole.h b/lib/expat/xmlrole.h index 4dd9f06f9..4dd9f06f9 100644 --- a/expat/xmlrole.h +++ b/lib/expat/xmlrole.h diff --git a/expat/xmltok.c b/lib/expat/xmltok.c index c23b348eb..c23b348eb 100644 --- a/expat/xmltok.c +++ b/lib/expat/xmltok.c diff --git a/expat/xmltok.h b/lib/expat/xmltok.h index ca867aa6b..ca867aa6b 100644 --- a/expat/xmltok.h +++ b/lib/expat/xmltok.h diff --git a/expat/xmltok_impl.c b/lib/expat/xmltok_impl.c index 5fa578a43..5fa578a43 100644 --- a/expat/xmltok_impl.c +++ b/lib/expat/xmltok_impl.c diff --git a/expat/xmltok_impl.h b/lib/expat/xmltok_impl.h index da0ea60a6..da0ea60a6 100644 --- a/expat/xmltok_impl.h +++ b/lib/expat/xmltok_impl.h diff --git a/expat/xmltok_ns.c b/lib/expat/xmltok_ns.c index 5afdfbe5c..5afdfbe5c 100644 --- a/expat/xmltok_ns.c +++ b/lib/expat/xmltok_ns.c diff --git a/iniFile/iniFile.cpp b/lib/inifile/iniFile.cpp index da523e783..da523e783 100644 --- a/iniFile/iniFile.cpp +++ b/lib/inifile/iniFile.cpp diff --git a/iniFile/iniFile.h b/lib/inifile/iniFile.h index 83d961fc6..83d961fc6 100644 --- a/iniFile/iniFile.h +++ b/lib/inifile/iniFile.h diff --git a/jsoncpp-src-0.5.0/include/json/autolink.h b/lib/jsoncpp/include/json/autolink.h index 37c9258ed..37c9258ed 100644 --- a/jsoncpp-src-0.5.0/include/json/autolink.h +++ b/lib/jsoncpp/include/json/autolink.h diff --git a/jsoncpp-src-0.5.0/include/json/config.h b/lib/jsoncpp/include/json/config.h index 5d334cbc5..5d334cbc5 100644 --- a/jsoncpp-src-0.5.0/include/json/config.h +++ b/lib/jsoncpp/include/json/config.h diff --git a/jsoncpp-src-0.5.0/include/json/features.h b/lib/jsoncpp/include/json/features.h index 5a9adec11..5a9adec11 100644 --- a/jsoncpp-src-0.5.0/include/json/features.h +++ b/lib/jsoncpp/include/json/features.h diff --git a/jsoncpp-src-0.5.0/include/json/forwards.h b/lib/jsoncpp/include/json/forwards.h index d0ce8300c..d0ce8300c 100644 --- a/jsoncpp-src-0.5.0/include/json/forwards.h +++ b/lib/jsoncpp/include/json/forwards.h diff --git a/jsoncpp-src-0.5.0/include/json/json.h b/lib/jsoncpp/include/json/json.h index c71ed65ab..c71ed65ab 100644 --- a/jsoncpp-src-0.5.0/include/json/json.h +++ b/lib/jsoncpp/include/json/json.h diff --git a/jsoncpp-src-0.5.0/include/json/reader.h b/lib/jsoncpp/include/json/reader.h index ee1d6a244..ee1d6a244 100644 --- a/jsoncpp-src-0.5.0/include/json/reader.h +++ b/lib/jsoncpp/include/json/reader.h diff --git a/jsoncpp-src-0.5.0/include/json/value.h b/lib/jsoncpp/include/json/value.h index 58bfd88e7..58bfd88e7 100644 --- a/jsoncpp-src-0.5.0/include/json/value.h +++ b/lib/jsoncpp/include/json/value.h diff --git a/jsoncpp-src-0.5.0/include/json/writer.h b/lib/jsoncpp/include/json/writer.h index 5f4b83be4..5f4b83be4 100644 --- a/jsoncpp-src-0.5.0/include/json/writer.h +++ b/lib/jsoncpp/include/json/writer.h diff --git a/jsoncpp-src-0.5.0/src/lib_json/json_batchallocator.h b/lib/jsoncpp/src/lib_json/json_batchallocator.h index 87ea5ed80..87ea5ed80 100644 --- a/jsoncpp-src-0.5.0/src/lib_json/json_batchallocator.h +++ b/lib/jsoncpp/src/lib_json/json_batchallocator.h diff --git a/jsoncpp-src-0.5.0/src/lib_json/json_internalarray.inl b/lib/jsoncpp/src/lib_json/json_internalarray.inl index 9b985d258..9b985d258 100644 --- a/jsoncpp-src-0.5.0/src/lib_json/json_internalarray.inl +++ b/lib/jsoncpp/src/lib_json/json_internalarray.inl diff --git a/jsoncpp-src-0.5.0/src/lib_json/json_internalmap.inl b/lib/jsoncpp/src/lib_json/json_internalmap.inl index 19771488d..19771488d 100644 --- a/jsoncpp-src-0.5.0/src/lib_json/json_internalmap.inl +++ b/lib/jsoncpp/src/lib_json/json_internalmap.inl diff --git a/lib/jsoncpp/src/lib_json/json_reader.cpp b/lib/jsoncpp/src/lib_json/json_reader.cpp new file mode 100644 index 000000000..e9d6b88d2 --- /dev/null +++ b/lib/jsoncpp/src/lib_json/json_reader.cpp @@ -0,0 +1,885 @@ +#include "../../include/json/reader.h" +#include "../../include/json/value.h" +#include <utility> +#include <cstdio> +#include <cassert> +#include <cstring> +#include <iostream> +#include <stdexcept> + +#if _MSC_VER >= 1400 // VC++ 8.0 +#pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. +#endif + +namespace Json { + +// Implementation of class Features +// //////////////////////////////// + +Features::Features() + : allowComments_( true ) + , strictRoot_( false ) +{ +} + + +Features +Features::all() +{ + return Features(); +} + + +Features +Features::strictMode() +{ + Features features; + features.allowComments_ = false; + features.strictRoot_ = true; + return features; +} + +// Implementation of class Reader +// //////////////////////////////// + + +static inline bool +in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4 ) +{ + return c == c1 || c == c2 || c == c3 || c == c4; +} + +static inline bool +in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4, Reader::Char c5 ) +{ + return c == c1 || c == c2 || c == c3 || c == c4 || c == c5; +} + + +static bool +containsNewLine( Reader::Location begin, + Reader::Location end ) +{ + for ( ;begin < end; ++begin ) + if ( *begin == '\n' || *begin == '\r' ) + return true; + return false; +} + +static std::string codePointToUTF8(unsigned int cp) +{ + std::string result; + + // based on description from http://en.wikipedia.org/wiki/UTF-8 + + if (cp <= 0x7f) + { + result.resize(1); + result[0] = static_cast<char>(cp); + } + else if (cp <= 0x7FF) + { + result.resize(2); + result[1] = static_cast<char>(0x80 | (0x3f & cp)); + result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6))); + } + else if (cp <= 0xFFFF) + { + result.resize(3); + result[2] = static_cast<char>(0x80 | (0x3f & cp)); + result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6))); + result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12))); + } + else if (cp <= 0x10FFFF) + { + result.resize(4); + result[3] = static_cast<char>(0x80 | (0x3f & cp)); + result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6))); + result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12))); + result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18))); + } + + return result; +} + + +// Class Reader +// ////////////////////////////////////////////////////////////////// + +Reader::Reader() + : features_( Features::all() ) +{ +} + + +Reader::Reader( const Features &features ) + : features_( features ) +{ +} + + +bool +Reader::parse( const std::string &document, + Value &root, + bool collectComments ) +{ + document_ = document; + const char *begin = document_.c_str(); + const char *end = begin + document_.length(); + return parse( begin, end, root, collectComments ); +} + + +bool +Reader::parse( std::istream& sin, + Value &root, + bool collectComments ) +{ + //std::istream_iterator<char> begin(sin); + //std::istream_iterator<char> end; + // Those would allow streamed input from a file, if parse() were a + // template function. + + // Since std::string is reference-counted, this at least does not + // create an extra copy. + std::string doc; + std::getline(sin, doc, (char)EOF); + return parse( doc, root, collectComments ); +} + +bool +Reader::parse( const char *beginDoc, const char *endDoc, + Value &root, + bool collectComments ) +{ + if ( !features_.allowComments_ ) + { + collectComments = false; + } + + begin_ = beginDoc; + end_ = endDoc; + collectComments_ = collectComments; + current_ = begin_; + lastValueEnd_ = 0; + lastValue_ = 0; + commentsBefore_ = ""; + errors_.clear(); + while ( !nodes_.empty() ) + nodes_.pop(); + nodes_.push( &root ); + + bool successful = readValue(); + Token token; + skipCommentTokens( token ); + if ( collectComments_ && !commentsBefore_.empty() ) + root.setComment( commentsBefore_, commentAfter ); + if ( features_.strictRoot_ ) + { + if ( !root.isArray() && !root.isObject() ) + { + // Set error location to start of doc, ideally should be first token found in doc + token.type_ = tokenError; + token.start_ = beginDoc; + token.end_ = endDoc; + addError( "A valid JSON document must be either an array or an object value.", + token ); + return false; + } + } + return successful; +} + + +bool +Reader::readValue() +{ + Token token; + skipCommentTokens( token ); + bool successful = true; + + if ( collectComments_ && !commentsBefore_.empty() ) + { + currentValue().setComment( commentsBefore_, commentBefore ); + commentsBefore_ = ""; + } + + + switch ( token.type_ ) + { + case tokenObjectBegin: + successful = readObject( token ); + break; + case tokenArrayBegin: + successful = readArray( token ); + break; + case tokenNumber: + successful = decodeNumber( token ); + break; + case tokenString: + successful = decodeString( token ); + break; + case tokenTrue: + currentValue() = true; + break; + case tokenFalse: + currentValue() = false; + break; + case tokenNull: + currentValue() = Value(); + break; + default: + return addError( "Syntax error: value, object or array expected.", token ); + } + + if ( collectComments_ ) + { + lastValueEnd_ = current_; + lastValue_ = ¤tValue(); + } + + return successful; +} + + +void +Reader::skipCommentTokens( Token &token ) +{ + if ( features_.allowComments_ ) + { + do + { + readToken( token ); + } + while ( token.type_ == tokenComment ); + } + else + { + readToken( token ); + } +} + + +bool +Reader::expectToken( TokenType type, Token &token, const char *message ) +{ + readToken( token ); + if ( token.type_ != type ) + return addError( message, token ); + return true; +} + + +bool +Reader::readToken( Token &token ) +{ + skipSpaces(); + token.start_ = current_; + Char c = getNextChar(); + bool ok = true; + switch ( c ) + { + case '{': + token.type_ = tokenObjectBegin; + break; + case '}': + token.type_ = tokenObjectEnd; + break; + case '[': + token.type_ = tokenArrayBegin; + break; + case ']': + token.type_ = tokenArrayEnd; + break; + case '"': + token.type_ = tokenString; + ok = readString(); + break; + case '/': + token.type_ = tokenComment; + ok = readComment(); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + token.type_ = tokenNumber; + readNumber(); + break; + case 't': + token.type_ = tokenTrue; + ok = match( "rue", 3 ); + break; + case 'f': + token.type_ = tokenFalse; + ok = match( "alse", 4 ); + break; + case 'n': + token.type_ = tokenNull; + ok = match( "ull", 3 ); + break; + case ',': + token.type_ = tokenArraySeparator; + break; + case ':': + token.type_ = tokenMemberSeparator; + break; + case 0: + token.type_ = tokenEndOfStream; + break; + default: + ok = false; + break; + } + if ( !ok ) + token.type_ = tokenError; + token.end_ = current_; + return true; +} + + +void +Reader::skipSpaces() +{ + while ( current_ != end_ ) + { + Char c = *current_; + if ( c == ' ' || c == '\t' || c == '\r' || c == '\n' ) + ++current_; + else + break; + } +} + + +bool +Reader::match( Location pattern, + int patternLength ) +{ + if ( end_ - current_ < patternLength ) + return false; + int index = patternLength; + while ( index-- ) + if ( current_[index] != pattern[index] ) + return false; + current_ += patternLength; + return true; +} + + +bool +Reader::readComment() +{ + Location commentBegin = current_ - 1; + Char c = getNextChar(); + bool successful = false; + if ( c == '*' ) + successful = readCStyleComment(); + else if ( c == '/' ) + successful = readCppStyleComment(); + if ( !successful ) + return false; + + if ( collectComments_ ) + { + CommentPlacement placement = commentBefore; + if ( lastValueEnd_ && !containsNewLine( lastValueEnd_, commentBegin ) ) + { + if ( c != '*' || !containsNewLine( commentBegin, current_ ) ) + placement = commentAfterOnSameLine; + } + + addComment( commentBegin, current_, placement ); + } + return true; +} + + +void +Reader::addComment( Location begin, + Location end, + CommentPlacement placement ) +{ + assert( collectComments_ ); + if ( placement == commentAfterOnSameLine ) + { + assert( lastValue_ != 0 ); + lastValue_->setComment( std::string( begin, end ), placement ); + } + else + { + if ( !commentsBefore_.empty() ) + commentsBefore_ += "\n"; + commentsBefore_ += std::string( begin, end ); + } +} + + +bool +Reader::readCStyleComment() +{ + while ( current_ != end_ ) + { + Char c = getNextChar(); + if ( c == '*' && *current_ == '/' ) + break; + } + return getNextChar() == '/'; +} + + +bool +Reader::readCppStyleComment() +{ + while ( current_ != end_ ) + { + Char c = getNextChar(); + if ( c == '\r' || c == '\n' ) + break; + } + return true; +} + + +void +Reader::readNumber() +{ + while ( current_ != end_ ) + { + if ( !(*current_ >= '0' && *current_ <= '9') && + !in( *current_, '.', 'e', 'E', '+', '-' ) ) + break; + ++current_; + } +} + +bool +Reader::readString() +{ + Char c = 0; + while ( current_ != end_ ) + { + c = getNextChar(); + if ( c == '\\' ) + getNextChar(); + else if ( c == '"' ) + break; + } + return c == '"'; +} + + +bool +Reader::readObject( Token &tokenStart ) +{ + Token tokenName; + std::string name; + currentValue() = Value( objectValue ); + while ( readToken( tokenName ) ) + { + bool initialTokenOk = true; + while ( tokenName.type_ == tokenComment && initialTokenOk ) + initialTokenOk = readToken( tokenName ); + if ( !initialTokenOk ) + break; + if ( tokenName.type_ == tokenObjectEnd && name.empty() ) // empty object + return true; + if ( tokenName.type_ != tokenString ) + break; + + name = ""; + if ( !decodeString( tokenName, name ) ) + return recoverFromError( tokenObjectEnd ); + + Token colon; + if ( !readToken( colon ) || colon.type_ != tokenMemberSeparator ) + { + return addErrorAndRecover( "Missing ':' after object member name", + colon, + tokenObjectEnd ); + } + Value &value = currentValue()[ name ]; + nodes_.push( &value ); + bool ok = readValue(); + nodes_.pop(); + if ( !ok ) // error already set + return recoverFromError( tokenObjectEnd ); + + Token comma; + if ( !readToken( comma ) + || ( comma.type_ != tokenObjectEnd && + comma.type_ != tokenArraySeparator && + comma.type_ != tokenComment ) ) + { + return addErrorAndRecover( "Missing ',' or '}' in object declaration", + comma, + tokenObjectEnd ); + } + bool finalizeTokenOk = true; + while ( comma.type_ == tokenComment && + finalizeTokenOk ) + finalizeTokenOk = readToken( comma ); + if ( comma.type_ == tokenObjectEnd ) + return true; + } + return addErrorAndRecover( "Missing '}' or object member name", + tokenName, + tokenObjectEnd ); +} + + +bool +Reader::readArray( Token &tokenStart ) +{ + currentValue() = Value( arrayValue ); + skipSpaces(); + if ( *current_ == ']' ) // empty array + { + Token endArray; + readToken( endArray ); + return true; + } + int index = 0; + while ( true ) + { + Value &value = currentValue()[ index++ ]; + nodes_.push( &value ); + bool ok = readValue(); + nodes_.pop(); + if ( !ok ) // error already set + return recoverFromError( tokenArrayEnd ); + + Token token; + // Accept Comment after last item in the array. + ok = readToken( token ); + while ( token.type_ == tokenComment && ok ) + { + ok = readToken( token ); + } + bool badTokenType = ( token.type_ == tokenArraySeparator && + token.type_ == tokenArrayEnd ); + if ( !ok || badTokenType ) + { + return addErrorAndRecover( "Missing ',' or ']' in array declaration", + token, + tokenArrayEnd ); + } + if ( token.type_ == tokenArrayEnd ) + break; + } + return true; +} + + +bool +Reader::decodeNumber( Token &token ) +{ + bool isDouble = false; + for ( Location inspect = token.start_; inspect != token.end_; ++inspect ) + { + isDouble = isDouble + || in( *inspect, '.', 'e', 'E', '+' ) + || ( *inspect == '-' && inspect != token.start_ ); + } + if ( isDouble ) + return decodeDouble( token ); + Location current = token.start_; + bool isNegative = *current == '-'; + if ( isNegative ) + ++current; + Value::UInt threshold = (isNegative ? Value::UInt(-Value::minInt) + : Value::maxUInt) / 10; + Value::UInt value = 0; + while ( current < token.end_ ) + { + Char c = *current++; + if ( c < '0' || c > '9' ) + return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); + if ( value >= threshold ) + return decodeDouble( token ); + value = value * 10 + Value::UInt(c - '0'); + } + if ( isNegative ) + currentValue() = -Value::Int( value ); + else if ( value <= Value::UInt(Value::maxInt) ) + currentValue() = Value::Int( value ); + else + currentValue() = value; + return true; +} + + +bool +Reader::decodeDouble( Token &token ) +{ + double value = 0; + const int bufferSize = 32; + int count; + int length = int(token.end_ - token.start_); + if ( length <= bufferSize ) + { + Char buffer[bufferSize]; + memcpy( buffer, token.start_, length ); + buffer[length] = 0; + count = sscanf( buffer, "%lf", &value ); + } + else + { + std::string buffer( token.start_, token.end_ ); + count = sscanf( buffer.c_str(), "%lf", &value ); + } + + if ( count != 1 ) + return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token ); + currentValue() = value; + return true; +} + + +bool +Reader::decodeString( Token &token ) +{ + std::string decoded; + if ( !decodeString( token, decoded ) ) + return false; + currentValue() = decoded; + return true; +} + + +bool +Reader::decodeString( Token &token, std::string &decoded ) +{ + decoded.reserve( token.end_ - token.start_ - 2 ); + Location current = token.start_ + 1; // skip '"' + Location end = token.end_ - 1; // do not include '"' + while ( current != end ) + { + Char c = *current++; + if ( c == '"' ) + break; + else if ( c == '\\' ) + { + if ( current == end ) + return addError( "Empty escape sequence in string", token, current ); + Char escape = *current++; + switch ( escape ) + { + case '"': decoded += '"'; break; + case '/': decoded += '/'; break; + case '\\': decoded += '\\'; break; + case 'b': decoded += '\b'; break; + case 'f': decoded += '\f'; break; + case 'n': decoded += '\n'; break; + case 'r': decoded += '\r'; break; + case 't': decoded += '\t'; break; + case 'u': + { + unsigned int unicode; + if ( !decodeUnicodeCodePoint( token, current, end, unicode ) ) + return false; + decoded += codePointToUTF8(unicode); + } + break; + default: + return addError( "Bad escape sequence in string", token, current ); + } + } + else + { + decoded += c; + } + } + return true; +} + +bool +Reader::decodeUnicodeCodePoint( Token &token, + Location ¤t, + Location end, + unsigned int &unicode ) +{ + + if ( !decodeUnicodeEscapeSequence( token, current, end, unicode ) ) + return false; + if (unicode >= 0xD800 && unicode <= 0xDBFF) + { + // surrogate pairs + if (end - current < 6) + return addError( "additional six characters expected to parse unicode surrogate pair.", token, current ); + unsigned int surrogatePair; + if (*(current++) == '\\' && *(current++)== 'u') + { + if (decodeUnicodeEscapeSequence( token, current, end, surrogatePair )) + { + unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF); + } + else + return false; + } + else + return addError( "expecting another \\u token to begin the second half of a unicode surrogate pair", token, current ); + } + return true; +} + +bool +Reader::decodeUnicodeEscapeSequence( Token &token, + Location ¤t, + Location end, + unsigned int &unicode ) +{ + if ( end - current < 4 ) + return addError( "Bad unicode escape sequence in string: four digits expected.", token, current ); + unicode = 0; + for ( int index =0; index < 4; ++index ) + { + Char c = *current++; + unicode *= 16; + if ( c >= '0' && c <= '9' ) + unicode += c - '0'; + else if ( c >= 'a' && c <= 'f' ) + unicode += c - 'a' + 10; + else if ( c >= 'A' && c <= 'F' ) + unicode += c - 'A' + 10; + else + return addError( "Bad unicode escape sequence in string: hexadecimal digit expected.", token, current ); + } + return true; +} + + +bool +Reader::addError( const std::string &message, + Token &token, + Location extra ) +{ + ErrorInfo info; + info.token_ = token; + info.message_ = message; + info.extra_ = extra; + errors_.push_back( info ); + return false; +} + + +bool +Reader::recoverFromError( TokenType skipUntilToken ) +{ + int errorCount = int(errors_.size()); + Token skip; + while ( true ) + { + if ( !readToken(skip) ) + errors_.resize( errorCount ); // discard errors caused by recovery + if ( skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream ) + break; + } + errors_.resize( errorCount ); + return false; +} + + +bool +Reader::addErrorAndRecover( const std::string &message, + Token &token, + TokenType skipUntilToken ) +{ + addError( message, token ); + return recoverFromError( skipUntilToken ); +} + + +Value & +Reader::currentValue() +{ + return *(nodes_.top()); +} + + +Reader::Char +Reader::getNextChar() +{ + if ( current_ == end_ ) + return 0; + return *current_++; +} + + +void +Reader::getLocationLineAndColumn( Location location, + int &line, + int &column ) const +{ + Location current = begin_; + Location lastLineStart = current; + line = 0; + while ( current < location && current != end_ ) + { + Char c = *current++; + if ( c == '\r' ) + { + if ( *current == '\n' ) + ++current; + lastLineStart = current; + ++line; + } + else if ( c == '\n' ) + { + lastLineStart = current; + ++line; + } + } + // column & line start at 1 + column = int(location - lastLineStart) + 1; + ++line; +} + + +std::string +Reader::getLocationLineAndColumn( Location location ) const +{ + int line, column; + getLocationLineAndColumn( location, line, column ); + char buffer[18+16+16+1]; + sprintf( buffer, "Line %d, Column %d", line, column ); + return buffer; +} + + +std::string +Reader::getFormatedErrorMessages() const +{ + std::string formattedMessage; + for ( Errors::const_iterator itError = errors_.begin(); + itError != errors_.end(); + ++itError ) + { + const ErrorInfo &error = *itError; + formattedMessage += "* " + getLocationLineAndColumn( error.token_.start_ ) + "\n"; + formattedMessage += " " + error.message_ + "\n"; + if ( error.extra_ ) + formattedMessage += "See " + getLocationLineAndColumn( error.extra_ ) + " for detail.\n"; + } + return formattedMessage; +} + +#define JSON_ASSERT( condition ) assert( condition ); +std::istream& operator>>( std::istream &sin, Value &root ) +{ + Json::Reader reader; + bool ok = reader.parse(sin, root, true); + JSON_ASSERT( ok ); + //if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages()); + return sin; +} + + +} // namespace Json diff --git a/lib/jsoncpp/src/lib_json/json_value.cpp b/lib/jsoncpp/src/lib_json/json_value.cpp new file mode 100644 index 000000000..ea033c400 --- /dev/null +++ b/lib/jsoncpp/src/lib_json/json_value.cpp @@ -0,0 +1,1727 @@ +#include <iostream> +#include "../../include/json/json.h" +#include "../../include/json/writer.h" +#include <utility> +#include <stdexcept> +#include <cstring> +#include <cassert> +#ifdef JSON_USE_CPPTL +# include <cpptl/conststring.h> +#endif +#include <cstddef> // size_t +#ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR +# include "json_batchallocator.h" +#endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR + +#define JSON_ASSERT_UNREACHABLE assert( false ) +#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw +#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message ); + +namespace Json { + +const Value Value::null; +const Int Value::minInt = Int( ~(UInt(-1)/2) ); +const Int Value::maxInt = Int( UInt(-1)/2 ); +const UInt Value::maxUInt = UInt(-1); + +// A "safe" implementation of strdup. Allow null pointer to be passed. +// Also avoid warning on msvc80. +// +//inline char *safeStringDup( const char *czstring ) +//{ +// if ( czstring ) +// { +// const size_t length = (unsigned int)( strlen(czstring) + 1 ); +// char *newString = static_cast<char *>( malloc( length ) ); +// memcpy( newString, czstring, length ); +// return newString; +// } +// return 0; +//} +// +//inline char *safeStringDup( const std::string &str ) +//{ +// if ( !str.empty() ) +// { +// const size_t length = str.length(); +// char *newString = static_cast<char *>( malloc( length + 1 ) ); +// memcpy( newString, str.c_str(), length ); +// newString[length] = 0; +// return newString; +// } +// return 0; +//} + +ValueAllocator::~ValueAllocator() +{ +} + +class DefaultValueAllocator : public ValueAllocator +{ +public: + virtual ~DefaultValueAllocator() + { + } + + virtual char *makeMemberName( const char *memberName ) + { + return duplicateStringValue( memberName ); + } + + virtual void releaseMemberName( char *memberName ) + { + releaseStringValue( memberName ); + } + + virtual char *duplicateStringValue( const char *value, + unsigned int length = unknown ) + { + //@todo invesgate this old optimization + //if ( !value || value[0] == 0 ) + // return 0; + + if ( length == unknown ) + length = (unsigned int)strlen(value); + char *newString = static_cast<char *>( malloc( length + 1 ) ); + memcpy( newString, value, length ); + newString[length] = 0; + return newString; + } + + virtual void releaseStringValue( char *value ) + { + if ( value ) + free( value ); + } +}; + +static ValueAllocator *&valueAllocator() +{ + static DefaultValueAllocator defaultAllocator; + static ValueAllocator *valueAllocator = &defaultAllocator; + return valueAllocator; +} + +static struct DummyValueAllocatorInitializer { + DummyValueAllocatorInitializer() + { + valueAllocator(); // ensure valueAllocator() statics are initialized before main(). + } +} dummyValueAllocatorInitializer; + + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ValueInternals... +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +#ifdef JSON_VALUE_USE_INTERNAL_MAP +# include "json_internalarray.inl" +# include "json_internalmap.inl" +#endif // JSON_VALUE_USE_INTERNAL_MAP + +# include "json_valueiterator.inl" + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class Value::CommentInfo +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + + +Value::CommentInfo::CommentInfo() + : comment_( 0 ) +{ +} + +Value::CommentInfo::~CommentInfo() +{ + if ( comment_ ) + valueAllocator()->releaseStringValue( comment_ ); +} + + +void +Value::CommentInfo::setComment( const char *text ) +{ + if ( comment_ ) + valueAllocator()->releaseStringValue( comment_ ); + JSON_ASSERT( text ); + //JSON_ASSERT_MESSAGE( text[0]=='\0' || text[0]=='/', "Comments must start with /"); + JSON_ASSERT( text[0]=='\0' || text[0]=='/' ); + // It seems that /**/ style comments are acceptable as well. + comment_ = valueAllocator()->duplicateStringValue( text ); +} + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class Value::CZString +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +# ifndef JSON_VALUE_USE_INTERNAL_MAP + +// Notes: index_ indicates if the string was allocated when +// a string is stored. + +Value::CZString::CZString( int index ) + : cstr_( 0 ) + , index_( index ) +{ +} + +Value::CZString::CZString( const char *cstr, DuplicationPolicy allocate ) + : cstr_( allocate == duplicate ? valueAllocator()->makeMemberName(cstr) + : cstr ) + , index_( allocate ) +{ +} + +Value::CZString::CZString( const CZString &other ) +: cstr_( other.index_ != noDuplication && other.cstr_ != 0 + ? valueAllocator()->makeMemberName( other.cstr_ ) + : other.cstr_ ) + , index_( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate) + : other.index_ ) +{ +} + +Value::CZString::~CZString() +{ + if ( cstr_ && index_ == duplicate ) + valueAllocator()->releaseMemberName( const_cast<char *>( cstr_ ) ); +} + +void +Value::CZString::swap( CZString &other ) +{ + std::swap( cstr_, other.cstr_ ); + std::swap( index_, other.index_ ); +} + +Value::CZString & +Value::CZString::operator =( const CZString &other ) +{ + CZString temp( other ); + swap( temp ); + return *this; +} + +bool +Value::CZString::operator<( const CZString &other ) const +{ + if ( cstr_ ) + return strcmp( cstr_, other.cstr_ ) < 0; + return index_ < other.index_; +} + +bool +Value::CZString::operator==( const CZString &other ) const +{ + if ( cstr_ ) + return strcmp( cstr_, other.cstr_ ) == 0; + return index_ == other.index_; +} + + +int +Value::CZString::index() const +{ + return index_; +} + + +const char * +Value::CZString::c_str() const +{ + return cstr_; +} + +bool +Value::CZString::isStaticString() const +{ + return index_ == noDuplication; +} + +#endif // ifndef JSON_VALUE_USE_INTERNAL_MAP + + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class Value::Value +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +/*! \internal Default constructor initialization must be equivalent to: + * memset( this, 0, sizeof(Value) ) + * This optimization is used in ValueInternalMap fast allocator. + */ +Value::Value( ValueType type ) + : type_( type ) + , allocated_( 0 ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + switch ( type ) + { + case nullValue: + break; + case intValue: + case uintValue: + value_.int_ = 0; + break; + case realValue: + value_.real_ = 0.0; + break; + case stringValue: + value_.string_ = 0; + break; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + value_.map_ = new ObjectValues(); + break; +#else + case arrayValue: + value_.array_ = arrayAllocator()->newArray(); + break; + case objectValue: + value_.map_ = mapAllocator()->newMap(); + break; +#endif + case booleanValue: + value_.bool_ = false; + break; + default: + JSON_ASSERT_UNREACHABLE; + } +} + + +Value::Value( Int value ) + : type_( intValue ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.int_ = value; +} + + +Value::Value( UInt value ) + : type_( uintValue ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.uint_ = value; +} + +Value::Value( double value ) + : type_( realValue ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.real_ = value; +} + +Value::Value( const char *value ) + : type_( stringValue ) + , allocated_( true ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = valueAllocator()->duplicateStringValue( value ); +} + + +Value::Value( const char *beginValue, + const char *endValue ) + : type_( stringValue ) + , allocated_( true ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = valueAllocator()->duplicateStringValue( beginValue, + UInt(endValue - beginValue) ); +} + + +Value::Value( const std::string &value ) + : type_( stringValue ) + , allocated_( true ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = valueAllocator()->duplicateStringValue( value.c_str(), + (unsigned int)value.length() ); + +} + +Value::Value( const StaticString &value ) + : type_( stringValue ) + , allocated_( false ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = const_cast<char *>( value.c_str() ); +} + + +# ifdef JSON_USE_CPPTL +Value::Value( const CppTL::ConstString &value ) + : type_( stringValue ) + , allocated_( true ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.string_ = valueAllocator()->duplicateStringValue( value, value.length() ); +} +# endif + +Value::Value( bool value ) + : type_( booleanValue ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + value_.bool_ = value; +} + + +Value::Value( const Value &other ) + : type_( other.type_ ) + , comments_( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_( 0 ) +#endif +{ + switch ( type_ ) + { + case nullValue: + case intValue: + case uintValue: + case realValue: + case booleanValue: + value_ = other.value_; + break; + case stringValue: + if ( other.value_.string_ ) + { + value_.string_ = valueAllocator()->duplicateStringValue( other.value_.string_ ); + allocated_ = true; + } + else + value_.string_ = 0; + break; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + value_.map_ = new ObjectValues( *other.value_.map_ ); + break; +#else + case arrayValue: + value_.array_ = arrayAllocator()->newArrayCopy( *other.value_.array_ ); + break; + case objectValue: + value_.map_ = mapAllocator()->newMapCopy( *other.value_.map_ ); + break; +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + if ( other.comments_ ) + { + comments_ = new CommentInfo[numberOfCommentPlacement]; + for ( int comment =0; comment < numberOfCommentPlacement; ++comment ) + { + const CommentInfo &otherComment = other.comments_[comment]; + if ( otherComment.comment_ ) + comments_[comment].setComment( otherComment.comment_ ); + } + } +} + + +Value::~Value() +{ + switch ( type_ ) + { + case nullValue: + case intValue: + case uintValue: + case realValue: + case booleanValue: + break; + case stringValue: + if ( allocated_ ) + valueAllocator()->releaseStringValue( value_.string_ ); + break; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + delete value_.map_; + break; +#else + case arrayValue: + arrayAllocator()->destructArray( value_.array_ ); + break; + case objectValue: + mapAllocator()->destructMap( value_.map_ ); + break; +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + + if ( comments_ ) + delete[] comments_; +} + +Value & +Value::operator=( const Value &other ) +{ + Value temp( other ); + swap( temp ); + return *this; +} + +void +Value::swap( Value &other ) +{ + ValueType temp = type_; + type_ = other.type_; + other.type_ = temp; + std::swap( value_, other.value_ ); + int temp2 = allocated_; + allocated_ = other.allocated_; + other.allocated_ = temp2; +} + +ValueType +Value::type() const +{ + return type_; +} + + +int +Value::compare( const Value &other ) +{ + /* + int typeDelta = other.type_ - type_; + switch ( type_ ) + { + case nullValue: + + return other.type_ == type_; + case intValue: + if ( other.type_.isNumeric() + case uintValue: + case realValue: + case booleanValue: + break; + case stringValue, + break; + case arrayValue: + delete value_.array_; + break; + case objectValue: + delete value_.map_; + default: + JSON_ASSERT_UNREACHABLE; + } + */ + return 0; // unreachable +} + +bool +Value::operator <( const Value &other ) const +{ + int typeDelta = type_ - other.type_; + if ( typeDelta ) + return typeDelta < 0 ? true : false; + switch ( type_ ) + { + case nullValue: + return false; + case intValue: + return value_.int_ < other.value_.int_; + case uintValue: + return value_.uint_ < other.value_.uint_; + case realValue: + return value_.real_ < other.value_.real_; + case booleanValue: + return value_.bool_ < other.value_.bool_; + case stringValue: + return ( value_.string_ == 0 && other.value_.string_ ) + || ( other.value_.string_ + && value_.string_ + && strcmp( value_.string_, other.value_.string_ ) < 0 ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + { + int delta = int( value_.map_->size() - other.value_.map_->size() ); + if ( delta ) + return delta < 0; + return (*value_.map_) < (*other.value_.map_); + } +#else + case arrayValue: + return value_.array_->compare( *(other.value_.array_) ) < 0; + case objectValue: + return value_.map_->compare( *(other.value_.map_) ) < 0; +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable +} + +bool +Value::operator <=( const Value &other ) const +{ + return !(other > *this); +} + +bool +Value::operator >=( const Value &other ) const +{ + return !(*this < other); +} + +bool +Value::operator >( const Value &other ) const +{ + return other < *this; +} + +bool +Value::operator ==( const Value &other ) const +{ + //if ( type_ != other.type_ ) + // GCC 2.95.3 says: + // attempt to take address of bit-field structure member `Json::Value::type_' + // Beats me, but a temp solves the problem. + int temp = other.type_; + if ( type_ != temp ) + return false; + switch ( type_ ) + { + case nullValue: + return true; + case intValue: + return value_.int_ == other.value_.int_; + case uintValue: + return value_.uint_ == other.value_.uint_; + case realValue: + return value_.real_ == other.value_.real_; + case booleanValue: + return value_.bool_ == other.value_.bool_; + case stringValue: + return ( value_.string_ == other.value_.string_ ) + || ( other.value_.string_ + && value_.string_ + && strcmp( value_.string_, other.value_.string_ ) == 0 ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + return value_.map_->size() == other.value_.map_->size() + && (*value_.map_) == (*other.value_.map_); +#else + case arrayValue: + return value_.array_->compare( *(other.value_.array_) ) == 0; + case objectValue: + return value_.map_->compare( *(other.value_.map_) ) == 0; +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable +} + +bool +Value::operator !=( const Value &other ) const +{ + return !( *this == other ); +} + +const char * +Value::asCString() const +{ + JSON_ASSERT( type_ == stringValue ); + return value_.string_; +} + + +std::string +Value::asString() const +{ + switch ( type_ ) + { + case nullValue: + return ""; + case stringValue: + return value_.string_ ? value_.string_ : ""; + case booleanValue: + return value_.bool_ ? "true" : "false"; + case intValue: + case uintValue: + case realValue: + case arrayValue: + case objectValue: + //JSON_ASSERT_MESSAGE( false, "Type is not convertible to string" ); + JSON_ASSERT( false ); + default: + JSON_ASSERT_UNREACHABLE; + } + return ""; // unreachable +} + +# ifdef JSON_USE_CPPTL +CppTL::ConstString +Value::asConstString() const +{ + return CppTL::ConstString( asString().c_str() ); +} +# endif + +Value::Int +Value::asInt() const +{ + switch ( type_ ) + { + case nullValue: + return 0; + case intValue: + return value_.int_; + case uintValue: + //JSON_ASSERT_MESSAGE( value_.uint_ < (unsigned)maxInt, "integer out of signed integer range" ); + JSON_ASSERT( value_.uint_ < (unsigned)maxInt ); + return value_.uint_; + case realValue: + //JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" ); + JSON_ASSERT( value_.real_ >= minInt && value_.real_ <= maxInt ); + return Int( value_.real_ ); + case booleanValue: + return value_.bool_ ? 1 : 0; + case stringValue: + case arrayValue: + case objectValue: + //JSON_ASSERT_MESSAGE( false, "Type is not convertible to int" ); + JSON_ASSERT( false ); + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable; +} + +Value::UInt +Value::asUInt() const +{ + switch ( type_ ) + { + case nullValue: + return 0; + case intValue: + //JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" ); + JSON_ASSERT( value_.int_ >= 0 ); + return value_.int_; + case uintValue: + return value_.uint_; + case realValue: + //JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" ); + JSON_ASSERT( value_.real_ >= 0 && value_.real_ <= maxUInt ); + return UInt( value_.real_ ); + case booleanValue: + return value_.bool_ ? 1 : 0; + case stringValue: + case arrayValue: + case objectValue: + //JSON_ASSERT_MESSAGE( false, "Type is not convertible to uint" ); + JSON_ASSERT( false ); + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable; +} + +double +Value::asDouble() const +{ + switch ( type_ ) + { + case nullValue: + return 0.0; + case intValue: + return value_.int_; + case uintValue: + return value_.uint_; + case realValue: + return value_.real_; + case booleanValue: + return value_.bool_ ? 1.0 : 0.0; + case stringValue: + case arrayValue: + case objectValue: + //JSON_ASSERT_MESSAGE( false, "Type is not convertible to double" ); + JSON_ASSERT( false ); + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable; +} + +bool +Value::asBool() const +{ + switch ( type_ ) + { + case nullValue: + return false; + case intValue: + case uintValue: + return value_.int_ != 0; + case realValue: + return value_.real_ != 0.0; + case booleanValue: + return value_.bool_; + case stringValue: + return value_.string_ && value_.string_[0] != 0; + case arrayValue: + case objectValue: + return value_.map_->size() != 0; + default: + JSON_ASSERT_UNREACHABLE; + } + return false; // unreachable; +} + + +bool +Value::isConvertibleTo( ValueType other ) const +{ + switch ( type_ ) + { + case nullValue: + return true; + case intValue: + return ( other == nullValue && value_.int_ == 0 ) + || other == intValue + || ( other == uintValue && value_.int_ >= 0 ) + || other == realValue + || other == stringValue + || other == booleanValue; + case uintValue: + return ( other == nullValue && value_.uint_ == 0 ) + || ( other == intValue && value_.uint_ <= (unsigned)maxInt ) + || other == uintValue + || other == realValue + || other == stringValue + || other == booleanValue; + case realValue: + return ( other == nullValue && value_.real_ == 0.0 ) + || ( other == intValue && value_.real_ >= minInt && value_.real_ <= maxInt ) + || ( other == uintValue && value_.real_ >= 0 && value_.real_ <= maxUInt ) + || other == realValue + || other == stringValue + || other == booleanValue; + case booleanValue: + return ( other == nullValue && value_.bool_ == false ) + || other == intValue + || other == uintValue + || other == realValue + || other == stringValue + || other == booleanValue; + case stringValue: + return other == stringValue + || ( other == nullValue && (!value_.string_ || value_.string_[0] == 0) ); + case arrayValue: + return other == arrayValue + || ( other == nullValue && value_.map_->size() == 0 ); + case objectValue: + return other == objectValue + || ( other == nullValue && value_.map_->size() == 0 ); + default: + JSON_ASSERT_UNREACHABLE; + } + return false; // unreachable; +} + + +/// Number of values in array or object +Value::UInt +Value::size() const +{ + switch ( type_ ) + { + case nullValue: + case intValue: + case uintValue: + case realValue: + case booleanValue: + case stringValue: + return 0; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: // size of the array is highest index + 1 + if ( !value_.map_->empty() ) + { + ObjectValues::const_iterator itLast = value_.map_->end(); + --itLast; + return (*itLast).first.index()+1; + } + return 0; + case objectValue: + return Int( value_.map_->size() ); +#else + case arrayValue: + return Int( value_.array_->size() ); + case objectValue: + return Int( value_.map_->size() ); +#endif + default: + JSON_ASSERT_UNREACHABLE; + } + return 0; // unreachable; +} + + +bool +Value::empty() const +{ + if ( isNull() || isArray() || isObject() ) + return size() == 0u; + else + return false; +} + + +bool +Value::operator!() const +{ + return isNull(); +} + + +void +Value::clear() +{ + JSON_ASSERT( type_ == nullValue || type_ == arrayValue || type_ == objectValue ); + + switch ( type_ ) + { +#ifndef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + case objectValue: + value_.map_->clear(); + break; +#else + case arrayValue: + value_.array_->clear(); + break; + case objectValue: + value_.map_->clear(); + break; +#endif + default: + break; + } +} + +void +Value::resize( UInt newSize ) +{ + JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); + if ( type_ == nullValue ) + *this = Value( arrayValue ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + UInt oldSize = size(); + if ( newSize == 0 ) + clear(); + else if ( newSize > oldSize ) + (*this)[ newSize - 1 ]; + else + { + for ( UInt index = newSize; index < oldSize; ++index ) + value_.map_->erase( index ); + assert( size() == newSize ); + } +#else + value_.array_->resize( newSize ); +#endif +} + + +Value & +Value::operator[]( UInt index ) +{ + JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); + if ( type_ == nullValue ) + *this = Value( arrayValue ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString key( index ); + ObjectValues::iterator it = value_.map_->lower_bound( key ); + if ( it != value_.map_->end() && (*it).first == key ) + return (*it).second; + + ObjectValues::value_type defaultValue( key, null ); + it = value_.map_->insert( it, defaultValue ); + return (*it).second; +#else + return value_.array_->resolveReference( index ); +#endif +} + + +const Value & +Value::operator[]( UInt index ) const +{ + JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); + if ( type_ == nullValue ) + return null; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString key( index ); + ObjectValues::const_iterator it = value_.map_->find( key ); + if ( it == value_.map_->end() ) + return null; + return (*it).second; +#else + Value *value = value_.array_->find( index ); + return value ? *value : null; +#endif +} + + +Value & +Value::operator[]( const char *key ) +{ + return resolveReference( key, false ); +} + + +Value & +Value::resolveReference( const char *key, + bool isStatic ) +{ + JSON_ASSERT( type_ == nullValue || type_ == objectValue ); + if ( type_ == nullValue ) + *this = Value( objectValue ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString actualKey( key, isStatic ? CZString::noDuplication + : CZString::duplicateOnCopy ); + ObjectValues::iterator it = value_.map_->lower_bound( actualKey ); + if ( it != value_.map_->end() && (*it).first == actualKey ) + return (*it).second; + + ObjectValues::value_type defaultValue( actualKey, null ); + it = value_.map_->insert( it, defaultValue ); + Value &value = (*it).second; + return value; +#else + return value_.map_->resolveReference( key, isStatic ); +#endif +} + + +Value +Value::get( UInt index, + const Value &defaultValue ) const +{ + const Value *value = &((*this)[index]); + return value == &null ? defaultValue : *value; +} + + +bool +Value::isValidIndex( UInt index ) const +{ + return index < size(); +} + + + +const Value & +Value::operator[]( const char *key ) const +{ + JSON_ASSERT( type_ == nullValue || type_ == objectValue ); + if ( type_ == nullValue ) + return null; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString actualKey( key, CZString::noDuplication ); + ObjectValues::const_iterator it = value_.map_->find( actualKey ); + if ( it == value_.map_->end() ) + return null; + return (*it).second; +#else + const Value *value = value_.map_->find( key ); + return value ? *value : null; +#endif +} + + +Value & +Value::operator[]( const std::string &key ) +{ + return (*this)[ key.c_str() ]; +} + + +const Value & +Value::operator[]( const std::string &key ) const +{ + return (*this)[ key.c_str() ]; +} + +Value & +Value::operator[]( const StaticString &key ) +{ + return resolveReference( key, true ); +} + + +# ifdef JSON_USE_CPPTL +Value & +Value::operator[]( const CppTL::ConstString &key ) +{ + return (*this)[ key.c_str() ]; +} + + +const Value & +Value::operator[]( const CppTL::ConstString &key ) const +{ + return (*this)[ key.c_str() ]; +} +# endif + + +Value & +Value::append( const Value &value ) +{ + return (*this)[size()] = value; +} + + +Value +Value::get( const char *key, + const Value &defaultValue ) const +{ + const Value *value = &((*this)[key]); + return value == &null ? defaultValue : *value; +} + + +Value +Value::get( const std::string &key, + const Value &defaultValue ) const +{ + return get( key.c_str(), defaultValue ); +} + +Value +Value::removeMember( const char* key ) +{ + JSON_ASSERT( type_ == nullValue || type_ == objectValue ); + if ( type_ == nullValue ) + return null; +#ifndef JSON_VALUE_USE_INTERNAL_MAP + CZString actualKey( key, CZString::noDuplication ); + ObjectValues::iterator it = value_.map_->find( actualKey ); + if ( it == value_.map_->end() ) + return null; + Value old(it->second); + value_.map_->erase(it); + return old; +#else + Value *value = value_.map_->find( key ); + if (value){ + Value old(*value); + value_.map_.remove( key ); + return old; + } else { + return null; + } +#endif +} + +Value +Value::removeMember( const std::string &key ) +{ + return removeMember( key.c_str() ); +} + +# ifdef JSON_USE_CPPTL +Value +Value::get( const CppTL::ConstString &key, + const Value &defaultValue ) const +{ + return get( key.c_str(), defaultValue ); +} +# endif + +bool +Value::isMember( const char *key ) const +{ + const Value *value = &((*this)[key]); + return value != &null; +} + + +bool +Value::isMember( const std::string &key ) const +{ + return isMember( key.c_str() ); +} + + +# ifdef JSON_USE_CPPTL +bool +Value::isMember( const CppTL::ConstString &key ) const +{ + return isMember( key.c_str() ); +} +#endif + +Value::Members +Value::getMemberNames() const +{ + JSON_ASSERT( type_ == nullValue || type_ == objectValue ); + if ( type_ == nullValue ) + return Value::Members(); + Members members; + members.reserve( value_.map_->size() ); +#ifndef JSON_VALUE_USE_INTERNAL_MAP + ObjectValues::const_iterator it = value_.map_->begin(); + ObjectValues::const_iterator itEnd = value_.map_->end(); + for ( ; it != itEnd; ++it ) + members.push_back( std::string( (*it).first.c_str() ) ); +#else + ValueInternalMap::IteratorState it; + ValueInternalMap::IteratorState itEnd; + value_.map_->makeBeginIterator( it ); + value_.map_->makeEndIterator( itEnd ); + for ( ; !ValueInternalMap::equals( it, itEnd ); ValueInternalMap::increment(it) ) + members.push_back( std::string( ValueInternalMap::key( it ) ) ); +#endif + return members; +} +// +//# ifdef JSON_USE_CPPTL +//EnumMemberNames +//Value::enumMemberNames() const +//{ +// if ( type_ == objectValue ) +// { +// return CppTL::Enum::any( CppTL::Enum::transform( +// CppTL::Enum::keys( *(value_.map_), CppTL::Type<const CZString &>() ), +// MemberNamesTransform() ) ); +// } +// return EnumMemberNames(); +//} +// +// +//EnumValues +//Value::enumValues() const +//{ +// if ( type_ == objectValue || type_ == arrayValue ) +// return CppTL::Enum::anyValues( *(value_.map_), +// CppTL::Type<const Value &>() ); +// return EnumValues(); +//} +// +//# endif + + +bool +Value::isNull() const +{ + return type_ == nullValue; +} + + +bool +Value::isBool() const +{ + return type_ == booleanValue; +} + + +bool +Value::isInt() const +{ + return type_ == intValue; +} + + +bool +Value::isUInt() const +{ + return type_ == uintValue; +} + + +bool +Value::isIntegral() const +{ + return type_ == intValue + || type_ == uintValue + || type_ == booleanValue; +} + + +bool +Value::isDouble() const +{ + return type_ == realValue; +} + + +bool +Value::isNumeric() const +{ + return isIntegral() || isDouble(); +} + + +bool +Value::isString() const +{ + return type_ == stringValue; +} + + +bool +Value::isArray() const +{ + return type_ == nullValue || type_ == arrayValue; +} + + +bool +Value::isObject() const +{ + return type_ == nullValue || type_ == objectValue; +} + + +void +Value::setComment( const char *comment, + CommentPlacement placement ) +{ + if ( !comments_ ) + comments_ = new CommentInfo[numberOfCommentPlacement]; + comments_[placement].setComment( comment ); +} + + +void +Value::setComment( const std::string &comment, + CommentPlacement placement ) +{ + setComment( comment.c_str(), placement ); +} + + +bool +Value::hasComment( CommentPlacement placement ) const +{ + return comments_ != 0 && comments_[placement].comment_ != 0; +} + +std::string +Value::getComment( CommentPlacement placement ) const +{ + if ( hasComment(placement) ) + return comments_[placement].comment_; + return ""; +} + + +std::string +Value::toStyledString() const +{ + StyledWriter writer; + return writer.write( *this ); +} + + +Value::const_iterator +Value::begin() const +{ + switch ( type_ ) + { +#ifdef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + if ( value_.array_ ) + { + ValueInternalArray::IteratorState it; + value_.array_->makeBeginIterator( it ); + return const_iterator( it ); + } + break; + case objectValue: + if ( value_.map_ ) + { + ValueInternalMap::IteratorState it; + value_.map_->makeBeginIterator( it ); + return const_iterator( it ); + } + break; +#else + case arrayValue: + case objectValue: + if ( value_.map_ ) + return const_iterator( value_.map_->begin() ); + break; +#endif + default: + break; + } + return const_iterator(); +} + +Value::const_iterator +Value::end() const +{ + switch ( type_ ) + { +#ifdef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + if ( value_.array_ ) + { + ValueInternalArray::IteratorState it; + value_.array_->makeEndIterator( it ); + return const_iterator( it ); + } + break; + case objectValue: + if ( value_.map_ ) + { + ValueInternalMap::IteratorState it; + value_.map_->makeEndIterator( it ); + return const_iterator( it ); + } + break; +#else + case arrayValue: + case objectValue: + if ( value_.map_ ) + return const_iterator( value_.map_->end() ); + break; +#endif + default: + break; + } + return const_iterator(); +} + + +Value::iterator +Value::begin() +{ + switch ( type_ ) + { +#ifdef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + if ( value_.array_ ) + { + ValueInternalArray::IteratorState it; + value_.array_->makeBeginIterator( it ); + return iterator( it ); + } + break; + case objectValue: + if ( value_.map_ ) + { + ValueInternalMap::IteratorState it; + value_.map_->makeBeginIterator( it ); + return iterator( it ); + } + break; +#else + case arrayValue: + case objectValue: + if ( value_.map_ ) + return iterator( value_.map_->begin() ); + break; +#endif + default: + break; + } + return iterator(); +} + +Value::iterator +Value::end() +{ + switch ( type_ ) + { +#ifdef JSON_VALUE_USE_INTERNAL_MAP + case arrayValue: + if ( value_.array_ ) + { + ValueInternalArray::IteratorState it; + value_.array_->makeEndIterator( it ); + return iterator( it ); + } + break; + case objectValue: + if ( value_.map_ ) + { + ValueInternalMap::IteratorState it; + value_.map_->makeEndIterator( it ); + return iterator( it ); + } + break; +#else + case arrayValue: + case objectValue: + if ( value_.map_ ) + return iterator( value_.map_->end() ); + break; +#endif + default: + break; + } + return iterator(); +} + + +// class PathArgument +// ////////////////////////////////////////////////////////////////// + +PathArgument::PathArgument() + : kind_( kindNone ) +{ +} + + +PathArgument::PathArgument( Value::UInt index ) + : index_( index ) + , kind_( kindIndex ) +{ +} + + +PathArgument::PathArgument( const char *key ) + : key_( key ) + , kind_( kindKey ) +{ +} + + +PathArgument::PathArgument( const std::string &key ) + : key_( key.c_str() ) + , kind_( kindKey ) +{ +} + +// class Path +// ////////////////////////////////////////////////////////////////// + +Path::Path( const std::string &path, + const PathArgument &a1, + const PathArgument &a2, + const PathArgument &a3, + const PathArgument &a4, + const PathArgument &a5 ) +{ + InArgs in; + in.push_back( &a1 ); + in.push_back( &a2 ); + in.push_back( &a3 ); + in.push_back( &a4 ); + in.push_back( &a5 ); + makePath( path, in ); +} + + +void +Path::makePath( const std::string &path, + const InArgs &in ) +{ + const char *current = path.c_str(); + const char *end = current + path.length(); + InArgs::const_iterator itInArg = in.begin(); + while ( current != end ) + { + if ( *current == '[' ) + { + ++current; + if ( *current == '%' ) + addPathInArg( path, in, itInArg, PathArgument::kindIndex ); + else + { + Value::UInt index = 0; + for ( ; current != end && *current >= '0' && *current <= '9'; ++current ) + index = index * 10 + Value::UInt(*current - '0'); + args_.push_back( index ); + } + if ( current == end || *current++ != ']' ) + invalidPath( path, int(current - path.c_str()) ); + } + else if ( *current == '%' ) + { + addPathInArg( path, in, itInArg, PathArgument::kindKey ); + ++current; + } + else if ( *current == '.' ) + { + ++current; + } + else + { + const char *beginName = current; + while ( current != end && !strchr( "[.", *current ) ) + ++current; + args_.push_back( std::string( beginName, current ) ); + } + } +} + + +void +Path::addPathInArg( const std::string &path, + const InArgs &in, + InArgs::const_iterator &itInArg, + PathArgument::Kind kind ) +{ + if ( itInArg == in.end() ) + { + // Error: missing argument %d + } + else if ( (*itInArg)->kind_ != kind ) + { + // Error: bad argument type + } + else + { + args_.push_back( **itInArg ); + } +} + + +void +Path::invalidPath( const std::string &path, + int location ) +{ + // Error: invalid path. +} + + +const Value & +Path::resolve( const Value &root ) const +{ + const Value *node = &root; + for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) + { + const PathArgument &arg = *it; + if ( arg.kind_ == PathArgument::kindIndex ) + { + if ( !node->isArray() || node->isValidIndex( arg.index_ ) ) + { + // Error: unable to resolve path (array value expected at position... + } + node = &((*node)[arg.index_]); + } + else if ( arg.kind_ == PathArgument::kindKey ) + { + if ( !node->isObject() ) + { + // Error: unable to resolve path (object value expected at position...) + } + node = &((*node)[arg.key_]); + if ( node == &Value::null ) + { + // Error: unable to resolve path (object has no member named '' at position...) + } + } + } + return *node; +} + + +Value +Path::resolve( const Value &root, + const Value &defaultValue ) const +{ + const Value *node = &root; + for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) + { + const PathArgument &arg = *it; + if ( arg.kind_ == PathArgument::kindIndex ) + { + if ( !node->isArray() || node->isValidIndex( arg.index_ ) ) + return defaultValue; + node = &((*node)[arg.index_]); + } + else if ( arg.kind_ == PathArgument::kindKey ) + { + if ( !node->isObject() ) + return defaultValue; + node = &((*node)[arg.key_]); + if ( node == &Value::null ) + return defaultValue; + } + } + return *node; +} + + +Value & +Path::make( Value &root ) const +{ + Value *node = &root; + for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it ) + { + const PathArgument &arg = *it; + if ( arg.kind_ == PathArgument::kindIndex ) + { + if ( !node->isArray() ) + { + // Error: node is not an array at position ... + } + node = &((*node)[arg.index_]); + } + else if ( arg.kind_ == PathArgument::kindKey ) + { + if ( !node->isObject() ) + { + // Error: node is not an object at position... + } + node = &((*node)[arg.key_]); + } + } + return *node; +} + + +} // namespace Json diff --git a/jsoncpp-src-0.5.0/src/lib_json/json_valueiterator.inl b/lib/jsoncpp/src/lib_json/json_valueiterator.inl index 736e260ea..736e260ea 100644 --- a/jsoncpp-src-0.5.0/src/lib_json/json_valueiterator.inl +++ b/lib/jsoncpp/src/lib_json/json_valueiterator.inl diff --git a/lib/jsoncpp/src/lib_json/json_writer.cpp b/lib/jsoncpp/src/lib_json/json_writer.cpp new file mode 100644 index 000000000..eff3fabeb --- /dev/null +++ b/lib/jsoncpp/src/lib_json/json_writer.cpp @@ -0,0 +1,829 @@ +#include "../../include/json/writer.h" +#include <utility> +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <iostream> +#include <sstream> +#include <iomanip> + +#if _MSC_VER >= 1400 // VC++ 8.0 +#pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. +#endif + +namespace Json { + +static bool isControlCharacter(char ch) +{ + return ch > 0 && ch <= 0x1F; +} + +static bool containsControlCharacter( const char* str ) +{ + while ( *str ) + { + if ( isControlCharacter( *(str++) ) ) + return true; + } + return false; +} +static void uintToString( unsigned int value, + char *¤t ) +{ + *--current = 0; + do + { + *--current = (value % 10) + '0'; + value /= 10; + } + while ( value != 0 ); +} + +std::string valueToString( Int value ) +{ + char buffer[32]; + char *current = buffer + sizeof(buffer); + bool isNegative = value < 0; + if ( isNegative ) + value = -value; + uintToString( UInt(value), current ); + if ( isNegative ) + *--current = '-'; + assert( current >= buffer ); + return current; +} + + +std::string valueToString( UInt value ) +{ + char buffer[32]; + char *current = buffer + sizeof(buffer); + uintToString( value, current ); + assert( current >= buffer ); + return current; +} + +std::string valueToString( double value ) +{ + char buffer[32]; +#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with visual studio 2005 to avoid warning. + sprintf_s(buffer, sizeof(buffer), "%#.16g", value); +#else + sprintf(buffer, "%#.16g", value); +#endif + char* ch = buffer + strlen(buffer) - 1; + if (*ch != '0') return buffer; // nothing to truncate, so save time + while(ch > buffer && *ch == '0'){ + --ch; + } + char* last_nonzero = ch; + while(ch >= buffer){ + switch(*ch){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + --ch; + continue; + case '.': + // Truncate zeroes to save bytes in output, but keep one. + *(last_nonzero+2) = '\0'; + return buffer; + default: + return buffer; + } + } + return buffer; +} + + +std::string valueToString( bool value ) +{ + return value ? "true" : "false"; +} + +std::string valueToQuotedString( const char *value ) +{ + // Not sure how to handle unicode... + if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL && !containsControlCharacter( value )) + return std::string("\"") + value + "\""; + // We have to walk value and escape any special characters. + // Appending to std::string is not efficient, but this should be rare. + // (Note: forward slashes are *not* rare, but I am not escaping them.) + unsigned maxsize = strlen(value)*2 + 3; // allescaped+quotes+NULL + std::string result; + result.reserve(maxsize); // to avoid lots of mallocs + result += "\""; + for (const char* c=value; *c != 0; ++c) + { + switch(*c) + { + case '\"': + result += "\\\""; + break; + case '\\': + result += "\\\\"; + break; + case '\b': + result += "\\b"; + break; + case '\f': + result += "\\f"; + break; + case '\n': + result += "\\n"; + break; + case '\r': + result += "\\r"; + break; + case '\t': + result += "\\t"; + break; + //case '/': + // Even though \/ is considered a legal escape in JSON, a bare + // slash is also legal, so I see no reason to escape it. + // (I hope I am not misunderstanding something. + // blep notes: actually escaping \/ may be useful in javascript to avoid </ + // sequence. + // Should add a flag to allow this compatibility mode and prevent this + // sequence from occurring. + default: + if ( isControlCharacter( *c ) ) + { + std::ostringstream oss; + oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*c); + result += oss.str(); + } + else + { + result += *c; + } + break; + } + } + result += "\""; + return result; +} + +// Class Writer +// ////////////////////////////////////////////////////////////////// +Writer::~Writer() +{ +} + + +// Class FastWriter +// ////////////////////////////////////////////////////////////////// + +FastWriter::FastWriter() + : yamlCompatiblityEnabled_( false ) +{ +} + + +void +FastWriter::enableYAMLCompatibility() +{ + yamlCompatiblityEnabled_ = true; +} + + +std::string +FastWriter::write( const Value &root ) +{ + document_ = ""; + writeValue( root ); + document_ += "\n"; + return document_; +} + + +void +FastWriter::writeValue( const Value &value ) +{ + switch ( value.type() ) + { + case nullValue: + document_ += "null"; + break; + case intValue: + document_ += valueToString( value.asInt() ); + break; + case uintValue: + document_ += valueToString( value.asUInt() ); + break; + case realValue: + document_ += valueToString( value.asDouble() ); + break; + case stringValue: + document_ += valueToQuotedString( value.asCString() ); + break; + case booleanValue: + document_ += valueToString( value.asBool() ); + break; + case arrayValue: + { + document_ += "["; + int size = value.size(); + for ( int index =0; index < size; ++index ) + { + if ( index > 0 ) + document_ += ","; + writeValue( value[index] ); + } + document_ += "]"; + } + break; + case objectValue: + { + Value::Members members( value.getMemberNames() ); + document_ += "{"; + for ( Value::Members::iterator it = members.begin(); + it != members.end(); + ++it ) + { + const std::string &name = *it; + if ( it != members.begin() ) + document_ += ","; + document_ += valueToQuotedString( name.c_str() ); + document_ += yamlCompatiblityEnabled_ ? ": " + : ":"; + writeValue( value[name] ); + } + document_ += "}"; + } + break; + } +} + + +// Class StyledWriter +// ////////////////////////////////////////////////////////////////// + +StyledWriter::StyledWriter() + : rightMargin_( 74 ) + , indentSize_( 3 ) +{ +} + + +std::string +StyledWriter::write( const Value &root ) +{ + document_ = ""; + addChildValues_ = false; + indentString_ = ""; + writeCommentBeforeValue( root ); + writeValue( root ); + writeCommentAfterValueOnSameLine( root ); + document_ += "\n"; + return document_; +} + + +void +StyledWriter::writeValue( const Value &value ) +{ + switch ( value.type() ) + { + case nullValue: + pushValue( "null" ); + break; + case intValue: + pushValue( valueToString( value.asInt() ) ); + break; + case uintValue: + pushValue( valueToString( value.asUInt() ) ); + break; + case realValue: + pushValue( valueToString( value.asDouble() ) ); + break; + case stringValue: + pushValue( valueToQuotedString( value.asCString() ) ); + break; + case booleanValue: + pushValue( valueToString( value.asBool() ) ); + break; + case arrayValue: + writeArrayValue( value); + break; + case objectValue: + { + Value::Members members( value.getMemberNames() ); + if ( members.empty() ) + pushValue( "{}" ); + else + { + writeWithIndent( "{" ); + indent(); + Value::Members::iterator it = members.begin(); + while ( true ) + { + const std::string &name = *it; + const Value &childValue = value[name]; + writeCommentBeforeValue( childValue ); + writeWithIndent( valueToQuotedString( name.c_str() ) ); + document_ += " : "; + writeValue( childValue ); + if ( ++it == members.end() ) + { + writeCommentAfterValueOnSameLine( childValue ); + break; + } + document_ += ","; + writeCommentAfterValueOnSameLine( childValue ); + } + unindent(); + writeWithIndent( "}" ); + } + } + break; + } +} + + +void +StyledWriter::writeArrayValue( const Value &value ) +{ + unsigned size = value.size(); + if ( size == 0 ) + pushValue( "[]" ); + else + { + bool isArrayMultiLine = isMultineArray( value ); + if ( isArrayMultiLine ) + { + writeWithIndent( "[" ); + indent(); + bool hasChildValue = !childValues_.empty(); + unsigned index =0; + while ( true ) + { + const Value &childValue = value[index]; + writeCommentBeforeValue( childValue ); + if ( hasChildValue ) + writeWithIndent( childValues_[index] ); + else + { + writeIndent(); + writeValue( childValue ); + } + if ( ++index == size ) + { + writeCommentAfterValueOnSameLine( childValue ); + break; + } + document_ += ","; + writeCommentAfterValueOnSameLine( childValue ); + } + unindent(); + writeWithIndent( "]" ); + } + else // output on a single line + { + assert( childValues_.size() == size ); + document_ += "[ "; + for ( unsigned index =0; index < size; ++index ) + { + if ( index > 0 ) + document_ += ", "; + document_ += childValues_[index]; + } + document_ += " ]"; + } + } +} + + +bool +StyledWriter::isMultineArray( const Value &value ) +{ + int size = value.size(); + bool isMultiLine = size*3 >= rightMargin_ ; + childValues_.clear(); + for ( int index =0; index < size && !isMultiLine; ++index ) + { + const Value &childValue = value[index]; + isMultiLine = isMultiLine || + ( (childValue.isArray() || childValue.isObject()) && + childValue.size() > 0 ); + } + if ( !isMultiLine ) // check if line length > max line length + { + childValues_.reserve( size ); + addChildValues_ = true; + int lineLength = 4 + (size-1)*2; // '[ ' + ', '*n + ' ]' + for ( int index =0; index < size && !isMultiLine; ++index ) + { + writeValue( value[index] ); + lineLength += int( childValues_[index].length() ); + isMultiLine = isMultiLine && hasCommentForValue( value[index] ); + } + addChildValues_ = false; + isMultiLine = isMultiLine || lineLength >= rightMargin_; + } + return isMultiLine; +} + + +void +StyledWriter::pushValue( const std::string &value ) +{ + if ( addChildValues_ ) + childValues_.push_back( value ); + else + document_ += value; +} + + +void +StyledWriter::writeIndent() +{ + if ( !document_.empty() ) + { + char last = document_[document_.length()-1]; + if ( last == ' ' ) // already indented + return; + if ( last != '\n' ) // Comments may add new-line + document_ += '\n'; + } + document_ += indentString_; +} + + +void +StyledWriter::writeWithIndent( const std::string &value ) +{ + writeIndent(); + document_ += value; +} + + +void +StyledWriter::indent() +{ + indentString_ += std::string( indentSize_, ' ' ); +} + + +void +StyledWriter::unindent() +{ + assert( int(indentString_.size()) >= indentSize_ ); + indentString_.resize( indentString_.size() - indentSize_ ); +} + + +void +StyledWriter::writeCommentBeforeValue( const Value &root ) +{ + if ( !root.hasComment( commentBefore ) ) + return; + document_ += normalizeEOL( root.getComment( commentBefore ) ); + document_ += "\n"; +} + + +void +StyledWriter::writeCommentAfterValueOnSameLine( const Value &root ) +{ + if ( root.hasComment( commentAfterOnSameLine ) ) + document_ += " " + normalizeEOL( root.getComment( commentAfterOnSameLine ) ); + + if ( root.hasComment( commentAfter ) ) + { + document_ += "\n"; + document_ += normalizeEOL( root.getComment( commentAfter ) ); + document_ += "\n"; + } +} + + +bool +StyledWriter::hasCommentForValue( const Value &value ) +{ + return value.hasComment( commentBefore ) + || value.hasComment( commentAfterOnSameLine ) + || value.hasComment( commentAfter ); +} + + +std::string +StyledWriter::normalizeEOL( const std::string &text ) +{ + std::string normalized; + normalized.reserve( text.length() ); + const char *begin = text.c_str(); + const char *end = begin + text.length(); + const char *current = begin; + while ( current != end ) + { + char c = *current++; + if ( c == '\r' ) // mac or dos EOL + { + if ( *current == '\n' ) // convert dos EOL + ++current; + normalized += '\n'; + } + else // handle unix EOL & other char + normalized += c; + } + return normalized; +} + + +// Class StyledStreamWriter +// ////////////////////////////////////////////////////////////////// + +StyledStreamWriter::StyledStreamWriter( std::string indentation ) + : document_(NULL) + , rightMargin_( 74 ) + , indentation_( indentation ) +{ +} + + +void +StyledStreamWriter::write( std::ostream &out, const Value &root ) +{ + document_ = &out; + addChildValues_ = false; + indentString_ = ""; + writeCommentBeforeValue( root ); + writeValue( root ); + writeCommentAfterValueOnSameLine( root ); + *document_ << "\n"; + document_ = NULL; // Forget the stream, for safety. +} + + +void +StyledStreamWriter::writeValue( const Value &value ) +{ + switch ( value.type() ) + { + case nullValue: + pushValue( "null" ); + break; + case intValue: + pushValue( valueToString( value.asInt() ) ); + break; + case uintValue: + pushValue( valueToString( value.asUInt() ) ); + break; + case realValue: + pushValue( valueToString( value.asDouble() ) ); + break; + case stringValue: + pushValue( valueToQuotedString( value.asCString() ) ); + break; + case booleanValue: + pushValue( valueToString( value.asBool() ) ); + break; + case arrayValue: + writeArrayValue( value); + break; + case objectValue: + { + Value::Members members( value.getMemberNames() ); + if ( members.empty() ) + pushValue( "{}" ); + else + { + writeWithIndent( "{" ); + indent(); + Value::Members::iterator it = members.begin(); + while ( true ) + { + const std::string &name = *it; + const Value &childValue = value[name]; + writeCommentBeforeValue( childValue ); + writeWithIndent( valueToQuotedString( name.c_str() ) ); + *document_ << " : "; + writeValue( childValue ); + if ( ++it == members.end() ) + { + writeCommentAfterValueOnSameLine( childValue ); + break; + } + *document_ << ","; + writeCommentAfterValueOnSameLine( childValue ); + } + unindent(); + writeWithIndent( "}" ); + } + } + break; + } +} + + +void +StyledStreamWriter::writeArrayValue( const Value &value ) +{ + unsigned size = value.size(); + if ( size == 0 ) + pushValue( "[]" ); + else + { + bool isArrayMultiLine = isMultineArray( value ); + if ( isArrayMultiLine ) + { + writeWithIndent( "[" ); + indent(); + bool hasChildValue = !childValues_.empty(); + unsigned index =0; + while ( true ) + { + const Value &childValue = value[index]; + writeCommentBeforeValue( childValue ); + if ( hasChildValue ) + writeWithIndent( childValues_[index] ); + else + { + writeIndent(); + writeValue( childValue ); + } + if ( ++index == size ) + { + writeCommentAfterValueOnSameLine( childValue ); + break; + } + *document_ << ","; + writeCommentAfterValueOnSameLine( childValue ); + } + unindent(); + writeWithIndent( "]" ); + } + else // output on a single line + { + assert( childValues_.size() == size ); + *document_ << "[ "; + for ( unsigned index =0; index < size; ++index ) + { + if ( index > 0 ) + *document_ << ", "; + *document_ << childValues_[index]; + } + *document_ << " ]"; + } + } +} + + +bool +StyledStreamWriter::isMultineArray( const Value &value ) +{ + int size = value.size(); + bool isMultiLine = size*3 >= rightMargin_ ; + childValues_.clear(); + for ( int index =0; index < size && !isMultiLine; ++index ) + { + const Value &childValue = value[index]; + isMultiLine = isMultiLine || + ( (childValue.isArray() || childValue.isObject()) && + childValue.size() > 0 ); + } + if ( !isMultiLine ) // check if line length > max line length + { + childValues_.reserve( size ); + addChildValues_ = true; + int lineLength = 4 + (size-1)*2; // '[ ' + ', '*n + ' ]' + for ( int index =0; index < size && !isMultiLine; ++index ) + { + writeValue( value[index] ); + lineLength += int( childValues_[index].length() ); + isMultiLine = isMultiLine && hasCommentForValue( value[index] ); + } + addChildValues_ = false; + isMultiLine = isMultiLine || lineLength >= rightMargin_; + } + return isMultiLine; +} + + +void +StyledStreamWriter::pushValue( const std::string &value ) +{ + if ( addChildValues_ ) + childValues_.push_back( value ); + else + *document_ << value; +} + + +void +StyledStreamWriter::writeIndent() +{ + /* + Some comments in this method would have been nice. ;-) + + if ( !document_.empty() ) + { + char last = document_[document_.length()-1]; + if ( last == ' ' ) // already indented + return; + if ( last != '\n' ) // Comments may add new-line + *document_ << '\n'; + } + */ + *document_ << '\n' << indentString_; +} + + +void +StyledStreamWriter::writeWithIndent( const std::string &value ) +{ + writeIndent(); + *document_ << value; +} + + +void +StyledStreamWriter::indent() +{ + indentString_ += indentation_; +} + + +void +StyledStreamWriter::unindent() +{ + assert( indentString_.size() >= indentation_.size() ); + indentString_.resize( indentString_.size() - indentation_.size() ); +} + + +void +StyledStreamWriter::writeCommentBeforeValue( const Value &root ) +{ + if ( !root.hasComment( commentBefore ) ) + return; + *document_ << normalizeEOL( root.getComment( commentBefore ) ); + *document_ << "\n"; +} + + +void +StyledStreamWriter::writeCommentAfterValueOnSameLine( const Value &root ) +{ + if ( root.hasComment( commentAfterOnSameLine ) ) + *document_ << " " + normalizeEOL( root.getComment( commentAfterOnSameLine ) ); + + if ( root.hasComment( commentAfter ) ) + { + *document_ << "\n"; + *document_ << normalizeEOL( root.getComment( commentAfter ) ); + *document_ << "\n"; + } +} + + +bool +StyledStreamWriter::hasCommentForValue( const Value &value ) +{ + return value.hasComment( commentBefore ) + || value.hasComment( commentAfterOnSameLine ) + || value.hasComment( commentAfter ); +} + + +std::string +StyledStreamWriter::normalizeEOL( const std::string &text ) +{ + std::string normalized; + normalized.reserve( text.length() ); + const char *begin = text.c_str(); + const char *end = begin + text.length(); + const char *current = begin; + while ( current != end ) + { + char c = *current++; + if ( c == '\r' ) // mac or dos EOL + { + if ( *current == '\n' ) // convert dos EOL + ++current; + normalized += '\n'; + } + else // handle unix EOL & other char + normalized += c; + } + return normalized; +} + + +std::ostream& operator<<( std::ostream &sout, const Value &root ) +{ + Json::StyledStreamWriter writer; + writer.write(sout, root); + return sout; +} + + +} // namespace Json diff --git a/jsoncpp-src-0.5.0/src/lib_json/sconscript b/lib/jsoncpp/src/lib_json/sconscript index f6520d185..f6520d185 100644 --- a/jsoncpp-src-0.5.0/src/lib_json/sconscript +++ b/lib/jsoncpp/src/lib_json/sconscript 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..a81a434e9 --- /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 "lib/expat/expat.h" + +#include "lib/lua/src/lua.h" +#include "lib/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 diff --git a/source/md5/md5.cpp b/lib/md5/md5.cpp index eae0fc3f2..eae0fc3f2 100644 --- a/source/md5/md5.cpp +++ b/lib/md5/md5.cpp diff --git a/source/md5/md5.h b/lib/md5/md5.h index ad5ad5384..ad5ad5384 100644 --- a/source/md5/md5.h +++ b/lib/md5/md5.h diff --git a/lib/sqlite/lsqlite3.c b/lib/sqlite/lsqlite3.c new file mode 100644 index 000000000..f896daf23 --- /dev/null +++ b/lib/sqlite/lsqlite3.c @@ -0,0 +1,2175 @@ +/************************************************************************ +* lsqlite3 * +* Copyright (C) 2002-2013 Tiago Dionizio, Doug Currie * +* All rights reserved. * +* Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt> * +* Author : Doug Currie <doug.currie@alum.mit.edu> * +* Library : lsqlite3 - a SQLite 3 database binding for Lua 5 * +* * +* Permission is hereby granted, free of charge, to any person obtaining * +* a copy of this software and associated documentation files (the * +* "Software"), to deal in the Software without restriction, including * +* without limitation the rights to use, copy, modify, merge, publish, * +* distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to * +* the following conditions: * +* * +* The above copyright notice and this permission notice shall be * +* included in all copies or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +************************************************************************/ +// Slightly modified by _Xoft to compile in MSVC + + + + +// 2013_04_07 _X: Added the following #define-s so that MSVC doesn't complain about non-secure stuff: +#define _CRT_SECURE_NO_WARNINGS +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + + + + +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#define LUA_LIB +#include "lib/lua/src/lua.h" +#include "lib/lua/src/lauxlib.h" + +#if LUA_VERSION_NUM > 501 +// +// Lua 5.2 +// +#define lua_strlen lua_rawlen +// luaL_typerror always used with arg at ndx == NULL +#define luaL_typerror(L,ndx,str) luaL_error(L,"bad argument %d (%s expected, got nil)",ndx,str) +// luaL_register used once, so below expansion is OK for this case +#define luaL_register(L,name,reg) lua_newtable(L);luaL_setfuncs(L,reg,0) +// luaL_openlib always used with name == NULL +#define luaL_openlib(L,name,reg,nup) luaL_setfuncs(L,reg,nup) +#endif + +#include "sqlite3.h" + +/* compile time features */ +#if !defined(SQLITE_OMIT_PROGRESS_CALLBACK) + #define SQLITE_OMIT_PROGRESS_CALLBACK 0 +#endif +#if !defined(LSQLITE_OMIT_UPDATE_HOOK) + #define LSQLITE_OMIT_UPDATE_HOOK 0 +#endif + +typedef struct sdb sdb; +typedef struct sdb_vm sdb_vm; +typedef struct sdb_func sdb_func; + +/* to use as C user data so i know what function sqlite is calling */ +struct sdb_func { + /* references to associated lua values */ + int fn_step; + int fn_finalize; + int udata; + + sdb *db; + char aggregate; + + sdb_func *next; +}; + +/* information about database */ +struct sdb { + /* associated lua state */ + lua_State *L; + /* sqlite database handle */ + sqlite3 *db; + + /* sql functions stack usage */ + sdb_func *func; /* top SQL function being called */ + + /* references */ + int busy_cb; /* busy callback */ + int busy_udata; + + int progress_cb; /* progress handler */ + int progress_udata; + + int trace_cb; /* trace callback */ + int trace_udata; + +#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK + + int update_hook_cb; /* update_hook callback */ + int update_hook_udata; + + int commit_hook_cb; /* commit_hook callback */ + int commit_hook_udata; + + int rollback_hook_cb; /* rollback_hook callback */ + int rollback_hook_udata; + +#endif +}; + +static const char *sqlite_meta = ":sqlite3"; +static const char *sqlite_vm_meta = ":sqlite3:vm"; +static const char *sqlite_ctx_meta = ":sqlite3:ctx"; +static int sqlite_ctx_meta_ref; + +/* +** ======================================================= +** Database Virtual Machine Operations +** ======================================================= +*/ + +static void vm_push_column(lua_State *L, sqlite3_stmt *vm, int idx) { + switch (sqlite3_column_type(vm, idx)) { + case SQLITE_INTEGER: + { + sqlite_int64 i64 = sqlite3_column_int64(vm, idx); + lua_Number n = (lua_Number)i64; + if (n == i64) + lua_pushnumber(L, n); + else + lua_pushlstring(L, (const char*)sqlite3_column_text(vm, idx), sqlite3_column_bytes(vm, idx)); + } + break; + case SQLITE_FLOAT: + lua_pushnumber(L, sqlite3_column_double(vm, idx)); + break; + case SQLITE_TEXT: + lua_pushlstring(L, (const char*)sqlite3_column_text(vm, idx), sqlite3_column_bytes(vm, idx)); + break; + case SQLITE_BLOB: + lua_pushlstring(L, sqlite3_column_blob(vm, idx), sqlite3_column_bytes(vm, idx)); + break; + case SQLITE_NULL: + lua_pushnil(L); + break; + default: + lua_pushnil(L); + break; + } +} + +/* virtual machine information */ +struct sdb_vm { + sdb *db; /* associated database handle */ + sqlite3_stmt *vm; /* virtual machine */ + + /* sqlite3_step info */ + int columns; /* number of columns in result */ + char has_values; /* true when step succeeds */ + + char temp; /* temporary vm used in db:rows */ +}; + +/* called with sql text on the lua stack */ +static sdb_vm *newvm(lua_State *L, sdb *db) { + sdb_vm *svm = (sdb_vm*)lua_newuserdata(L, sizeof(sdb_vm)); + + luaL_getmetatable(L, sqlite_vm_meta); + lua_setmetatable(L, -2); /* set metatable */ + + svm->db = db; + svm->columns = 0; + svm->has_values = 0; + svm->vm = NULL; + svm->temp = 0; + + /* add an entry on the database table: svm -> sql text */ + lua_pushlightuserdata(L, db); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, svm); + lua_pushvalue(L, -4); /* the sql text */ + lua_rawset(L, -3); + lua_pop(L, 1); + + return svm; +} + +static int cleanupvm(lua_State *L, sdb_vm *svm) { + /* remove entry in database table - no harm if not present in the table */ + lua_pushlightuserdata(L, svm->db); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, svm); + lua_pushnil(L); + lua_rawset(L, -3); + lua_pop(L, 1); + + svm->columns = 0; + svm->has_values = 0; + + if (!svm->vm) return 0; + + lua_pushnumber(L, sqlite3_finalize(svm->vm)); + svm->vm = NULL; + return 1; +} + +static int stepvm(lua_State *L, sdb_vm *svm) { + int result; + int loop_limit = 3; + while ( loop_limit-- ) { + result = sqlite3_step(svm->vm); + if ( result==SQLITE_ERROR ) { + result = sqlite3_reset (svm->vm); + } + if ( result==SQLITE_SCHEMA ) { + sqlite3_stmt *vn; + const char *sql; + /* recover sql text */ + lua_pushlightuserdata(L, svm->db); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, svm); + lua_rawget(L, -2); /* sql text */ + sql = luaL_checkstring(L, -1); + /* re-prepare */ + result = sqlite3_prepare(svm->db->db, sql, -1, &vn, NULL); + if (result != SQLITE_OK) break; + sqlite3_transfer_bindings(svm->vm, vn); + sqlite3_finalize(svm->vm); + svm->vm = vn; + lua_pop(L,2); + } else { + break; + } + } + return result; +} + +static sdb_vm *lsqlite_getvm(lua_State *L, int index) { + sdb_vm *svm = (sdb_vm*)luaL_checkudata(L, index, sqlite_vm_meta); + if (svm == NULL) luaL_argerror(L, index, "bad sqlite virtual machine"); + return svm; +} + +static sdb_vm *lsqlite_checkvm(lua_State *L, int index) { + sdb_vm *svm = lsqlite_getvm(L, index); + if (svm->vm == NULL) luaL_argerror(L, index, "attempt to use closed sqlite virtual machine"); + return svm; +} + +static int dbvm_isopen(lua_State *L) { + sdb_vm *svm = lsqlite_getvm(L, 1); + lua_pushboolean(L, svm->vm != NULL ? 1 : 0); + return 1; +} + +static int dbvm_tostring(lua_State *L) { + char buff[39]; + sdb_vm *svm = lsqlite_getvm(L, 1); + if (svm->vm == NULL) + strcpy(buff, "closed"); + else + sprintf(buff, "%p", svm); + lua_pushfstring(L, "sqlite virtual machine (%s)", buff); + return 1; +} + +static int dbvm_gc(lua_State *L) { + sdb_vm *svm = lsqlite_getvm(L, 1); + if (svm->vm != NULL) /* ignore closed vms */ + cleanupvm(L, svm); + return 0; +} + +static int dbvm_step(lua_State *L) { + int result; + sdb_vm *svm = lsqlite_checkvm(L, 1); + + result = stepvm(L, svm); + svm->has_values = result == SQLITE_ROW ? 1 : 0; + svm->columns = sqlite3_data_count(svm->vm); + + lua_pushnumber(L, result); + return 1; +} + +static int dbvm_finalize(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + return cleanupvm(L, svm); +} + +static int dbvm_reset(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_reset(svm->vm); + lua_pushnumber(L, sqlite3_errcode(svm->db->db)); + return 1; +} + +static void dbvm_check_contents(lua_State *L, sdb_vm *svm) { + if (!svm->has_values) { + luaL_error(L, "misuse of function"); + } +} + +static void dbvm_check_index(lua_State *L, sdb_vm *svm, int index) { + if (index < 0 || index >= svm->columns) { + luaL_error(L, "index out of range [0..%d]", svm->columns - 1); + } +} + +static void dbvm_check_bind_index(lua_State *L, sdb_vm *svm, int index) { + if (index < 1 || index > sqlite3_bind_parameter_count(svm->vm)) { + luaL_error(L, "bind index out of range [1..%d]", sqlite3_bind_parameter_count(svm->vm)); + } +} + +/* +** ======================================================= +** Virtual Machine - generic info +** ======================================================= +*/ +static int dbvm_columns(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + lua_pushnumber(L, sqlite3_column_count(svm->vm)); + return 1; +} + +/* +** ======================================================= +** Virtual Machine - getters +** ======================================================= +*/ + +static int dbvm_get_value(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + int index = luaL_checkint(L, 2); + dbvm_check_contents(L, svm); + dbvm_check_index(L, svm, index); + vm_push_column(L, svm->vm, index); + return 1; +} + +static int dbvm_get_name(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + int index = (int)luaL_checknumber(L, 2); + dbvm_check_index(L, svm, index); + lua_pushstring(L, sqlite3_column_name(svm->vm, index)); + return 1; +} + +static int dbvm_get_type(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + int index = (int)luaL_checknumber(L, 2); + dbvm_check_index(L, svm, index); + lua_pushstring(L, sqlite3_column_decltype(svm->vm, index)); + return 1; +} + +static int dbvm_get_values(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int columns = svm->columns; + int n; + dbvm_check_contents(L, svm); + + lua_newtable(L); + for (n = 0; n < columns;) { + vm_push_column(L, vm, n++); + lua_rawseti(L, -2, n); + } + return 1; +} + +static int dbvm_get_names(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int columns = sqlite3_column_count(vm); /* valid as soon as statement prepared */ + int n; + + lua_newtable(L); + for (n = 0; n < columns;) { + lua_pushstring(L, sqlite3_column_name(vm, n++)); + lua_rawseti(L, -2, n); + } + return 1; +} + +static int dbvm_get_types(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int columns = sqlite3_column_count(vm); /* valid as soon as statement prepared */ + int n; + + lua_newtable(L); + for (n = 0; n < columns;) { + lua_pushstring(L, sqlite3_column_decltype(vm, n++)); + lua_rawseti(L, -2, n); + } + return 1; +} + +static int dbvm_get_uvalues(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int columns = svm->columns; + int n; + dbvm_check_contents(L, svm); + + lua_checkstack(L, columns); + for (n = 0; n < columns; ++n) + vm_push_column(L, vm, n); + return columns; +} + +static int dbvm_get_unames(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int columns = sqlite3_column_count(vm); /* valid as soon as statement prepared */ + int n; + + lua_checkstack(L, columns); + for (n = 0; n < columns; ++n) + lua_pushstring(L, sqlite3_column_name(vm, n)); + return columns; +} + +static int dbvm_get_utypes(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int columns = sqlite3_column_count(vm); /* valid as soon as statement prepared */ + int n; + + lua_checkstack(L, columns); + for (n = 0; n < columns; ++n) + lua_pushstring(L, sqlite3_column_decltype(vm, n)); + return columns; +} + +static int dbvm_get_named_values(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int columns = svm->columns; + int n; + dbvm_check_contents(L, svm); + + lua_newtable(L); + for (n = 0; n < columns; ++n) { + lua_pushstring(L, sqlite3_column_name(vm, n)); + vm_push_column(L, vm, n); + lua_rawset(L, -3); + } + return 1; +} + +static int dbvm_get_named_types(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int columns = sqlite3_column_count(vm); + int n; + + lua_newtable(L); + for (n = 0; n < columns; ++n) { + lua_pushstring(L, sqlite3_column_name(vm, n)); + lua_pushstring(L, sqlite3_column_decltype(vm, n)); + lua_rawset(L, -3); + } + return 1; +} + +/* +** ======================================================= +** Virtual Machine - Bind +** ======================================================= +*/ + +static int dbvm_bind_index(lua_State *L, sqlite3_stmt *vm, int index, int lindex) { + switch (lua_type(L, lindex)) { + case LUA_TSTRING: + return sqlite3_bind_text(vm, index, lua_tostring(L, lindex), lua_strlen(L, lindex), SQLITE_TRANSIENT); + case LUA_TNUMBER: + return sqlite3_bind_double(vm, index, lua_tonumber(L, lindex)); + case LUA_TBOOLEAN: + return sqlite3_bind_int(vm, index, lua_toboolean(L, lindex) ? 1 : 0); + case LUA_TNONE: + case LUA_TNIL: + return sqlite3_bind_null(vm, index); + default: + luaL_error(L, "index (%d) - invalid data type for bind (%s)", index, lua_typename(L, lua_type(L, lindex))); + return SQLITE_MISUSE; /*!*/ + } +} + + +static int dbvm_bind_parameter_count(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + lua_pushnumber(L, sqlite3_bind_parameter_count(svm->vm)); + return 1; +} + +static int dbvm_bind_parameter_name(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + int index = (int)luaL_checknumber(L, 2); + dbvm_check_bind_index(L, svm, index); + lua_pushstring(L, sqlite3_bind_parameter_name(svm->vm, index)); + return 1; +} + +static int dbvm_bind(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int index = luaL_checkint(L, 2); + int result; + + dbvm_check_bind_index(L, svm, index); + result = dbvm_bind_index(L, vm, index, 3); + + lua_pushnumber(L, result); + return 1; +} + +static int dbvm_bind_blob(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + int index = luaL_checkint(L, 2); + const char *value = luaL_checkstring(L, 3); + int len = lua_strlen(L, 3); + + lua_pushnumber(L, sqlite3_bind_blob(svm->vm, index, value, len, SQLITE_TRANSIENT)); + return 1; +} + +static int dbvm_bind_values(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int top = lua_gettop(L); + int result, n; + + if (top - 1 != sqlite3_bind_parameter_count(vm)) + luaL_error(L, + "incorrect number of parameters to bind (%d given, %d to bind)", + top - 1, + sqlite3_bind_parameter_count(vm) + ); + + for (n = 2; n <= top; ++n) { + if ((result = dbvm_bind_index(L, vm, n - 1, n)) != SQLITE_OK) { + lua_pushnumber(L, result); + return 1; + } + } + + lua_pushnumber(L, SQLITE_OK); + return 1; +} + +static int dbvm_bind_names(lua_State *L) { + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm = svm->vm; + int count = sqlite3_bind_parameter_count(vm); + const char *name; + int result, n; + luaL_checktype(L, 2, LUA_TTABLE); + + for (n = 1; n <= count; ++n) { + name = sqlite3_bind_parameter_name(vm, n); + if (name && (name[0] == ':' || name[0] == '$')) { + lua_pushstring(L, ++name); + lua_gettable(L, 2); + result = dbvm_bind_index(L, vm, n, -1); + lua_pop(L, 1); + } + else { + lua_pushnumber(L, n); + lua_gettable(L, 2); + result = dbvm_bind_index(L, vm, n, -1); + lua_pop(L, 1); + } + + if (result != SQLITE_OK) { + lua_pushnumber(L, result); + return 1; + } + } + + lua_pushnumber(L, SQLITE_OK); + return 1; +} + +/* +** ======================================================= +** Database (internal management) +** ======================================================= +*/ + +/* +** When creating database handles, always creates a `closed' database handle +** before opening the actual database; so, if there is a memory error, the +** database is not left opened. +** +** Creates a new 'table' and leaves it in the stack +*/ +static sdb *newdb (lua_State *L) { + sdb *db = (sdb*)lua_newuserdata(L, sizeof(sdb)); + db->L = L; + db->db = NULL; /* database handle is currently `closed' */ + db->func = NULL; + + db->busy_cb = + db->busy_udata = + db->progress_cb = + db->progress_udata = + db->trace_cb = + db->trace_udata = +#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK + db->update_hook_cb = + db->update_hook_udata = + db->commit_hook_cb = + db->commit_hook_udata = + db->rollback_hook_cb = + db->rollback_hook_udata = +#endif + LUA_NOREF; + + luaL_getmetatable(L, sqlite_meta); + lua_setmetatable(L, -2); /* set metatable */ + + /* to keep track of 'open' virtual machines */ + lua_pushlightuserdata(L, db); + lua_newtable(L); + lua_rawset(L, LUA_REGISTRYINDEX); + + return db; +} + +static int cleanupdb(lua_State *L, sdb *db) { + sdb_func *func; + sdb_func *func_next; + int top; + int result; + + /* free associated virtual machines */ + lua_pushlightuserdata(L, db); + lua_rawget(L, LUA_REGISTRYINDEX); + + /* close all used handles */ + top = lua_gettop(L); + lua_pushnil(L); + while (lua_next(L, -2)) { + sdb_vm *svm = lua_touserdata(L, -2); /* key: vm; val: sql text */ + cleanupvm(L, svm); + + lua_settop(L, top); + lua_pushnil(L); + } + + lua_pop(L, 1); /* pop vm table */ + + /* remove entry in lua registry table */ + lua_pushlightuserdata(L, db); + lua_pushnil(L); + lua_rawset(L, LUA_REGISTRYINDEX); + + /* 'free' all references */ + luaL_unref(L, LUA_REGISTRYINDEX, db->busy_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->busy_udata); + luaL_unref(L, LUA_REGISTRYINDEX, db->progress_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->progress_udata); + luaL_unref(L, LUA_REGISTRYINDEX, db->trace_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->trace_udata); +#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK + luaL_unref(L, LUA_REGISTRYINDEX, db->update_hook_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->update_hook_udata); + luaL_unref(L, LUA_REGISTRYINDEX, db->commit_hook_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->commit_hook_udata); + luaL_unref(L, LUA_REGISTRYINDEX, db->rollback_hook_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->rollback_hook_udata); +#endif + + /* close database */ + result = sqlite3_close(db->db); + db->db = NULL; + + /* free associated memory with created functions */ + func = db->func; + while (func) { + func_next = func->next; + luaL_unref(L, LUA_REGISTRYINDEX, func->fn_step); + luaL_unref(L, LUA_REGISTRYINDEX, func->fn_finalize); + luaL_unref(L, LUA_REGISTRYINDEX, func->udata); + free(func); + func = func_next; + } + db->func = NULL; + return result; +} + +static sdb *lsqlite_getdb(lua_State *L, int index) { + sdb *db = (sdb*)luaL_checkudata(L, index, sqlite_meta); + if (db == NULL) luaL_typerror(L, index, "sqlite database"); + return db; +} + +static sdb *lsqlite_checkdb(lua_State *L, int index) { + sdb *db = lsqlite_getdb(L, index); + if (db->db == NULL) luaL_argerror(L, index, "attempt to use closed sqlite database"); + return db; +} + + +/* +** ======================================================= +** User Defined Functions - Context Methods +** ======================================================= +*/ +typedef struct { + sqlite3_context *ctx; + int ud; +} lcontext; + +static lcontext *lsqlite_make_context(lua_State *L) { + lcontext *ctx = (lcontext*)lua_newuserdata(L, sizeof(lcontext)); + lua_rawgeti(L, LUA_REGISTRYINDEX, sqlite_ctx_meta_ref); + lua_setmetatable(L, -2); + ctx->ctx = NULL; + ctx->ud = LUA_NOREF; + return ctx; +} + +static lcontext *lsqlite_getcontext(lua_State *L, int index) { + lcontext *ctx = (lcontext*)luaL_checkudata(L, index, sqlite_ctx_meta); + if (ctx == NULL) luaL_typerror(L, index, "sqlite context"); + return ctx; +} + +static lcontext *lsqlite_checkcontext(lua_State *L, int index) { + lcontext *ctx = lsqlite_getcontext(L, index); + if (ctx->ctx == NULL) luaL_argerror(L, index, "invalid sqlite context"); + return ctx; +} + +static int lcontext_tostring(lua_State *L) { + char buff[39]; + lcontext *ctx = lsqlite_getcontext(L, 1); + if (ctx->ctx == NULL) + strcpy(buff, "closed"); + else + sprintf(buff, "%p", ctx->ctx); + lua_pushfstring(L, "sqlite function context (%s)", buff); + return 1; +} + +static void lcontext_check_aggregate(lua_State *L, lcontext *ctx) { + sdb_func *func = (sdb_func*)sqlite3_user_data(ctx->ctx); + if (!func->aggregate) { + luaL_error(L, "attempt to call aggregate method from scalar function"); + } +} + +static int lcontext_user_data(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + sdb_func *func = (sdb_func*)sqlite3_user_data(ctx->ctx); + lua_rawgeti(L, LUA_REGISTRYINDEX, func->udata); + return 1; +} + +static int lcontext_get_aggregate_context(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + lcontext_check_aggregate(L, ctx); + lua_rawgeti(L, LUA_REGISTRYINDEX, ctx->ud); + return 1; +} + +static int lcontext_set_aggregate_context(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + lcontext_check_aggregate(L, ctx); + lua_settop(L, 2); + luaL_unref(L, LUA_REGISTRYINDEX, ctx->ud); + ctx->ud = luaL_ref(L, LUA_REGISTRYINDEX); + return 0; +} + +static int lcontext_aggregate_count(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + lcontext_check_aggregate(L, ctx); + lua_pushnumber(L, sqlite3_aggregate_count(ctx->ctx)); + return 1; +} + +#if 0 +void *sqlite3_get_auxdata(sqlite3_context*, int); +void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*)); +#endif + +static int lcontext_result(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + switch (lua_type(L, 2)) { + case LUA_TNUMBER: + sqlite3_result_double(ctx->ctx, luaL_checknumber(L, 2)); + break; + case LUA_TSTRING: + sqlite3_result_text(ctx->ctx, luaL_checkstring(L, 2), lua_strlen(L, 2), SQLITE_TRANSIENT); + break; + case LUA_TNIL: + case LUA_TNONE: + sqlite3_result_null(ctx->ctx); + break; + default: + luaL_error(L, "invalid result type %s", lua_typename(L, 2)); + break; + } + + return 0; +} + +static int lcontext_result_blob(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + const char *blob = luaL_checkstring(L, 2); + int size = lua_strlen(L, 2); + sqlite3_result_blob(ctx->ctx, (const void*)blob, size, SQLITE_TRANSIENT); + return 0; +} + +static int lcontext_result_double(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + double d = luaL_checknumber(L, 2); + sqlite3_result_double(ctx->ctx, d); + return 0; +} + +static int lcontext_result_error(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + const char *err = luaL_checkstring(L, 2); + int size = lua_strlen(L, 2); + sqlite3_result_error(ctx->ctx, err, size); + return 0; +} + +static int lcontext_result_int(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + int i = luaL_checkint(L, 2); + sqlite3_result_int(ctx->ctx, i); + return 0; +} + +static int lcontext_result_null(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + sqlite3_result_null(ctx->ctx); + return 0; +} + +static int lcontext_result_text(lua_State *L) { + lcontext *ctx = lsqlite_checkcontext(L, 1); + const char *text = luaL_checkstring(L, 2); + int size = lua_strlen(L, 2); + sqlite3_result_text(ctx->ctx, text, size, SQLITE_TRANSIENT); + return 0; +} + +/* +** ======================================================= +** Database Methods +** ======================================================= +*/ + +static int db_isopen(lua_State *L) { + sdb *db = lsqlite_getdb(L, 1); + lua_pushboolean(L, db->db != NULL ? 1 : 0); + return 1; +} + +static int db_last_insert_rowid(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + /* conversion warning: int64 -> luaNumber */ + sqlite_int64 rowid = sqlite3_last_insert_rowid(db->db); + lua_Number n = (lua_Number)rowid; + if (n == rowid) + lua_pushnumber(L, n); + else + lua_pushfstring(L, "%ll", rowid); + return 1; +} + +static int db_changes(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + lua_pushnumber(L, sqlite3_changes(db->db)); + return 1; +} + +static int db_total_changes(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + lua_pushnumber(L, sqlite3_total_changes(db->db)); + return 1; +} + +static int db_errcode(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + lua_pushnumber(L, sqlite3_errcode(db->db)); + return 1; +} + +static int db_errmsg(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + lua_pushstring(L, sqlite3_errmsg(db->db)); + return 1; +} + +static int db_interrupt(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + sqlite3_interrupt(db->db); + return 0; +} + +/* +** Registering SQL functions: +*/ + +static void db_push_value(lua_State *L, sqlite3_value *value) { + switch (sqlite3_value_type(value)) { + case SQLITE_TEXT: + lua_pushlstring(L, (const char*)sqlite3_value_text(value), sqlite3_value_bytes(value)); + break; + + case SQLITE_INTEGER: + { + sqlite_int64 i64 = sqlite3_value_int64(value); + lua_Number n = (lua_Number)i64; + if (n == i64) + lua_pushnumber(L, n); + else + lua_pushlstring(L, (const char*)sqlite3_value_text(value), sqlite3_value_bytes(value)); + } + break; + + case SQLITE_FLOAT: + lua_pushnumber(L, sqlite3_value_double(value)); + break; + + case SQLITE_BLOB: + lua_pushlstring(L, sqlite3_value_blob(value), sqlite3_value_bytes(value)); + break; + + case SQLITE_NULL: + lua_pushnil(L); + break; + + default: + /* things done properly (SQLite + Lua SQLite) + ** this should never happen */ + lua_pushnil(L); + break; + } +} + +/* +** callback functions used when calling registered sql functions +*/ + +/* scalar function to be called +** callback params: context, values... */ +static void db_sql_normal_function(sqlite3_context *context, int argc, sqlite3_value **argv) { + sdb_func *func = (sdb_func*)sqlite3_user_data(context); + lua_State *L = func->db->L; + int n; + lcontext *ctx; + + int top = lua_gettop(L); + + /* ensure there is enough space in the stack */ + lua_checkstack(L, argc + 3); + + lua_rawgeti(L, LUA_REGISTRYINDEX, func->fn_step); /* function to call */ + + if (!func->aggregate) { + ctx = lsqlite_make_context(L); /* push context - used to set results */ + } + else { + /* reuse context userdata value */ + void *p = sqlite3_aggregate_context(context, 1); + /* i think it is OK to use assume that using a light user data + ** as an entry on LUA REGISTRY table will be unique */ + lua_pushlightuserdata(L, p); + lua_rawget(L, LUA_REGISTRYINDEX); /* context table */ + + if (lua_isnil(L, -1)) { /* not yet created? */ + lua_pop(L, 1); + ctx = lsqlite_make_context(L); + lua_pushlightuserdata(L, p); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } + else + ctx = lsqlite_getcontext(L, -1); + } + + /* push params */ + for (n = 0; n < argc; ++n) { + db_push_value(L, argv[n]); + } + + /* set context */ + ctx->ctx = context; + + if (lua_pcall(L, argc + 1, 0, 0)) { + const char *errmsg = lua_tostring(L, -1); + int size = lua_strlen(L, -1); + sqlite3_result_error(context, errmsg, size); + } + + /* invalidate context */ + ctx->ctx = NULL; + + if (!func->aggregate) { + luaL_unref(L, LUA_REGISTRYINDEX, ctx->ud); + } + + lua_settop(L, top); +} + +static void db_sql_finalize_function(sqlite3_context *context) { + sdb_func *func = (sdb_func*)sqlite3_user_data(context); + lua_State *L = func->db->L; + void *p = sqlite3_aggregate_context(context, 1); /* minimal mem usage */ + lcontext *ctx; + int top = lua_gettop(L); + + lua_rawgeti(L, LUA_REGISTRYINDEX, func->fn_finalize); /* function to call */ + + /* i think it is OK to use assume that using a light user data + ** as an entry on LUA REGISTRY table will be unique */ + lua_pushlightuserdata(L, p); + lua_rawget(L, LUA_REGISTRYINDEX); /* context table */ + + if (lua_isnil(L, -1)) { /* not yet created? - shouldn't happen in finalize function */ + lua_pop(L, 1); + ctx = lsqlite_make_context(L); + lua_pushlightuserdata(L, p); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } + else + ctx = lsqlite_getcontext(L, -1); + + /* set context */ + ctx->ctx = context; + + if (lua_pcall(L, 1, 0, 0)) { + sqlite3_result_error(context, lua_tostring(L, -1), -1); + } + + /* invalidate context */ + ctx->ctx = NULL; + + /* cleanup context */ + luaL_unref(L, LUA_REGISTRYINDEX, ctx->ud); + /* remove it from registry */ + lua_pushlightuserdata(L, p); + lua_pushnil(L); + lua_rawset(L, LUA_REGISTRYINDEX); + + lua_settop(L, top); +} + +/* +** Register a normal function +** Params: db, function name, number arguments, [ callback | step, finalize], user data +** Returns: true on sucess +** +** Normal function: +** Params: context, params +** +** Aggregate function: +** Params of step: context, params +** Params of finalize: context +*/ +static int db_register_function(lua_State *L, int aggregate) { + sdb *db = lsqlite_checkdb(L, 1); + const char *name; + int args; + int result; + sdb_func *func; + + /* safety measure */ + if (aggregate) aggregate = 1; + + name = luaL_checkstring(L, 2); + args = luaL_checkint(L, 3); + luaL_checktype(L, 4, LUA_TFUNCTION); + if (aggregate) luaL_checktype(L, 5, LUA_TFUNCTION); + + /* maybe an alternative way to allocate memory should be used/avoided */ + func = (sdb_func*)malloc(sizeof(sdb_func)); + if (func == NULL) { + luaL_error(L, "out of memory"); + } + + result = sqlite3_create_function( + db->db, name, args, SQLITE_UTF8, func, + aggregate ? NULL : db_sql_normal_function, + aggregate ? db_sql_normal_function : NULL, + aggregate ? db_sql_finalize_function : NULL + ); + + if (result == SQLITE_OK) { + /* safety measures for userdata field to be present in the stack */ + lua_settop(L, 5 + aggregate); + + /* save registered function in db function list */ + func->db = db; + func->aggregate = aggregate; + func->next = db->func; + db->func = func; + + /* save the setp/normal function callback */ + lua_pushvalue(L, 4); + func->fn_step = luaL_ref(L, LUA_REGISTRYINDEX); + /* save user data */ + lua_pushvalue(L, 5+aggregate); + func->udata = luaL_ref(L, LUA_REGISTRYINDEX); + + if (aggregate) { + lua_pushvalue(L, 5); + func->fn_finalize = luaL_ref(L, LUA_REGISTRYINDEX); + } + else + func->fn_finalize = LUA_NOREF; + } + else { + /* free allocated memory */ + free(func); + } + + lua_pushboolean(L, result == SQLITE_OK ? 1 : 0); + return 1; +} + +static int db_create_function(lua_State *L) { + return db_register_function(L, 0); +} + +static int db_create_aggregate(lua_State *L) { + return db_register_function(L, 1); +} + +/* create_collation; contributed by Thomas Lauer +*/ + +typedef struct { + lua_State *L; + int ref; +} scc; + +static int collwrapper(scc *co,int l1,const void *p1, + int l2,const void *p2) { + int res=0; + lua_State *L=co->L; + lua_rawgeti(L,LUA_REGISTRYINDEX,co->ref); + lua_pushlstring(L,p1,l1); + lua_pushlstring(L,p2,l2); + if (lua_pcall(L,2,1,0)==0) res=(int)lua_tonumber(L,-1); + lua_pop(L,1); + return res; +} + +static void collfree(scc *co) { + if (co) { + luaL_unref(co->L,LUA_REGISTRYINDEX,co->ref); + free(co); + } +} + +static int db_create_collation(lua_State *L) { + sdb *db=lsqlite_checkdb(L,1); + const char *collname=luaL_checkstring(L,2); + scc *co=NULL; + int (*collfunc)(scc *,int,const void *,int,const void *)=NULL; + lua_settop(L,3); /* default args to nil, and exclude extras */ + if (lua_isfunction(L,3)) collfunc=collwrapper; + else if (!lua_isnil(L,3)) + luaL_error(L,"create_collation: function or nil expected"); + if (collfunc != NULL) { + co=(scc *)malloc(sizeof(scc)); /* userdata is a no-no as it + will be garbage-collected */ + if (co) { + co->L=L; + /* lua_settop(L,3) above means we don't need: lua_pushvalue(L,3); */ + co->ref=luaL_ref(L,LUA_REGISTRYINDEX); + } + else luaL_error(L,"create_collation: could not allocate callback"); + } + sqlite3_create_collation_v2(db->db, collname, SQLITE_UTF8, + (void *)co, + (int(*)(void*,int,const void*,int,const void*))collfunc, + (void(*)(void*))collfree); + return 0; +} + +/* +** trace callback: +** Params: database, callback function, userdata +** +** callback function: +** Params: userdata, sql +*/ +static void db_trace_callback(void *user, const char *sql) { + sdb *db = (sdb*)user; + lua_State *L = db->L; + int top = lua_gettop(L); + + /* setup lua callback call */ + lua_rawgeti(L, LUA_REGISTRYINDEX, db->trace_cb); /* get callback */ + lua_rawgeti(L, LUA_REGISTRYINDEX, db->trace_udata); /* get callback user data */ + lua_pushstring(L, sql); /* traced sql statement */ + + /* call lua function */ + lua_pcall(L, 2, 0, 0); + /* ignore any error generated by this function */ + + lua_settop(L, top); +} + +static int db_trace(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + + if (lua_gettop(L) < 2 || lua_isnil(L, 2)) { + luaL_unref(L, LUA_REGISTRYINDEX, db->trace_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->trace_udata); + + db->trace_cb = + db->trace_udata = LUA_NOREF; + + /* clear trace handler */ + sqlite3_trace(db->db, NULL, NULL); + } + else { + luaL_checktype(L, 2, LUA_TFUNCTION); + + /* make sure we have an userdata field (even if nil) */ + lua_settop(L, 3); + + luaL_unref(L, LUA_REGISTRYINDEX, db->trace_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->trace_udata); + + db->trace_udata = luaL_ref(L, LUA_REGISTRYINDEX); + db->trace_cb = luaL_ref(L, LUA_REGISTRYINDEX); + + /* set trace handler */ + sqlite3_trace(db->db, db_trace_callback, db); + } + + return 0; +} + +#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK + +/* +** update_hook callback: +** Params: database, callback function, userdata +** +** callback function: +** Params: userdata, {one of SQLITE_INSERT, SQLITE_DELETE, or SQLITE_UPDATE}, +** database name, table name (containing the affected row), rowid of the row +*/ +static void db_update_hook_callback(void *user, int op, char const *dbname, char const *tblname, sqlite3_int64 rowid) { + sdb *db = (sdb*)user; + lua_State *L = db->L; + int top = lua_gettop(L); + lua_Number n = (lua_Number)rowid; + + /* setup lua callback call */ + lua_rawgeti(L, LUA_REGISTRYINDEX, db->update_hook_cb); /* get callback */ + lua_rawgeti(L, LUA_REGISTRYINDEX, db->update_hook_udata); /* get callback user data */ + lua_pushnumber(L, (lua_Number )op); + lua_pushstring(L, dbname); /* update_hook database name */ + lua_pushstring(L, tblname); /* update_hook database name */ + if (n == rowid) + lua_pushnumber(L, n); + else + lua_pushfstring(L, "%ll", rowid); + + /* call lua function */ + lua_pcall(L, 5, 0, 0); + /* ignore any error generated by this function */ + + lua_settop(L, top); +} + +static int db_update_hook(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + + if (lua_gettop(L) < 2 || lua_isnil(L, 2)) { + luaL_unref(L, LUA_REGISTRYINDEX, db->update_hook_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->update_hook_udata); + + db->update_hook_cb = + db->update_hook_udata = LUA_NOREF; + + /* clear update_hook handler */ + sqlite3_update_hook(db->db, NULL, NULL); + } + else { + luaL_checktype(L, 2, LUA_TFUNCTION); + + /* make sure we have an userdata field (even if nil) */ + lua_settop(L, 3); + + luaL_unref(L, LUA_REGISTRYINDEX, db->update_hook_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->update_hook_udata); + + db->update_hook_udata = luaL_ref(L, LUA_REGISTRYINDEX); + db->update_hook_cb = luaL_ref(L, LUA_REGISTRYINDEX); + + /* set update_hook handler */ + sqlite3_update_hook(db->db, db_update_hook_callback, db); + } + + return 0; +} + +/* +** commit_hook callback: +** Params: database, callback function, userdata +** +** callback function: +** Params: userdata +** Returned value: Return false or nil to continue the COMMIT operation normally. +** return true (non false, non nil), then the COMMIT is converted into a ROLLBACK. +*/ +static int db_commit_hook_callback(void *user) { + sdb *db = (sdb*)user; + lua_State *L = db->L; + int top = lua_gettop(L); + int rollback = 0; + + /* setup lua callback call */ + lua_rawgeti(L, LUA_REGISTRYINDEX, db->commit_hook_cb); /* get callback */ + lua_rawgeti(L, LUA_REGISTRYINDEX, db->commit_hook_udata); /* get callback user data */ + + /* call lua function */ + if (!lua_pcall(L, 1, 1, 0)) + rollback = lua_toboolean(L, -1); /* use result if there was no error */ + + lua_settop(L, top); + return rollback; +} + +static int db_commit_hook(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + + if (lua_gettop(L) < 2 || lua_isnil(L, 2)) { + luaL_unref(L, LUA_REGISTRYINDEX, db->commit_hook_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->commit_hook_udata); + + db->commit_hook_cb = + db->commit_hook_udata = LUA_NOREF; + + /* clear commit_hook handler */ + sqlite3_commit_hook(db->db, NULL, NULL); + } + else { + luaL_checktype(L, 2, LUA_TFUNCTION); + + /* make sure we have an userdata field (even if nil) */ + lua_settop(L, 3); + + luaL_unref(L, LUA_REGISTRYINDEX, db->commit_hook_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->commit_hook_udata); + + db->commit_hook_udata = luaL_ref(L, LUA_REGISTRYINDEX); + db->commit_hook_cb = luaL_ref(L, LUA_REGISTRYINDEX); + + /* set commit_hook handler */ + sqlite3_commit_hook(db->db, db_commit_hook_callback, db); + } + + return 0; +} + +/* +** rollback hook callback: +** Params: database, callback function, userdata +** +** callback function: +** Params: userdata +*/ +static void db_rollback_hook_callback(void *user) { + sdb *db = (sdb*)user; + lua_State *L = db->L; + int top = lua_gettop(L); + + /* setup lua callback call */ + lua_rawgeti(L, LUA_REGISTRYINDEX, db->rollback_hook_cb); /* get callback */ + lua_rawgeti(L, LUA_REGISTRYINDEX, db->rollback_hook_udata); /* get callback user data */ + + /* call lua function */ + lua_pcall(L, 1, 0, 0); + /* ignore any error generated by this function */ + + lua_settop(L, top); +} + +static int db_rollback_hook(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + + if (lua_gettop(L) < 2 || lua_isnil(L, 2)) { + luaL_unref(L, LUA_REGISTRYINDEX, db->rollback_hook_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->rollback_hook_udata); + + db->rollback_hook_cb = + db->rollback_hook_udata = LUA_NOREF; + + /* clear rollback_hook handler */ + sqlite3_rollback_hook(db->db, NULL, NULL); + } + else { + luaL_checktype(L, 2, LUA_TFUNCTION); + + /* make sure we have an userdata field (even if nil) */ + lua_settop(L, 3); + + luaL_unref(L, LUA_REGISTRYINDEX, db->rollback_hook_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->rollback_hook_udata); + + db->rollback_hook_udata = luaL_ref(L, LUA_REGISTRYINDEX); + db->rollback_hook_cb = luaL_ref(L, LUA_REGISTRYINDEX); + + /* set rollback_hook handler */ + sqlite3_rollback_hook(db->db, db_rollback_hook_callback, db); + } + + return 0; +} + +#endif /* #if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK */ + +#if !defined(SQLITE_OMIT_PROGRESS_CALLBACK) || !SQLITE_OMIT_PROGRESS_CALLBACK + +/* +** progress handler: +** Params: database, number of opcodes, callback function, userdata +** +** callback function: +** Params: userdata +** returns: 0 to return immediatly and return SQLITE_ABORT, non-zero to continue +*/ +static int db_progress_callback(void *user) { + int result = 1; /* abort by default */ + sdb *db = (sdb*)user; + lua_State *L = db->L; + int top = lua_gettop(L); + + lua_rawgeti(L, LUA_REGISTRYINDEX, db->progress_cb); + lua_rawgeti(L, LUA_REGISTRYINDEX, db->progress_udata); + + /* call lua function */ + if (!lua_pcall(L, 1, 1, 0)) + result = lua_toboolean(L, -1); + + lua_settop(L, top); + return result; +} + +static int db_progress_handler(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + + if (lua_gettop(L) < 2 || lua_isnil(L, 2)) { + luaL_unref(L, LUA_REGISTRYINDEX, db->progress_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->progress_udata); + + db->progress_cb = + db->progress_udata = LUA_NOREF; + + /* clear busy handler */ + sqlite3_progress_handler(db->db, 0, NULL, NULL); + } + else { + int nop = luaL_checkint(L, 2); /* number of opcodes */ + luaL_checktype(L, 3, LUA_TFUNCTION); + + /* make sure we have an userdata field (even if nil) */ + lua_settop(L, 4); + + luaL_unref(L, LUA_REGISTRYINDEX, db->progress_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->progress_udata); + + db->progress_udata = luaL_ref(L, LUA_REGISTRYINDEX); + db->progress_cb = luaL_ref(L, LUA_REGISTRYINDEX); + + /* set progress callback */ + sqlite3_progress_handler(db->db, nop, db_progress_callback, db); + } + + return 0; +} + +#else /* #if !defined(SQLITE_OMIT_PROGRESS_CALLBACK) || !SQLITE_OMIT_PROGRESS_CALLBACK */ + +static int db_progress_handler(lua_State *L) { + lua_pushliteral(L, "progress callback support disabled at compile time"); + lua_error(L); + return 0; +} + +#endif /* #if !defined(SQLITE_OMIT_PROGRESS_CALLBACK) || !SQLITE_OMIT_PROGRESS_CALLBACK */ + +/* +** busy handler: +** Params: database, callback function, userdata +** +** callback function: +** Params: userdata, number of tries +** returns: 0 to return immediatly and return SQLITE_BUSY, non-zero to try again +*/ +static int db_busy_callback(void *user, int tries) { + int retry = 0; /* abort by default */ + sdb *db = (sdb*)user; + lua_State *L = db->L; + int top = lua_gettop(L); + + lua_rawgeti(L, LUA_REGISTRYINDEX, db->busy_cb); + lua_rawgeti(L, LUA_REGISTRYINDEX, db->busy_udata); + lua_pushnumber(L, tries); + + /* call lua function */ + if (!lua_pcall(L, 2, 1, 0)) + retry = lua_toboolean(L, -1); + + lua_settop(L, top); + return retry; +} + +static int db_busy_handler(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + + if (lua_gettop(L) < 2 || lua_isnil(L, 2)) { + luaL_unref(L, LUA_REGISTRYINDEX, db->busy_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->busy_udata); + + db->busy_cb = + db->busy_udata = LUA_NOREF; + + /* clear busy handler */ + sqlite3_busy_handler(db->db, NULL, NULL); + } + else { + luaL_checktype(L, 2, LUA_TFUNCTION); + /* make sure we have an userdata field (even if nil) */ + lua_settop(L, 3); + + luaL_unref(L, LUA_REGISTRYINDEX, db->busy_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->busy_udata); + + db->busy_udata = luaL_ref(L, LUA_REGISTRYINDEX); + db->busy_cb = luaL_ref(L, LUA_REGISTRYINDEX); + + /* set busy handler */ + sqlite3_busy_handler(db->db, db_busy_callback, db); + } + + return 0; +} + +static int db_busy_timeout(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + int timeout = luaL_checkint(L, 2); + sqlite3_busy_timeout(db->db, timeout); + + /* if there was a timeout callback registered, it is now + ** invalid/useless. free any references we may have */ + luaL_unref(L, LUA_REGISTRYINDEX, db->busy_cb); + luaL_unref(L, LUA_REGISTRYINDEX, db->busy_udata); + db->busy_cb = + db->busy_udata = LUA_NOREF; + + return 0; +} + +/* +** Params: db, sql, callback, user +** returns: code [, errmsg] +** +** Callback: +** Params: user, number of columns, values, names +** Returns: 0 to continue, other value will cause abort +*/ +static int db_exec_callback(void* user, int columns, char **data, char **names) { + int result = SQLITE_ABORT; /* abort by default */ + lua_State *L = (lua_State*)user; + int n; + + int top = lua_gettop(L); + + lua_pushvalue(L, 3); /* function to call */ + lua_pushvalue(L, 4); /* user data */ + lua_pushnumber(L, columns); /* total number of rows in result */ + + /* column values */ + lua_pushvalue(L, 6); + for (n = 0; n < columns;) { + lua_pushstring(L, data[n++]); + lua_rawseti(L, -2, n); + } + + /* columns names */ + lua_pushvalue(L, 5); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + lua_newtable(L); + lua_pushvalue(L, -1); + lua_replace(L, 5); + for (n = 0; n < columns;) { + lua_pushstring(L, names[n++]); + lua_rawseti(L, -2, n); + } + } + + /* call lua function */ + if (!lua_pcall(L, 4, 1, 0)) { + if (lua_isnumber(L, -1)) + result = (int)lua_tonumber(L, -1); + } + + lua_settop(L, top); + return result; +} + +static int db_exec(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + const char *sql = luaL_checkstring(L, 2); + int result; + + if (!lua_isnoneornil(L, 3)) { + /* stack: + ** 3: callback function + ** 4: userdata + ** 5: column names + ** 6: reusable column values + */ + luaL_checktype(L, 3, LUA_TFUNCTION); + lua_settop(L, 4); /* 'trap' userdata - nil extra parameters */ + lua_pushnil(L); /* column names not known at this point */ + lua_newtable(L); /* column values table */ + + result = sqlite3_exec(db->db, sql, db_exec_callback, L, NULL); + } + else { + /* no callbacks */ + result = sqlite3_exec(db->db, sql, NULL, NULL, NULL); + } + + lua_pushnumber(L, result); + return 1; +} + +/* +** Params: db, sql +** returns: code, compiled length or error message +*/ +static int db_prepare(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + const char *sql = luaL_checkstring(L, 2); + int sql_len = lua_strlen(L, 2); + const char *sqltail; + sdb_vm *svm; + lua_settop(L,2); /* sql is on top of stack for call to newvm */ + svm = newvm(L, db); + + if (sqlite3_prepare(db->db, sql, sql_len, &svm->vm, &sqltail) != SQLITE_OK) { + cleanupvm(L, svm); + + lua_pushnil(L); + lua_pushnumber(L, sqlite3_errcode(db->db)); + return 2; + } + + /* vm already in the stack */ + lua_pushstring(L, sqltail); + return 2; +} + +static int db_do_next_row(lua_State *L, int packed) { + int result; + sdb_vm *svm = lsqlite_checkvm(L, 1); + sqlite3_stmt *vm; + int columns; + int i; + + result = stepvm(L, svm); + vm = svm->vm; /* stepvm may change svm->vm if re-prepare is needed */ + svm->has_values = result == SQLITE_ROW ? 1 : 0; + svm->columns = columns = sqlite3_data_count(vm); + + if (result == SQLITE_ROW) { + if (packed) { + lua_newtable(L); + if (packed == 1) { + for (i = 0; i < columns;) { + vm_push_column(L, vm, i); + lua_rawseti(L, -2, ++i); + } + } + else { + for (i = 0; i < columns; ++i) { + lua_pushstring(L, sqlite3_column_name(vm, i)); + vm_push_column(L, vm, i); + lua_rawset(L, -3); + } + } + return 1; + } + else { + lua_checkstack(L, columns); + for (i = 0; i < columns; ++i) + vm_push_column(L, vm, i); + return svm->columns; + } + } + + if (svm->temp) { + /* finalize and check for errors */ + result = sqlite3_finalize(vm); + svm->vm = NULL; + cleanupvm(L, svm); + } + else if (result == SQLITE_DONE) { + result = sqlite3_reset(vm); + } + + if (result != SQLITE_OK) { + lua_pushstring(L, sqlite3_errmsg(svm->db->db)); + lua_error(L); + } + return 0; +} + +static int db_next_row(lua_State *L) { + return db_do_next_row(L, 0); +} + +static int db_next_packed_row(lua_State *L) { + return db_do_next_row(L, 1); +} + +static int db_next_named_row(lua_State *L) { + return db_do_next_row(L, 2); +} + +static int dbvm_do_rows(lua_State *L, int(*f)(lua_State *)) { + /* sdb_vm *svm = */ + lsqlite_checkvm(L, 1); + lua_pushvalue(L,1); + lua_pushcfunction(L, f); + lua_insert(L, -2); + return 2; +} + +static int dbvm_rows(lua_State *L) { + return dbvm_do_rows(L, db_next_packed_row); +} + +static int dbvm_nrows(lua_State *L) { + return dbvm_do_rows(L, db_next_named_row); +} + +static int dbvm_urows(lua_State *L) { + return dbvm_do_rows(L, db_next_row); +} + +static int db_do_rows(lua_State *L, int(*f)(lua_State *)) { + sdb *db = lsqlite_checkdb(L, 1); + const char *sql = luaL_checkstring(L, 2); + sdb_vm *svm; + lua_settop(L,2); /* sql is on top of stack for call to newvm */ + svm = newvm(L, db); + svm->temp = 1; + + if (sqlite3_prepare(db->db, sql, -1, &svm->vm, NULL) != SQLITE_OK) { + cleanupvm(L, svm); + + lua_pushstring(L, sqlite3_errmsg(svm->db->db)); + lua_error(L); + } + + lua_pushcfunction(L, f); + lua_insert(L, -2); + return 2; +} + +static int db_rows(lua_State *L) { + return db_do_rows(L, db_next_packed_row); +} + +static int db_nrows(lua_State *L) { + return db_do_rows(L, db_next_named_row); +} + +/* unpacked version of db:rows */ +static int db_urows(lua_State *L) { + return db_do_rows(L, db_next_row); +} + +static int db_tostring(lua_State *L) { + char buff[32]; + sdb *db = lsqlite_getdb(L, 1); + if (db->db == NULL) + strcpy(buff, "closed"); + else + sprintf(buff, "%p", lua_touserdata(L, 1)); + lua_pushfstring(L, "sqlite database (%s)", buff); + return 1; +} + +static int db_close(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + lua_pushnumber(L, cleanupdb(L, db)); + return 1; +} + +static int db_close_vm(lua_State *L) { + sdb *db = lsqlite_checkdb(L, 1); + /* cleanup temporary only tables? */ + int temp = lua_toboolean(L, 2); + + /* free associated virtual machines */ + lua_pushlightuserdata(L, db); + lua_rawget(L, LUA_REGISTRYINDEX); + + /* close all used handles */ + lua_pushnil(L); + while (lua_next(L, -2)) { + sdb_vm *svm = lua_touserdata(L, -2); /* key: vm; val: sql text */ + + if ((!temp || svm->temp) && svm->vm) + { + sqlite3_finalize(svm->vm); + svm->vm = NULL; + } + + /* leave key in the stack */ + lua_pop(L, 1); + } + return 0; +} + +static int db_gc(lua_State *L) { + sdb *db = lsqlite_getdb(L, 1); + if (db->db != NULL) /* ignore closed databases */ + cleanupdb(L, db); + return 0; +} + +/* +** ======================================================= +** General library functions +** ======================================================= +*/ + +static int lsqlite_version(lua_State *L) { + lua_pushstring(L, sqlite3_libversion()); + return 1; +} + +static int lsqlite_complete(lua_State *L) { + const char *sql = luaL_checkstring(L, 1); + lua_pushboolean(L, sqlite3_complete(sql)); + return 1; +} + +#ifndef WIN32 +static int lsqlite_temp_directory(lua_State *L) { + const char *oldtemp = sqlite3_temp_directory; + + if (!lua_isnone(L, 1)) { + const char *temp = luaL_optstring(L, 1, NULL); + if (sqlite3_temp_directory) { + sqlite3_free((char*)sqlite3_temp_directory); + } + if (temp) { + sqlite3_temp_directory = sqlite3_mprintf("%s", temp); + } + else { + sqlite3_temp_directory = NULL; + } + } + lua_pushstring(L, oldtemp); + return 1; +} +#endif + +static int lsqlite_do_open(lua_State *L, const char *filename) { + sdb *db = newdb(L); /* create and leave in stack */ + + if (sqlite3_open(filename, &db->db) == SQLITE_OK) { + /* database handle already in the stack - return it */ + return 1; + } + + /* failed to open database */ + lua_pushnil(L); /* push nil */ + lua_pushnumber(L, sqlite3_errcode(db->db)); + lua_pushstring(L, sqlite3_errmsg(db->db)); /* push error message */ + + /* clean things up */ + cleanupdb(L, db); + + /* return */ + return 3; +} + +static int lsqlite_open(lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + return lsqlite_do_open(L, filename); +} + +static int lsqlite_open_memory(lua_State *L) { + return lsqlite_do_open(L, ":memory:"); +} + +static int lsqlite_newindex(lua_State *L) { + lua_pushliteral(L, "attempt to change readonly table"); + lua_error(L); + return 0; +} + +/* +** ======================================================= +** Register functions +** ======================================================= +*/ + +#define SC(s) { #s, SQLITE_ ## s }, +#define LSC(s) { #s, LSQLITE_ ## s }, + +static const struct { + const char* name; + int value; +} sqlite_constants[] = { + /* error codes */ + SC(OK) SC(ERROR) SC(INTERNAL) SC(PERM) + SC(ABORT) SC(BUSY) SC(LOCKED) SC(NOMEM) + SC(READONLY) SC(INTERRUPT) SC(IOERR) SC(CORRUPT) + SC(NOTFOUND) SC(FULL) SC(CANTOPEN) SC(PROTOCOL) + SC(EMPTY) SC(SCHEMA) SC(TOOBIG) SC(CONSTRAINT) + SC(MISMATCH) SC(MISUSE) SC(NOLFS) + SC(FORMAT) SC(NOTADB) + + /* sqlite_step specific return values */ + SC(RANGE) SC(ROW) SC(DONE) + + /* column types */ + SC(INTEGER) SC(FLOAT) SC(TEXT) SC(BLOB) + SC(NULL) + + /* Authorizer Action Codes */ + SC(CREATE_INDEX ) + SC(CREATE_TABLE ) + SC(CREATE_TEMP_INDEX ) + SC(CREATE_TEMP_TABLE ) + SC(CREATE_TEMP_TRIGGER) + SC(CREATE_TEMP_VIEW ) + SC(CREATE_TRIGGER ) + SC(CREATE_VIEW ) + SC(DELETE ) + SC(DROP_INDEX ) + SC(DROP_TABLE ) + SC(DROP_TEMP_INDEX ) + SC(DROP_TEMP_TABLE ) + SC(DROP_TEMP_TRIGGER ) + SC(DROP_TEMP_VIEW ) + SC(DROP_TRIGGER ) + SC(DROP_VIEW ) + SC(INSERT ) + SC(PRAGMA ) + SC(READ ) + SC(SELECT ) + SC(TRANSACTION ) + SC(UPDATE ) + SC(ATTACH ) + SC(DETACH ) + SC(ALTER_TABLE ) + SC(REINDEX ) + SC(ANALYZE ) + SC(CREATE_VTABLE ) + SC(DROP_VTABLE ) + SC(FUNCTION ) + SC(SAVEPOINT ) + + /* terminator */ + { NULL, 0 } +}; + +/* ======================================================= */ + +static const luaL_Reg dblib[] = { + {"isopen", db_isopen }, + {"last_insert_rowid", db_last_insert_rowid }, + {"changes", db_changes }, + {"total_changes", db_total_changes }, + {"errcode", db_errcode }, + {"error_code", db_errcode }, + {"errmsg", db_errmsg }, + {"error_message", db_errmsg }, + {"interrupt", db_interrupt }, + + {"create_function", db_create_function }, + {"create_aggregate", db_create_aggregate }, + {"create_collation", db_create_collation }, + + {"trace", db_trace }, + {"progress_handler", db_progress_handler }, + {"busy_timeout", db_busy_timeout }, + {"busy_handler", db_busy_handler }, +#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK + {"update_hook", db_update_hook }, + {"commit_hook", db_commit_hook }, + {"rollback_hook", db_rollback_hook }, +#endif + + {"prepare", db_prepare }, + {"rows", db_rows }, + {"urows", db_urows }, + {"nrows", db_nrows }, + + {"exec", db_exec }, + {"execute", db_exec }, + {"close", db_close }, + {"close_vm", db_close_vm }, + + {"__tostring", db_tostring }, + {"__gc", db_gc }, + + {NULL, NULL} +}; + +static const luaL_Reg vmlib[] = { + {"isopen", dbvm_isopen }, + + {"step", dbvm_step }, + {"reset", dbvm_reset }, + {"finalize", dbvm_finalize }, + + {"columns", dbvm_columns }, + + {"bind", dbvm_bind }, + {"bind_values", dbvm_bind_values }, + {"bind_names", dbvm_bind_names }, + {"bind_blob", dbvm_bind_blob }, + {"bind_parameter_count",dbvm_bind_parameter_count}, + {"bind_parameter_name", dbvm_bind_parameter_name}, + + {"get_value", dbvm_get_value }, + {"get_values", dbvm_get_values }, + {"get_name", dbvm_get_name }, + {"get_names", dbvm_get_names }, + {"get_type", dbvm_get_type }, + {"get_types", dbvm_get_types }, + {"get_uvalues", dbvm_get_uvalues }, + {"get_unames", dbvm_get_unames }, + {"get_utypes", dbvm_get_utypes }, + + {"get_named_values", dbvm_get_named_values }, + {"get_named_types", dbvm_get_named_types }, + + {"rows", dbvm_rows }, + {"urows", dbvm_urows }, + {"nrows", dbvm_nrows }, + + /* compatibility names (added by request) */ + {"idata", dbvm_get_values }, + {"inames", dbvm_get_names }, + {"itypes", dbvm_get_types }, + {"data", dbvm_get_named_values }, + {"type", dbvm_get_named_types }, + + {"__tostring", dbvm_tostring }, + {"__gc", dbvm_gc }, + + { NULL, NULL } +}; + +static const luaL_Reg ctxlib[] = { + {"user_data", lcontext_user_data }, + + {"get_aggregate_data", lcontext_get_aggregate_context }, + {"set_aggregate_data", lcontext_set_aggregate_context }, + {"aggregate_count", lcontext_aggregate_count }, + + {"result", lcontext_result }, + {"result_null", lcontext_result_null }, + {"result_number", lcontext_result_double }, + {"result_double", lcontext_result_double }, + {"result_int", lcontext_result_int }, + {"result_text", lcontext_result_text }, + {"result_blob", lcontext_result_blob }, + {"result_error", lcontext_result_error }, + + {"__tostring", lcontext_tostring }, + {NULL, NULL} +}; + +static const luaL_Reg sqlitelib[] = { + {"version", lsqlite_version }, + {"complete", lsqlite_complete }, +#ifndef WIN32 + {"temp_directory", lsqlite_temp_directory }, +#endif + {"open", lsqlite_open }, + {"open_memory", lsqlite_open_memory }, + + {"__newindex", lsqlite_newindex }, + {NULL, NULL} +}; + +static void create_meta(lua_State *L, const char *name, const luaL_Reg *lib) { + luaL_newmetatable(L, name); + lua_pushstring(L, "__index"); + lua_pushvalue(L, -2); /* push metatable */ + lua_rawset(L, -3); /* metatable.__index = metatable */ + + /* register metatable functions */ + luaL_openlib(L, NULL, lib, 0); + + /* remove metatable from stack */ + lua_pop(L, 1); +} + +LUALIB_API int luaopen_lsqlite3(lua_State *L) { + create_meta(L, sqlite_meta, dblib); + create_meta(L, sqlite_vm_meta, vmlib); + create_meta(L, sqlite_ctx_meta, ctxlib); + + luaL_getmetatable(L, sqlite_ctx_meta); + sqlite_ctx_meta_ref = luaL_ref(L, LUA_REGISTRYINDEX); + + /* register (local) sqlite metatable */ + luaL_register(L, "sqlite3", sqlitelib); + + { + int i = 0; + /* add constants to global table */ + while (sqlite_constants[i].name) { + lua_pushstring(L, sqlite_constants[i].name); + lua_pushnumber(L, sqlite_constants[i].value); + lua_rawset(L, -3); + ++i; + } + } + + /* set sqlite's metatable to itself - set as readonly (__newindex) */ + lua_pushvalue(L, -1); + lua_setmetatable(L, -2); + + return 1; +} + + + + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + + + + diff --git a/source/SQLite/sqlite3.c b/lib/sqlite/sqlite3.c index 37ee4ad38..37ee4ad38 100644 --- a/source/SQLite/sqlite3.c +++ b/lib/sqlite/sqlite3.c diff --git a/source/SQLite/sqlite3.h b/lib/sqlite/sqlite3.h index 1332eb162..1332eb162 100644 --- a/source/SQLite/sqlite3.h +++ b/lib/sqlite/sqlite3.h diff --git a/source/SQLite/urls.txt b/lib/sqlite/urls.txt index 131d70bbf..131d70bbf 100644 --- a/source/SQLite/urls.txt +++ b/lib/sqlite/urls.txt diff --git a/tolua++-1.0.93/COPYRIGHT b/lib/tolua++/COPYRIGHT index 9e99e0080..9e99e0080 100644 --- a/tolua++-1.0.93/COPYRIGHT +++ b/lib/tolua++/COPYRIGHT diff --git a/tolua++-1.0.93/INSTALL b/lib/tolua++/INSTALL index 5ee408f9e..5ee408f9e 100644 --- a/tolua++-1.0.93/INSTALL +++ b/lib/tolua++/INSTALL diff --git a/tolua++-1.0.93/Makefile b/lib/tolua++/Makefile index 92ded6c4e..92ded6c4e 100644 --- a/tolua++-1.0.93/Makefile +++ b/lib/tolua++/Makefile diff --git a/tolua++-1.0.93/README b/lib/tolua++/README index cee381fb3..cee381fb3 100644 --- a/tolua++-1.0.93/README +++ b/lib/tolua++/README diff --git a/tolua++-1.0.93/README-5.1 b/lib/tolua++/README-5.1 index f06f785e3..f06f785e3 100644 --- a/tolua++-1.0.93/README-5.1 +++ b/lib/tolua++/README-5.1 diff --git a/tolua++-1.0.93/SConstruct b/lib/tolua++/SConstruct index 5c1e7746e..5c1e7746e 100644 --- a/tolua++-1.0.93/SConstruct +++ b/lib/tolua++/SConstruct diff --git a/lib/tolua++/include/tolua++.h b/lib/tolua++/include/tolua++.h new file mode 100644 index 000000000..3ebd8d246 --- /dev/null +++ b/lib/tolua++/include/tolua++.h @@ -0,0 +1,186 @@ +/* tolua +** Support code for Lua bindings. +** Written by Waldemar Celes +** TeCGraf/PUC-Rio +** Apr 2003 +** $Id: $ +*/ + +/* This code is free software; you can redistribute it and/or modify it. +** The software provided hereunder is on an "as is" basis, and +** the author has no obligation to provide maintenance, support, updates, +** enhancements, or modifications. +*/ + + +#ifndef TOLUA_H +#define TOLUA_H + +#ifndef TOLUA_API +#define TOLUA_API extern +#endif + +#define TOLUA_VERSION "tolua++-1.0.92" + +#ifdef __cplusplus +extern "C" { +#endif + +#define tolua_pushcppstring(x,y) tolua_pushstring(x,y.c_str()) +#define tolua_iscppstring tolua_isstring + +#define tolua_iscppstringarray tolua_isstringarray +#define tolua_pushfieldcppstring(L,lo,idx,s) tolua_pushfieldstring(L, lo, idx, s.c_str()) + +#ifndef TEMPLATE_BIND + #define TEMPLATE_BIND(p) +#endif + +#define TOLUA_TEMPLATE_BIND(p) + +#define TOLUA_PROTECTED_DESTRUCTOR +#define TOLUA_PROPERTY_TYPE(p) + +typedef int lua_Object; + +#include "../../lua/src/lua.h" +#include "../../lua/src/lauxlib.h" + +struct tolua_Error +{ + int index; + int array; + const char* type; +}; +typedef struct tolua_Error tolua_Error; + +#define TOLUA_NOPEER LUA_REGISTRYINDEX /* for lua 5.1 */ + +TOLUA_API const char* tolua_typename (lua_State* L, int lo); +TOLUA_API void tolua_error (lua_State* L, const char* msg, tolua_Error* err); +TOLUA_API int tolua_isnoobj (lua_State* L, int lo, tolua_Error* err); +TOLUA_API int tolua_isvalue (lua_State* L, int lo, int def, tolua_Error* err); +TOLUA_API int tolua_isvaluenil (lua_State* L, int lo, tolua_Error* err); +TOLUA_API int tolua_isboolean (lua_State* L, int lo, int def, tolua_Error* err); +TOLUA_API int tolua_isnumber (lua_State* L, int lo, int def, tolua_Error* err); +TOLUA_API int tolua_isstring (lua_State* L, int lo, int def, tolua_Error* err); +TOLUA_API int tolua_istable (lua_State* L, int lo, int def, tolua_Error* err); +TOLUA_API int tolua_isusertable (lua_State* L, int lo, const char* type, int def, tolua_Error* err); +TOLUA_API int tolua_isuserdata (lua_State* L, int lo, int def, tolua_Error* err); +TOLUA_API int tolua_isusertype (lua_State* L, int lo, const char* type, int def, tolua_Error* err); +TOLUA_API int tolua_isvaluearray + (lua_State* L, int lo, int dim, int def, tolua_Error* err); +TOLUA_API int tolua_isbooleanarray + (lua_State* L, int lo, int dim, int def, tolua_Error* err); +TOLUA_API int tolua_isnumberarray + (lua_State* L, int lo, int dim, int def, tolua_Error* err); +TOLUA_API int tolua_isstringarray + (lua_State* L, int lo, int dim, int def, tolua_Error* err); +TOLUA_API int tolua_istablearray + (lua_State* L, int lo, int dim, int def, tolua_Error* err); +TOLUA_API int tolua_isuserdataarray + (lua_State* L, int lo, int dim, int def, tolua_Error* err); +TOLUA_API int tolua_isusertypearray + (lua_State* L, int lo, const char* type, int dim, int def, tolua_Error* err); + +TOLUA_API void tolua_open (lua_State* L); + +TOLUA_API void* tolua_copy (lua_State* L, void* value, unsigned int size); +TOLUA_API int tolua_register_gc (lua_State* L, int lo); +TOLUA_API int tolua_default_collect (lua_State* tolua_S); + +TOLUA_API void tolua_usertype (lua_State* L, const char* type); +TOLUA_API void tolua_beginmodule (lua_State* L, const char* name); +TOLUA_API void tolua_endmodule (lua_State* L); +TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar); +TOLUA_API void tolua_class (lua_State* L, const char* name, const char* base); +TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col); +TOLUA_API void tolua_function (lua_State* L, const char* name, lua_CFunction func); +TOLUA_API void tolua_constant (lua_State* L, const char* name, lua_Number value); +TOLUA_API void tolua_variable (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set); +TOLUA_API void tolua_array (lua_State* L,const char* name, lua_CFunction get, lua_CFunction set); + +/* TOLUA_API void tolua_set_call_event(lua_State* L, lua_CFunction func, char* type); */ +/* TOLUA_API void tolua_addbase(lua_State* L, char* name, char* base); */ + +TOLUA_API void tolua_pushvalue (lua_State* L, int lo); +TOLUA_API void tolua_pushboolean (lua_State* L, int value); +TOLUA_API void tolua_pushnumber (lua_State* L, lua_Number value); +TOLUA_API void tolua_pushstring (lua_State* L, const char* value); +TOLUA_API void tolua_pushuserdata (lua_State* L, void* value); +TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type); +TOLUA_API void tolua_pushusertype_and_takeownership(lua_State* L, void* value, const char* type); +TOLUA_API void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v); +TOLUA_API void tolua_pushfieldboolean (lua_State* L, int lo, int index, int v); +TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, lua_Number v); +TOLUA_API void tolua_pushfieldstring (lua_State* L, int lo, int index, const char* v); +TOLUA_API void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v); +TOLUA_API void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, const char* type); +TOLUA_API void tolua_pushfieldusertype_and_takeownership (lua_State* L, int lo, int index, void* v, const char* type); + +TOLUA_API lua_Number tolua_tonumber (lua_State* L, int narg, lua_Number def); +TOLUA_API const char* tolua_tostring (lua_State* L, int narg, const char* def); +TOLUA_API void* tolua_touserdata (lua_State* L, int narg, void* def); +TOLUA_API void* tolua_tousertype (lua_State* L, int narg, void* def); +TOLUA_API int tolua_tovalue (lua_State* L, int narg, int def); +TOLUA_API int tolua_toboolean (lua_State* L, int narg, int def); +TOLUA_API lua_Number tolua_tofieldnumber (lua_State* L, int lo, int index, lua_Number def); +TOLUA_API const char* tolua_tofieldstring (lua_State* L, int lo, int index, const char* def); +TOLUA_API void* tolua_tofielduserdata (lua_State* L, int lo, int index, void* def); +TOLUA_API void* tolua_tofieldusertype (lua_State* L, int lo, int index, void* def); +TOLUA_API int tolua_tofieldvalue (lua_State* L, int lo, int index, int def); +TOLUA_API int tolua_getfieldboolean (lua_State* L, int lo, int index, int def); + +TOLUA_API void tolua_dobuffer(lua_State* L, char* B, unsigned int size, const char* name); + +TOLUA_API int class_gc_event (lua_State* L); + +#ifdef __cplusplus +static inline const char* tolua_tocppstring (lua_State* L, int narg, const char* def) { + + const char* s = tolua_tostring(L, narg, def); + return s?s:""; +}; + +static inline const char* tolua_tofieldcppstring (lua_State* L, int lo, int index, const char* def) { + + const char* s = tolua_tofieldstring(L, lo, index, def); + return s?s:""; +}; + +#else +#define tolua_tocppstring tolua_tostring +#define tolua_tofieldcppstring tolua_tofieldstring +#endif + +TOLUA_API int tolua_fast_isa(lua_State *L, int mt_indexa, int mt_indexb, int super_index); + +#ifndef Mtolua_new +#define Mtolua_new(EXP) new EXP +#endif + +#ifndef Mtolua_delete +#define Mtolua_delete(EXP) delete EXP +#endif + +#ifndef Mtolua_new_dim +#define Mtolua_new_dim(EXP, len) new EXP[len] +#endif + +#ifndef Mtolua_delete_dim +#define Mtolua_delete_dim(EXP) delete [] EXP +#endif + +#ifndef tolua_outside +#define tolua_outside +#endif + +#ifndef tolua_owned +#define tolua_owned +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tolua++-1.0.93/src/bin/SCsub b/lib/tolua++/src/bin/SCsub index 35ccd7a24..35ccd7a24 100644 --- a/tolua++-1.0.93/src/bin/SCsub +++ b/lib/tolua++/src/bin/SCsub diff --git a/tolua++-1.0.93/src/bin/lua/all.lua b/lib/tolua++/src/bin/lua/all.lua index 83f8a3cb9..83f8a3cb9 100644 --- a/tolua++-1.0.93/src/bin/lua/all.lua +++ b/lib/tolua++/src/bin/lua/all.lua diff --git a/tolua++-1.0.93/src/bin/lua/array.lua b/lib/tolua++/src/bin/lua/array.lua index f35aa98ce..f35aa98ce 100644 --- a/tolua++-1.0.93/src/bin/lua/array.lua +++ b/lib/tolua++/src/bin/lua/array.lua diff --git a/tolua++-1.0.93/src/bin/lua/basic.lua b/lib/tolua++/src/bin/lua/basic.lua index f651f1fe6..f651f1fe6 100644 --- a/tolua++-1.0.93/src/bin/lua/basic.lua +++ b/lib/tolua++/src/bin/lua/basic.lua diff --git a/tolua++-1.0.93/src/bin/lua/class.lua b/lib/tolua++/src/bin/lua/class.lua index 592705282..592705282 100644 --- a/tolua++-1.0.93/src/bin/lua/class.lua +++ b/lib/tolua++/src/bin/lua/class.lua diff --git a/tolua++-1.0.93/src/bin/lua/clean.lua b/lib/tolua++/src/bin/lua/clean.lua index fd5b7b635..fd5b7b635 100644 --- a/tolua++-1.0.93/src/bin/lua/clean.lua +++ b/lib/tolua++/src/bin/lua/clean.lua diff --git a/tolua++-1.0.93/src/bin/lua/code.lua b/lib/tolua++/src/bin/lua/code.lua index 5e19b6bbf..5e19b6bbf 100644 --- a/tolua++-1.0.93/src/bin/lua/code.lua +++ b/lib/tolua++/src/bin/lua/code.lua diff --git a/tolua++-1.0.93/src/bin/lua/compat-5.1.lua b/lib/tolua++/src/bin/lua/compat-5.1.lua index 7a2c60b69..7a2c60b69 100644 --- a/tolua++-1.0.93/src/bin/lua/compat-5.1.lua +++ b/lib/tolua++/src/bin/lua/compat-5.1.lua diff --git a/tolua++-1.0.93/src/bin/lua/compat.lua b/lib/tolua++/src/bin/lua/compat.lua index 45d6ae1ba..45d6ae1ba 100644 --- a/tolua++-1.0.93/src/bin/lua/compat.lua +++ b/lib/tolua++/src/bin/lua/compat.lua diff --git a/tolua++-1.0.93/src/bin/lua/container.lua b/lib/tolua++/src/bin/lua/container.lua index 2d11db7df..2d11db7df 100644 --- a/tolua++-1.0.93/src/bin/lua/container.lua +++ b/lib/tolua++/src/bin/lua/container.lua diff --git a/tolua++-1.0.93/src/bin/lua/custom.lua b/lib/tolua++/src/bin/lua/custom.lua index de5912fb3..de5912fb3 100644 --- a/tolua++-1.0.93/src/bin/lua/custom.lua +++ b/lib/tolua++/src/bin/lua/custom.lua diff --git a/tolua++-1.0.93/src/bin/lua/declaration.lua b/lib/tolua++/src/bin/lua/declaration.lua index 73bbe910e..73bbe910e 100644 --- a/tolua++-1.0.93/src/bin/lua/declaration.lua +++ b/lib/tolua++/src/bin/lua/declaration.lua diff --git a/tolua++-1.0.93/src/bin/lua/define.lua b/lib/tolua++/src/bin/lua/define.lua index 96a28d878..96a28d878 100644 --- a/tolua++-1.0.93/src/bin/lua/define.lua +++ b/lib/tolua++/src/bin/lua/define.lua diff --git a/tolua++-1.0.93/src/bin/lua/doit.lua b/lib/tolua++/src/bin/lua/doit.lua index 51dd0cf3c..51dd0cf3c 100644 --- a/tolua++-1.0.93/src/bin/lua/doit.lua +++ b/lib/tolua++/src/bin/lua/doit.lua diff --git a/tolua++-1.0.93/src/bin/lua/enumerate.lua b/lib/tolua++/src/bin/lua/enumerate.lua index 99fe74629..99fe74629 100644 --- a/tolua++-1.0.93/src/bin/lua/enumerate.lua +++ b/lib/tolua++/src/bin/lua/enumerate.lua diff --git a/tolua++-1.0.93/src/bin/lua/feature.lua b/lib/tolua++/src/bin/lua/feature.lua index 042b5d28e..042b5d28e 100644 --- a/tolua++-1.0.93/src/bin/lua/feature.lua +++ b/lib/tolua++/src/bin/lua/feature.lua diff --git a/tolua++-1.0.93/src/bin/lua/function.lua b/lib/tolua++/src/bin/lua/function.lua index 2358e9ff7..2358e9ff7 100644 --- a/tolua++-1.0.93/src/bin/lua/function.lua +++ b/lib/tolua++/src/bin/lua/function.lua diff --git a/tolua++-1.0.93/src/bin/lua/module.lua b/lib/tolua++/src/bin/lua/module.lua index 57dceb7d5..57dceb7d5 100644 --- a/tolua++-1.0.93/src/bin/lua/module.lua +++ b/lib/tolua++/src/bin/lua/module.lua diff --git a/tolua++-1.0.93/src/bin/lua/namespace.lua b/lib/tolua++/src/bin/lua/namespace.lua index 6ca80e6e3..6ca80e6e3 100644 --- a/tolua++-1.0.93/src/bin/lua/namespace.lua +++ b/lib/tolua++/src/bin/lua/namespace.lua diff --git a/tolua++-1.0.93/src/bin/lua/operator.lua b/lib/tolua++/src/bin/lua/operator.lua index 675027cd7..675027cd7 100644 --- a/tolua++-1.0.93/src/bin/lua/operator.lua +++ b/lib/tolua++/src/bin/lua/operator.lua diff --git a/tolua++-1.0.93/src/bin/lua/package.lua b/lib/tolua++/src/bin/lua/package.lua index eec136904..eec136904 100644 --- a/tolua++-1.0.93/src/bin/lua/package.lua +++ b/lib/tolua++/src/bin/lua/package.lua diff --git a/tolua++-1.0.93/src/bin/lua/template_class.lua b/lib/tolua++/src/bin/lua/template_class.lua index b1ed05abe..b1ed05abe 100644 --- a/tolua++-1.0.93/src/bin/lua/template_class.lua +++ b/lib/tolua++/src/bin/lua/template_class.lua diff --git a/tolua++-1.0.93/src/bin/lua/typedef.lua b/lib/tolua++/src/bin/lua/typedef.lua index a78a84155..a78a84155 100644 --- a/tolua++-1.0.93/src/bin/lua/typedef.lua +++ b/lib/tolua++/src/bin/lua/typedef.lua diff --git a/tolua++-1.0.93/src/bin/lua/variable.lua b/lib/tolua++/src/bin/lua/variable.lua index fbc705dd8..fbc705dd8 100644 --- a/tolua++-1.0.93/src/bin/lua/variable.lua +++ b/lib/tolua++/src/bin/lua/variable.lua diff --git a/tolua++-1.0.93/src/bin/lua/verbatim.lua b/lib/tolua++/src/bin/lua/verbatim.lua index fd3b29b35..fd3b29b35 100644 --- a/tolua++-1.0.93/src/bin/lua/verbatim.lua +++ b/lib/tolua++/src/bin/lua/verbatim.lua diff --git a/lib/tolua++/src/bin/tolua.c b/lib/tolua++/src/bin/tolua.c new file mode 100644 index 000000000..fd8e1ed1e --- /dev/null +++ b/lib/tolua++/src/bin/tolua.c @@ -0,0 +1,169 @@ +/* tolua +** Support code for Lua bindings. +** Written by Waldemar Celes +** TeCGraf/PUC-Rio +** Aug 2003 +** $Id:$ +*/ + +/* This code is free software; you can redistribute it and/or modify it. +** The software provided hereunder is on an "as is" basis, and +** the author has no obligation to provide maintenance, support, updates, +** enhancements, or modifications. +*/ + +#include "../../include/tolua++.h" + +#include "../../../lua/src/lua.h" +#include "../../../lua/src/lualib.h" +#include "../../../lua/src/lauxlib.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +static void help (void) +{ + fprintf(stderr,"\n" + "usage: tolua++ [options] input_file\n" + "\n" + "Command line options are:\n" + " -v : print version information.\n" + " -o file : set output file; default is stdout.\n" + " -H file : create include file.\n" + " -n name : set package name; default is input file root name.\n" + " -p : parse only.\n" + " -P : parse and print structure information (for debug).\n" + " -S : disable support for c++ strings.\n" + " -1 : substract 1 to operator[] index (for compatibility with tolua5).\n" + " -L file : run lua file (with dofile()) before doing anything.\n" + " -D : disable automatic exporting of destructors for classes that have\n" + " constructors (for compatibility with tolua5)\n" + " -W : disable warnings for unsupported features (for compatibility\n" + " with tolua5)\n" + " -C : disable cleanup of included lua code (for easier debugging)\n" + " -E value[=value] : add extra values to the luastate\n" + " -t : export a list of types asociates with the C++ typeid name\n" + " -q : don't print warnings to the console\n" + " -h : print this message.\n" + "Should the input file be omitted, stdin is assumed;\n" + "in that case, the package name must be explicitly set.\n\n" + ); +} + +static void version (void) +{ + fprintf(stderr, "%s (written by W. Celes, A. Manzur)\n",TOLUA_VERSION); +} + +static void setfield (lua_State* L, int table, char* f, char* v) +{ + lua_pushstring(L,f); + lua_pushstring(L,v); + lua_settable(L,table); +} + +static void add_extra (lua_State* L, char* value) { + int len; + lua_getglobal(L, "_extra_parameters"); + len = luaL_getn(L, -1); + lua_pushstring(L, value); + lua_rawseti(L, -2, len+1); + lua_pop(L, 1); +}; + +static void error (char* o) +{ + fprintf(stderr,"tolua: unknown option '%s'\n",o); + help(); + exit(1); +} + +int main (int argc, char* argv[]) +{ + #ifdef LUA_VERSION_NUM /* lua 5.1 */ + lua_State* L = luaL_newstate(); + luaL_openlibs(L); + #else + lua_State* L = lua_open(); + luaopen_base(L); + luaopen_io(L); + luaopen_string(L); + luaopen_table(L); + luaopen_math(L); + luaopen_debug(L); + #endif + + lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION"); + lua_pushstring(L,LUA_VERSION); lua_setglobal(L,"TOLUA_LUA_VERSION"); + + if (argc==1) + { + help(); + return 0; + } + else + { + int i, t; + lua_newtable(L); + lua_setglobal(L, "_extra_parameters"); + lua_newtable(L); + lua_pushvalue(L,-1); + lua_setglobal(L,"flags"); + t = lua_gettop(L); + for (i=1; i<argc; ++i) + { + if (*argv[i] == '-') + { + switch (argv[i][1]) + { + case 'v': version(); return 0; + case 'h': help(); return 0; + case 'p': setfield(L,t,"p",""); break; + case 'P': setfield(L,t,"P",""); break; + case 'o': setfield(L,t,"o",argv[++i]); break; + case 'n': setfield(L,t,"n",argv[++i]); break; + case 'H': setfield(L,t,"H",argv[++i]); break; + case 'S': setfield(L,t,"S",""); break; + case '1': setfield(L,t,"1",""); break; + case 'L': setfield(L,t,"L",argv[++i]); break; + case 'D': setfield(L,t,"D",""); break; + case 'W': setfield(L,t,"W",""); break; + case 'C': setfield(L,t,"C",""); break; + case 'E': add_extra(L,argv[++i]); break; + case 't': setfield(L,t,"t",""); break; + case 'q': setfield(L,t,"q",""); break; + default: error(argv[i]); break; + } + } + else + { + setfield(L,t,"f",argv[i]); + break; + } + } + lua_pop(L,1); + } +/* #define TOLUA_SCRIPT_RUN */ +#ifndef TOLUA_SCRIPT_RUN + { + int tolua_tolua_open (lua_State* L); + tolua_tolua_open(L); + } +#else + { + char* p; + char path[BUFSIZ]; + strcpy(path,argv[0]); + p = strrchr(path,'/'); + if (p==NULL) p = strrchr(path,'\\'); + p = (p==NULL) ? path : p+1; + sprintf(p,"%s","../src/bin/lua/"); + lua_pushstring(L,path); lua_setglobal(L,"path"); + strcat(path,"all.lua"); + lua_dofile(L,path); + } +#endif + return 0; +} diff --git a/tolua++-1.0.93/src/bin/tolua_scons.pkg b/lib/tolua++/src/bin/tolua_scons.pkg index da458ea7c..da458ea7c 100644 --- a/tolua++-1.0.93/src/bin/tolua_scons.pkg +++ b/lib/tolua++/src/bin/tolua_scons.pkg diff --git a/tolua++-1.0.93/src/bin/toluabind.c b/lib/tolua++/src/bin/toluabind.c index bf71cf158..bf71cf158 100644 --- a/tolua++-1.0.93/src/bin/toluabind.c +++ b/lib/tolua++/src/bin/toluabind.c diff --git a/tolua++-1.0.93/src/bin/toluabind.h b/lib/tolua++/src/bin/toluabind.h index 7f1f018c9..7f1f018c9 100644 --- a/tolua++-1.0.93/src/bin/toluabind.h +++ b/lib/tolua++/src/bin/toluabind.h diff --git a/tolua++-1.0.93/src/bin/toluabind_default.c b/lib/tolua++/src/bin/toluabind_default.c index b5db813bf..b5db813bf 100644 --- a/tolua++-1.0.93/src/bin/toluabind_default.c +++ b/lib/tolua++/src/bin/toluabind_default.c diff --git a/tolua++-1.0.93/src/bin/toluabind_default.h b/lib/tolua++/src/bin/toluabind_default.h index c31a14875..c31a14875 100644 --- a/tolua++-1.0.93/src/bin/toluabind_default.h +++ b/lib/tolua++/src/bin/toluabind_default.h diff --git a/tolua++-1.0.93/src/lib/SCsub b/lib/tolua++/src/lib/SCsub index 2f9a24691..2f9a24691 100644 --- a/tolua++-1.0.93/src/lib/SCsub +++ b/lib/tolua++/src/lib/SCsub diff --git a/lib/tolua++/src/lib/tolua_event.c b/lib/tolua++/src/lib/tolua_event.c new file mode 100644 index 000000000..3075a60b3 --- /dev/null +++ b/lib/tolua++/src/lib/tolua_event.c @@ -0,0 +1,536 @@ +/* tolua: event functions +** Support code for Lua bindings. +** Written by Waldemar Celes +** TeCGraf/PUC-Rio +** Apr 2003 +** $Id: $ +*/ + +/* This code is free software; you can redistribute it and/or modify it. +** The software provided hereunder is on an "as is" basis, and +** the author has no obligation to provide maintenance, support, updates, +** enhancements, or modifications. +*/ + +#include <stdio.h> + +#include "../../include/tolua++.h" + +/* Store at ubox + * It stores, creating the corresponding table if needed, + * the pair key/value in the corresponding ubox table +*/ +static void storeatubox (lua_State* L, int lo) +{ + #ifdef LUA_VERSION_NUM + lua_getfenv(L, lo); + if (lua_rawequal(L, -1, TOLUA_NOPEER)) { + lua_pop(L, 1); + lua_newtable(L); + lua_pushvalue(L, -1); + lua_setfenv(L, lo); /* stack: k,v,table */ + }; + lua_insert(L, -3); + lua_settable(L, -3); /* on lua 5.1, we trade the "tolua_peers" lookup for a settable call */ + lua_pop(L, 1); + #else + /* stack: key value (to be stored) */ + lua_pushstring(L,"tolua_peers"); + lua_rawget(L,LUA_REGISTRYINDEX); /* stack: k v ubox */ + lua_pushvalue(L,lo); + lua_rawget(L,-2); /* stack: k v ubox ubox[u] */ + if (!lua_istable(L,-1)) + { + lua_pop(L,1); /* stack: k v ubox */ + lua_newtable(L); /* stack: k v ubox table */ + lua_pushvalue(L,1); + lua_pushvalue(L,-2); /* stack: k v ubox table u table */ + lua_rawset(L,-4); /* stack: k v ubox ubox[u]=table */ + } + lua_insert(L,-4); /* put table before k */ + lua_pop(L,1); /* pop ubox */ + lua_rawset(L,-3); /* store at table */ + lua_pop(L,1); /* pop ubox[u] */ + #endif +} + +/* Module index function +*/ +static int module_index_event (lua_State* L) +{ + lua_pushstring(L,".get"); + lua_rawget(L,-3); + if (lua_istable(L,-1)) + { + lua_pushvalue(L,2); /* key */ + lua_rawget(L,-2); + if (lua_iscfunction(L,-1)) + { + lua_call(L,0,1); + return 1; + } + else if (lua_istable(L,-1)) + return 1; + } + /* call old index meta event */ + if (lua_getmetatable(L,1)) + { + lua_pushstring(L,"__index"); + lua_rawget(L,-2); + lua_pushvalue(L,1); + lua_pushvalue(L,2); + if (lua_isfunction(L,-1)) + { + lua_call(L,2,1); + return 1; + } + else if (lua_istable(L,-1)) + { + lua_gettable(L,-3); + return 1; + } + } + lua_pushnil(L); + return 1; +} + +/* Module newindex function +*/ +static int module_newindex_event (lua_State* L) +{ + lua_pushstring(L,".set"); + lua_rawget(L,-4); + if (lua_istable(L,-1)) + { + lua_pushvalue(L,2); /* key */ + lua_rawget(L,-2); + if (lua_iscfunction(L,-1)) + { + lua_pushvalue(L,1); /* only to be compatible with non-static vars */ + lua_pushvalue(L,3); /* value */ + lua_call(L,2,0); + return 0; + } + } + /* call old newindex meta event */ + if (lua_getmetatable(L,1) && lua_getmetatable(L,-1)) + { + lua_pushstring(L,"__newindex"); + lua_rawget(L,-2); + if (lua_isfunction(L,-1)) + { + lua_pushvalue(L,1); + lua_pushvalue(L,2); + lua_pushvalue(L,3); + lua_call(L,3,0); + } + } + lua_settop(L,3); + lua_rawset(L,-3); + return 0; +} + +/* Class index function + * If the object is a userdata (ie, an object), it searches the field in + * the alternative table stored in the corresponding "ubox" table. +*/ +static int class_index_event (lua_State* L) +{ + int t = lua_type(L,1); + if (t == LUA_TUSERDATA) + { + /* Access alternative table */ + #ifdef LUA_VERSION_NUM /* new macro on version 5.1 */ + lua_getfenv(L,1); + if (!lua_rawequal(L, -1, TOLUA_NOPEER)) { + lua_pushvalue(L, 2); /* key */ + lua_gettable(L, -2); /* on lua 5.1, we trade the "tolua_peers" lookup for a gettable call */ + if (!lua_isnil(L, -1)) + return 1; + }; + #else + lua_pushstring(L,"tolua_peers"); + lua_rawget(L,LUA_REGISTRYINDEX); /* stack: obj key ubox */ + lua_pushvalue(L,1); + lua_rawget(L,-2); /* stack: obj key ubox ubox[u] */ + if (lua_istable(L,-1)) + { + lua_pushvalue(L,2); /* key */ + lua_rawget(L,-2); /* stack: obj key ubox ubox[u] value */ + if (!lua_isnil(L,-1)) + return 1; + } + #endif + lua_settop(L,2); /* stack: obj key */ + /* Try metatables */ + lua_pushvalue(L,1); /* stack: obj key obj */ + while (lua_getmetatable(L,-1)) + { /* stack: obj key obj mt */ + lua_remove(L,-2); /* stack: obj key mt */ + if (lua_isnumber(L,2)) /* check if key is a numeric value */ + { + /* try operator[] */ + lua_pushstring(L,".geti"); + lua_rawget(L,-2); /* stack: obj key mt func */ + if (lua_isfunction(L,-1)) + { + lua_pushvalue(L,1); + lua_pushvalue(L,2); + lua_call(L,2,1); + return 1; + } + } + else + { + lua_pushvalue(L,2); /* stack: obj key mt key */ + lua_rawget(L,-2); /* stack: obj key mt value */ + if (!lua_isnil(L,-1)) + return 1; + else + lua_pop(L,1); + /* try C/C++ variable */ + lua_pushstring(L,".get"); + lua_rawget(L,-2); /* stack: obj key mt tget */ + if (lua_istable(L,-1)) + { + lua_pushvalue(L,2); + lua_rawget(L,-2); /* stack: obj key mt value */ + if (lua_iscfunction(L,-1)) + { + lua_pushvalue(L,1); + lua_pushvalue(L,2); + lua_call(L,2,1); + return 1; + } + else if (lua_istable(L,-1)) + { + /* deal with array: create table to be returned and cache it in ubox */ + void* u = *((void**)lua_touserdata(L,1)); + lua_newtable(L); /* stack: obj key mt value table */ + lua_pushstring(L,".self"); + lua_pushlightuserdata(L,u); + lua_rawset(L,-3); /* store usertype in ".self" */ + lua_insert(L,-2); /* stack: obj key mt table value */ + lua_setmetatable(L,-2); /* set stored value as metatable */ + lua_pushvalue(L,-1); /* stack: obj key met table table */ + lua_pushvalue(L,2); /* stack: obj key mt table table key */ + lua_insert(L,-2); /* stack: obj key mt table key table */ + storeatubox(L,1); /* stack: obj key mt table */ + return 1; + } + } + } + lua_settop(L,3); + } + lua_pushnil(L); + return 1; + } + else if (t== LUA_TTABLE) + { + module_index_event(L); + return 1; + } + lua_pushnil(L); + return 1; +} + +/* Newindex function + * It first searches for a C/C++ varaible to be set. + * Then, it either stores it in the alternative ubox table (in the case it is + * an object) or in the own table (that represents the class or module). +*/ +static int class_newindex_event (lua_State* L) +{ + int t = lua_type(L,1); + if (t == LUA_TUSERDATA) + { + /* Try accessing a C/C++ variable to be set */ + lua_getmetatable(L,1); + while (lua_istable(L,-1)) /* stack: t k v mt */ + { + if (lua_isnumber(L,2)) /* check if key is a numeric value */ + { + /* try operator[] */ + lua_pushstring(L,".seti"); + lua_rawget(L,-2); /* stack: obj key mt func */ + if (lua_isfunction(L,-1)) + { + lua_pushvalue(L,1); + lua_pushvalue(L,2); + lua_pushvalue(L,3); + lua_call(L,3,0); + return 0; + } + } + else + { + lua_pushstring(L,".set"); + lua_rawget(L,-2); /* stack: t k v mt tset */ + if (lua_istable(L,-1)) + { + lua_pushvalue(L,2); + lua_rawget(L,-2); /* stack: t k v mt tset func */ + if (lua_iscfunction(L,-1)) + { + lua_pushvalue(L,1); + lua_pushvalue(L,3); + lua_call(L,2,0); + return 0; + } + lua_pop(L,1); /* stack: t k v mt tset */ + } + lua_pop(L,1); /* stack: t k v mt */ + if (!lua_getmetatable(L,-1)) /* stack: t k v mt mt */ + lua_pushnil(L); + lua_remove(L,-2); /* stack: t k v mt */ + } + } + lua_settop(L,3); /* stack: t k v */ + + /* then, store as a new field */ + storeatubox(L,1); + } + else if (t== LUA_TTABLE) + { + module_newindex_event(L); + } + return 0; +} + +static int class_call_event(lua_State* L) { + + if (lua_istable(L, 1)) { + lua_pushstring(L, ".call"); + lua_rawget(L, 1); + if (lua_isfunction(L, -1)) { + + lua_insert(L, 1); + lua_call(L, lua_gettop(L)-1, 1); + + return 1; + }; + }; + tolua_error(L,"Attempt to call a non-callable object.",NULL); + return 0; +}; + +static int do_operator (lua_State* L, const char* op) +{ + if (lua_isuserdata(L,1)) + { + /* Try metatables */ + lua_pushvalue(L,1); /* stack: op1 op2 */ + while (lua_getmetatable(L,-1)) + { /* stack: op1 op2 op1 mt */ + lua_remove(L,-2); /* stack: op1 op2 mt */ + lua_pushstring(L,op); /* stack: op1 op2 mt key */ + lua_rawget(L,-2); /* stack: obj key mt func */ + if (lua_isfunction(L,-1)) + { + lua_pushvalue(L,1); + lua_pushvalue(L,2); + lua_call(L,2,1); + return 1; + } + lua_settop(L,3); + } + } + tolua_error(L,"Attempt to perform operation on an invalid operand",NULL); + return 0; +} + +static int class_add_event (lua_State* L) +{ + return do_operator(L,".add"); +} + +static int class_sub_event (lua_State* L) +{ + return do_operator(L,".sub"); +} + +static int class_mul_event (lua_State* L) +{ + return do_operator(L,".mul"); +} + +static int class_div_event (lua_State* L) +{ + return do_operator(L,".div"); +} + +static int class_lt_event (lua_State* L) +{ + return do_operator(L,".lt"); +} + +static int class_le_event (lua_State* L) +{ + return do_operator(L,".le"); +} + +static int class_eq_event (lua_State* L) +{ + /* copying code from do_operator here to return false when no operator is found */ + if (lua_isuserdata(L,1)) + { + /* Try metatables */ + lua_pushvalue(L,1); /* stack: op1 op2 */ + while (lua_getmetatable(L,-1)) + { /* stack: op1 op2 op1 mt */ + lua_remove(L,-2); /* stack: op1 op2 mt */ + lua_pushstring(L,".eq"); /* stack: op1 op2 mt key */ + lua_rawget(L,-2); /* stack: obj key mt func */ + if (lua_isfunction(L,-1)) + { + lua_pushvalue(L,1); + lua_pushvalue(L,2); + lua_call(L,2,1); + return 1; + } + lua_settop(L,3); + } + } + + lua_settop(L, 3); + lua_pushboolean(L, 0); + return 1; +} + +/* +static int class_gc_event (lua_State* L) +{ + void* u = *((void**)lua_touserdata(L,1)); + fprintf(stderr, "collecting: looking at %p\n", u); + lua_pushstring(L,"tolua_gc"); + lua_rawget(L,LUA_REGISTRYINDEX); + lua_pushlightuserdata(L,u); + lua_rawget(L,-2); + if (lua_isfunction(L,-1)) + { + lua_pushvalue(L,1); + lua_call(L,1,0); + lua_pushlightuserdata(L,u); + lua_pushnil(L); + lua_rawset(L,-3); + } + lua_pop(L,2); + return 0; +} +*/ +TOLUA_API int class_gc_event (lua_State* L) +{ + void* u = *((void**)lua_touserdata(L,1)); + int top; + /*fprintf(stderr, "collecting: looking at %p\n", u);*/ + /* + lua_pushstring(L,"tolua_gc"); + lua_rawget(L,LUA_REGISTRYINDEX); + */ + lua_pushvalue(L, lua_upvalueindex(1)); + lua_pushlightuserdata(L,u); + lua_rawget(L,-2); /* stack: gc umt */ + lua_getmetatable(L,1); /* stack: gc umt mt */ + /*fprintf(stderr, "checking type\n");*/ + top = lua_gettop(L); + if (tolua_fast_isa(L,top,top-1, lua_upvalueindex(2))) /* make sure we collect correct type */ + { + /*fprintf(stderr, "Found type!\n");*/ + /* get gc function */ + lua_pushliteral(L,".collector"); + lua_rawget(L,-2); /* stack: gc umt mt collector */ + if (lua_isfunction(L,-1)) { + /*fprintf(stderr, "Found .collector!\n");*/ + } + else { + lua_pop(L,1); + /*fprintf(stderr, "Using default cleanup\n");*/ + lua_pushcfunction(L,tolua_default_collect); + } + + lua_pushvalue(L,1); /* stack: gc umt mt collector u */ + lua_call(L,1,0); + + lua_pushlightuserdata(L,u); /* stack: gc umt mt u */ + lua_pushnil(L); /* stack: gc umt mt u nil */ + lua_rawset(L,-5); /* stack: gc umt mt */ + } + lua_pop(L,3); + return 0; +} + + +/* Register module events + * It expects the metatable on the top of the stack +*/ +TOLUA_API void tolua_moduleevents (lua_State* L) +{ + lua_pushstring(L,"__index"); + lua_pushcfunction(L,module_index_event); + lua_rawset(L,-3); + lua_pushstring(L,"__newindex"); + lua_pushcfunction(L,module_newindex_event); + lua_rawset(L,-3); +} + +/* Check if the object on the top has a module metatable +*/ +TOLUA_API int tolua_ismodulemetatable (lua_State* L) +{ + int r = 0; + if (lua_getmetatable(L,-1)) + { + lua_pushstring(L,"__index"); + lua_rawget(L,-2); + r = (lua_tocfunction(L,-1) == module_index_event); + lua_pop(L,2); + } + return r; +} + +/* Register class events + * It expects the metatable on the top of the stack +*/ +TOLUA_API void tolua_classevents (lua_State* L) +{ + lua_pushstring(L,"__index"); + lua_pushcfunction(L,class_index_event); + lua_rawset(L,-3); + lua_pushstring(L,"__newindex"); + lua_pushcfunction(L,class_newindex_event); + lua_rawset(L,-3); + + lua_pushstring(L,"__add"); + lua_pushcfunction(L,class_add_event); + lua_rawset(L,-3); + lua_pushstring(L,"__sub"); + lua_pushcfunction(L,class_sub_event); + lua_rawset(L,-3); + lua_pushstring(L,"__mul"); + lua_pushcfunction(L,class_mul_event); + lua_rawset(L,-3); + lua_pushstring(L,"__div"); + lua_pushcfunction(L,class_div_event); + lua_rawset(L,-3); + + lua_pushstring(L,"__lt"); + lua_pushcfunction(L,class_lt_event); + lua_rawset(L,-3); + lua_pushstring(L,"__le"); + lua_pushcfunction(L,class_le_event); + lua_rawset(L,-3); + lua_pushstring(L,"__eq"); + lua_pushcfunction(L,class_eq_event); + lua_rawset(L,-3); + + lua_pushstring(L,"__call"); + lua_pushcfunction(L,class_call_event); + lua_rawset(L,-3); + + lua_pushstring(L,"__gc"); + lua_pushstring(L, "tolua_gc_event"); + lua_rawget(L, LUA_REGISTRYINDEX); + /*lua_pushcfunction(L,class_gc_event);*/ + lua_rawset(L,-3); +} + diff --git a/tolua++-1.0.93/src/lib/tolua_event.h b/lib/tolua++/src/lib/tolua_event.h index 898f33dfc..898f33dfc 100644 --- a/tolua++-1.0.93/src/lib/tolua_event.h +++ b/lib/tolua++/src/lib/tolua_event.h diff --git a/lib/tolua++/src/lib/tolua_is.c b/lib/tolua++/src/lib/tolua_is.c new file mode 100644 index 000000000..b470477ff --- /dev/null +++ b/lib/tolua++/src/lib/tolua_is.c @@ -0,0 +1,621 @@ +/* tolua: functions to check types. +** Support code for Lua bindings. +** Written by Waldemar Celes +** TeCGraf/PUC-Rio +** Apr 2003 +** $Id: $ +*/ + +/* This code is free software; you can redistribute it and/or modify it. +** The software provided hereunder is on an "as is" basis, and +** the author has no obligation to provide maintenance, support, updates, +** enhancements, or modifications. +*/ + +#include "../../include/tolua++.h" +#include "../../../lua/src/lauxlib.h" + +#include <stdlib.h> +#include <string.h> + +/* a fast check if a is b, without parameter validation + i.e. if b is equal to a or a superclass of a. */ +TOLUA_API int tolua_fast_isa(lua_State *L, int mt_indexa, int mt_indexb, int super_index) +{ + int result; + if (lua_rawequal(L,mt_indexa,mt_indexb)) + result = 1; + else + { + if (super_index) { + lua_pushvalue(L, super_index); + } else { + lua_pushliteral(L,"tolua_super"); + lua_rawget(L,LUA_REGISTRYINDEX); /* stack: super */ + }; + lua_pushvalue(L,mt_indexa); /* stack: super mta */ + lua_rawget(L,-2); /* stack: super super[mta] */ + lua_pushvalue(L,mt_indexb); /* stack: super super[mta] mtb */ + lua_rawget(L,LUA_REGISTRYINDEX); /* stack: super super[mta] typenameB */ + lua_rawget(L,-2); /* stack: super super[mta] bool */ + result = lua_toboolean(L,-1); + lua_pop(L,3); + } + return result; +} + +/* Push and returns the corresponding object typename */ +TOLUA_API const char* tolua_typename (lua_State* L, int lo) +{ + int tag = lua_type(L,lo); + if (tag == LUA_TNONE) + lua_pushstring(L,"[no object]"); + else if (tag != LUA_TUSERDATA && tag != LUA_TTABLE) + lua_pushstring(L,lua_typename(L,tag)); + else if (tag == LUA_TUSERDATA) + { + if (!lua_getmetatable(L,lo)) + lua_pushstring(L,lua_typename(L,tag)); + else + { + lua_rawget(L,LUA_REGISTRYINDEX); + if (!lua_isstring(L,-1)) + { + lua_pop(L,1); + lua_pushstring(L,"[undefined]"); + } + } + } + else /* is table */ + { + lua_pushvalue(L,lo); + lua_rawget(L,LUA_REGISTRYINDEX); + if (!lua_isstring(L,-1)) + { + lua_pop(L,1); + lua_pushstring(L,"table"); + } + else + { + lua_pushstring(L,"class "); + lua_insert(L,-2); + lua_concat(L,2); + } + } + return lua_tostring(L,-1); +} + +TOLUA_API void tolua_error (lua_State* L, const char* msg, tolua_Error* err) +{ + if (msg[0] == '#') + { + const char* expected = err->type; + const char* provided = tolua_typename(L,err->index); + if (msg[1]=='f') + { + int narg = err->index; + if (err->array) + luaL_error(L,"%s\n argument #%d is array of '%s'; array of '%s' expected.\n", + msg+2,narg,provided,expected); + else + luaL_error(L,"%s\n argument #%d is '%s'; '%s' expected.\n", + msg+2,narg,provided,expected); + } + else if (msg[1]=='v') + { + if (err->array) + luaL_error(L,"%s\n value is array of '%s'; array of '%s' expected.\n", + msg+2,provided,expected); + else + luaL_error(L,"%s\n value is '%s'; '%s' expected.\n", + msg+2,provided,expected); + } + } + else + luaL_error(L,msg); +} + +/* the equivalent of lua_is* for usertable */ +static int lua_isusertable (lua_State* L, int lo, const char* type) +{ + int r = 0; + if (lo < 0) lo = lua_gettop(L)+lo+1; + lua_pushvalue(L,lo); + lua_rawget(L,LUA_REGISTRYINDEX); /* get registry[t] */ + if (lua_isstring(L,-1)) + { + r = strcmp(lua_tostring(L,-1),type)==0; + if (!r) + { + /* try const */ + lua_pushstring(L,"const "); + lua_insert(L,-2); + lua_concat(L,2); + r = lua_isstring(L,-1) && strcmp(lua_tostring(L,-1),type)==0; + } + } + lua_pop(L, 1); + return r; +} + +int push_table_instance(lua_State* L, int lo) { + + if (lua_istable(L, lo)) { + + lua_pushstring(L, ".c_instance"); + lua_gettable(L, lo); + if (lua_isuserdata(L, -1)) { + + lua_replace(L, lo); + return 1; + } else { + + lua_pop(L, 1); + return 0; + }; + } else { + return 0; + }; + + return 0; +}; + +/* the equivalent of lua_is* for usertype */ +static int lua_isusertype (lua_State* L, int lo, const char* type) +{ + if (!lua_isuserdata(L,lo)) { + if (!push_table_instance(L, lo)) { + return 0; + }; + }; + { + /* check if it is of the same type */ + int r; + const char *tn; + if (lua_getmetatable(L,lo)) /* if metatable? */ + { + lua_rawget(L,LUA_REGISTRYINDEX); /* get registry[mt] */ + tn = lua_tostring(L,-1); + r = tn && (strcmp(tn,type) == 0); + lua_pop(L, 1); + if (r) + return 1; + else + { + /* check if it is a specialized class */ + lua_pushstring(L,"tolua_super"); + lua_rawget(L,LUA_REGISTRYINDEX); /* get super */ + lua_getmetatable(L,lo); + lua_rawget(L,-2); /* get super[mt] */ + if (lua_istable(L,-1)) + { + int b; + lua_pushstring(L,type); + lua_rawget(L,-2); /* get super[mt][type] */ + b = lua_toboolean(L,-1); + lua_pop(L,3); + if (b) + return 1; + } + } + } + } + return 0; +} + +TOLUA_API int tolua_isnoobj (lua_State* L, int lo, tolua_Error* err) +{ + if (lua_gettop(L)<abs(lo)) + return 1; + err->index = lo; + err->array = 0; + err->type = "[no object]"; + return 0; +} + +TOLUA_API int tolua_isboolean (lua_State* L, int lo, int def, tolua_Error* err) +{ + if (def && lua_gettop(L)<abs(lo)) + return 1; + if (lua_isnil(L,lo) || lua_isboolean(L,lo)) + return 1; + err->index = lo; + err->array = 0; + err->type = "boolean"; + return 0; +} + +TOLUA_API int tolua_isnumber (lua_State* L, int lo, int def, tolua_Error* err) +{ + if (def && lua_gettop(L)<abs(lo)) + return 1; + if (lua_isnumber(L,lo)) + return 1; + err->index = lo; + err->array = 0; + err->type = "number"; + return 0; +} + +TOLUA_API int tolua_isstring (lua_State* L, int lo, int def, tolua_Error* err) +{ + if (def && lua_gettop(L)<abs(lo)) + return 1; + if (lua_isnil(L,lo) || lua_isstring(L,lo)) + return 1; + err->index = lo; + err->array = 0; + err->type = "string"; + return 0; +} + +TOLUA_API int tolua_istable (lua_State* L, int lo, int def, tolua_Error* err) +{ + if (def && lua_gettop(L)<abs(lo)) + return 1; + if (lua_istable(L,lo)) + return 1; + err->index = lo; + err->array = 0; + err->type = "table"; + return 0; +} + +TOLUA_API int tolua_isusertable (lua_State* L, int lo, const char* type, int def, tolua_Error* err) +{ + if (def && lua_gettop(L)<abs(lo)) + return 1; + if (lua_isusertable(L,lo,type)) + return 1; + err->index = lo; + err->array = 0; + err->type = type; + return 0; +} + + +TOLUA_API int tolua_isuserdata (lua_State* L, int lo, int def, tolua_Error* err) +{ + if (def && lua_gettop(L)<abs(lo)) + return 1; + if (lua_isnil(L,lo) || lua_isuserdata(L,lo)) + return 1; + err->index = lo; + err->array = 0; + err->type = "userdata"; + return 0; +} + +TOLUA_API int tolua_isvaluenil (lua_State* L, int lo, tolua_Error* err) { + + if (lua_gettop(L)<abs(lo)) + return 0; /* somebody else should chack this */ + if (!lua_isnil(L, lo)) + return 0; + + err->index = lo; + err->array = 0; + err->type = "value"; + return 1; +}; + +TOLUA_API int tolua_isvalue (lua_State* L, int lo, int def, tolua_Error* err) +{ + if (def || abs(lo)<=lua_gettop(L)) /* any valid index */ + return 1; + err->index = lo; + err->array = 0; + err->type = "value"; + return 0; +} + +TOLUA_API int tolua_isusertype (lua_State* L, int lo, const char* type, int def, tolua_Error* err) +{ + if (def && lua_gettop(L)<abs(lo)) + return 1; + if (lua_isnil(L,lo) || lua_isusertype(L,lo,type)) + return 1; + err->index = lo; + err->array = 0; + err->type = type; + return 0; +} + +TOLUA_API int tolua_isvaluearray + (lua_State* L, int lo, int dim, int def, tolua_Error* err) +{ + if (!tolua_istable(L,lo,def,err)) + return 0; + else + return 1; +} + +TOLUA_API int tolua_isbooleanarray + (lua_State* L, int lo, int dim, int def, tolua_Error* err) +{ + if (!tolua_istable(L,lo,def,err)) + return 0; + else + { + int i; + for (i=1; i<=dim; ++i) + { + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!(lua_isnil(L,-1) || lua_isboolean(L,-1)) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "boolean"; + return 0; + } + lua_pop(L,1); + } + } + return 1; +} + +TOLUA_API int tolua_isnumberarray + (lua_State* L, int lo, int dim, int def, tolua_Error* err) +{ + if (!tolua_istable(L,lo,def,err)) + return 0; + else + { + int i; + for (i=1; i<=dim; ++i) + { + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!lua_isnumber(L,-1) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "number"; + return 0; + } + lua_pop(L,1); + } + } + return 1; +} + +TOLUA_API int tolua_isstringarray + (lua_State* L, int lo, int dim, int def, tolua_Error* err) +{ + if (!tolua_istable(L,lo,def,err)) + return 0; + else + { + int i; + for (i=1; i<=dim; ++i) + { + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!(lua_isnil(L,-1) || lua_isstring(L,-1)) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "string"; + return 0; + } + lua_pop(L,1); + } + } + return 1; +} + +TOLUA_API int tolua_istablearray + (lua_State* L, int lo, int dim, int def, tolua_Error* err) +{ + if (!tolua_istable(L,lo,def,err)) + return 0; + else + { + int i; + for (i=1; i<=dim; ++i) + { + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (! lua_istable(L,-1) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "table"; + return 0; + } + lua_pop(L,1); + } + } + return 1; +} + +TOLUA_API int tolua_isuserdataarray + (lua_State* L, int lo, int dim, int def, tolua_Error* err) +{ + if (!tolua_istable(L,lo,def,err)) + return 0; + else + { + int i; + for (i=1; i<=dim; ++i) + { + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!(lua_isnil(L,-1) || lua_isuserdata(L,-1)) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "userdata"; + return 0; + } + lua_pop(L,1); + } + } + return 1; +} + +TOLUA_API int tolua_isusertypearray + (lua_State* L, int lo, const char* type, int dim, int def, tolua_Error* err) +{ + if (!tolua_istable(L,lo,def,err)) + return 0; + else + { + int i; + for (i=1; i<=dim; ++i) + { + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!(lua_isnil(L,-1) || lua_isuserdata(L,-1)) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->type = type; + err->array = 1; + return 0; + } + lua_pop(L,1); + } + } + return 1; +} + +#if 0 +int tolua_isbooleanfield + (lua_State* L, int lo, int i, int def, tolua_Error* err) +{ + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!(lua_isnil(L,-1) || lua_isboolean(L,-1)) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "boolean"; + return 0; + } + lua_pop(L,1); + return 1; +} + +int tolua_isnumberfield + (lua_State* L, int lo, int i, int def, tolua_Error* err) +{ + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!lua_isnumber(L,-1) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "number"; + return 0; + } + lua_pop(L,1); + return 1; +} + +int tolua_isstringfield + (lua_State* L, int lo, int i, int def, tolua_Error* err) +{ + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!(lua_isnil(L,-1) || lua_isstring(L,-1)) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "string"; + return 0; + } + lua_pop(L,1); + return 1; +} + +int tolua_istablefield + (lua_State* L, int lo, int i, int def, tolua_Error* err) +{ + lua_pushnumber(L,i+1); + lua_gettable(L,lo); + if (! lua_istable(L,-1) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "table"; + return 0; + } + lua_pop(L,1); +} + +int tolua_isusertablefield + (lua_State* L, int lo, const char* type, int i, int def, tolua_Error* err) +{ + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (! lua_isusertable(L,-1,type) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = type; + return 0; + } + lua_pop(L,1); + return 1; +} + +int tolua_isuserdatafield + (lua_State* L, int lo, int i, int def, tolua_Error* err) +{ + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!(lua_isnil(L,-1) || lua_isuserdata(L,-1)) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->array = 1; + err->type = "userdata"; + return 0; + } + lua_pop(L,1); + return 1; +} + +int tolua_isusertypefield + (lua_State* L, int lo, const char* type, int i, int def, tolua_Error* err) +{ + lua_pushnumber(L,i); + lua_gettable(L,lo); + if (!(lua_isnil(L,-1) || lua_isusertype(L,-1,type)) && + !(def && lua_isnil(L,-1)) + ) + { + err->index = lo; + err->type = type; + err->array = 1; + return 0; + } + lua_pop(L,1); + return 1; +} + +#endif diff --git a/lib/tolua++/src/lib/tolua_map.c b/lib/tolua++/src/lib/tolua_map.c new file mode 100644 index 000000000..7c4a22336 --- /dev/null +++ b/lib/tolua++/src/lib/tolua_map.c @@ -0,0 +1,704 @@ +/* tolua: functions to map features +** Support code for Lua bindings. +** Written by Waldemar Celes +** TeCGraf/PUC-Rio +** Apr 2003 +** $Id: $ +*/ + +/* This code is free software; you can redistribute it and/or modify it. +** The software provided hereunder is on an "as is" basis, and +** the author has no obligation to provide maintenance, support, updates, +** enhancements, or modifications. +*/ + +#include "../../include/tolua++.h" +#include "../../../lua/src/lauxlib.h" +#include "tolua_event.h" + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + + +/* Create metatable + * Create and register new metatable +*/ +static int tolua_newmetatable (lua_State* L, char* name) +{ + int r = luaL_newmetatable(L,name); + + #ifdef LUA_VERSION_NUM /* only lua 5.1 */ + if (r) { + lua_pushvalue(L, -1); + lua_pushstring(L, name); + lua_settable(L, LUA_REGISTRYINDEX); /* reg[mt] = type_name */ + }; + #endif + + if (r) + tolua_classevents(L); /* set meta events */ + lua_pop(L,1); + return r; +} + +/* Map super classes + * It sets 'name' as being also a 'base', mapping all super classes of 'base' in 'name' +*/ +static void mapsuper (lua_State* L, const char* name, const char* base) +{ + /* push registry.super */ + lua_pushstring(L,"tolua_super"); + lua_rawget(L,LUA_REGISTRYINDEX); /* stack: super */ + luaL_getmetatable(L,name); /* stack: super mt */ + lua_rawget(L,-2); /* stack: super table */ + if (lua_isnil(L,-1)) + { + /* create table */ + lua_pop(L,1); + lua_newtable(L); /* stack: super table */ + luaL_getmetatable(L,name); /* stack: super table mt */ + lua_pushvalue(L,-2); /* stack: super table mt table */ + lua_rawset(L,-4); /* stack: super table */ + } + + /* set base as super class */ + lua_pushstring(L,base); + lua_pushboolean(L,1); + lua_rawset(L,-3); /* stack: super table */ + + /* set all super class of base as super class of name */ + luaL_getmetatable(L,base); /* stack: super table base_mt */ + lua_rawget(L,-3); /* stack: super table base_table */ + if (lua_istable(L,-1)) + { + /* traverse base table */ + lua_pushnil(L); /* first key */ + while (lua_next(L,-2) != 0) + { + /* stack: ... base_table key value */ + lua_pushvalue(L,-2); /* stack: ... base_table key value key */ + lua_insert(L,-2); /* stack: ... base_table key key value */ + lua_rawset(L,-5); /* stack: ... base_table key */ + } + } + lua_pop(L,3); /* stack: <empty> */ +} + +/* creates a 'tolua_ubox' table for base clases, and +// expects the metatable and base metatable on the stack */ +static void set_ubox(lua_State* L) { + + /* mt basemt */ + if (!lua_isnil(L, -1)) { + lua_pushstring(L, "tolua_ubox"); + lua_rawget(L,-2); + } else { + lua_pushnil(L); + }; + /* mt basemt base_ubox */ + if (!lua_isnil(L,-1)) { + lua_pushstring(L, "tolua_ubox"); + lua_insert(L, -2); + /* mt basemt key ubox */ + lua_rawset(L,-4); + /* (mt with ubox) basemt */ + } else { + /* mt basemt nil */ + lua_pop(L, 1); + lua_pushstring(L,"tolua_ubox"); lua_newtable(L); + /* make weak value metatable for ubox table to allow userdata to be + garbage-collected */ + lua_newtable(L); lua_pushliteral(L, "__mode"); lua_pushliteral(L, "v"); lua_rawset(L, -3); /* stack: string ubox mt */ + lua_setmetatable(L, -2); /* stack:mt basemt string ubox */ + lua_rawset(L,-4); + }; + +}; + +/* Map inheritance + * It sets 'name' as derived from 'base' by setting 'base' as metatable of 'name' +*/ +static void mapinheritance (lua_State* L, const char* name, const char* base) +{ + /* set metatable inheritance */ + luaL_getmetatable(L,name); + + if (base && *base) + luaL_getmetatable(L,base); + else { + + if (lua_getmetatable(L, -1)) { /* already has a mt, we don't overwrite it */ + lua_pop(L, 2); + return; + }; + luaL_getmetatable(L,"tolua_commonclass"); + }; + + set_ubox(L); + + lua_setmetatable(L,-2); + lua_pop(L,1); +} + +/* Object type +*/ +static int tolua_bnd_type (lua_State* L) +{ + tolua_typename(L,lua_gettop(L)); + return 1; +} + +/* Take ownership +*/ +static int tolua_bnd_takeownership (lua_State* L) +{ + int success = 0; + if (lua_isuserdata(L,1)) + { + if (lua_getmetatable(L,1)) /* if metatable? */ + { + lua_pop(L,1); /* clear metatable off stack */ + /* force garbage collection to avoid C to reuse a to-be-collected address */ + #ifdef LUA_VERSION_NUM + lua_gc(L, LUA_GCCOLLECT, 0); + #else + lua_setgcthreshold(L,0); + #endif + + success = tolua_register_gc(L,1); + } + } + lua_pushboolean(L,success!=0); + return 1; +} + +/* Release ownership +*/ +static int tolua_bnd_releaseownership (lua_State* L) +{ + int done = 0; + if (lua_isuserdata(L,1)) + { + void* u = *((void**)lua_touserdata(L,1)); + /* force garbage collection to avoid releasing a to-be-collected address */ + #ifdef LUA_VERSION_NUM + lua_gc(L, LUA_GCCOLLECT, 0); + #else + lua_setgcthreshold(L,0); + #endif + lua_pushstring(L,"tolua_gc"); + lua_rawget(L,LUA_REGISTRYINDEX); + lua_pushlightuserdata(L,u); + lua_rawget(L,-2); + lua_getmetatable(L,1); + if (lua_rawequal(L,-1,-2)) /* check that we are releasing the correct type */ + { + lua_pushlightuserdata(L,u); + lua_pushnil(L); + lua_rawset(L,-5); + done = 1; + } + } + lua_pushboolean(L,done!=0); + return 1; +} + +/* Type casting +*/ +static int tolua_bnd_cast (lua_State* L) +{ + +/* // old code + void* v = tolua_tousertype(L,1,NULL); + const char* s = tolua_tostring(L,2,NULL); + if (v && s) + tolua_pushusertype(L,v,s); + else + lua_pushnil(L); + return 1; +*/ + + void* v; + const char* s; + if (lua_islightuserdata(L, 1)) { + v = tolua_touserdata(L, 1, NULL); + } else { + v = tolua_tousertype(L, 1, 0); + }; + + s = tolua_tostring(L,2,NULL); + if (v && s) + tolua_pushusertype(L,v,s); + else + lua_pushnil(L); + return 1; +} + +/* Inheritance +*/ +static int tolua_bnd_inherit (lua_State* L) { + + /* stack: lua object, c object */ + lua_pushstring(L, ".c_instance"); + lua_pushvalue(L, -2); + lua_rawset(L, -4); + /* l_obj[".c_instance"] = c_obj */ + + return 0; +}; + +#ifdef LUA_VERSION_NUM /* lua 5.1 */ +static int tolua_bnd_setpeer(lua_State* L) { + + /* stack: userdata, table */ + if (!lua_isuserdata(L, -2)) { + lua_pushstring(L, "Invalid argument #1 to setpeer: userdata expected."); + lua_error(L); + }; + + if (lua_isnil(L, -1)) { + + lua_pop(L, 1); + lua_pushvalue(L, TOLUA_NOPEER); + }; + lua_setfenv(L, -2); + + return 0; +}; + +static int tolua_bnd_getpeer(lua_State* L) { + + /* stack: userdata */ + lua_getfenv(L, -1); + if (lua_rawequal(L, -1, TOLUA_NOPEER)) { + lua_pop(L, 1); + lua_pushnil(L); + }; + return 1; +}; +#endif + +/* static int class_gc_event (lua_State* L); */ + +TOLUA_API void tolua_open (lua_State* L) +{ + int top = lua_gettop(L); + lua_pushstring(L,"tolua_opened"); + lua_rawget(L,LUA_REGISTRYINDEX); + if (!lua_isboolean(L,-1)) + { + lua_pushstring(L,"tolua_opened"); lua_pushboolean(L,1); lua_rawset(L,LUA_REGISTRYINDEX); + + #ifndef LUA_VERSION_NUM /* only prior to lua 5.1 */ + /* create peer object table */ + lua_pushstring(L, "tolua_peers"); lua_newtable(L); + /* make weak key metatable for peers indexed by userdata object */ + lua_newtable(L); lua_pushliteral(L, "__mode"); lua_pushliteral(L, "k"); lua_rawset(L, -3); /* stack: string peers mt */ + lua_setmetatable(L, -2); /* stack: string peers */ + lua_rawset(L,LUA_REGISTRYINDEX); + #endif + + /* create object ptr -> udata mapping table */ + lua_pushstring(L,"tolua_ubox"); lua_newtable(L); + /* make weak value metatable for ubox table to allow userdata to be + garbage-collected */ + lua_newtable(L); lua_pushliteral(L, "__mode"); lua_pushliteral(L, "v"); lua_rawset(L, -3); /* stack: string ubox mt */ + lua_setmetatable(L, -2); /* stack: string ubox */ + lua_rawset(L,LUA_REGISTRYINDEX); + + lua_pushstring(L,"tolua_super"); lua_newtable(L); lua_rawset(L,LUA_REGISTRYINDEX); + lua_pushstring(L,"tolua_gc"); lua_newtable(L);lua_rawset(L,LUA_REGISTRYINDEX); + + /* create gc_event closure */ + lua_pushstring(L, "tolua_gc_event"); + lua_pushstring(L, "tolua_gc"); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushstring(L, "tolua_super"); + lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushcclosure(L, class_gc_event, 2); + lua_rawset(L, LUA_REGISTRYINDEX); + + tolua_newmetatable(L,"tolua_commonclass"); + + tolua_module(L,NULL,0); + tolua_beginmodule(L,NULL); + tolua_module(L,"tolua",0); + tolua_beginmodule(L,"tolua"); + tolua_function(L,"type",tolua_bnd_type); + tolua_function(L,"takeownership",tolua_bnd_takeownership); + tolua_function(L,"releaseownership",tolua_bnd_releaseownership); + tolua_function(L,"cast",tolua_bnd_cast); + tolua_function(L,"inherit", tolua_bnd_inherit); + #ifdef LUA_VERSION_NUM /* lua 5.1 */ + tolua_function(L, "setpeer", tolua_bnd_setpeer); + tolua_function(L, "getpeer", tolua_bnd_getpeer); + #endif + + tolua_endmodule(L); + tolua_endmodule(L); + } + lua_settop(L,top); +} + +/* Copy a C object +*/ +TOLUA_API void* tolua_copy (lua_State* L, void* value, unsigned int size) +{ + void* clone = (void*)malloc(size); + if (clone) + memcpy(clone,value,size); + else + tolua_error(L,"insuficient memory",NULL); + return clone; +} + +/* Default collect function +*/ +TOLUA_API int tolua_default_collect (lua_State* tolua_S) +{ + void* self = tolua_tousertype(tolua_S,1,0); + free(self); + return 0; +} + +/* Do clone +*/ +TOLUA_API int tolua_register_gc (lua_State* L, int lo) +{ + int success = 1; + void *value = *(void **)lua_touserdata(L,lo); + lua_pushstring(L,"tolua_gc"); + lua_rawget(L,LUA_REGISTRYINDEX); + lua_pushlightuserdata(L,value); + lua_rawget(L,-2); + if (!lua_isnil(L,-1)) /* make sure that object is not already owned */ + success = 0; + else + { + lua_pushlightuserdata(L,value); + lua_getmetatable(L,lo); + lua_rawset(L,-4); + } + lua_pop(L,2); + return success; +} + +/* Register a usertype + * It creates the correspoding metatable in the registry, for both 'type' and 'const type'. + * It maps 'const type' as being also a 'type' +*/ +TOLUA_API void tolua_usertype (lua_State* L, const char* type) +{ + char ctype[128] = "const "; + strncat(ctype,type,120); + + /* create both metatables */ + if (tolua_newmetatable(L,ctype) && tolua_newmetatable(L,type)) + mapsuper(L,type,ctype); /* 'type' is also a 'const type' */ +} + + +/* Begin module + * It pushes the module (or class) table on the stack +*/ +TOLUA_API void tolua_beginmodule (lua_State* L, const char* name) +{ + if (name) + { + lua_pushstring(L,name); + lua_rawget(L,-2); + } + else + lua_pushvalue(L,LUA_GLOBALSINDEX); +} + +/* End module + * It pops the module (or class) from the stack +*/ +TOLUA_API void tolua_endmodule (lua_State* L) +{ + lua_pop(L,1); +} + +/* Map module + * It creates a new module +*/ +#if 1 +TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar) +{ + if (name) + { + /* tolua module */ + lua_pushstring(L,name); + lua_rawget(L,-2); + if (!lua_istable(L,-1)) /* check if module already exists */ + { + lua_pop(L,1); + lua_newtable(L); + lua_pushstring(L,name); + lua_pushvalue(L,-2); + lua_rawset(L,-4); /* assing module into module */ + } + } + else + { + /* global table */ + lua_pushvalue(L,LUA_GLOBALSINDEX); + } + if (hasvar) + { + if (!tolua_ismodulemetatable(L)) /* check if it already has a module metatable */ + { + /* create metatable to get/set C/C++ variable */ + lua_newtable(L); + tolua_moduleevents(L); + if (lua_getmetatable(L,-2)) + lua_setmetatable(L,-2); /* set old metatable as metatable of metatable */ + lua_setmetatable(L,-2); + } + } + lua_pop(L,1); /* pop module */ +} +#else +TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar) +{ + if (name) + { + /* tolua module */ + lua_pushstring(L,name); + lua_newtable(L); + } + else + { + /* global table */ + lua_pushvalue(L,LUA_GLOBALSINDEX); + } + if (hasvar) + { + /* create metatable to get/set C/C++ variable */ + lua_newtable(L); + tolua_moduleevents(L); + if (lua_getmetatable(L,-2)) + lua_setmetatable(L,-2); /* set old metatable as metatable of metatable */ + lua_setmetatable(L,-2); + } + if (name) + lua_rawset(L,-3); /* assing module into module */ + else + lua_pop(L,1); /* pop global table */ +} +#endif + +static void push_collector(lua_State* L, const char* type, lua_CFunction col) { + + /* push collector function, but only if it's not NULL, or if there's no + collector already */ + if (!col) return; + luaL_getmetatable(L,type); + lua_pushstring(L,".collector"); + /* + if (!col) { + lua_pushvalue(L, -1); + lua_rawget(L, -3); + if (!lua_isnil(L, -1)) { + lua_pop(L, 3); + return; + }; + lua_pop(L, 1); + }; + // */ + lua_pushcfunction(L,col); + + lua_rawset(L,-3); + lua_pop(L, 1); +}; + +/* Map C class + * It maps a C class, setting the appropriate inheritance and super classes. +*/ +TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col) +{ + char cname[128] = "const "; + char cbase[128] = "const "; + strncat(cname,name,120); + strncat(cbase,base,120); + + mapinheritance(L,name,base); + mapinheritance(L,cname,name); + + mapsuper(L,cname,cbase); + mapsuper(L,name,base); + + lua_pushstring(L,lname); + + push_collector(L, name, col); + /* + luaL_getmetatable(L,name); + lua_pushstring(L,".collector"); + lua_pushcfunction(L,col); + + lua_rawset(L,-3); + */ + + luaL_getmetatable(L,name); + lua_rawset(L,-3); /* assign class metatable to module */ + + /* now we also need to store the collector table for the const + instances of the class */ + push_collector(L, cname, col); + /* + luaL_getmetatable(L,cname); + lua_pushstring(L,".collector"); + lua_pushcfunction(L,col); + lua_rawset(L,-3); + lua_pop(L,1); + */ + + +} + +/* Add base + * It adds additional base classes to a class (for multiple inheritance) + * (not for now) +TOLUA_API void tolua_addbase(lua_State* L, char* name, char* base) { + + char cname[128] = "const "; + char cbase[128] = "const "; + strncat(cname,name,120); + strncat(cbase,base,120); + + mapsuper(L,cname,cbase); + mapsuper(L,name,base); +}; +*/ + +/* Map function + * It assigns a function into the current module (or class) +*/ +TOLUA_API void tolua_function (lua_State* L, const char* name, lua_CFunction func) +{ + lua_pushstring(L,name); + lua_pushcfunction(L,func); + lua_rawset(L,-3); +} + +/* sets the __call event for the class (expects the class' main table on top) */ +/* never really worked :( +TOLUA_API void tolua_set_call_event(lua_State* L, lua_CFunction func, char* type) { + + lua_getmetatable(L, -1); + //luaL_getmetatable(L, type); + lua_pushstring(L,"__call"); + lua_pushcfunction(L,func); + lua_rawset(L,-3); + lua_pop(L, 1); +}; +*/ + +/* Map constant number + * It assigns a constant number into the current module (or class) +*/ +TOLUA_API void tolua_constant (lua_State* L, const char* name, lua_Number value) +{ + lua_pushstring(L,name); + tolua_pushnumber(L,value); + lua_rawset(L,-3); +} + + +/* Map variable + * It assigns a variable into the current module (or class) +*/ +TOLUA_API void tolua_variable (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set) +{ + /* get func */ + lua_pushstring(L,".get"); + lua_rawget(L,-2); + if (!lua_istable(L,-1)) + { + /* create .get table, leaving it at the top */ + lua_pop(L,1); + lua_newtable(L); + lua_pushstring(L,".get"); + lua_pushvalue(L,-2); + lua_rawset(L,-4); + } + lua_pushstring(L,name); + lua_pushcfunction(L,get); + lua_rawset(L,-3); /* store variable */ + lua_pop(L,1); /* pop .get table */ + + /* set func */ + if (set) + { + lua_pushstring(L,".set"); + lua_rawget(L,-2); + if (!lua_istable(L,-1)) + { + /* create .set table, leaving it at the top */ + lua_pop(L,1); + lua_newtable(L); + lua_pushstring(L,".set"); + lua_pushvalue(L,-2); + lua_rawset(L,-4); + } + lua_pushstring(L,name); + lua_pushcfunction(L,set); + lua_rawset(L,-3); /* store variable */ + lua_pop(L,1); /* pop .set table */ + } +} + +/* Access const array + * It reports an error when trying to write into a const array +*/ +static int const_array (lua_State* L) +{ + luaL_error(L,"value of const array cannot be changed"); + return 0; +} + +/* Map an array + * It assigns an array into the current module (or class) +*/ +TOLUA_API void tolua_array (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set) +{ + lua_pushstring(L,".get"); + lua_rawget(L,-2); + if (!lua_istable(L,-1)) + { + /* create .get table, leaving it at the top */ + lua_pop(L,1); + lua_newtable(L); + lua_pushstring(L,".get"); + lua_pushvalue(L,-2); + lua_rawset(L,-4); + } + lua_pushstring(L,name); + + lua_newtable(L); /* create array metatable */ + lua_pushvalue(L,-1); + lua_setmetatable(L,-2); /* set the own table as metatable (for modules) */ + lua_pushstring(L,"__index"); + lua_pushcfunction(L,get); + lua_rawset(L,-3); + lua_pushstring(L,"__newindex"); + lua_pushcfunction(L,set?set:const_array); + lua_rawset(L,-3); + + lua_rawset(L,-3); /* store variable */ + lua_pop(L,1); /* pop .get table */ +} + + +TOLUA_API void tolua_dobuffer(lua_State* L, char* B, unsigned int size, const char* name) { + + #ifdef LUA_VERSION_NUM /* lua 5.1 */ + luaL_loadbuffer(L, B, size, name) || lua_pcall(L, 0, 0, 0); + #else + lua_dobuffer(L, B, size, name); + #endif +}; + diff --git a/lib/tolua++/src/lib/tolua_push.c b/lib/tolua++/src/lib/tolua_push.c new file mode 100644 index 000000000..947f0e7a5 --- /dev/null +++ b/lib/tolua++/src/lib/tolua_push.c @@ -0,0 +1,171 @@ +/* tolua: functions to push C values. +** Support code for Lua bindings. +** Written by Waldemar Celes +** TeCGraf/PUC-Rio +** Apr 2003 +** $Id: $ +*/ + +/* This code is free software; you can redistribute it and/or modify it. +** The software provided hereunder is on an "as is" basis, and +** the author has no obligation to provide maintenance, support, updates, +** enhancements, or modifications. +*/ + +#include "../../include/tolua++.h" +#include "../../../lua/src/lauxlib.h" + +#include <stdlib.h> + +TOLUA_API void tolua_pushvalue (lua_State* L, int lo) +{ + lua_pushvalue(L,lo); +} + +TOLUA_API void tolua_pushboolean (lua_State* L, int value) +{ + lua_pushboolean(L,value); +} + +TOLUA_API void tolua_pushnumber (lua_State* L, lua_Number value) +{ + lua_pushnumber(L,value); +} + +TOLUA_API void tolua_pushstring (lua_State* L, const char* value) +{ + if (value == NULL) + lua_pushnil(L); + else + lua_pushstring(L,value); +} + +TOLUA_API void tolua_pushuserdata (lua_State* L, void* value) +{ + if (value == NULL) + lua_pushnil(L); + else + lua_pushlightuserdata(L,value); +} + +TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type) +{ + if (value == NULL) + lua_pushnil(L); + else + { + luaL_getmetatable(L, type); + lua_pushstring(L,"tolua_ubox"); + lua_rawget(L,-2); /* stack: mt ubox */ + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + lua_pushstring(L, "tolua_ubox"); + lua_rawget(L, LUA_REGISTRYINDEX); + }; + lua_pushlightuserdata(L,value); + lua_rawget(L,-2); /* stack: mt ubox ubox[u] */ + if (lua_isnil(L,-1)) + { + lua_pop(L,1); /* stack: mt ubox */ + lua_pushlightuserdata(L,value); + *(void**)lua_newuserdata(L,sizeof(void *)) = value; /* stack: mt ubox u newud */ + lua_pushvalue(L,-1); /* stack: mt ubox u newud newud */ + lua_insert(L,-4); /* stack: mt newud ubox u newud */ + lua_rawset(L,-3); /* stack: mt newud ubox */ + lua_pop(L,1); /* stack: mt newud */ + /*luaL_getmetatable(L,type);*/ + lua_pushvalue(L, -2); /* stack: mt newud mt */ + lua_setmetatable(L,-2); /* stack: mt newud */ + + #ifdef LUA_VERSION_NUM + lua_pushvalue(L, TOLUA_NOPEER); + lua_setfenv(L, -2); + #endif + } + else + { + /* check the need of updating the metatable to a more specialized class */ + lua_insert(L,-2); /* stack: mt ubox[u] ubox */ + lua_pop(L,1); /* stack: mt ubox[u] */ + lua_pushstring(L,"tolua_super"); + lua_rawget(L,LUA_REGISTRYINDEX); /* stack: mt ubox[u] super */ + lua_getmetatable(L,-2); /* stack: mt ubox[u] super mt */ + lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] */ + if (lua_istable(L,-1)) + { + lua_pushstring(L,type); /* stack: mt ubox[u] super super[mt] type */ + lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] flag */ + if (lua_toboolean(L,-1) == 1) /* if true */ + { + lua_pop(L,3); /* mt ubox[u]*/ + lua_remove(L, -2); + return; + } + } + /* type represents a more specilized type */ + /*luaL_getmetatable(L,type); // stack: mt ubox[u] super super[mt] flag mt */ + lua_pushvalue(L, -5); /* stack: mt ubox[u] super super[mt] flag mt */ + lua_setmetatable(L,-5); /* stack: mt ubox[u] super super[mt] flag */ + lua_pop(L,3); /* stack: mt ubox[u] */ + } + lua_remove(L, -2); /* stack: ubox[u]*/ + } +} + +TOLUA_API void tolua_pushusertype_and_takeownership (lua_State* L, void* value, const char* type) +{ + tolua_pushusertype(L,value,type); + tolua_register_gc(L,lua_gettop(L)); +} + +TOLUA_API void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v) +{ + lua_pushnumber(L,index); + lua_pushvalue(L,v); + lua_settable(L,lo); +} + +TOLUA_API void tolua_pushfieldboolean (lua_State* L, int lo, int index, int v) +{ + lua_pushnumber(L,index); + lua_pushboolean(L,v); + lua_settable(L,lo); +} + + +TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, lua_Number v) +{ + lua_pushnumber(L,index); + tolua_pushnumber(L,v); + lua_settable(L,lo); +} + +TOLUA_API void tolua_pushfieldstring (lua_State* L, int lo, int index, const char* v) +{ + lua_pushnumber(L,index); + tolua_pushstring(L,v); + lua_settable(L,lo); +} + +TOLUA_API void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v) +{ + lua_pushnumber(L,index); + tolua_pushuserdata(L,v); + lua_settable(L,lo); +} + +TOLUA_API void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, const char* type) +{ + lua_pushnumber(L,index); + tolua_pushusertype(L,v,type); + lua_settable(L,lo); +} + +TOLUA_API void tolua_pushfieldusertype_and_takeownership (lua_State* L, int lo, int index, void* v, const char* type) +{ + lua_pushnumber(L,index); + tolua_pushusertype(L,v,type); + tolua_register_gc(L,lua_gettop(L)); + lua_settable(L,lo); +} + diff --git a/lib/tolua++/src/lib/tolua_to.c b/lib/tolua++/src/lib/tolua_to.c new file mode 100644 index 000000000..04132e901 --- /dev/null +++ b/lib/tolua++/src/lib/tolua_to.c @@ -0,0 +1,133 @@ +/* tolua: funcitons to convert to C types +** Support code for Lua bindings. +** Written by Waldemar Celes +** TeCGraf/PUC-Rio +** Apr 2003 +** $Id: $ +*/ + +/* This code is free software; you can redistribute it and/or modify it. +** The software provided hereunder is on an "as is" basis, and +** the author has no obligation to provide maintenance, support, updates, +** enhancements, or modifications. +*/ + +#include "../../include/tolua++.h" + +#include <string.h> +#include <stdlib.h> + +TOLUA_API lua_Number tolua_tonumber (lua_State* L, int narg, lua_Number def) +{ + return lua_gettop(L)<abs(narg) ? def : lua_tonumber(L,narg); +} + +TOLUA_API const char* tolua_tostring (lua_State* L, int narg, const char* def) +{ + return lua_gettop(L)<abs(narg) ? def : lua_tostring(L,narg); +} + +TOLUA_API void* tolua_touserdata (lua_State* L, int narg, void* def) +{ + + /* return lua_gettop(L)<abs(narg) ? def : lua_touserdata(L,narg); */ + + if (lua_gettop(L)<abs(narg)) { + return def; + }; + + if (lua_islightuserdata(L, narg)) { + + return lua_touserdata(L,narg); + }; + + return tolua_tousertype(L, narg, def); +} + +extern int push_table_instance(lua_State* L, int lo); + +TOLUA_API void* tolua_tousertype (lua_State* L, int narg, void* def) +{ + if (lua_gettop(L)<abs(narg)) + return def; + else + { + void* u; + if (!lua_isuserdata(L, narg)) { + if (!push_table_instance(L, narg)) return NULL; + }; + u = lua_touserdata(L,narg); + return (u==NULL) ? NULL : *((void**)u); /* nil represents NULL */ + } +} + +TOLUA_API int tolua_tovalue (lua_State* L, int narg, int def) +{ + return lua_gettop(L)<abs(narg) ? def : narg; +} + +TOLUA_API int tolua_toboolean (lua_State* L, int narg, int def) +{ + return lua_gettop(L)<abs(narg) ? def : lua_toboolean(L,narg); +} + +TOLUA_API lua_Number tolua_tofieldnumber (lua_State* L, int lo, int index, lua_Number def) +{ + double v; + lua_pushnumber(L,index); + lua_gettable(L,lo); + v = lua_isnil(L,-1) ? def : lua_tonumber(L,-1); + lua_pop(L,1); + return v; +} + +TOLUA_API const char* tolua_tofieldstring +(lua_State* L, int lo, int index, const char* def) +{ + const char* v; + lua_pushnumber(L,index); + lua_gettable(L,lo); + v = lua_isnil(L,-1) ? def : lua_tostring(L,-1); + lua_pop(L,1); + return v; +} + +TOLUA_API void* tolua_tofielduserdata (lua_State* L, int lo, int index, void* def) +{ + void* v; + lua_pushnumber(L,index); + lua_gettable(L,lo); + v = lua_isnil(L,-1) ? def : lua_touserdata(L,-1); + lua_pop(L,1); + return v; +} + +TOLUA_API void* tolua_tofieldusertype (lua_State* L, int lo, int index, void* def) +{ + void* v; + lua_pushnumber(L,index); + lua_gettable(L,lo); + v = lua_isnil(L,-1) ? def : (*(void **)(lua_touserdata(L, -1))); /* lua_unboxpointer(L,-1); */ + lua_pop(L,1); + return v; +} + +TOLUA_API int tolua_tofieldvalue (lua_State* L, int lo, int index, int def) +{ + int v; + lua_pushnumber(L,index); + lua_gettable(L,lo); + v = lua_isnil(L,-1) ? def : lo; + lua_pop(L,1); + return v; +} + +TOLUA_API int tolua_getfieldboolean (lua_State* L, int lo, int index, int def) +{ + int v; + lua_pushnumber(L,index); + lua_gettable(L,lo); + v = lua_isnil(L,-1) ? 0 : lua_toboolean(L,-1); + lua_pop(L,1); + return v; +} diff --git a/tolua++-1.0.93/win32/tolualib/tolualib.vcproj b/lib/tolua++/win32/tolualib/tolualib.vcproj index 598b2d6fe..598b2d6fe 100644 --- a/tolua++-1.0.93/win32/tolualib/tolualib.vcproj +++ b/lib/tolua++/win32/tolualib/tolualib.vcproj diff --git a/tolua++-1.0.93/win32/tolualib/tolualib.vcproj.LAPTOPF.Kevin.user b/lib/tolua++/win32/tolualib/tolualib.vcproj.LAPTOPF.Kevin.user index eaf548aa5..eaf548aa5 100644 --- a/tolua++-1.0.93/win32/tolualib/tolualib.vcproj.LAPTOPF.Kevin.user +++ b/lib/tolua++/win32/tolualib/tolualib.vcproj.LAPTOPF.Kevin.user diff --git a/tolua++-1.0.93/win32/tolualib/tolualib.vcxproj b/lib/tolua++/win32/tolualib/tolualib.vcxproj index f12bfda86..f12bfda86 100644 --- a/tolua++-1.0.93/win32/tolualib/tolualib.vcxproj +++ b/lib/tolua++/win32/tolualib/tolualib.vcxproj diff --git a/tolua++-1.0.93/win32/tolualib/tolualib.vcxproj.filters b/lib/tolua++/win32/tolualib/tolualib.vcxproj.filters index 99f8ce3b6..99f8ce3b6 100644 --- a/tolua++-1.0.93/win32/tolualib/tolualib.vcxproj.filters +++ b/lib/tolua++/win32/tolualib/tolualib.vcxproj.filters diff --git a/tolua++-1.0.93/win32/tolualib/tolualib.vcxproj.user b/lib/tolua++/win32/tolualib/tolualib.vcxproj.user index 4c1e1937c..4c1e1937c 100644 --- a/tolua++-1.0.93/win32/tolualib/tolualib.vcxproj.user +++ b/lib/tolua++/win32/tolualib/tolualib.vcxproj.user diff --git a/tolua++-1.0.93/win32/vc7/clean.bat b/lib/tolua++/win32/vc7/clean.bat index b8f4f2b2f..b8f4f2b2f 100644 --- a/tolua++-1.0.93/win32/vc7/clean.bat +++ b/lib/tolua++/win32/vc7/clean.bat diff --git a/tolua++-1.0.93/win32/vc7/toluapp.sln b/lib/tolua++/win32/vc7/toluapp.sln index 1ab8be380..1ab8be380 100644 --- a/tolua++-1.0.93/win32/vc7/toluapp.sln +++ b/lib/tolua++/win32/vc7/toluapp.sln diff --git a/tolua++-1.0.93/win32/vc7/toluapp.vcproj b/lib/tolua++/win32/vc7/toluapp.vcproj index 285bd2d42..285bd2d42 100644 --- a/tolua++-1.0.93/win32/vc7/toluapp.vcproj +++ b/lib/tolua++/win32/vc7/toluapp.vcproj diff --git a/tolua++-1.0.93/win32/vc7/toluapp.vcproj.LAPTOPF.Kevin.user b/lib/tolua++/win32/vc7/toluapp.vcproj.LAPTOPF.Kevin.user index a2de0fbb2..a2de0fbb2 100644 --- a/tolua++-1.0.93/win32/vc7/toluapp.vcproj.LAPTOPF.Kevin.user +++ b/lib/tolua++/win32/vc7/toluapp.vcproj.LAPTOPF.Kevin.user diff --git a/tolua++-1.0.93/win32/vc7/toluapp.vcxproj b/lib/tolua++/win32/vc7/toluapp.vcxproj index 45601b36f..45601b36f 100644 --- a/tolua++-1.0.93/win32/vc7/toluapp.vcxproj +++ b/lib/tolua++/win32/vc7/toluapp.vcxproj diff --git a/tolua++-1.0.93/win32/vc7/toluapp.vcxproj.filters b/lib/tolua++/win32/vc7/toluapp.vcxproj.filters index c23b20870..c23b20870 100644 --- a/tolua++-1.0.93/win32/vc7/toluapp.vcxproj.filters +++ b/lib/tolua++/win32/vc7/toluapp.vcxproj.filters diff --git a/tolua++-1.0.93/win32/vc7/toluapp.vcxproj.user b/lib/tolua++/win32/vc7/toluapp.vcxproj.user index 4c1e1937c..4c1e1937c 100644 --- a/tolua++-1.0.93/win32/vc7/toluapp.vcxproj.user +++ b/lib/tolua++/win32/vc7/toluapp.vcxproj.user diff --git a/zlib-1.2.7/adler32.c b/lib/zlib/adler32.c index a868f073d..a868f073d 100644 --- a/zlib-1.2.7/adler32.c +++ b/lib/zlib/adler32.c diff --git a/zlib-1.2.7/compress.c b/lib/zlib/compress.c index ea4dfbe9d..ea4dfbe9d 100644 --- a/zlib-1.2.7/compress.c +++ b/lib/zlib/compress.c diff --git a/zlib-1.2.7/crc32.c b/lib/zlib/crc32.c index 979a7190a..979a7190a 100644 --- a/zlib-1.2.7/crc32.c +++ b/lib/zlib/crc32.c diff --git a/zlib-1.2.7/crc32.h b/lib/zlib/crc32.h index 9e0c77810..9e0c77810 100644 --- a/zlib-1.2.7/crc32.h +++ b/lib/zlib/crc32.h diff --git a/zlib-1.2.7/deflate.c b/lib/zlib/deflate.c index 9e4c2cbc8..9e4c2cbc8 100644 --- a/zlib-1.2.7/deflate.c +++ b/lib/zlib/deflate.c diff --git a/zlib-1.2.7/deflate.h b/lib/zlib/deflate.h index fbac44d90..fbac44d90 100644 --- a/zlib-1.2.7/deflate.h +++ b/lib/zlib/deflate.h diff --git a/zlib-1.2.7/example.c b/lib/zlib/example.c index f515a4853..f515a4853 100644 --- a/zlib-1.2.7/example.c +++ b/lib/zlib/example.c diff --git a/zlib-1.2.7/gzclose.c b/lib/zlib/gzclose.c index caeb99a31..caeb99a31 100644 --- a/zlib-1.2.7/gzclose.c +++ b/lib/zlib/gzclose.c diff --git a/zlib-1.2.7/gzguts.h b/lib/zlib/gzguts.h index ee3f281aa..ee3f281aa 100644 --- a/zlib-1.2.7/gzguts.h +++ b/lib/zlib/gzguts.h diff --git a/zlib-1.2.7/gzlib.c b/lib/zlib/gzlib.c index ca55c6ea9..ca55c6ea9 100644 --- a/zlib-1.2.7/gzlib.c +++ b/lib/zlib/gzlib.c diff --git a/zlib-1.2.7/gzread.c b/lib/zlib/gzread.c index 3493d34d4..3493d34d4 100644 --- a/zlib-1.2.7/gzread.c +++ b/lib/zlib/gzread.c diff --git a/zlib-1.2.7/gzwrite.c b/lib/zlib/gzwrite.c index 27cb3428e..27cb3428e 100644 --- a/zlib-1.2.7/gzwrite.c +++ b/lib/zlib/gzwrite.c diff --git a/zlib-1.2.7/infback.c b/lib/zlib/infback.c index 981aff17c..981aff17c 100644 --- a/zlib-1.2.7/infback.c +++ b/lib/zlib/infback.c diff --git a/zlib-1.2.7/inffast.c b/lib/zlib/inffast.c index 2f1d60b43..2f1d60b43 100644 --- a/zlib-1.2.7/inffast.c +++ b/lib/zlib/inffast.c diff --git a/zlib-1.2.7/inffast.h b/lib/zlib/inffast.h index e5c1aa4ca..e5c1aa4ca 100644 --- a/zlib-1.2.7/inffast.h +++ b/lib/zlib/inffast.h diff --git a/zlib-1.2.7/inffixed.h b/lib/zlib/inffixed.h index d62832776..d62832776 100644 --- a/zlib-1.2.7/inffixed.h +++ b/lib/zlib/inffixed.h diff --git a/zlib-1.2.7/inflate.c b/lib/zlib/inflate.c index 47418a1e1..47418a1e1 100644 --- a/zlib-1.2.7/inflate.c +++ b/lib/zlib/inflate.c diff --git a/zlib-1.2.7/inflate.h b/lib/zlib/inflate.h index 95f4986d4..95f4986d4 100644 --- a/zlib-1.2.7/inflate.h +++ b/lib/zlib/inflate.h diff --git a/zlib-1.2.7/inftrees.c b/lib/zlib/inftrees.c index abcd7c45e..abcd7c45e 100644 --- a/zlib-1.2.7/inftrees.c +++ b/lib/zlib/inftrees.c diff --git a/zlib-1.2.7/inftrees.h b/lib/zlib/inftrees.h index baa53a0b1..baa53a0b1 100644 --- a/zlib-1.2.7/inftrees.h +++ b/lib/zlib/inftrees.h diff --git a/zlib-1.2.7/minigzip.c b/lib/zlib/minigzip.c index aa7ac7a04..aa7ac7a04 100644 --- a/zlib-1.2.7/minigzip.c +++ b/lib/zlib/minigzip.c diff --git a/zlib-1.2.7/trees.c b/lib/zlib/trees.c index 8c32b214b..8c32b214b 100644 --- a/zlib-1.2.7/trees.c +++ b/lib/zlib/trees.c diff --git a/zlib-1.2.7/trees.h b/lib/zlib/trees.h index d35639d82..d35639d82 100644 --- a/zlib-1.2.7/trees.h +++ b/lib/zlib/trees.h diff --git a/zlib-1.2.7/uncompr.c b/lib/zlib/uncompr.c index ad98be3a5..ad98be3a5 100644 --- a/zlib-1.2.7/uncompr.c +++ b/lib/zlib/uncompr.c diff --git a/zlib-1.2.7/zconf.h b/lib/zlib/zconf.h index 8a46a58b3..8a46a58b3 100644 --- a/zlib-1.2.7/zconf.h +++ b/lib/zlib/zconf.h diff --git a/zlib-1.2.7/zlib.h b/lib/zlib/zlib.h index 3edf3acdb..3edf3acdb 100644 --- a/zlib-1.2.7/zlib.h +++ b/lib/zlib/zlib.h diff --git a/zlib-1.2.7/zutil.c b/lib/zlib/zutil.c index 65e0d3b72..65e0d3b72 100644 --- a/zlib-1.2.7/zutil.c +++ b/lib/zlib/zutil.c diff --git a/zlib-1.2.7/zutil.h b/lib/zlib/zutil.h index 4e3dcc6ae..4e3dcc6ae 100644 --- a/zlib-1.2.7/zutil.h +++ b/lib/zlib/zutil.h |