cjson
.github
workflows CI.yml ci-fuzz.yml
CONTRIBUTING.md
fuzzing
inputs test1 test10 test11 test2 test3 test3.bu test3.uf test3.uu test4 test5 test6 test7 test8 test9
.gitignore CMakeLists.txt afl-prepare-linux.sh afl.c afl.sh cjson_read_fuzzer.c fuzz_main.c json.dict ossfuzz.sh
library_config cJSONConfig.cmake.in cJSONConfigVersion.cmake.in libcjson.pc.in libcjson_utils.pc.in uninstall.cmake
tests
inputs test1 test1.expected test10 test10.expected test11 test11.expected test2 test2.expected test3 test3.expected test4 test4.expected test5 test5.expected test6 test7 test7.expected test8 test8.expected test9 test9.expected
json-patch-tests .editorconfig .gitignore .npmignore README.md cjson-utils-tests.json package.json spec_tests.json tests.json
unity
auto colour_prompt.rb colour_reporter.rb generate_config.yml generate_module.rb generate_test_runner.rb parse_output.rb stylize_as_junit.rb test_file_filter.rb type_sanitizer.rb unity_test_summary.py unity_test_summary.rb unity_to_junit.py
docs ThrowTheSwitchCodingStandard.md UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf UnityAssertionsReference.md UnityConfigurationGuide.md UnityGettingStartedGuide.md UnityHelperScriptsGuide.md license.txt
examples
example_1
src ProductionCode.c ProductionCode.h ProductionCode2.c ProductionCode2.h
makefile readme.txt
example_2
src ProductionCode.c ProductionCode.h ProductionCode2.c ProductionCode2.h
makefile readme.txt
example_3
helper UnityHelper.c UnityHelper.h
src ProductionCode.c ProductionCode.h ProductionCode2.c ProductionCode2.h
rakefile.rb rakefile_helper.rb readme.txt target_gcc_32.yml
unity_config.h
extras
eclipse error_parsers.txt
fixture
src unity_fixture.c unity_fixture.h unity_fixture_internals.h unity_fixture_malloc_overrides.h
rakefile.rb rakefile_helper.rb readme.txt
release build.info version.info
src unity.c unity.h unity_internals.h
.gitattributes .gitignore .travis.yml README.md
CMakeLists.txt cjson_add.c common.h compare_tests.c json_patch_tests.c minify_tests.c misc_tests.c misc_utils_tests.c old_utils_tests.c parse_array.c parse_examples.c parse_hex4.c parse_number.c parse_object.c parse_string.c parse_value.c parse_with_opts.c print_array.c print_number.c print_object.c print_string.c print_value.c readme_examples.c unity_setup.c
.editorconfig .gitattributes .gitignore .travis.yml CHANGELOG.md CMakeLists.txt CONTRIBUTORS.md LICENSE Makefile README.md SECURITY.md appveyor.yml cJSON.c cJSON.h cJSON_Utils.c cJSON_Utils.h test.c valgrind.supp
curl
.circleci config.yml
.github
ISSUE_TEMPLATE bug_report.yml config.yml docs.yml
scripts cleancmd.pl cmp-config.pl cmp-pkg-config.sh codespell-ignore.words codespell.sh distfiles.sh pyspelling.words pyspelling.yaml randcurl.pl requirements-docs.txt requirements-proselint.txt requirements.txt shellcheck-ci.sh shellcheck.sh spellcheck.curl trimmarkdownheader.pl typos.sh typos.toml verify-examples.pl verify-synopsis.pl yamlcheck.sh yamlcheck.yaml
workflows appveyor-status.yml checkdocs.yml checksrc.yml checkurls.yml codeql.yml configure-vs-cmake.yml curl-for-win.yml distcheck.yml fuzz.yml http3-linux.yml label.yml linux-old.yml linux.yml macos.yml non-native.yml windows.yml
CODEOWNERS CONTRIBUTING.md FUNDING.yml dependabot.yml labeler.yml lock.yml stale.yml
CMake CurlSymbolHiding.cmake CurlTests.c FindBrotli.cmake FindCares.cmake FindGSS.cmake FindGnuTLS.cmake FindLDAP.cmake FindLibbacktrace.cmake FindLibgsasl.cmake FindLibidn2.cmake FindLibpsl.cmake FindLibssh.cmake FindLibssh2.cmake FindLibuv.cmake FindMbedTLS.cmake FindNGHTTP2.cmake FindNGHTTP3.cmake FindNGTCP2.cmake FindNettle.cmake FindQuiche.cmake FindRustls.cmake FindWolfSSL.cmake FindZstd.cmake Macros.cmake OtherTests.cmake PickyWarnings.cmake Utilities.cmake cmake_uninstall.in.cmake curl-config.in.cmake unix-cache.cmake win32-cache.cmake
LICENSES BSD-4-Clause-UC.txt ISC.txt curl.txt
docs
cmdline-opts .gitignore CMakeLists.txt MANPAGE.md Makefile.am Makefile.inc _AUTHORS.md _BUGS.md _DESCRIPTION.md _ENVIRONMENT.md _EXITCODES.md _FILES.md _GLOBBING.md _NAME.md _OPTIONS.md _OUTPUT.md _PROGRESS.md _PROTOCOLS.md _PROXYPREFIX.md _SEEALSO.md _SYNOPSIS.md _URL.md _VARIABLES.md _VERSION.md _WWW.md abstract-unix-socket.md alt-svc.md anyauth.md append.md aws-sigv4.md basic.md ca-native.md cacert.md capath.md cert-status.md cert-type.md cert.md ciphers.md compressed-ssh.md compressed.md config.md connect-timeout.md connect-to.md continue-at.md cookie-jar.md cookie.md create-dirs.md create-file-mode.md crlf.md crlfile.md curves.md data-ascii.md data-binary.md data-raw.md data-urlencode.md data.md delegation.md digest.md disable-eprt.md disable-epsv.md disable.md disallow-username-in-url.md dns-interface.md dns-ipv4-addr.md dns-ipv6-addr.md dns-servers.md doh-cert-status.md doh-insecure.md doh-url.md dump-ca-embed.md dump-header.md ech.md egd-file.md engine.md etag-compare.md etag-save.md expect100-timeout.md fail-early.md fail-with-body.md fail.md false-start.md follow.md form-escape.md form-string.md form.md ftp-account.md ftp-alternative-to-user.md ftp-create-dirs.md ftp-method.md ftp-pasv.md ftp-port.md ftp-pret.md ftp-skip-pasv-ip.md ftp-ssl-ccc-mode.md ftp-ssl-ccc.md ftp-ssl-control.md get.md globoff.md happy-eyeballs-timeout-ms.md haproxy-clientip.md haproxy-protocol.md head.md header.md help.md hostpubmd5.md hostpubsha256.md hsts.md http0.9.md http1.0.md http1.1.md http2-prior-knowledge.md http2.md http3-only.md http3.md ignore-content-length.md insecure.md interface.md ip-tos.md ipfs-gateway.md ipv4.md ipv6.md json.md junk-session-cookies.md keepalive-cnt.md keepalive-time.md key-type.md key.md knownhosts.md krb.md libcurl.md limit-rate.md list-only.md local-port.md location-trusted.md location.md login-options.md mail-auth.md mail-from.md mail-rcpt-allowfails.md mail-rcpt.md mainpage.idx manual.md max-filesize.md max-redirs.md max-time.md metalink.md mptcp.md negotiate.md netrc-file.md netrc-optional.md netrc.md next.md no-alpn.md no-buffer.md no-clobber.md no-keepalive.md no-npn.md no-progress-meter.md no-sessionid.md noproxy.md ntlm-wb.md ntlm.md oauth2-bearer.md out-null.md output-dir.md output.md parallel-immediate.md parallel-max-host.md parallel-max.md parallel.md pass.md path-as-is.md pinnedpubkey.md post301.md post302.md post303.md preproxy.md progress-bar.md proto-default.md proto-redir.md proto.md proxy-anyauth.md proxy-basic.md proxy-ca-native.md proxy-cacert.md proxy-capath.md proxy-cert-type.md proxy-cert.md proxy-ciphers.md proxy-crlfile.md proxy-digest.md proxy-header.md proxy-http2.md proxy-insecure.md proxy-key-type.md proxy-key.md proxy-negotiate.md proxy-ntlm.md proxy-pass.md proxy-pinnedpubkey.md proxy-service-name.md proxy-ssl-allow-beast.md proxy-ssl-auto-client-cert.md proxy-tls13-ciphers.md proxy-tlsauthtype.md proxy-tlspassword.md proxy-tlsuser.md proxy-tlsv1.md proxy-user.md proxy.md proxy1.0.md proxytunnel.md pubkey.md quote.md random-file.md range.md rate.md raw.md referer.md remote-header-name.md remote-name-all.md remote-name.md remote-time.md remove-on-error.md request-target.md request.md resolve.md retry-all-errors.md retry-connrefused.md retry-delay.md retry-max-time.md retry.md sasl-authzid.md sasl-ir.md service-name.md show-error.md show-headers.md sigalgs.md silent.md skip-existing.md socks4.md socks4a.md socks5-basic.md socks5-gssapi-nec.md socks5-gssapi-service.md socks5-gssapi.md socks5-hostname.md socks5.md speed-limit.md speed-time.md ssl-allow-beast.md ssl-auto-client-cert.md ssl-no-revoke.md ssl-reqd.md ssl-revoke-best-effort.md ssl-sessions.md ssl.md sslv2.md sslv3.md stderr.md styled-output.md suppress-connect-headers.md tcp-fastopen.md tcp-nodelay.md telnet-option.md tftp-blksize.md tftp-no-options.md time-cond.md tls-earlydata.md tls-max.md tls13-ciphers.md tlsauthtype.md tlspassword.md tlsuser.md tlsv1.0.md tlsv1.1.md tlsv1.2.md tlsv1.3.md tlsv1.md tr-encoding.md trace-ascii.md trace-config.md trace-ids.md trace-time.md trace.md unix-socket.md upload-file.md upload-flags.md url-query.md url.md use-ascii.md user-agent.md user.md variable.md verbose.md version.md vlan-priority.md write-out.md xattr.md
examples .checksrc .gitignore 10-at-a-time.c CMakeLists.txt Makefile.am Makefile.example Makefile.inc README.md adddocsref.pl address-scope.c altsvc.c anyauthput.c block_ip.c cacertinmem.c certinfo.c chkspeed.c connect-to.c cookie_interface.c crawler.c debug.c default-scheme.c ephiperfifo.c evhiperfifo.c externalsocket.c fileupload.c ftp-delete.c ftp-wildcard.c ftpget.c ftpgetinfo.c ftpgetresp.c ftpsget.c ftpupload.c ftpuploadfrommem.c ftpuploadresume.c getinfo.c getinmemory.c getredirect.c getreferrer.c ghiper.c headerapi.c hiperfifo.c hsts-preload.c htmltidy.c htmltitle.cpp http-options.c http-post.c http2-download.c http2-pushinmemory.c http2-serverpush.c http2-upload.c http3-present.c http3.c httpcustomheader.c httpput-postfields.c httpput.c https.c imap-append.c imap-authzid.c imap-copy.c imap-create.c imap-delete.c imap-examine.c imap-fetch.c imap-list.c imap-lsub.c imap-multi.c imap-noop.c imap-search.c imap-ssl.c imap-store.c imap-tls.c interface.c ipv6.c keepalive.c localport.c log_failed_transfers.c maxconnects.c multi-app.c multi-debugcallback.c multi-double.c multi-event.c multi-formadd.c multi-legacy.c multi-post.c multi-single.c multi-uv.c netrc.c parseurl.c persistent.c pop3-authzid.c pop3-dele.c pop3-list.c pop3-multi.c pop3-noop.c pop3-retr.c pop3-ssl.c pop3-stat.c pop3-tls.c pop3-top.c pop3-uidl.c post-callback.c postinmemory.c postit2-formadd.c postit2.c progressfunc.c protofeats.c range.c resolve.c rtsp-options.c sendrecv.c sepheaders.c sessioninfo.c sftpget.c sftpuploadresume.c shared-connection-cache.c simple.c simplepost.c simplessl.c smooth-gtk-thread.c smtp-authzid.c smtp-expn.c smtp-mail.c smtp-mime.c smtp-multi.c smtp-ssl.c smtp-tls.c smtp-vrfy.c sslbackend.c synctime.c threaded.c unixsocket.c url2file.c urlapi.c usercertinmem.c version-check.pl websocket-cb.c websocket-updown.c websocket.c xmlstream.c
internals BUFQ.md BUFREF.md CHECKSRC.md CLIENT-READERS.md CLIENT-WRITERS.md CODE_STYLE.md CONNECTION-FILTERS.md CREDENTIALS.md CURLX.md DYNBUF.md HASH.md LLIST.md MID.md MQTT.md MULTI-EV.md NEW-PROTOCOL.md PEERS.md PORTING.md RATELIMITS.md README.md SCORECARD.md SPLAY.md STRPARSE.md THRDPOOL-AND-QUEUE.md TIME-KEEPING.md TLS-SESSIONS.md UINT_SETS.md WEBSOCKET.md
libcurl
opts CMakeLists.txt CURLINFO_ACTIVESOCKET.md CURLINFO_APPCONNECT_TIME.md CURLINFO_APPCONNECT_TIME_T.md CURLINFO_CAINFO.md CURLINFO_CAPATH.md CURLINFO_CERTINFO.md CURLINFO_CONDITION_UNMET.md CURLINFO_CONNECT_TIME.md CURLINFO_CONNECT_TIME_T.md CURLINFO_CONN_ID.md CURLINFO_CONTENT_LENGTH_DOWNLOAD.md CURLINFO_CONTENT_LENGTH_DOWNLOAD_T.md CURLINFO_CONTENT_LENGTH_UPLOAD.md CURLINFO_CONTENT_LENGTH_UPLOAD_T.md CURLINFO_CONTENT_TYPE.md CURLINFO_COOKIELIST.md CURLINFO_EARLYDATA_SENT_T.md CURLINFO_EFFECTIVE_METHOD.md CURLINFO_EFFECTIVE_URL.md CURLINFO_FILETIME.md CURLINFO_FILETIME_T.md CURLINFO_FTP_ENTRY_PATH.md CURLINFO_HEADER_SIZE.md CURLINFO_HTTPAUTH_AVAIL.md CURLINFO_HTTPAUTH_USED.md CURLINFO_HTTP_CONNECTCODE.md CURLINFO_HTTP_VERSION.md CURLINFO_LASTSOCKET.md CURLINFO_LOCAL_IP.md CURLINFO_LOCAL_PORT.md CURLINFO_NAMELOOKUP_TIME.md CURLINFO_NAMELOOKUP_TIME_T.md CURLINFO_NUM_CONNECTS.md CURLINFO_OS_ERRNO.md CURLINFO_POSTTRANSFER_TIME_T.md CURLINFO_PRETRANSFER_TIME.md CURLINFO_PRETRANSFER_TIME_T.md CURLINFO_PRIMARY_IP.md CURLINFO_PRIMARY_PORT.md CURLINFO_PRIVATE.md CURLINFO_PROTOCOL.md CURLINFO_PROXYAUTH_AVAIL.md CURLINFO_PROXYAUTH_USED.md CURLINFO_PROXY_ERROR.md CURLINFO_PROXY_SSL_VERIFYRESULT.md CURLINFO_QUEUE_TIME_T.md CURLINFO_REDIRECT_COUNT.md CURLINFO_REDIRECT_TIME.md CURLINFO_REDIRECT_TIME_T.md CURLINFO_REDIRECT_URL.md CURLINFO_REFERER.md CURLINFO_REQUEST_SIZE.md CURLINFO_RESPONSE_CODE.md CURLINFO_RETRY_AFTER.md CURLINFO_RTSP_CLIENT_CSEQ.md CURLINFO_RTSP_CSEQ_RECV.md CURLINFO_RTSP_SERVER_CSEQ.md CURLINFO_RTSP_SESSION_ID.md CURLINFO_SCHEME.md CURLINFO_SIZE_DELIVERED.md CURLINFO_SIZE_DOWNLOAD.md CURLINFO_SIZE_DOWNLOAD_T.md CURLINFO_SIZE_UPLOAD.md CURLINFO_SIZE_UPLOAD_T.md CURLINFO_SPEED_DOWNLOAD.md CURLINFO_SPEED_DOWNLOAD_T.md CURLINFO_SPEED_UPLOAD.md CURLINFO_SPEED_UPLOAD_T.md CURLINFO_SSL_ENGINES.md CURLINFO_SSL_VERIFYRESULT.md CURLINFO_STARTTRANSFER_TIME.md CURLINFO_STARTTRANSFER_TIME_T.md CURLINFO_TLS_SESSION.md CURLINFO_TLS_SSL_PTR.md CURLINFO_TOTAL_TIME.md CURLINFO_TOTAL_TIME_T.md CURLINFO_USED_PROXY.md CURLINFO_XFER_ID.md CURLMINFO_XFERS_ADDED.md CURLMINFO_XFERS_CURRENT.md CURLMINFO_XFERS_DONE.md CURLMINFO_XFERS_PENDING.md CURLMINFO_XFERS_RUNNING.md CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE.md CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE.md CURLMOPT_MAXCONNECTS.md CURLMOPT_MAX_CONCURRENT_STREAMS.md CURLMOPT_MAX_HOST_CONNECTIONS.md CURLMOPT_MAX_PIPELINE_LENGTH.md CURLMOPT_MAX_TOTAL_CONNECTIONS.md CURLMOPT_NETWORK_CHANGED.md CURLMOPT_NOTIFYDATA.md CURLMOPT_NOTIFYFUNCTION.md CURLMOPT_PIPELINING.md CURLMOPT_PIPELINING_SERVER_BL.md CURLMOPT_PIPELINING_SITE_BL.md CURLMOPT_PUSHDATA.md CURLMOPT_PUSHFUNCTION.md CURLMOPT_QUICK_EXIT.md CURLMOPT_RESOLVE_THREADS_MAX.md CURLMOPT_SOCKETDATA.md CURLMOPT_SOCKETFUNCTION.md CURLMOPT_TIMERDATA.md CURLMOPT_TIMERFUNCTION.md CURLOPT_ABSTRACT_UNIX_SOCKET.md CURLOPT_ACCEPTTIMEOUT_MS.md CURLOPT_ACCEPT_ENCODING.md CURLOPT_ADDRESS_SCOPE.md CURLOPT_ALTSVC.md CURLOPT_ALTSVC_CTRL.md CURLOPT_APPEND.md CURLOPT_AUTOREFERER.md CURLOPT_AWS_SIGV4.md CURLOPT_BUFFERSIZE.md CURLOPT_CAINFO.md CURLOPT_CAINFO_BLOB.md CURLOPT_CAPATH.md CURLOPT_CA_CACHE_TIMEOUT.md CURLOPT_CERTINFO.md CURLOPT_CHUNK_BGN_FUNCTION.md CURLOPT_CHUNK_DATA.md CURLOPT_CHUNK_END_FUNCTION.md CURLOPT_CLOSESOCKETDATA.md CURLOPT_CLOSESOCKETFUNCTION.md CURLOPT_CONNECTTIMEOUT.md CURLOPT_CONNECTTIMEOUT_MS.md CURLOPT_CONNECT_ONLY.md CURLOPT_CONNECT_TO.md CURLOPT_CONV_FROM_NETWORK_FUNCTION.md CURLOPT_CONV_FROM_UTF8_FUNCTION.md CURLOPT_CONV_TO_NETWORK_FUNCTION.md CURLOPT_COOKIE.md CURLOPT_COOKIEFILE.md CURLOPT_COOKIEJAR.md CURLOPT_COOKIELIST.md CURLOPT_COOKIESESSION.md CURLOPT_COPYPOSTFIELDS.md CURLOPT_CRLF.md CURLOPT_CRLFILE.md CURLOPT_CURLU.md CURLOPT_CUSTOMREQUEST.md CURLOPT_DEBUGDATA.md CURLOPT_DEBUGFUNCTION.md CURLOPT_DEFAULT_PROTOCOL.md CURLOPT_DIRLISTONLY.md CURLOPT_DISALLOW_USERNAME_IN_URL.md CURLOPT_DNS_CACHE_TIMEOUT.md CURLOPT_DNS_INTERFACE.md CURLOPT_DNS_LOCAL_IP4.md CURLOPT_DNS_LOCAL_IP6.md CURLOPT_DNS_SERVERS.md CURLOPT_DNS_SHUFFLE_ADDRESSES.md CURLOPT_DNS_USE_GLOBAL_CACHE.md CURLOPT_DOH_SSL_VERIFYHOST.md CURLOPT_DOH_SSL_VERIFYPEER.md CURLOPT_DOH_SSL_VERIFYSTATUS.md CURLOPT_DOH_URL.md CURLOPT_ECH.md CURLOPT_EGDSOCKET.md CURLOPT_ERRORBUFFER.md CURLOPT_EXPECT_100_TIMEOUT_MS.md CURLOPT_FAILONERROR.md CURLOPT_FILETIME.md CURLOPT_FNMATCH_DATA.md CURLOPT_FNMATCH_FUNCTION.md CURLOPT_FOLLOWLOCATION.md CURLOPT_FORBID_REUSE.md CURLOPT_FRESH_CONNECT.md CURLOPT_FTPPORT.md CURLOPT_FTPSSLAUTH.md CURLOPT_FTP_ACCOUNT.md CURLOPT_FTP_ALTERNATIVE_TO_USER.md CURLOPT_FTP_CREATE_MISSING_DIRS.md CURLOPT_FTP_FILEMETHOD.md CURLOPT_FTP_SKIP_PASV_IP.md CURLOPT_FTP_SSL_CCC.md CURLOPT_FTP_USE_EPRT.md CURLOPT_FTP_USE_EPSV.md CURLOPT_FTP_USE_PRET.md CURLOPT_GSSAPI_DELEGATION.md CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.md CURLOPT_HAPROXYPROTOCOL.md CURLOPT_HAPROXY_CLIENT_IP.md CURLOPT_HEADER.md CURLOPT_HEADERDATA.md CURLOPT_HEADERFUNCTION.md CURLOPT_HEADEROPT.md CURLOPT_HSTS.md CURLOPT_HSTSREADDATA.md CURLOPT_HSTSREADFUNCTION.md CURLOPT_HSTSWRITEDATA.md CURLOPT_HSTSWRITEFUNCTION.md CURLOPT_HSTS_CTRL.md CURLOPT_HTTP09_ALLOWED.md CURLOPT_HTTP200ALIASES.md CURLOPT_HTTPAUTH.md CURLOPT_HTTPGET.md CURLOPT_HTTPHEADER.md CURLOPT_HTTPPOST.md CURLOPT_HTTPPROXYTUNNEL.md CURLOPT_HTTP_CONTENT_DECODING.md CURLOPT_HTTP_TRANSFER_DECODING.md CURLOPT_HTTP_VERSION.md CURLOPT_IGNORE_CONTENT_LENGTH.md CURLOPT_INFILESIZE.md CURLOPT_INFILESIZE_LARGE.md CURLOPT_INTERFACE.md CURLOPT_INTERLEAVEDATA.md CURLOPT_INTERLEAVEFUNCTION.md CURLOPT_IOCTLDATA.md CURLOPT_IOCTLFUNCTION.md CURLOPT_IPRESOLVE.md CURLOPT_ISSUERCERT.md CURLOPT_ISSUERCERT_BLOB.md CURLOPT_KEEP_SENDING_ON_ERROR.md CURLOPT_KEYPASSWD.md CURLOPT_KRBLEVEL.md CURLOPT_LOCALPORT.md CURLOPT_LOCALPORTRANGE.md CURLOPT_LOGIN_OPTIONS.md CURLOPT_LOW_SPEED_LIMIT.md CURLOPT_LOW_SPEED_TIME.md CURLOPT_MAIL_AUTH.md CURLOPT_MAIL_FROM.md CURLOPT_MAIL_RCPT.md CURLOPT_MAIL_RCPT_ALLOWFAILS.md CURLOPT_MAXAGE_CONN.md CURLOPT_MAXCONNECTS.md CURLOPT_MAXFILESIZE.md CURLOPT_MAXFILESIZE_LARGE.md CURLOPT_MAXLIFETIME_CONN.md CURLOPT_MAXREDIRS.md CURLOPT_MAX_RECV_SPEED_LARGE.md CURLOPT_MAX_SEND_SPEED_LARGE.md CURLOPT_MIMEPOST.md CURLOPT_MIME_OPTIONS.md CURLOPT_NETRC.md CURLOPT_NETRC_FILE.md CURLOPT_NEW_DIRECTORY_PERMS.md CURLOPT_NEW_FILE_PERMS.md CURLOPT_NOBODY.md CURLOPT_NOPROGRESS.md CURLOPT_NOPROXY.md CURLOPT_NOSIGNAL.md CURLOPT_OPENSOCKETDATA.md CURLOPT_OPENSOCKETFUNCTION.md CURLOPT_PASSWORD.md CURLOPT_PATH_AS_IS.md CURLOPT_PINNEDPUBLICKEY.md CURLOPT_PIPEWAIT.md CURLOPT_PORT.md CURLOPT_POST.md CURLOPT_POSTFIELDS.md CURLOPT_POSTFIELDSIZE.md CURLOPT_POSTFIELDSIZE_LARGE.md CURLOPT_POSTQUOTE.md CURLOPT_POSTREDIR.md CURLOPT_PREQUOTE.md CURLOPT_PREREQDATA.md CURLOPT_PREREQFUNCTION.md CURLOPT_PRE_PROXY.md CURLOPT_PRIVATE.md CURLOPT_PROGRESSDATA.md CURLOPT_PROGRESSFUNCTION.md CURLOPT_PROTOCOLS.md CURLOPT_PROTOCOLS_STR.md CURLOPT_PROXY.md CURLOPT_PROXYAUTH.md CURLOPT_PROXYHEADER.md CURLOPT_PROXYPASSWORD.md CURLOPT_PROXYPORT.md CURLOPT_PROXYTYPE.md CURLOPT_PROXYUSERNAME.md CURLOPT_PROXYUSERPWD.md CURLOPT_PROXY_CAINFO.md CURLOPT_PROXY_CAINFO_BLOB.md CURLOPT_PROXY_CAPATH.md CURLOPT_PROXY_CRLFILE.md CURLOPT_PROXY_ISSUERCERT.md CURLOPT_PROXY_ISSUERCERT_BLOB.md CURLOPT_PROXY_KEYPASSWD.md CURLOPT_PROXY_PINNEDPUBLICKEY.md CURLOPT_PROXY_SERVICE_NAME.md CURLOPT_PROXY_SSLCERT.md CURLOPT_PROXY_SSLCERTTYPE.md CURLOPT_PROXY_SSLCERT_BLOB.md CURLOPT_PROXY_SSLKEY.md CURLOPT_PROXY_SSLKEYTYPE.md CURLOPT_PROXY_SSLKEY_BLOB.md CURLOPT_PROXY_SSLVERSION.md CURLOPT_PROXY_SSL_CIPHER_LIST.md CURLOPT_PROXY_SSL_OPTIONS.md CURLOPT_PROXY_SSL_VERIFYHOST.md CURLOPT_PROXY_SSL_VERIFYPEER.md CURLOPT_PROXY_TLS13_CIPHERS.md CURLOPT_PROXY_TLSAUTH_PASSWORD.md CURLOPT_PROXY_TLSAUTH_TYPE.md CURLOPT_PROXY_TLSAUTH_USERNAME.md CURLOPT_PROXY_TRANSFER_MODE.md CURLOPT_PUT.md CURLOPT_QUICK_EXIT.md CURLOPT_QUOTE.md CURLOPT_RANDOM_FILE.md CURLOPT_RANGE.md CURLOPT_READDATA.md CURLOPT_READFUNCTION.md CURLOPT_REDIR_PROTOCOLS.md CURLOPT_REDIR_PROTOCOLS_STR.md CURLOPT_REFERER.md CURLOPT_REQUEST_TARGET.md CURLOPT_RESOLVE.md CURLOPT_RESOLVER_START_DATA.md CURLOPT_RESOLVER_START_FUNCTION.md CURLOPT_RESUME_FROM.md CURLOPT_RESUME_FROM_LARGE.md CURLOPT_RTSP_CLIENT_CSEQ.md CURLOPT_RTSP_REQUEST.md CURLOPT_RTSP_SERVER_CSEQ.md CURLOPT_RTSP_SESSION_ID.md CURLOPT_RTSP_STREAM_URI.md CURLOPT_RTSP_TRANSPORT.md CURLOPT_SASL_AUTHZID.md CURLOPT_SASL_IR.md CURLOPT_SEEKDATA.md CURLOPT_SEEKFUNCTION.md CURLOPT_SERVER_RESPONSE_TIMEOUT.md CURLOPT_SERVER_RESPONSE_TIMEOUT_MS.md CURLOPT_SERVICE_NAME.md CURLOPT_SHARE.md CURLOPT_SOCKOPTDATA.md CURLOPT_SOCKOPTFUNCTION.md CURLOPT_SOCKS5_AUTH.md CURLOPT_SOCKS5_GSSAPI_NEC.md CURLOPT_SOCKS5_GSSAPI_SERVICE.md CURLOPT_SSH_AUTH_TYPES.md CURLOPT_SSH_COMPRESSION.md CURLOPT_SSH_HOSTKEYDATA.md CURLOPT_SSH_HOSTKEYFUNCTION.md CURLOPT_SSH_HOST_PUBLIC_KEY_MD5.md CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256.md CURLOPT_SSH_KEYDATA.md CURLOPT_SSH_KEYFUNCTION.md CURLOPT_SSH_KNOWNHOSTS.md CURLOPT_SSH_PRIVATE_KEYFILE.md CURLOPT_SSH_PUBLIC_KEYFILE.md CURLOPT_SSLCERT.md CURLOPT_SSLCERTTYPE.md CURLOPT_SSLCERT_BLOB.md CURLOPT_SSLENGINE.md CURLOPT_SSLENGINE_DEFAULT.md CURLOPT_SSLKEY.md CURLOPT_SSLKEYTYPE.md CURLOPT_SSLKEY_BLOB.md CURLOPT_SSLVERSION.md CURLOPT_SSL_CIPHER_LIST.md CURLOPT_SSL_CTX_DATA.md CURLOPT_SSL_CTX_FUNCTION.md CURLOPT_SSL_EC_CURVES.md CURLOPT_SSL_ENABLE_ALPN.md CURLOPT_SSL_ENABLE_NPN.md CURLOPT_SSL_FALSESTART.md CURLOPT_SSL_OPTIONS.md CURLOPT_SSL_SESSIONID_CACHE.md CURLOPT_SSL_SIGNATURE_ALGORITHMS.md CURLOPT_SSL_VERIFYHOST.md CURLOPT_SSL_VERIFYPEER.md CURLOPT_SSL_VERIFYSTATUS.md CURLOPT_STDERR.md CURLOPT_STREAM_DEPENDS.md CURLOPT_STREAM_DEPENDS_E.md CURLOPT_STREAM_WEIGHT.md CURLOPT_SUPPRESS_CONNECT_HEADERS.md CURLOPT_TCP_FASTOPEN.md CURLOPT_TCP_KEEPALIVE.md CURLOPT_TCP_KEEPCNT.md CURLOPT_TCP_KEEPIDLE.md CURLOPT_TCP_KEEPINTVL.md CURLOPT_TCP_NODELAY.md CURLOPT_TELNETOPTIONS.md CURLOPT_TFTP_BLKSIZE.md CURLOPT_TFTP_NO_OPTIONS.md CURLOPT_TIMECONDITION.md CURLOPT_TIMEOUT.md CURLOPT_TIMEOUT_MS.md CURLOPT_TIMEVALUE.md CURLOPT_TIMEVALUE_LARGE.md CURLOPT_TLS13_CIPHERS.md CURLOPT_TLSAUTH_PASSWORD.md CURLOPT_TLSAUTH_TYPE.md CURLOPT_TLSAUTH_USERNAME.md CURLOPT_TRAILERDATA.md CURLOPT_TRAILERFUNCTION.md CURLOPT_TRANSFERTEXT.md CURLOPT_TRANSFER_ENCODING.md CURLOPT_UNIX_SOCKET_PATH.md CURLOPT_UNRESTRICTED_AUTH.md CURLOPT_UPKEEP_INTERVAL_MS.md CURLOPT_UPLOAD.md CURLOPT_UPLOAD_BUFFERSIZE.md CURLOPT_UPLOAD_FLAGS.md CURLOPT_URL.md CURLOPT_USERAGENT.md CURLOPT_USERNAME.md CURLOPT_USERPWD.md CURLOPT_USE_SSL.md CURLOPT_VERBOSE.md CURLOPT_WILDCARDMATCH.md CURLOPT_WRITEDATA.md CURLOPT_WRITEFUNCTION.md CURLOPT_WS_OPTIONS.md CURLOPT_XFERINFODATA.md CURLOPT_XFERINFOFUNCTION.md CURLOPT_XOAUTH2_BEARER.md CURLSHOPT_LOCKFUNC.md CURLSHOPT_SHARE.md CURLSHOPT_UNLOCKFUNC.md CURLSHOPT_UNSHARE.md CURLSHOPT_USERDATA.md Makefile.am Makefile.inc
.gitignore ABI.md CMakeLists.txt Makefile.am Makefile.inc curl_easy_cleanup.md curl_easy_duphandle.md curl_easy_escape.md curl_easy_getinfo.md curl_easy_header.md curl_easy_init.md curl_easy_nextheader.md curl_easy_option_by_id.md curl_easy_option_by_name.md curl_easy_option_next.md curl_easy_pause.md curl_easy_perform.md curl_easy_recv.md curl_easy_reset.md curl_easy_send.md curl_easy_setopt.md curl_easy_ssls_export.md curl_easy_ssls_import.md curl_easy_strerror.md curl_easy_unescape.md curl_easy_upkeep.md curl_escape.md curl_formadd.md curl_formfree.md curl_formget.md curl_free.md curl_getdate.md curl_getenv.md curl_global_cleanup.md curl_global_init.md curl_global_init_mem.md curl_global_sslset.md curl_global_trace.md curl_mime_addpart.md curl_mime_data.md curl_mime_data_cb.md curl_mime_encoder.md curl_mime_filedata.md curl_mime_filename.md curl_mime_free.md curl_mime_headers.md curl_mime_init.md curl_mime_name.md curl_mime_subparts.md curl_mime_type.md curl_mprintf.md curl_multi_add_handle.md curl_multi_assign.md curl_multi_cleanup.md curl_multi_fdset.md curl_multi_get_handles.md curl_multi_get_offt.md curl_multi_info_read.md curl_multi_init.md curl_multi_notify_disable.md curl_multi_notify_enable.md curl_multi_perform.md curl_multi_poll.md curl_multi_remove_handle.md curl_multi_setopt.md curl_multi_socket.md curl_multi_socket_action.md curl_multi_socket_all.md curl_multi_strerror.md curl_multi_timeout.md curl_multi_wait.md curl_multi_waitfds.md curl_multi_wakeup.md curl_pushheader_byname.md curl_pushheader_bynum.md curl_share_cleanup.md curl_share_init.md curl_share_setopt.md curl_share_strerror.md curl_slist_append.md curl_slist_free_all.md curl_strequal.md curl_strnequal.md curl_unescape.md curl_url.md curl_url_cleanup.md curl_url_dup.md curl_url_get.md curl_url_set.md curl_url_strerror.md curl_version.md curl_version_info.md curl_ws_meta.md curl_ws_recv.md curl_ws_send.md curl_ws_start_frame.md libcurl-easy.md libcurl-env-dbg.md libcurl-env.md libcurl-errors.md libcurl-multi.md libcurl-security.md libcurl-share.md libcurl-thread.md libcurl-tutorial.md libcurl-url.md libcurl-ws.md libcurl.m4 libcurl.md mksymbolsmanpage.pl symbols-in-versions symbols.pl
tests CI.md FILEFORMAT.md HTTP.md TEST-SUITE.md
.gitignore ALTSVC.md BINDINGS.md BUG-BOUNTY.md BUGS.md CIPHERS-TLS12.md CIPHERS.md CMakeLists.txt CODE_OF_CONDUCT.md CODE_REVIEW.md CONTRIBUTE.md CURL-DISABLE.md CURLDOWN.md DEPRECATE.md DISTROS.md EARLY-RELEASE.md ECH.md EXPERIMENTAL.md FAQ.md FEATURES.md GOVERNANCE.md HELP-US.md HISTORY.md HSTS.md HTTP-COOKIES.md HTTP3.md HTTPSRR.md INFRASTRUCTURE.md INSTALL-CMAKE.md INSTALL.md INTERNALS.md IPFS.md KNOWN_BUGS.md KNOWN_RISKS.md MAIL-ETIQUETTE.md MANUAL.md Makefile.am README.md RELEASE-PROCEDURE.md ROADMAP.md RUSTLS.md SECURITY-ADVISORY.md SPONSORS.md SSL-PROBLEMS.md SSLCERTS.md THANKS THANKS-filter TODO.md TheArtOfHttpScripting.md URL-SYNTAX.md VERIFY.md VERSIONS.md VULN-DISCLOSURE-POLICY.md curl-config.md mk-ca-bundle.md options-in-versions runtests.md testcurl.md wcurl.md
include
curl Makefile.am curl.h curlver.h easy.h header.h mprintf.h multi.h options.h stdcheaders.h system.h typecheck-gcc.h urlapi.h websockets.h
Makefile.am README.md
lib
curlx base64.c base64.h basename.c basename.h dynbuf.c dynbuf.h fopen.c fopen.h inet_ntop.c inet_ntop.h inet_pton.c inet_pton.h multibyte.c multibyte.h nonblock.c nonblock.h snprintf.c snprintf.h strcopy.c strcopy.h strdup.c strdup.h strerr.c strerr.h strparse.c strparse.h timediff.c timediff.h timeval.c timeval.h version_win32.c version_win32.h wait.c wait.h warnless.c warnless.h winapi.c winapi.h
vauth cleartext.c cram.c digest.c digest.h digest_sspi.c gsasl.c krb5_gssapi.c krb5_sspi.c ntlm.c ntlm_sspi.c oauth2.c spnego_gssapi.c spnego_sspi.c vauth.c vauth.h
vquic curl_ngtcp2.c curl_ngtcp2.h curl_quiche.c curl_quiche.h vquic-tls.c vquic-tls.h vquic.c vquic.h vquic_int.h
vssh libssh.c libssh2.c ssh.h vssh.c vssh.h
vtls apple.c apple.h cipher_suite.c cipher_suite.h gtls.c gtls.h hostcheck.c hostcheck.h keylog.c keylog.h mbedtls.c mbedtls.h openssl.c openssl.h rustls.c rustls.h schannel.c schannel.h schannel_int.h schannel_verify.c vtls.c vtls.h vtls_int.h vtls_scache.c vtls_scache.h vtls_spack.c vtls_spack.h wolfssl.c wolfssl.h x509asn1.c x509asn1.h
.gitignore CMakeLists.txt Makefile.am Makefile.inc Makefile.soname altsvc.c altsvc.h amigaos.c amigaos.h arpa_telnet.h asyn-ares.c asyn-base.c asyn-thrdd.c asyn.h bufq.c bufq.h bufref.c bufref.h cf-dns.c cf-dns.h cf-h1-proxy.c cf-h1-proxy.h cf-h2-proxy.c cf-h2-proxy.h cf-haproxy.c cf-haproxy.h cf-https-connect.c cf-https-connect.h cf-ip-happy.c cf-ip-happy.h cf-socket.c cf-socket.h cfilters.c cfilters.h config-mac.h config-os400.h config-riscos.h config-win32.h conncache.c conncache.h connect.c connect.h content_encoding.c content_encoding.h cookie.c cookie.h creds.c creds.h cshutdn.c cshutdn.h curl_addrinfo.c curl_addrinfo.h curl_config-cmake.h.in curl_ctype.h curl_endian.c curl_endian.h curl_fnmatch.c curl_fnmatch.h curl_fopen.c curl_fopen.h curl_get_line.c curl_get_line.h curl_gethostname.c curl_gethostname.h curl_gssapi.c curl_gssapi.h curl_hmac.h curl_ldap.h curl_md4.h curl_md5.h curl_memrchr.c curl_memrchr.h curl_ntlm_core.c curl_ntlm_core.h curl_printf.h curl_range.c curl_range.h curl_sasl.c curl_sasl.h curl_setup.h curl_sha256.h curl_sha512_256.c curl_sha512_256.h curl_share.c curl_share.h curl_sspi.c curl_sspi.h curl_threads.c curl_threads.h curl_trc.c curl_trc.h cw-out.c cw-out.h cw-pause.c cw-pause.h dict.c dict.h dllmain.c dnscache.c dnscache.h doh.c doh.h dynhds.c dynhds.h easy.c easy_lock.h easygetopt.c easyif.h easyoptions.c easyoptions.h escape.c escape.h fake_addrinfo.c fake_addrinfo.h file.c file.h fileinfo.c fileinfo.h formdata.c formdata.h ftp-int.h ftp.c ftp.h ftplistparser.c ftplistparser.h functypes.h getenv.c getinfo.c getinfo.h gopher.c gopher.h hash.c hash.h headers.c headers.h hmac.c hostip.c hostip.h hostip4.c hostip6.c hsts.c hsts.h http.c http.h http1.c http1.h http2.c http2.h http_aws_sigv4.c http_aws_sigv4.h http_chunks.c http_chunks.h http_digest.c http_digest.h http_negotiate.c http_negotiate.h http_ntlm.c http_ntlm.h http_proxy.c http_proxy.h httpsrr.c httpsrr.h idn.c idn.h if2ip.c if2ip.h imap.c imap.h ldap.c libcurl.def libcurl.rc libcurl.vers.in llist.c llist.h macos.c macos.h md4.c md5.c memdebug.c mime.c mime.h mprintf.c mqtt.c mqtt.h multi.c multi_ev.c multi_ev.h multi_ntfy.c multi_ntfy.h multihandle.h multiif.h netrc.c netrc.h noproxy.c noproxy.h openldap.c optiontable.pl parsedate.c parsedate.h peer.c peer.h pingpong.c pingpong.h pop3.c pop3.h progress.c progress.h protocol.c protocol.h psl.c psl.h rand.c rand.h ratelimit.c ratelimit.h request.c request.h rtsp.c rtsp.h select.c select.h sendf.c sendf.h setopt.c setopt.h setup-os400.h setup-vms.h setup-win32.h sha256.c sigpipe.h slist.c slist.h smb.c smb.h smtp.c smtp.h sockaddr.h socketpair.c socketpair.h socks.c socks.h socks_gssapi.c socks_sspi.c splay.c splay.h strcase.c strcase.h strequal.c strerror.c strerror.h system_win32.c system_win32.h telnet.c telnet.h tftp.c tftp.h thrdpool.c thrdpool.h thrdqueue.c thrdqueue.h transfer.c transfer.h uint-bset.c uint-bset.h uint-hash.c uint-hash.h uint-spbset.c uint-spbset.h uint-table.c uint-table.h url.c url.h urlapi-int.h urlapi.c urldata.h version.c ws.c ws.h
m4 .gitignore curl-amissl.m4 curl-apple-sectrust.m4 curl-compilers.m4 curl-confopts.m4 curl-functions.m4 curl-gnutls.m4 curl-mbedtls.m4 curl-openssl.m4 curl-override.m4 curl-reentrant.m4 curl-rustls.m4 curl-schannel.m4 curl-sysconfig.m4 curl-wolfssl.m4 xc-am-iface.m4 xc-cc-check.m4 xc-lt-iface.m4 xc-val-flgs.m4 zz40-xc-ovr.m4 zz50-xc-ovr.m4
projects
OS400
rpg-examples HEADERAPI HTTPPOST INMEMORY SIMPLE1 SIMPLE2 SMTPSRCMBR
.checksrc README.OS400 ccsidcurl.c ccsidcurl.h config400.default curl.cmd curl.inc.in curlcl.c curlmain.c initscript.sh make-docs.sh make-include.sh make-lib.sh make-src.sh make-tests.sh makefile.sh os400sys.c os400sys.h
Windows
tmpl .gitattributes README.txt curl-all.sln curl.sln curl.vcxproj curl.vcxproj.filters libcurl.sln libcurl.vcxproj libcurl.vcxproj.filters
.gitignore README.md generate.bat
vms Makefile.am backup_gnv_curl_src.com build_curl-config_script.com build_gnv_curl.com build_gnv_curl_pcsi_desc.com build_gnv_curl_pcsi_text.com build_gnv_curl_release_notes.com build_libcurl_pc.com build_vms.com clean_gnv_curl.com compare_curl_source.com config_h.com curl_crtl_init.c curl_gnv_build_steps.txt curl_release_note_start.txt curl_startup.com curlmsg.h curlmsg.msg curlmsg.sdl curlmsg_vms.h generate_config_vms_h_curl.com generate_vax_transfer.com gnv_conftest.c_first gnv_curl_configure.sh gnv_libcurl_symbols.opt gnv_link_curl.com macro32_exactcase.patch make_gnv_curl_install.sh make_pcsi_curl_kit_name.com pcsi_gnv_curl_file_list.txt pcsi_product_gnv_curl.com readme report_openssl_version.c setup_gnv_curl_build.com stage_curl_install.com vms_eco_level.h
Makefile.am README.md
scripts .checksrc CMakeLists.txt Makefile.am badwords badwords-all badwords.txt cd2cd cd2nroff cdall checksrc-all.pl checksrc.pl cmakelint.sh completion.pl contributors.sh contrithanks.sh coverage.sh delta dmaketgz extract-unit-protos firefox-db2pem.sh installcheck.sh maketgz managen mdlinkcheck mk-ca-bundle.pl mk-unity.pl nroff2cd perlcheck.sh pythonlint.sh randdisable release-notes.pl release-tools.sh schemetable.c singleuse.pl spacecheck.pl top-complexity top-length verify-release wcurl
src
toolx tool_time.c tool_time.h
.checksrc .gitignore CMakeLists.txt Makefile.am Makefile.inc config2setopts.c config2setopts.h curl.rc curlinfo.c mk-file-embed.pl mkhelp.pl slist_wc.c slist_wc.h terminal.c terminal.h tool_cb_dbg.c tool_cb_dbg.h tool_cb_hdr.c tool_cb_hdr.h tool_cb_prg.c tool_cb_prg.h tool_cb_rea.c tool_cb_rea.h tool_cb_see.c tool_cb_see.h tool_cb_soc.c tool_cb_soc.h tool_cb_wrt.c tool_cb_wrt.h tool_cfgable.c tool_cfgable.h tool_dirhie.c tool_dirhie.h tool_doswin.c tool_doswin.h tool_easysrc.c tool_easysrc.h tool_filetime.c tool_filetime.h tool_findfile.c tool_findfile.h tool_formparse.c tool_formparse.h tool_getparam.c tool_getparam.h tool_getpass.c tool_getpass.h tool_help.c tool_help.h tool_helpers.c tool_helpers.h tool_hugehelp.h tool_ipfs.c tool_ipfs.h tool_libinfo.c tool_libinfo.h tool_listhelp.c tool_main.c tool_main.h tool_msgs.c tool_msgs.h tool_operate.c tool_operate.h tool_operhlp.c tool_operhlp.h tool_paramhlp.c tool_paramhlp.h tool_parsecfg.c tool_parsecfg.h tool_progress.c tool_progress.h tool_sdecls.h tool_setopt.c tool_setopt.h tool_setup.h tool_ssls.c tool_ssls.h tool_stderr.c tool_stderr.h tool_urlglob.c tool_urlglob.h tool_util.c tool_util.h tool_version.h tool_vms.c tool_vms.h tool_writeout.c tool_writeout.h tool_writeout_json.c tool_writeout_json.h tool_xattr.c tool_xattr.h var.c var.h
tests
certs .gitignore CMakeLists.txt Makefile.am Makefile.inc genserv.pl srp-verifier-conf srp-verifier-db test-ca.cnf test-ca.prm test-client-cert.prm test-client-eku-only.prm test-localhost-san-first.prm test-localhost-san-last.prm test-localhost.nn.prm test-localhost.prm test-localhost0h.prm
cmake CMakeLists.txt test.c test.cpp test.sh
data .gitignore DISABLED Makefile.am data-xml1 data1400.c data1401.c data1402.c data1403.c data1404.c data1405.c data1406.c data1407.c data1420.c data1461.txt data1463.txt data1465.c data1481.c data1705-1.md data1705-2.md data1705-3.md data1705-4.md data1705-stdout.1 data1706-1.md data1706-2.md data1706-3.md data1706-4.md data1706-stdout.txt data320.html test1 test10 test100 test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 test1008 test1009 test101 test1010 test1011 test1012 test1013 test1014 test1015 test1016 test1017 test1018 test1019 test102 test1020 test1021 test1022 test1023 test1024 test1025 test1026 test1027 test1028 test1029 test103 test1030 test1031 test1032 test1033 test1034 test1035 test1036 test1037 test1038 test1039 test104 test1040 test1041 test1042 test1043 test1044 test1045 test1046 test1047 test1048 test1049 test105 test1050 test1051 test1052 test1053 test1054 test1055 test1056 test1057 test1058 test1059 test106 test1060 test1061 test1062 test1063 test1064 test1065 test1066 test1067 test1068 test1069 test107 test1070 test1071 test1072 test1073 test1074 test1075 test1076 test1077 test1078 test1079 test108 test1080 test1081 test1082 test1083 test1084 test1085 test1086 test1087 test1088 test1089 test109 test1090 test1091 test1092 test1093 test1094 test1095 test1096 test1097 test1098 test1099 test11 test110 test1100 test1101 test1102 test1103 test1104 test1105 test1106 test1107 test1108 test1109 test111 test1110 test1111 test1112 test1113 test1114 test1115 test1116 test1117 test1118 test1119 test112 test1120 test1121 test1122 test1123 test1124 test1125 test1126 test1127 test1128 test1129 test113 test1130 test1131 test1132 test1133 test1134 test1135 test1136 test1137 test1138 test1139 test114 test1140 test1141 test1142 test1143 test1144 test1145 test1146 test1147 test1148 test1149 test115 test1150 test1151 test1152 test1153 test1154 test1155 test1156 test1157 test1158 test1159 test116 test1160 test1161 test1162 test1163 test1164 test1165 test1166 test1167 test1168 test1169 test117 test1170 test1171 test1172 test1173 test1174 test1175 test1176 test1177 test1178 test1179 test118 test1180 test1181 test1182 test1183 test1184 test1185 test1186 test1187 test1188 test1189 test119 test1190 test1191 test1192 test1193 test1194 test1195 test1196 test1197 test1198 test1199 test12 test120 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 test1208 test1209 test121 test1210 test1211 test1212 test1213 test1214 test1215 test1216 test1217 test1218 test1219 test122 test1220 test1221 test1222 test1223 test1224 test1225 test1226 test1227 test1228 test1229 test123 test1230 test1231 test1232 test1233 test1234 test1235 test1236 test1237 test1238 test1239 test124 test1240 test1241 test1242 test1243 test1244 test1245 test1246 test1247 test1248 test1249 test125 test1250 test1251 test1252 test1253 test1254 test1255 test1256 test1257 test1258 test1259 test126 test1260 test1261 test1262 test1263 test1264 test1265 test1266 test1267 test1268 test1269 test127 test1270 test1271 test1272 test1273 test1274 test1275 test1276 test1277 test1278 test1279 test128 test1280 test1281 test1282 test1283 test1284 test1285 test1286 test1287 test1288 test1289 test129 test1290 test1291 test1292 test1293 test1294 test1295 test1296 test1297 test1298 test1299 test13 test130 test1300 test1301 test1302 test1303 test1304 test1305 test1306 test1307 test1308 test1309 test131 test1310 test1311 test1312 test1313 test1314 test1315 test1316 test1317 test1318 test1319 test132 test1320 test1321 test1322 test1323 test1324 test1325 test1326 test1327 test1328 test1329 test133 test1330 test1331 test1332 test1333 test1334 test1335 test1336 test1337 test1338 test1339 test134 test1340 test1341 test1342 test1343 test1344 test1345 test1346 test1347 test1348 test1349 test135 test1350 test1351 test1352 test1353 test1354 test1355 test1356 test1357 test1358 test1359 test136 test1360 test1361 test1362 test1363 test1364 test1365 test1366 test1367 test1368 test1369 test137 test1370 test1371 test1372 test1373 test1374 test1375 test1376 test1377 test1378 test1379 test138 test1380 test1381 test1382 test1383 test1384 test1385 test1386 test1387 test1388 test1389 test139 test1390 test1391 test1392 test1393 test1394 test1395 test1396 test1397 test1398 test1399 test14 test140 test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 test1408 test1409 test141 test1410 test1411 test1412 test1413 test1414 test1415 test1416 test1417 test1418 test1419 test142 test1420 test1421 test1422 test1423 test1424 test1425 test1426 test1427 test1428 test1429 test143 test1430 test1431 test1432 test1433 test1434 test1435 test1436 test1437 test1438 test1439 test144 test1440 test1441 test1442 test1443 test1444 test1445 test1446 test1447 test1448 test1449 test145 test1450 test1451 test1452 test1453 test1454 test1455 test1456 test1457 test1458 test1459 test146 test1460 test1461 test1462 test1463 test1464 test1465 test1466 test1467 test1468 test1469 test147 test1470 test1471 test1472 test1473 test1474 test1475 test1476 test1477 test1478 test1479 test148 test1480 test1481 test1482 test1483 test1484 test1485 test1486 test1487 test1488 test1489 test149 test1490 test1491 test1492 test1493 test1494 test1495 test1496 test1497 test1498 test1499 test15 test150 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 test1508 test1509 test151 test1510 test1511 test1512 test1513 test1514 test1515 test1516 test1517 test1518 test1519 test152 test1520 test1521 test1522 test1523 test1524 test1525 test1526 test1527 test1528 test1529 test153 test1530 test1531 test1532 test1533 test1534 test1535 test1536 test1537 test1538 test1539 test154 test1540 test1541 test1542 test1543 test1544 test1545 test1546 test1547 test1548 test1549 test155 test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 test1558 test1559 test156 test1560 test1561 test1562 test1563 test1564 test1565 test1566 test1567 test1568 test1569 test157 test1570 test1571 test1572 test1573 test1574 test1575 test1576 test1577 test1578 test1579 test158 test1580 test1581 test1582 test1583 test1584 test1585 test1586 test1587 test1588 test1589 test159 test1590 test1591 test1592 test1593 test1594 test1595 test1596 test1597 test1598 test1599 test16 test160 test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 test1608 test1609 test161 test1610 test1611 test1612 test1613 test1614 test1615 test1616 test1617 test1618 test1619 test162 test1620 test1621 test1622 test1623 test1624 test1625 test1626 test1627 test1628 test1629 test163 test1630 test1631 test1632 test1633 test1634 test1635 test1636 test1637 test1638 test1639 test164 test1640 test1641 test1642 test1643 test1644 test1645 test165 test1650 test1651 test1652 test1653 test1654 test1655 test1656 test1657 test1658 test1659 test166 test1660 test1661 test1662 test1663 test1664 test1665 test1666 test1667 test1668 test1669 test167 test1670 test1671 test1672 test1673 test1674 test1675 test1676 test168 test1680 test1681 test1682 test1683 test1684 test1685 test169 test17 test170 test1700 test1701 test1702 test1703 test1704 test1705 test1706 test1707 test1708 test1709 test171 test1710 test1711 test1712 test1713 test1714 test1715 test172 test1720 test1721 test173 test174 test175 test176 test177 test178 test179 test18 test180 test1800 test1801 test1802 test181 test182 test183 test184 test1847 test1848 test1849 test185 test1850 test1851 test186 test187 test188 test189 test19 test190 test1900 test1901 test1902 test1903 test1904 test1905 test1906 test1907 test1908 test1909 test191 test1910 test1911 test1912 test1913 test1914 test1915 test1916 test1917 test1918 test1919 test192 test1920 test1921 test193 test1933 test1934 test1935 test1936 test1937 test1938 test1939 test194 test1940 test1941 test1942 test1943 test1944 test1945 test1946 test1947 test1948 test195 test1955 test1956 test1957 test1958 test1959 test196 test1960 test1964 test1965 test1966 test197 test1970 test1971 test1972 test1973 test1974 test1975 test1976 test1977 test1978 test1979 test198 test1980 test1981 test1982 test1983 test1984 test199 test2 test20 test200 test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 test2008 test2009 test201 test2010 test2011 test2012 test2013 test2014 test202 test2023 test2024 test2025 test2026 test2027 test2028 test2029 test203 test2030 test2031 test2032 test2033 test2034 test2035 test2037 test2038 test2039 test204 test2040 test2041 test2042 test2043 test2044 test2045 test2046 test2047 test2048 test2049 test205 test2050 test2051 test2052 test2053 test2054 test2055 test2056 test2057 test2058 test2059 test206 test2060 test2061 test2062 test2063 test2064 test2065 test2066 test2067 test2068 test2069 test207 test2070 test2071 test2072 test2073 test2074 test2075 test2076 test2077 test2078 test2079 test208 test2080 test2081 test2082 test2083 test2084 test2085 test2086 test2087 test2088 test2089 test209 test2090 test2091 test2092 test21 test210 test2100 test2101 test2102 test2103 test2104 test211 test212 test213 test214 test215 test216 test217 test218 test219 test22 test220 test2200 test2201 test2202 test2203 test2204 test2205 test2206 test2207 test221 test222 test223 test224 test225 test226 test227 test228 test229 test23 test230 test2300 test2301 test2302 test2303 test2304 test2306 test2307 test2308 test2309 test231 test232 test233 test234 test235 test236 test237 test238 test239 test24 test240 test2400 test2401 test2402 test2403 test2404 test2405 test2406 test2407 test2408 test2409 test241 test2410 test2411 test242 test243 test244 test245 test246 test247 test248 test249 test25 test250 test2500 test2501 test2502 test2503 test2504 test2505 test2506 test251 test252 test253 test254 test255 test256 test257 test258 test259 test26 test260 test2600 test2601 test2602 test2603 test2604 test2605 test261 test262 test263 test264 test265 test266 test267 test268 test269 test27 test270 test2700 test2701 test2702 test2703 test2704 test2705 test2706 test2707 test2708 test2709 test271 test2710 test2711 test2712 test2713 test2714 test2715 test2716 test2717 test2718 test2719 test272 test2720 test2721 test2722 test2723 test273 test274 test275 test276 test277 test278 test279 test28 test280 test281 test282 test283 test284 test285 test286 test287 test288 test289 test29 test290 test291 test292 test293 test294 test295 test296 test297 test298 test299 test3 test30 test300 test3000 test3001 test3002 test3003 test3004 test3005 test3006 test3007 test3008 test3009 test301 test3010 test3011 test3012 test3013 test3014 test3015 test3016 test3017 test3018 test3019 test302 test3020 test3021 test3022 test3023 test3024 test3025 test3026 test3027 test3028 test3029 test303 test3030 test3031 test3032 test3033 test3034 test3035 test3036 test304 test305 test306 test307 test308 test309 test31 test310 test3100 test3101 test3102 test3103 test3104 test3105 test3106 test311 test312 test313 test314 test315 test316 test317 test318 test319 test32 test320 test3200 test3201 test3202 test3203 test3204 test3205 test3206 test3207 test3208 test3209 test321 test3210 test3211 test3212 test3213 test3214 test3215 test3216 test3217 test3218 test3219 test322 test3220 test323 test324 test325 test326 test327 test328 test329 test33 test330 test3300 test3301 test3302 test331 test332 test333 test334 test335 test336 test337 test338 test339 test34 test340 test341 test342 test343 test344 test345 test346 test347 test348 test349 test35 test350 test351 test352 test353 test354 test355 test356 test357 test358 test359 test36 test360 test361 test362 test363 test364 test365 test366 test367 test368 test369 test37 test370 test371 test372 test373 test374 test375 test376 test378 test379 test38 test380 test381 test383 test384 test385 test386 test387 test388 test389 test39 test390 test391 test392 test393 test394 test395 test396 test397 test398 test399 test4 test40 test400 test4000 test4001 test401 test402 test403 test404 test405 test406 test407 test408 test409 test41 test410 test411 test412 test413 test414 test415 test416 test417 test418 test419 test42 test420 test421 test422 test423 test424 test425 test426 test427 test428 test429 test43 test430 test431 test432 test433 test434 test435 test436 test437 test438 test439 test44 test440 test441 test442 test443 test444 test445 test446 test447 test448 test449 test45 test450 test451 test452 test453 test454 test455 test456 test457 test458 test459 test46 test460 test461 test462 test463 test467 test468 test469 test47 test470 test471 test472 test473 test474 test475 test476 test477 test478 test479 test48 test480 test481 test482 test483 test484 test485 test486 test487 test488 test489 test49 test490 test491 test492 test493 test494 test495 test496 test497 test498 test499 test5 test50 test500 test501 test502 test503 test504 test505 test506 test507 test508 test509 test51 test510 test511 test512 test513 test514 test515 test516 test517 test518 test519 test52 test520 test521 test522 test523 test524 test525 test526 test527 test528 test529 test53 test530 test531 test532 test533 test534 test535 test536 test537 test538 test539 test54 test540 test541 test542 test543 test544 test545 test546 test547 test548 test549 test55 test550 test551 test552 test553 test554 test555 test556 test557 test558 test559 test56 test560 test561 test562 test563 test564 test565 test566 test567 test568 test569 test57 test570 test571 test572 test573 test574 test575 test576 test577 test578 test579 test58 test580 test581 test582 test583 test584 test585 test586 test587 test588 test589 test59 test590 test591 test592 test593 test594 test595 test596 test597 test598 test599 test6 test60 test600 test601 test602 test603 test604 test605 test606 test607 test608 test609 test61 test610 test611 test612 test613 test614 test615 test616 test617 test618 test619 test62 test620 test621 test622 test623 test624 test625 test626 test627 test628 test629 test63 test630 test631 test632 test633 test634 test635 test636 test637 test638 test639 test64 test640 test641 test642 test643 test644 test645 test646 test647 test648 test649 test65 test650 test651 test652 test653 test654 test655 test656 test658 test659 test66 test660 test661 test662 test663 test664 test665 test666 test667 test668 test669 test67 test670 test671 test672 test673 test674 test675 test676 test677 test678 test679 test68 test680 test681 test682 test683 test684 test685 test686 test687 test688 test689 test69 test690 test691 test692 test693 test694 test695 test696 test697 test698 test699 test7 test70 test700 test701 test702 test703 test704 test705 test706 test707 test708 test709 test71 test710 test711 test712 test713 test714 test715 test716 test717 test718 test719 test72 test720 test721 test722 test723 test724 test725 test726 test727 test728 test729 test73 test730 test731 test732 test733 test734 test735 test736 test737 test738 test739 test74 test740 test741 test742 test743 test744 test745 test746 test747 test748 test749 test75 test750 test751 test752 test753 test754 test755 test756 test757 test758 test759 test76 test760 test761 test762 test763 test764 test765 test766 test767 test768 test769 test77 test770 test771 test772 test773 test774 test775 test776 test777 test778 test779 test78 test780 test781 test782 test783 test784 test785 test786 test787 test788 test789 test79 test790 test791 test792 test793 test794 test795 test796 test797 test798 test799 test8 test80 test800 test801 test802 test803 test804 test805 test806 test807 test808 test809 test81 test810 test811 test812 test813 test814 test815 test816 test817 test818 test819 test82 test820 test821 test822 test823 test824 test825 test826 test827 test828 test829 test83 test830 test831 test832 test833 test834 test835 test836 test837 test838 test839 test84 test840 test841 test842 test843 test844 test845 test846 test847 test848 test849 test85 test850 test851 test852 test853 test854 test855 test856 test857 test858 test859 test86 test860 test861 test862 test863 test864 test865 test866 test867 test868 test869 test87 test870 test871 test872 test873 test874 test875 test876 test877 test878 test879 test88 test880 test881 test882 test883 test884 test885 test886 test887 test888 test889 test89 test890 test891 test892 test893 test894 test895 test896 test897 test898 test899 test9 test90 test900 test901 test902 test903 test904 test905 test906 test907 test908 test909 test91 test910 test911 test912 test913 test914 test915 test916 test917 test918 test919 test92 test920 test921 test922 test923 test924 test925 test926 test927 test928 test929 test93 test930 test931 test932 test933 test934 test935 test936 test937 test938 test939 test94 test940 test941 test942 test943 test944 test945 test946 test947 test948 test949 test95 test950 test951 test952 test953 test954 test955 test956 test957 test958 test959 test96 test960 test961 test962 test963 test964 test965 test966 test967 test968 test969 test97 test970 test971 test972 test973 test974 test975 test976 test977 test978 test979 test98 test980 test981 test982 test983 test984 test985 test986 test987 test988 test989 test99 test990 test991 test992 test993 test994 test995 test996 test997 test998 test999
http
testenv
mod_curltest .gitignore mod_curltest.c
__init__.py caddy.py certs.py client.py curl.py dante.py dnsd.py env.py httpd.py nghttpx.py ports.py sshd.py vsftpd.py ws_echo_server.py
.gitignore CMakeLists.txt Makefile.am config.ini.in conftest.py requirements.txt scorecard.py test_01_basic.py test_02_download.py test_03_goaway.py test_04_stuttered.py test_05_errors.py test_06_eyeballs.py test_07_upload.py test_08_caddy.py test_09_push.py test_10_proxy.py test_11_unix.py test_12_reuse.py test_13_proxy_auth.py test_14_auth.py test_15_tracing.py test_16_info.py test_17_ssl_use.py test_18_methods.py test_19_shutdown.py test_20_websockets.py test_21_resolve.py test_22_httpsrr.py test_30_vsftpd.py test_31_vsftpds.py test_32_ftps_vsftpd.py test_40_socks.py test_50_scp.py test_51_sftp.py
libtest .gitignore CMakeLists.txt Makefile.am Makefile.inc cli_ftp_upload.c cli_h2_pausing.c cli_h2_serverpush.c cli_h2_upgrade_extreme.c cli_hx_download.c cli_hx_upload.c cli_tls_session_reuse.c cli_upload_pausing.c cli_ws_data.c cli_ws_pingpong.c first.c first.h lib1156.c lib1301.c lib1308.c lib1485.c lib1500.c lib1501.c lib1502.c lib1506.c lib1507.c lib1508.c lib1509.c lib1510.c lib1511.c lib1512.c lib1513.c lib1514.c lib1515.c lib1517.c lib1518.c lib1520.c lib1522.c lib1523.c lib1525.c lib1526.c lib1527.c lib1528.c lib1529.c lib1530.c lib1531.c lib1532.c lib1533.c lib1534.c lib1535.c lib1536.c lib1537.c lib1538.c lib1540.c lib1541.c lib1542.c lib1545.c lib1549.c lib1550.c lib1551.c lib1552.c lib1553.c lib1554.c lib1555.c lib1556.c lib1557.c lib1558.c lib1559.c lib1560.c lib1564.c lib1565.c lib1567.c lib1568.c lib1569.c lib1571.c lib1576.c lib1582.c lib1587.c lib1588.c lib1589.c lib1591.c lib1592.c lib1593.c lib1594.c lib1597.c lib1598.c lib1599.c lib1662.c lib1900.c lib1901.c lib1902.c lib1903.c lib1905.c lib1906.c lib1907.c lib1908.c lib1910.c lib1911.c lib1912.c lib1913.c lib1915.c lib1916.c lib1918.c lib1919.c lib1920.c lib1921.c lib1933.c lib1934.c lib1935.c lib1936.c lib1937.c lib1938.c lib1939.c lib1940.c lib1945.c lib1947.c lib1948.c lib1955.c lib1956.c lib1957.c lib1958.c lib1959.c lib1960.c lib1964.c lib1965.c lib1970.c lib1971.c lib1972.c lib1973.c lib1974.c lib1975.c lib1977.c lib1978.c lib2023.c lib2032.c lib2082.c lib2301.c lib2302.c lib2304.c lib2306.c lib2308.c lib2309.c lib2402.c lib2404.c lib2405.c lib2502.c lib2504.c lib2505.c lib2506.c lib2700.c lib3010.c lib3025.c lib3026.c lib3027.c lib3033.c lib3034.c lib3100.c lib3101.c lib3102.c lib3103.c lib3104.c lib3105.c lib3207.c lib3208.c lib500.c lib501.c lib502.c lib503.c lib504.c lib505.c lib506.c lib507.c lib508.c lib509.c lib510.c lib511.c lib512.c lib513.c lib514.c lib515.c lib516.c lib517.c lib518.c lib519.c lib520.c lib521.c lib523.c lib524.c lib525.c lib526.c lib530.c lib533.c lib536.c lib537.c lib539.c lib540.c lib541.c lib542.c lib543.c lib544.c lib547.c lib549.c lib552.c lib553.c lib554.c lib555.c lib556.c lib557.c lib558.c lib559.c lib560.c lib562.c lib564.c lib566.c lib567.c lib568.c lib569.c lib570.c lib571.c lib572.c lib573.c lib574.c lib575.c lib576.c lib578.c lib579.c lib582.c lib583.c lib586.c lib589.c lib590.c lib591.c lib597.c lib598.c lib599.c lib643.c lib650.c lib651.c lib652.c lib653.c lib654.c lib655.c lib658.c lib659.c lib661.c lib666.c lib667.c lib668.c lib670.c lib674.c lib676.c lib677.c lib678.c lib694.c lib695.c lib751.c lib753.c lib757.c lib758.c lib766.c memptr.c mk-lib1521.pl test1013.pl test1022.pl test307.pl test610.pl test613.pl testtrace.c testtrace.h testutil.c testutil.h unitcheck.h
server .checksrc .gitignore CMakeLists.txt Makefile.am Makefile.inc dnsd.c first.c first.h getpart.c mqttd.c resolve.c rtspd.c sockfilt.c socksd.c sws.c tftpd.c util.c
tunit .gitignore CMakeLists.txt Makefile.am Makefile.inc README.md tool1394.c tool1604.c tool1621.c tool1622.c tool1623.c tool1720.c
unit .gitignore CMakeLists.txt Makefile.am Makefile.inc README.md unit1300.c unit1302.c unit1303.c unit1304.c unit1305.c unit1307.c unit1309.c unit1323.c unit1330.c unit1395.c unit1396.c unit1397.c unit1398.c unit1399.c unit1600.c unit1601.c unit1602.c unit1603.c unit1605.c unit1606.c unit1607.c unit1608.c unit1609.c unit1610.c unit1611.c unit1612.c unit1614.c unit1615.c unit1616.c unit1620.c unit1625.c unit1626.c unit1627.c unit1636.c unit1650.c unit1651.c unit1652.c unit1653.c unit1654.c unit1655.c unit1656.c unit1657.c unit1658.c unit1660.c unit1661.c unit1663.c unit1664.c unit1666.c unit1667.c unit1668.c unit1669.c unit1674.c unit1675.c unit1676.c unit1979.c unit1980.c unit2600.c unit2601.c unit2602.c unit2603.c unit2604.c unit2605.c unit3200.c unit3205.c unit3211.c unit3212.c unit3213.c unit3214.c unit3216.c unit3219.c unit3300.c unit3301.c unit3302.c
.gitignore CMakeLists.txt Makefile.am allversions.pm appveyor.pm azure.pm config.in configurehelp.pm.in devtest.pl dictserver.py directories.pm ech_combos.py ech_tests.sh ftpserver.pl getpart.pm globalconfig.pm http-server.pl http2-server.pl http3-server.pl memanalyze.pl memanalyzer.pm negtelnetserver.py nghttpx.conf pathhelp.pm processhelp.pm requirements.txt rtspserver.pl runner.pm runtests.pl secureserver.pl serverhelp.pm servers.pm smbserver.py sshhelp.pm sshserver.pl test1119.pl test1135.pl test1139.pl test1140.pl test1165.pl test1167.pl test1173.pl test1175.pl test1177.pl test1222.pl test1275.pl test1276.pl test1477.pl test1486.pl test1488.pl test1544.pl test1707.pl test745.pl test971.pl testcurl.pl testutil.pm tftpserver.pl util.py valgrind.pm valgrind.supp
.clang-tidy.yml .dir-locals.el .editorconfig .git-blame-ignore-revs .gitattributes .gitignore .mailmap CHANGES.md CMakeLists.txt COPYING Dockerfile GIT-INFO.md Makefile.am README README.md RELEASE-NOTES REUSE.toml SECURITY.md acinclude.m4 appveyor.sh appveyor.yml configure.ac curl-config.in libcurl.pc.in renovate.json
examples .env config.ini crypto_test.lua env_test.lua fs_example.lua http_server.lua https_test.lua ini_example.lua json.lua log.lua path_fs_example.lua process_example.lua request_download.lua request_test.lua run_all.lua sqlite_example.lua sqlite_http_template.lua stash_test.lua template_test.lua timer.lua websocket.lua
iniparser
.github
ISSUE_TEMPLATE config.yml
workflows disable-pull-requests.yml trigger-gitlab-ci.yml
cmake JoinPaths.cmake config.cmake.in pc.in
example iniexample.c iniwrite.c parse.c twisted-errors.ini twisted-genhuge.py twisted-ofkey.ini twisted-ofval.ini twisted.ini
src dictionary.c dictionary.h iniparser.c iniparser.h
test
ressources
bad_ini ends_well.ini twisted-errors.ini twisted-ofkey.ini twisted-ofval.ini
good_ini empty.ini spaced.ini spaced2.ini twisted.ini
gruezi.ini old.ini quotes.ini utf8.ini
CMakeLists.txt test_dictionary.c test_iniparser.c unity-config.yml unity_config.h
.cmake-format.py .gitignore .gitlab-ci.yml .gitmessage .travis.yml AUTHORS CMakeLists.txt FAQ-en.md FAQ-zhcn.md INSTALL LICENSE README.md compile_commands.json
jinjac
example CMakeLists.txt example.c
jinjac_test_app CMakeLists.txt jinjac_test_app.c
libjinjac
include jinjac.h
src CMakeLists.txt ast.c ast.h block_statement.c block_statement.h buffer.c buffer.h buildin.c buildin.h common.h convert.c convert.h flex_decl.h jfunction.c jfunction.h jinja_expression.l jinja_expression.y jinjac_parse.c jinjac_parse.h jinjac_stream.c jinjac_stream.h jlist.c jlist.h jobject.c jobject.h parameter.c parameter.h str_obj.c str_obj.h trace.c trace.h
CMakeLists.txt
test .gitignore CMakeLists.txt autotest.rb test_01.expected test_01.jinja test_01b.expected test_01b.jinja test_01c.expected test_01c.jinja test_01d.expected test_01d.jinja test_02.expected test_02.jinja test_03.expected test_03.jinja test_04.expected test_04.jinja test_05.expected test_05.jinja test_06.expected test_06.jinja test_07.expected test_07.jinja test_08.expected test_08.jinja test_08b.expected test_08b.jinja test_09.expected test_09.jinja test_10.expected test_10.jinja test_11.expected test_11.jinja test_12.expected test_12.jinja test_13.expected test_13.jinja test_14.expected test_14.jinja test_15.expected test_15.jinja test_16.expected test_16.jinja test_17.expected test_17.jinja test_18.expected test_18.jinja test_18b.expected test_18b.jinja test_18c.expected test_18c.jinja test_19.expected test_19.jinja test_19b.expected test_19b.jinja test_19c.expected test_19c.jinja test_19d.expected test_19d.jinja test_19e.expected test_19e.jinja test_19f.expected test_19f.jinja test_20.expected test_20.jinja test_21.expected test_21.jinja test_22.expected test_22.jinja test_22a.expected test_22a.jinja test_22b.expected test_22b.jinja test_23.expected test_23.jinja test_24.expected test_24.jinja
.gitignore CMakeLists.txt LICENSE.txt README.md build_coverage.sh build_debug.sh build_release.sh cppcheck_analysis.sh
libev Changes LICENSE Makefile Makefile.am Makefile.in README Symbols.ev Symbols.event aclocal.m4 autogen.sh compile config.guess config.h config.h.in config.status config.sub configure configure.ac depcomp ev++.h ev.3 ev.c ev.h ev.pod ev_epoll.c ev_kqueue.c ev_poll.c ev_port.c ev_select.c ev_vars.h ev_win32.c ev_wrap.h event.c event.h install-sh libev.m4 libtool ltmain.sh missing mkinstalldirs stamp-h1
luajit
doc
img contact.png
bluequad-print.css bluequad.css contact.html ext_buffer.html ext_c_api.html ext_ffi.html ext_ffi_api.html ext_ffi_semantics.html ext_ffi_tutorial.html ext_jit.html ext_profiler.html extensions.html install.html luajit.html running.html
dynasm dasm_arm.h dasm_arm.lua dasm_arm64.h dasm_arm64.lua dasm_mips.h dasm_mips.lua dasm_mips64.lua dasm_ppc.h dasm_ppc.lua dasm_proto.h dasm_x64.lua dasm_x86.h dasm_x86.lua dynasm.lua
etc luajit.1 luajit.pc
src
host .gitignore README buildvm.c buildvm.h buildvm_asm.c buildvm_fold.c buildvm_lib.c buildvm_libbc.h buildvm_peobj.c genlibbc.lua genminilua.lua genversion.lua minilua.c
jit .gitignore bc.lua bcsave.lua dis_arm.lua dis_arm64.lua dis_arm64be.lua dis_mips.lua dis_mips64.lua dis_mips64el.lua dis_mips64r6.lua dis_mips64r6el.lua dis_mipsel.lua dis_ppc.lua dis_x64.lua dis_x86.lua dump.lua p.lua v.lua zone.lua
.gitignore Makefile Makefile.dep lauxlib.h lib_aux.c lib_base.c lib_bit.c lib_buffer.c lib_debug.c lib_ffi.c lib_init.c lib_io.c lib_jit.c lib_math.c lib_os.c lib_package.c lib_string.c lib_table.c lj_alloc.c lj_alloc.h lj_api.c lj_arch.h lj_asm.c lj_asm.h lj_asm_arm.h lj_asm_arm64.h lj_asm_mips.h lj_asm_ppc.h lj_asm_x86.h lj_assert.c lj_bc.c lj_bc.h lj_bcdump.h lj_bcread.c lj_bcwrite.c lj_buf.c lj_buf.h lj_carith.c lj_carith.h lj_ccall.c lj_ccall.h lj_ccallback.c lj_ccallback.h lj_cconv.c lj_cconv.h lj_cdata.c lj_cdata.h lj_char.c lj_char.h lj_clib.c lj_clib.h lj_cparse.c lj_cparse.h lj_crecord.c lj_crecord.h lj_ctype.c lj_ctype.h lj_debug.c lj_debug.h lj_def.h lj_dispatch.c lj_dispatch.h lj_emit_arm.h lj_emit_arm64.h lj_emit_mips.h lj_emit_ppc.h lj_emit_x86.h lj_err.c lj_err.h lj_errmsg.h lj_ff.h lj_ffrecord.c lj_ffrecord.h lj_frame.h lj_func.c lj_func.h lj_gc.c lj_gc.h lj_gdbjit.c lj_gdbjit.h lj_ir.c lj_ir.h lj_ircall.h lj_iropt.h lj_jit.h lj_lex.c lj_lex.h lj_lib.c lj_lib.h lj_load.c lj_mcode.c lj_mcode.h lj_meta.c lj_meta.h lj_obj.c lj_obj.h lj_opt_dce.c lj_opt_fold.c lj_opt_loop.c lj_opt_mem.c lj_opt_narrow.c lj_opt_sink.c lj_opt_split.c lj_parse.c lj_parse.h lj_prng.c lj_prng.h lj_profile.c lj_profile.h lj_record.c lj_record.h lj_serialize.c lj_serialize.h lj_snap.c lj_snap.h lj_state.c lj_state.h lj_str.c lj_str.h lj_strfmt.c lj_strfmt.h lj_strfmt_num.c lj_strscan.c lj_strscan.h lj_tab.c lj_tab.h lj_target.h lj_target_arm.h lj_target_arm64.h lj_target_mips.h lj_target_ppc.h lj_target_x86.h lj_trace.c lj_trace.h lj_traceerr.h lj_udata.c lj_udata.h lj_vm.h lj_vmevent.c lj_vmevent.h lj_vmmath.c ljamalg.c lua.h lua.hpp luaconf.h luajit.c luajit_rolling.h lualib.h msvcbuild.bat nxbuild.bat ps4build.bat ps5build.bat psvitabuild.bat vm_arm.dasc vm_arm64.dasc vm_mips.dasc vm_mips64.dasc vm_ppc.dasc vm_x64.dasc vm_x86.dasc xb1build.bat xedkbuild.bat
.gitattributes .gitignore .relver COPYRIGHT Makefile README
sqlite shell.c sqlite3.c sqlite3.h sqlite3ext.h
wolfssl
.github
ISSUE_TEMPLATE bug_report.yaml other.yaml
actions
install-apt-deps action.yml
scripts
zephyr-4.x external_libc.conf zephyr-test.sh
openssl-ech.sh tls-anvil-test.sh
workflows
disabled haproxy.yml hitch.yml hostap.yml
hostap-files
configs
07c9f183ea744ac04585fb6dd10220c75a5e2e74 hostapd.config tests wpa_supplicant.config
b607d2723e927a3446d89aed813f1aa6068186bb hostapd.config tests wpa_supplicant.config
hostap_2_10 extra.patch hostapd.config tests wpa_supplicant.config
Makefile README dbus-wpa_supplicant.conf
ada.yml arduino.yml async-examples.yml async.yml atecc608-sim.yml bind.yml cmake-autoconf.yml cmake.yml codespell.yml coverity-scan-fixes.yml cryptocb-only.yml curl.yml cyrus-sasl.yml disable-pk-algs.yml docker-Espressif.yml docker-OpenWrt.yml emnet-nonblock.yml fil-c.yml freertos-mem-track.yml gencertbuf.yml grpc.yml haproxy.yml hostap-vm.yml intelasm-c-fallback.yml ipmitool.yml jwt-cpp.yml krb5.yml libspdm.yml libssh2.yml libvncserver.yml linuxkm.yml macos-apple-native-cert-validation.yml mbedtls.sh mbedtls.yml membrowse-comment.yml membrowse-onboard.yml membrowse-report.yml memcached.sh memcached.yml mono.yml mosquitto.yml msmtp.yml msys2.yml multi-arch.yml multi-compiler.yml net-snmp.yml nginx.yml no-malloc.yml no-tls.yml nss.sh nss.yml ntp.yml ocsp.yml openldap.yml openssh.yml openssl-ech.yml opensslcoexist.yml openvpn.yml os-check.yml packaging.yml pam-ipmi.yml pq-all.yml pr-commit-check.yml psk.yml puf.yml python.yml rng-tools.yml rust-wrapper.yml se050-sim.yml smallStackSize.yml socat.yml softhsm.yml sssd.yml stm32-sim.yml stsafe-a120-sim.yml stunnel.yml symbol-prefixes.yml threadx.yml tls-anvil.yml trackmemory.yml watcomc.yml win-csharp-test.yml wolfCrypt-Wconversion.yml wolfboot-integration.yml wolfsm.yml xcode.yml zephyr-4.x.yml zephyr.yml
PULL_REQUEST_TEMPLATE.md SECURITY.md membrowse-targets.json
Docker
OpenWrt Dockerfile README.md runTests.sh
packaging
debian Dockerfile
fedora Dockerfile
wolfCLU Dockerfile README.md
yocto Dockerfile buildAndPush.sh
Dockerfile Dockerfile.cross-compiler README.md buildAndPush.sh include.am run.sh
IDE
ARDUINO
sketches
wolfssl_client README.md
wolfssl_server README.md
wolfssl_version README.md
README.md
Arduino_README_prepend.md README.md include.am keywords.txt library.properties.template wolfssl-arduino.cpp wolfssl-arduino.sh wolfssl.h
AURIX Cpu0_Main.c README.md include.am user_settings.h wolf_main.c
Android Android.bp README.md include.am user_settings.h
CRYPTOCELL README.md include.am main.c user_settings.h
CSBENCH include.am user_settings.h
ECLIPSE
DEOS
deos_wolfssl .options
README.md deos_malloc.c include.am tls_wolfssl.c tls_wolfssl.h user_settings.h
MICRIUM README.md client_wolfssl.c client_wolfssl.h include.am server_wolfssl.c server_wolfssl.h user_settings.h wolfsslRunTests.c
RTTHREAD README.md include.am user_settings.h wolfssl_test.c
SIFIVE README.md include.am
Espressif
ESP-IDF
examples
template
VisualGDB wolfssl_template_IDF_v5.1_ESP32.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h
CMakeLists.txt Kconfig.projbuild component.mk main.c
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp8266
wolfssl_benchmark
VisualGDB wolfssl_benchmark_IDF_v4.4_ESP32.sln wolfssl_benchmark_IDF_v4.4_ESP32.vgdbproj wolfssl_benchmark_IDF_v5_ESP32.sln wolfssl_benchmark_IDF_v5_ESP32.vgdbproj wolfssl_benchmark_IDF_v5_ESP32C3.sln wolfssl_benchmark_IDF_v5_ESP32C3.vgdbproj wolfssl_benchmark_IDF_v5_ESP32S3.sln wolfssl_benchmark_IDF_v5_ESP32S3.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h
CMakeLists.txt Kconfig.projbuild component.mk main.c
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp8266
wolfssl_client
VisualGDB README.md wolfssl_client_IDF_v5_ESP32.sln wolfssl_client_IDF_v5_ESP32.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include client-tls.h main.h time_helper.h wifi_connect.h
CMakeLists.txt Kconfig.projbuild client-tls.c component.mk main.c time_helper.c wifi_connect.c
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_client_ESP8266.vgdbproj
wolfssl_server
VisualGDB README.md wolfssl_server_IDF_v5_ESP32.sln wolfssl_server_IDF_v5_ESP32.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h server-tls.h time_helper.h wifi_connect.h
CMakeLists.txt Kconfig.projbuild component.mk main.c server-tls.c time_helper.c wifi_connect.c
CMakeLists.txt Makefile README.md README_server_sm.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32c2 sdkconfig.defaults.esp8266 wolfssl_server_ESP8266.vgdbproj
wolfssl_test
VisualGDB wolfssl_test-IDF_v5_ESP32.sln wolfssl_test-IDF_v5_ESP32.vgdbproj wolfssl_test-IDF_v5_ESP32C3.sln wolfssl_test-IDF_v5_ESP32C3.vgdbproj wolfssl_test-IDF_v5_ESP32C6.sln wolfssl_test-IDF_v5_ESP32C6.vgdbproj wolfssl_test_IDF_v5_ESP32S3.sln wolfssl_test_IDF_v5_ESP32S3.vgdbproj
components
wolfssl
include user_settings.h
CMakeLists.txt Kconfig README.md component.mk
main
include main.h
CMakeLists.txt Kconfig.projbuild component.mk main.c
CMakeLists.txt Makefile README.md partitions_singleapp_large.csv sdkconfig.defaults sdkconfig.defaults.esp32 sdkconfig.defaults.esp32c3 sdkconfig.defaults.esp32c6 sdkconfig.defaults.esp32h2 sdkconfig.defaults.esp32s2 sdkconfig.defaults.esp32s3 sdkconfig.defaults.esp8266 testAll.sh testMonitor.sh wolfssl_test_ESP8266.sln wolfssl_test_ESP8266.vgdbproj
wolfssl_test_idf
VisualGDB VisualGDB_wolfssl_test_idf.sln VisualGDB_wolfssl_test_idf.vgdbproj
main CMakeLists.txt Kconfig.projbuild component.mk main.c main_wip.c.ex time_helper.c time_helper.h
CMakeLists.txt Kconfig.projbuild README.md component.mk sdkconfig.defaults
README.md
libs CMakeLists.txt README.md component.mk tigard.cfg
test CMakeLists.txt README.md component.mk test_wolfssl.c
README.md README_32se.md UPDATE.md compileAllExamples.sh dummy_config_h dummy_test_paths.h setup.sh setup_win.bat user_settings.h
README.md include.am
GCC-ARM
Header user_settings.h
Source armtarget.c benchmark_main.c test_main.c tls_client.c tls_server.c wolf_main.c
Makefile Makefile.bench Makefile.client Makefile.common Makefile.server Makefile.static Makefile.test README.md include.am linker.ld linker_fips.ld
Gaisler-BCC README.md include.am
HEXAGON
DSP Makefile wolfssl_dsp.idl
Makefile README.md build.sh ecc-verify-benchmark.c ecc-verify.c include.am user_settings.h
HEXIWEAR
wolfSSL_HW .cwGeneratedFileSetLog user_settings.h
IAR-EWARM
Projects
benchmark benchmark-main.c current_time.c wolfCrypt-benchmark.ewd wolfCrypt-benchmark.ewp
common minimum-startup.c wolfssl.icf
lib wolfSSL-Lib.ewd wolfSSL-Lib.ewp
test test-main.c wolfCrypt-test.ewd wolfCrypt-test.ewp
user_settings.h wolfssl.eww
embOS
SAMV71_XULT
embOS_SAMV71_XULT_Linker_Script samv71q21_wolfssl.icf
embOS_SAMV71_XULT_user_settings user_settings.h user_settings_simple_example.h user_settings_verbose_example.h
embOS_wolfcrypt_benchmark_SAMV71_XULT
Application runBenchmarks.c
README_wolfcrypt_benchmark wolfcrypt_benchmark.ewd wolfcrypt_benchmark.ewp
embOS_wolfcrypt_lib_SAMV71_XULT README_wolfcrypt_lib wolfcrypt_lib.ewd wolfcrypt_lib.ewp
embOS_wolfcrypt_test_SAMV71_XULT
Application runWolfcryptTests.c
README_wolfcrypt_test wolfcrypt_test.ewd wolfcrypt_test.ewp
README_SAMV71
custom_port
custom_port_Linker_Script samv71q21_wolfssl.icf
custom_port_user_settings user_settings.h
wolfcrypt_benchmark_custom_port
Application runBenchmarks.c
wolfcrypt_test_custom_port
Application runWolfcryptTests.c
README_custom_port
extract_trial_here README_extract_trial_here
README
.gitignore README
IAR-MSP430 Makefile README.md include.am main.c user_settings.h
INTIME-RTOS Makefile README.md include.am libwolfssl.c libwolfssl.vcxproj user_settings.h wolfExamples.c wolfExamples.h wolfExamples.sln wolfExamples.vcxproj wolfssl-lib.sln wolfssl-lib.vcxproj
Infineon README.md include.am user_settings.h
KDS
config user_settings.h
include.am
LINUX-SGX README.md build.sh clean.sh include.am sgx_t_static.mk
LPCXPRESSO
lib_wolfssl lpc_18xx_port.c user_settings.h
wolf_example
src lpc_18xx_startup.c wolfssl_example.c
readme.txt
README.md
M68K
benchmark Makefile main.cpp
testwolfcrypt Makefile main.cpp
Makefile README.md include.am user_settings.h
MCUEXPRESSO
RT1170 fsl_caam_c.patch fsl_caam_h.patch user_settings.h
benchmark
source run_benchmark.c
wolfssl liblinks.xml
README.md include.am user_settings.h wolfcrypt_test.c
MDK-ARM
LPC43xx time-LCP43xx.c
MDK-ARM
wolfSSL Retarget.c cert_data.c cert_data.h config-BARE-METAL.h config-FS.h config-RTX-TCP-FS.h config-WOLFLIB.h main.c shell.c time-CortexM3-4.c time-dummy.c wolfssl_MDK_ARM.c wolfssl_MDK_ARM.h
STM32F2xx_StdPeriph_Lib time-STM32F2xx.c
MDK5-ARM
Conf user_settings.h
Inc wolfssl_MDK_ARM.h
Projects
CryptBenchmark Abstract.txt CryptBenchmark.sct CryptBenchmark.uvoptx CryptBenchmark.uvprojx main.c
CryptTest Abstract.txt CryptTest.sct CryptTest.uvoptx CryptTest.uvprojx main.c
EchoClient Abstract.txt EchoClient.uvoptx EchoClient.uvprojx main.c wolfssl-link.sct
EchoServer Abstract.txt EchoServer.uvoptx EchoServer.uvprojx main.c wolfssl-link.sct
SimpleClient Abstract.txt SimpleClient.uvoptx SimpleClient.uvprojx main.c wolfssl-link.sct
SimpleServer Abstract.txt SimpleServer.uvoptx SimpleServer.uvprojx main.c wolfssl-link.sct
wolfSSL-Full Abstract.txt main.c shell.c time-CortexM3-4.c wolfsslFull.uvoptx wolfsslFull.uvprojx
wolfSSL-Lib Abstract.txt wolfSSL-Lib.uvoptx wolfSSL-Lib.uvprojx
Src ssl-dummy.c
README.md include.am
MPLABX16
wolfcrypt_test.X
nbproject
private configurations.xml private.xml
configurations.xml include.am project.xml
Makefile
wolfssl.X
nbproject configurations.xml include.am project.xml
Makefile
README.md include.am main.c user_settings.h
MQX Makefile README-jp.md README.md client-tls.c include.am server-tls.c user_config.h user_settings.h
MSVS-2019-AZSPHERE
client client.c client.h
server server.c server.h
shared util.h
wolfssl_new_azsphere
HardwareDefinitions
avnet_mt3620_sk
inc
hw template_appliance.h
template_appliance.json
mt3620_rdb
inc
hw template_appliance.h
template_appliance.json
seeed_mt3620_mdb
inc
hw template_appliance.h
template_appliance.json
.gitignore CMakeLists.txt CMakeSettings.json app_manifest.json applibs_versions.h launch.vs.json main.c
README.md include.am user_settings.h
MYSQL CMakeLists_wolfCrypt.txt CMakeLists_wolfSSL.txt do.sh
NDS README.md
NETOS Makefile.wolfcrypt.inc README.md include.am user_settings.h user_settings.h-cert2425 user_settings.h-cert3389 wolfssl_netos_custom.c
OPENSTM32 README.md
PlatformIO
examples
wolfssl_benchmark
include README main.h
lib README
src CMakeLists.txt main.c
test README
CMakeLists.txt README.md platformio.ini sdkconfig.defaults wolfssl_benchmark.code-workspace
wolfssl_test
include README main.h
lib README
src CMakeLists.txt main.c
test README
CMakeLists.txt README.md platformio.ini sdkconfig.defaults wolfssl_test.code-workspace
README.md wolfssl_platformio.code-workspace
README.md include.am
QNX
CAAM-DRIVER Makefile
example-client Makefile client-tls.c
example-cmac Makefile cmac-test.c
example-server Makefile server-tls.c
testwolfcrypt Makefile
wolfssl Makefile user_settings.h
README.md include.am
RISCV
SIFIVE-HIFIVE1 Makefile README.md include.am main.c user_settings.h
SIFIVE-UNLEASHED README.md include.am
include.am
ROWLEY-CROSSWORKS-ARM Kinetis_FlashPlacement.xml README.md arm_startup.c benchmark_main.c hw.h include.am kinetis_hw.c retarget.c test_main.c user_settings.h wolfssl.hzp wolfssl_ltc.hzp
Renesas
cs+
Projects
common strings.h unistd.h user_settings.h wolfssl_dummy.c
t4_demo README_en.txt README_jp.txt t4_demo.mtpj wolf_client.c wolf_demo.h wolf_main.c wolf_server.c
test test.mtpj test_main.c
wolfssl_lib wolfssl_lib.mtpj
README include.am
e2studio
DK-S7G2
benchmark-template
src app_entry.c
example_server-template
src app_entry.c
wolfcrypttest-template
src app_entry.c
wolfssl-template-project configuration.xml
README.md include.am user_settings.h
Projects
common strings.h unistd.h user_settings.h wolfssl_dummy.c
test
src key_data.c key_data.h test_main.c wolf_client.c wolf_server.c wolfssl_demo.h
tools generate_rsa_keypair.sh genhexbuf.pl rsa_pss_sign.sh
wolfssl
src .gitkeep
wolfcrypt
src .gitkeep
README include.am
RA6M3
benchmark-wolfcrypt
common .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
client-wolfssl
common
src .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
wolfssl_thread_entry.h
common
ra6m3g README.md
src freertos_tcp_port.c
user_settings.h util.h
server-wolfssl
common
src .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
wolfssl_thread_entry.h
test-wolfcrypt
common .gitkeep
script .gitkeep
src wolfssl_thread_entry.c
wolfssl
src .gitkeep
wolfcrypt .gitkeep
README.md README_APRA6M_en.md README_APRA6M_jp.md include.am
RA6M3G README.md
RA6M4
common user_settings.h wolfssl_demo.h
test
key_data key_data.h key_data_sce.c
src
SEGGER_RTT myprint.c
common .gitignore
test_main.c wolf_client.c wolfssl_sce_unit_test.c
test_RA6M4Debug.launch
tools
example_keys generate_SignedCA.sh rsa_private.pem rsa_public.pem
README.md
README.md include.am
RX65N
GR-ROSE
common strings.h unistd.h user_settings.h wolfssl_dummy.c
smc smc.scfg
test
src key_data.c key_data.h test_main.c wolf_client.c wolf_server.c wolfssl_demo.h
test.rcpc test_HardwareDebug.launch
tools
example_keys generate_SignedCA.sh rsa_private.pem rsa_public.pem
README.md
wolfssl wolfssl.rcpc
README_EN.md README_JP.md include.am
RSK
resource section.esi
wolfssl wolfssl.rcpc
wolfssl_demo key_data.c key_data.h user_settings.h wolfssl_demo.c wolfssl_demo.h
InstructionManualForExample_RSK+RX65N-2MB_EN.pdf InstructionManualForExample_RSK+RX65N-2MB_JP.pdf README_EN.md README_JP.md include.am
RX72N
EnvisionKit
Simple
common sectioninfo.esi wolfssl_dummy.c
test
src
client simple_tcp_client.c simple_tls_tsip_client.c
server simple_tcp_server.c simple_tls_server.c
test_main.c wolfssl_simple_demo.h
test.rcpc test.scfg test_HardwareDebug.launch
wolfssl wolfssl.rcpc
README_EN.md README_JP.md
resource section.esi
tools
example_keys generate_SignedCA.sh rsa_private.pem rsa_public.pem
README.md
wolfssl wolfssl.rcpc
wolfssl_demo key_data.c key_data.h user_settings.h wolfssl_demo.c wolfssl_demo.h wolfssl_tsip_unit_test.c
InstructionManualForExample_RX72N_EnvisonKit_EN.pdf InstructionManualForExample_RX72N_EnvisonKit_JP.pdf README_EN.md README_JP.md include.am
RZN2L
common user_settings.h wolfssl_demo.h
test
src
serial_io app_print.c
test wolf_client.c wolf_server.c wolfssl_rsip_unit_test.c
wolfCrypt .gitignore
wolfSSL .gitignore
local_system_init.c rzn2l_tst_thread_entry.c wolfssl_dummy.c
README.md include.am
SK-S7G2
common user_settings.h
wolfssl_lib configuration.xml
.gitignore README.md include.am
STARCORE README.txt include.am starcore_test.c user_settings.h
STM32Cube README.md STM32_Benchmarks.md default_conf.ftl include.am main.c wolfssl_example.c wolfssl_example.h
SimplicityStudio README.md include.am test_wolf.c user_settings.h
TRUESTUDIO
wolfssl user_settings.h
README include.am
VS-ARM README.md include.am user_settings.h wolfssl.sln wolfssl.vcxproj
VS-AZURE-SPHERE
client app_manifest.json client.c client.h client.vcxproj
server app_manifest.json server.c server.h server.vcxproj
shared util.h
wolfcrypt_test app_manifest.json wolfcrypt_test.vcxproj
README.md include.am user_settings.h wolfssl.sln wolfssl.vcxproj
VisualDSP include.am user_settings.h wolf_tasks.c
WICED-STUDIO README include.am user_settings.h
WIN README.txt include.am test.vcxproj user_settings.h user_settings_dtls.h wolfssl-fips.sln wolfssl-fips.vcxproj
WIN-SGX ReadMe.txt include.am wolfSSL_SGX.edl wolfSSL_SGX.sln wolfSSL_SGX.vcxproj
WIN-SRTP-KDF-140-3 README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxproj
WIN10 README.txt include.am resource.h test.vcxproj user_settings.h wolfssl-fips.rc wolfssl-fips.sln wolfssl-fips.vcxproj
WINCE README.md include.am user_settings.h user_settings.h.140-2-deprecated
WORKBENCH README.md include.am
XCODE
Benchmark
wolfBench
Assets.xcassets
AppIcon.appiconset Contents.json
Base.lproj LaunchScreen.storyboard Main.storyboard
AppDelegate.h AppDelegate.m Info.plist ViewController.h ViewController.m main.m
wolfBench.xcodeproj project.pbxproj
include.am
wolfssl-FIPS.xcodeproj project.pbxproj
wolfssl.xcodeproj project.pbxproj
wolfssl_testsuite.xcodeproj project.pbxproj
README.md build-for-i386.sh include.am user_settings.h
XCODE-FIPSv2
macOS-C++
Intel user_settings.h
M1 user_settings.h
include.am user_settings.h
XCODE-FIPSv5 README include.am user_settings.h
XCODE-FIPSv6 README include.am user_settings.h
XilinxSDK
2018_2 lscript.ld
2019_2
wolfCrypt_example
src lscript.ld
wolfCrypt_example_system wolfCrypt_example_system.sprj
2022_1
wolfCrypt_FreeRTOS_example wolfCrypt_FreeRTOS_example.prj
wolfCrypt_FreeRTOS_example_system wolfCrypt_FreeRTOS_example_system.sprj
wolfCrypt_example wolfCrypt_example.prj
wolfCrypt_example_system wolfCrypt_example_system.sprj
.gitignore
README.md bench.sh combine.sh eclipse_formatter_profile.xml graph.sh include.am user_settings.h wolfssl_example.c
apple-universal
wolfssl-multiplatform
wolfssl-multiplatform
Assets.xcassets
AccentColor.colorset Contents.json
AppIcon.appiconset Contents.json
Contents.json
ContentView.swift simple_client_example.c simple_client_example.h wolfssl-multiplatform-Bridging-Header.h wolfssl_multiplatform.entitlements wolfssl_multiplatformApp.swift wolfssl_test_driver.c wolfssl_test_driver.h
wolfssl-multiplatform.xcodeproj project.pbxproj
.gitignore README.md build-wolfssl-framework.sh include.am
iotsafe Makefile README.md ca-cert.c devices.c devices.h include.am main.c memory-tls.c startup.c target.ld user_settings.h
iotsafe-raspberrypi Makefile README.md client-tls13.c include.am main.c
mynewt README.md apps.wolfcrypttest.pkg.yml crypto.wolfssl.pkg.yml crypto.wolfssl.syscfg.yml include.am setup.sh
zephyr README.md include.am
include.am
RTOS
nuttx
wolfssl .gitignore Kconfig Make.defs Makefile README.md setup-wolfssl.sh user_settings.h
include.am
bsdkm Makefile README.md bsdkm_wc_port.h include.am wolfkmod.c wolfkmod_aes.c x86_vecreg.c
certs
1024 ca-cert.der ca-cert.pem ca-key.der ca-key.pem client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der dh1024.der dh1024.pem dsa-pub-1024.pem dsa1024.der dsa1024.pem include.am rsa1024.der server-cert.der server-cert.pem server-key.der server-key.pem
3072 client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der include.am
4096 client-cert.der client-cert.pem client-key.der client-key.pem client-keyPub.der include.am
acert
rsa_pss acert.pem acert_ietf.pem acert_ietf_pubkey.pem acert_pubkey.pem
acert.pem acert_ietf.pem acert_ietf_pubkey.pem acert_pubkey.pem include.am
aia ca-issuers-cert.pem multi-aia-cert.pem overflow-aia-cert.pem
crl
extra-crls ca-int-cert-revoked.pem claim-root.pem crl_critical_entry.pem crlnum_57oct.pem crlnum_64oct.pem general-server-crl.pem large_crlnum.pem large_crlnum2.pem
hash_der 0fdb2da4.r0
hash_pem 0fdb2da4.r0
bad_time_fmt.pem ca-int-ecc.pem ca-int.pem ca-int2-ecc.pem ca-int2.pem caEcc384Crl.pem caEccCrl.der caEccCrl.pem cliCrl.pem client-int-ecc.pem client-int.pem crl.der crl.pem crl.revoked crl2.der crl2.pem crl_reason.pem crl_rsapss.pem eccCliCRL.pem eccSrvCRL.pem gencrls.sh include.am server-goodaltCrl.pem server-goodaltwildCrl.pem server-goodcnCrl.pem server-goodcnwildCrl.pem server-int-ecc.pem server-int.pem wolfssl.cnf
dilithium bench_dilithium_level2_key.der bench_dilithium_level3_key.der bench_dilithium_level5_key.der include.am
ecc bp256r1-key.der bp256r1-key.pem ca-secp256k1-cert.pem ca-secp256k1-key.pem client-bp256r1-cert.der client-bp256r1-cert.pem client-secp256k1-cert.der client-secp256k1-cert.pem genecc.sh include.am secp256k1-key.der secp256k1-key.pem secp256k1-param.pem secp256k1-privkey.der secp256k1-privkey.pem server-bp256r1-cert.der server-bp256r1-cert.pem server-secp256k1-cert.der server-secp256k1-cert.pem server2-secp256k1-cert.der server2-secp256k1-cert.pem wolfssl.cnf wolfssl_384.cnf
ed25519 ca-ed25519-key.der ca-ed25519-key.pem ca-ed25519-priv.der ca-ed25519-priv.pem ca-ed25519.der ca-ed25519.pem client-ed25519-key.der client-ed25519-key.pem client-ed25519-priv.der client-ed25519-priv.pem client-ed25519.der client-ed25519.pem eddsa-ed25519.der eddsa-ed25519.pem gen-ed25519-certs.sh gen-ed25519-keys.sh gen-ed25519.sh include.am root-ed25519-key.der root-ed25519-key.pem root-ed25519-priv.der root-ed25519-priv.pem root-ed25519.der root-ed25519.pem server-ed25519-cert.pem server-ed25519-key.der server-ed25519-key.pem server-ed25519-priv.der server-ed25519-priv.pem server-ed25519.der server-ed25519.pem
ed448 ca-ed448-key.der ca-ed448-key.pem ca-ed448-priv.der ca-ed448-priv.pem ca-ed448.der ca-ed448.pem client-ed448-key.der client-ed448-key.pem client-ed448-priv.der client-ed448-priv.pem client-ed448.der client-ed448.pem gen-ed448-certs.sh gen-ed448-keys.sh include.am root-ed448-key.der root-ed448-key.pem root-ed448-priv.der root-ed448-priv.pem root-ed448.der root-ed448.pem server-ed448-cert.pem server-ed448-key.der server-ed448-key.pem server-ed448-priv.der server-ed448-priv.pem server-ed448.der server-ed448.pem
external DigiCertGlobalRootCA.pem README.txt ca-digicert-ev.pem ca-globalsign-root.pem ca-google-root.pem ca_collection.pem include.am
falcon bench_falcon_level1_key.der bench_falcon_level5_key.der include.am
intermediate
ca_false_intermediate gentestcert.sh int_ca.key server.key test_ca.key test_ca.pem test_int_not_cacert.pem test_sign_bynoca_srv.pem wolfssl_base.conf wolfssl_srv.conf
ca-ecc-bad-aki.der ca-ecc-bad-aki.pem ca-int-cert.der ca-int-cert.pem ca-int-ecc-cert.der ca-int-ecc-cert.pem ca-int-ecc-key.der ca-int-ecc-key.pem ca-int-key.der ca-int-key.pem ca-int2-cert.der ca-int2-cert.pem ca-int2-ecc-cert.der ca-int2-ecc-cert.pem ca-int2-ecc-key.der ca-int2-ecc-key.pem ca-int2-key.der ca-int2-key.pem client-chain-alt-ecc.pem client-chain-alt.pem client-chain-ecc.der client-chain-ecc.pem client-chain.der client-chain.pem client-int-cert.der client-int-cert.pem client-int-ecc-cert.der client-int-ecc-cert.pem genintcerts.sh include.am server-chain-alt-ecc.pem server-chain-alt.pem server-chain-ecc.der server-chain-ecc.pem server-chain-short.pem server-chain.der server-chain.pem server-int-cert.der server-int-cert.pem server-int-ecc-cert.der server-int-ecc-cert.pem
lms bc_hss_L2_H5_W8_root.der bc_hss_L3_H5_W4_root.der bc_lms_chain_ca.der bc_lms_chain_leaf.der bc_lms_native_bc_root.der bc_lms_sha256_h10_w8_root.der bc_lms_sha256_h5_w4_root.der include.am
mldsa README.txt include.am mldsa44-cert.der mldsa44-cert.pem mldsa44-key.pem mldsa44_bare-priv.der mldsa44_bare-seed.der mldsa44_oqskeypair.der mldsa44_priv-only.der mldsa44_pub-spki.der mldsa44_seed-only.der mldsa44_seed-priv.der mldsa65-cert.der mldsa65-cert.pem mldsa65-key.pem mldsa65_bare-priv.der mldsa65_bare-seed.der mldsa65_oqskeypair.der mldsa65_priv-only.der mldsa65_pub-spki.der mldsa65_seed-only.der mldsa65_seed-priv.der mldsa87-cert.der mldsa87-cert.pem mldsa87-key.pem mldsa87_bare-priv.der mldsa87_bare-seed.der mldsa87_oqskeypair.der mldsa87_priv-only.der mldsa87_pub-spki.der mldsa87_seed-only.der mldsa87_seed-priv.der
ocsp imposter-root-ca-cert.der imposter-root-ca-cert.pem imposter-root-ca-key.der imposter-root-ca-key.pem include.am index-ca-and-intermediate-cas.txt index-ca-and-intermediate-cas.txt.attr index-intermediate1-ca-issued-certs.txt index-intermediate1-ca-issued-certs.txt.attr index-intermediate2-ca-issued-certs.txt index-intermediate2-ca-issued-certs.txt.attr index-intermediate3-ca-issued-certs.txt index-intermediate3-ca-issued-certs.txt.attr intermediate1-ca-cert.der intermediate1-ca-cert.pem intermediate1-ca-key.der intermediate1-ca-key.pem intermediate2-ca-cert.der intermediate2-ca-cert.pem intermediate2-ca-key.der intermediate2-ca-key.pem intermediate3-ca-cert.der intermediate3-ca-cert.pem intermediate3-ca-key.der intermediate3-ca-key.pem ocsp-responder-cert.der ocsp-responder-cert.pem ocsp-responder-key.der ocsp-responder-key.pem openssl.cnf renewcerts-for-test.sh renewcerts.sh root-ca-cert.der root-ca-cert.pem root-ca-crl.pem root-ca-key.der root-ca-key.pem server1-cert.der server1-cert.pem server1-chain-noroot.pem server1-key.der server1-key.pem server2-cert.der server2-cert.pem server2-key.der server2-key.pem server3-cert.der server3-cert.pem server3-key.der server3-key.pem server4-cert.der server4-cert.pem server4-key.der server4-key.pem server5-cert.der server5-cert.pem server5-key.der server5-key.pem test-leaf-response.der test-multi-response.der test-response-nointern.der test-response-rsapss.der test-response.der
p521 ca-p521-key.der ca-p521-key.pem ca-p521-priv.der ca-p521-priv.pem ca-p521.der ca-p521.pem client-p521-key.der client-p521-key.pem client-p521-priv.der client-p521-priv.pem client-p521.der client-p521.pem gen-p521-certs.sh gen-p521-keys.sh include.am root-p521-key.der root-p521-key.pem root-p521-priv.der root-p521-priv.pem root-p521.der root-p521.pem server-p521-cert.pem server-p521-key.der server-p521-key.pem server-p521-priv.der server-p521-priv.pem server-p521.der server-p521.pem
renewcerts wolfssl.cnf
rpk client-cert-rpk.der client-ecc-cert-rpk.der include.am server-cert-rpk.der server-ecc-cert-rpk.der
rsapss ca-3072-rsapss-key.der ca-3072-rsapss-key.pem ca-3072-rsapss-priv.der ca-3072-rsapss-priv.pem ca-3072-rsapss.der ca-3072-rsapss.pem ca-rsapss-key.der ca-rsapss-key.pem ca-rsapss-priv.der ca-rsapss-priv.pem ca-rsapss.der ca-rsapss.pem client-3072-rsapss-key.der client-3072-rsapss-key.pem client-3072-rsapss-priv.der client-3072-rsapss-priv.pem client-3072-rsapss.der client-3072-rsapss.pem client-rsapss-key.der client-rsapss-key.pem client-rsapss-priv.der client-rsapss-priv.pem client-rsapss.der client-rsapss.pem gen-rsapss-keys.sh include.am renew-rsapss-certs.sh root-3072-rsapss-key.der root-3072-rsapss-key.pem root-3072-rsapss-priv.der root-3072-rsapss-priv.pem root-3072-rsapss.der root-3072-rsapss.pem root-rsapss-key.der root-rsapss-key.pem root-rsapss-priv.der root-rsapss-priv.pem root-rsapss.der root-rsapss.pem server-3072-rsapss-cert.pem server-3072-rsapss-key.der server-3072-rsapss-key.pem server-3072-rsapss-priv.der server-3072-rsapss-priv.pem server-3072-rsapss.der server-3072-rsapss.pem server-mix-rsapss-cert.pem server-rsapss-cert.pem server-rsapss-key.der server-rsapss-key.pem server-rsapss-priv.der server-rsapss-priv.pem server-rsapss.der server-rsapss.pem
sia timestamping-sia-cert.pem
slhdsa bench_slhdsa_sha2_128f_key.der bench_slhdsa_sha2_128s_key.der bench_slhdsa_sha2_192f_key.der bench_slhdsa_sha2_192s_key.der bench_slhdsa_sha2_256f_key.der bench_slhdsa_sha2_256s_key.der bench_slhdsa_shake128f_key.der bench_slhdsa_shake128s_key.der bench_slhdsa_shake192f_key.der bench_slhdsa_shake192s_key.der bench_slhdsa_shake256f_key.der bench_slhdsa_shake256s_key.der client-mldsa44-priv.pem client-mldsa44-sha2.der client-mldsa44-sha2.pem client-mldsa44-shake.der client-mldsa44-shake.pem gen-slhdsa-mldsa-certs.sh include.am root-slhdsa-sha2-128s-priv.der root-slhdsa-sha2-128s-priv.pem root-slhdsa-sha2-128s.der root-slhdsa-sha2-128s.pem root-slhdsa-shake-128s-priv.der root-slhdsa-shake-128s-priv.pem root-slhdsa-shake-128s.der root-slhdsa-shake-128s.pem server-mldsa44-priv.pem server-mldsa44-sha2.der server-mldsa44-sha2.pem server-mldsa44-shake.der server-mldsa44-shake.pem
sm2 ca-sm2-key.der ca-sm2-key.pem ca-sm2-priv.der ca-sm2-priv.pem ca-sm2.der ca-sm2.pem client-sm2-key.der client-sm2-key.pem client-sm2-priv.der client-sm2-priv.pem client-sm2.der client-sm2.pem fix_sm2_spki.py gen-sm2-certs.sh gen-sm2-keys.sh include.am root-sm2-key.der root-sm2-key.pem root-sm2-priv.der root-sm2-priv.pem root-sm2.der root-sm2.pem self-sm2-cert.pem self-sm2-key.pem self-sm2-priv.pem server-sm2-cert.der server-sm2-cert.pem server-sm2-key.der server-sm2-key.pem server-sm2-priv.der server-sm2-priv.pem server-sm2.der server-sm2.pem
statickeys dh-ffdhe2048-params.pem dh-ffdhe2048-pub.der dh-ffdhe2048-pub.pem dh-ffdhe2048.der dh-ffdhe2048.pem ecc-secp256r1.der ecc-secp256r1.pem gen-static.sh include.am x25519-pub.der x25519-pub.pem x25519.der x25519.pem
test
expired expired-ca.der expired-ca.pem expired-cert.der expired-cert.pem
catalog.txt cert-bad-neg-int.der cert-bad-oid.der cert-bad-utf8.der cert-ext-ia.cfg cert-ext-ia.der cert-ext-ia.pem cert-ext-joi.cfg cert-ext-joi.der cert-ext-joi.pem cert-ext-mnc.der cert-ext-multiple.cfg cert-ext-multiple.der cert-ext-multiple.pem cert-ext-nc-combined.der cert-ext-nc-combined.pem cert-ext-nc.cfg cert-ext-nc.der cert-ext-nc.pem cert-ext-ncdns.der cert-ext-ncdns.pem cert-ext-ncip.der cert-ext-ncip.pem cert-ext-ncmixed.der cert-ext-ncmulti.der cert-ext-ncmulti.pem cert-ext-ncrid.der cert-ext-ncrid.pem cert-ext-nct.cfg cert-ext-nct.der cert-ext-nct.pem cert-ext-ndir-exc.cfg cert-ext-ndir-exc.der cert-ext-ndir-exc.pem cert-ext-ndir.cfg cert-ext-ndir.der cert-ext-ndir.pem cert-ext-ns.der cert-over-max-altnames.cfg cert-over-max-altnames.der cert-over-max-altnames.pem cert-over-max-nc.cfg cert-over-max-nc.der cert-over-max-nc.pem client-ecc-cert-ski.hex cn-ip-literal.der cn-ip-wildcard.der crit-cert.pem crit-key.pem dh1024.der dh1024.pem dh512.der dh512.pem digsigku.pem encrypteddata.msg gen-badsig.sh gen-ext-certs.sh gen-testcerts.sh include.am kari-keyid-cms.msg ktri-keyid-cms.msg ossl-trusted-cert.pem server-badaltname.der server-badaltname.pem server-badaltnull.der server-badaltnull.pem server-badcn.der server-badcn.pem server-badcnnull.der server-badcnnull.pem server-cert-ecc-badsig.der server-cert-ecc-badsig.pem server-cert-rsa-badsig.der server-cert-rsa-badsig.pem server-duplicate-policy.pem server-garbage.der server-garbage.pem server-goodalt.der server-goodalt.pem server-goodaltwild.der server-goodaltwild.pem server-goodcn.der server-goodcn.pem server-goodcnwild.der server-goodcnwild.pem server-localhost.der server-localhost.pem smime-test-canon.p7s smime-test-multipart-badsig.p7s smime-test-multipart.p7s smime-test.p7s
test-pathlen assemble-chains.sh chainA-ICA1-key.pem chainA-ICA1-pathlen0.pem chainA-assembled.pem chainA-entity-key.pem chainA-entity.pem chainB-ICA1-key.pem chainB-ICA1-pathlen0.pem chainB-ICA2-key.pem chainB-ICA2-pathlen1.pem chainB-assembled.pem chainB-entity-key.pem chainB-entity.pem chainC-ICA1-key.pem chainC-ICA1-pathlen1.pem chainC-assembled.pem chainC-entity-key.pem chainC-entity.pem chainD-ICA1-key.pem chainD-ICA1-pathlen127.pem chainD-assembled.pem chainD-entity-key.pem chainD-entity.pem chainE-ICA1-key.pem chainE-ICA1-pathlen128.pem chainE-assembled.pem chainE-entity-key.pem chainE-entity.pem chainF-ICA1-key.pem chainF-ICA1-pathlen1.pem chainF-ICA2-key.pem chainF-ICA2-pathlen0.pem chainF-assembled.pem chainF-entity-key.pem chainF-entity.pem chainG-ICA1-key.pem chainG-ICA1-pathlen0.pem chainG-ICA2-key.pem chainG-ICA2-pathlen1.pem chainG-ICA3-key.pem chainG-ICA3-pathlen99.pem chainG-ICA4-key.pem chainG-ICA4-pathlen5.pem chainG-ICA5-key.pem chainG-ICA5-pathlen20.pem chainG-ICA6-key.pem chainG-ICA6-pathlen10.pem chainG-ICA7-key.pem chainG-ICA7-pathlen100.pem chainG-assembled.pem chainG-entity-key.pem chainG-entity.pem chainH-ICA1-key.pem chainH-ICA1-pathlen0.pem chainH-ICA2-key.pem chainH-ICA2-pathlen2.pem chainH-ICA3-key.pem chainH-ICA3-pathlen2.pem chainH-ICA4-key.pem chainH-ICA4-pathlen2.pem chainH-assembled.pem chainH-entity-key.pem chainH-entity.pem chainI-ICA1-key.pem chainI-ICA1-no_pathlen.pem chainI-ICA2-key.pem chainI-ICA2-no_pathlen.pem chainI-ICA3-key.pem chainI-ICA3-pathlen2.pem chainI-assembled.pem chainI-entity-key.pem chainI-entity.pem chainJ-ICA1-key.pem chainJ-ICA1-no_pathlen.pem chainJ-ICA2-key.pem chainJ-ICA2-no_pathlen.pem chainJ-ICA3-key.pem chainJ-ICA3-no_pathlen.pem chainJ-ICA4-key.pem chainJ-ICA4-pathlen2.pem chainJ-assembled.pem chainJ-entity-key.pem chainJ-entity.pem include.am refreshkeys.sh
test-serial0 ee_normal.pem ee_serial0.pem generate_certs.sh include.am intermediate_serial0.pem root_serial0.pem root_serial0_key.pem selfsigned_nonca_serial0.pem
xmss bc_xmss_chain_ca.der bc_xmss_chain_leaf.der bc_xmss_sha2_10_256_root.der bc_xmss_sha2_16_256_root.der bc_xmssmt_sha2_20_2_256_root.der bc_xmssmt_sha2_20_4_256_root.der bc_xmssmt_sha2_40_8_256_root.der include.am
ca-cert-chain.der ca-cert.der ca-cert.pem ca-ecc-cert.der ca-ecc-cert.pem ca-ecc-key.der ca-ecc-key.pem ca-ecc384-cert.der ca-ecc384-cert.pem ca-ecc384-key.der ca-ecc384-key.pem ca-key-pkcs8-attribute.der ca-key.der ca-key.pem check_dates.sh client-absolute-urn.pem client-ca-cert.der client-ca-cert.pem client-ca.pem client-cert-ext.der client-cert-ext.pem client-cert.der client-cert.pem client-crl-dist.der client-crl-dist.pem client-ecc-ca-cert.der client-ecc-ca-cert.pem client-ecc-cert.der client-ecc-cert.pem client-ecc384-cert.der client-ecc384-cert.pem client-ecc384-key.der client-ecc384-key.pem client-key.der client-key.pem client-keyEnc.pem client-keyPub.der client-keyPub.pem client-relative-uri.pem client-uri-cert.pem csr.attr.der csr.dsa.der csr.dsa.pem csr.ext.der csr.signed.der dh-priv-2048.der dh-priv-2048.pem dh-pub-2048.der dh-pub-2048.pem dh-pubkey-2048.der dh2048.der dh2048.pem dh3072.der dh3072.pem dh4096.der dh4096.pem dsa-pubkey-2048.der dsa2048.der dsa2048.pem dsa3072.der dsaparams.der dsaparams.pem ecc-client-key.der ecc-client-key.pem ecc-client-keyPub.der ecc-client-keyPub.pem ecc-key-comp.pem ecc-keyPkcs8.der ecc-keyPkcs8.pem ecc-keyPkcs8Enc.der ecc-keyPkcs8Enc.pem ecc-keyPub.der ecc-keyPub.pem ecc-params.der ecc-params.pem ecc-privOnlyCert.pem ecc-privOnlyKey.pem ecc-privkey.der ecc-privkey.pem ecc-privkeyPkcs8.der ecc-privkeyPkcs8.pem ecc-rsa-server.p12 empty-issuer-cert.pem entity-no-ca-bool-cert.pem entity-no-ca-bool-key.pem fpki-cert.der fpki-certpol-cert.der gen_revoked.sh include.am renewcerts.sh rid-cert.der rsa-pub-2048.pem rsa2048.der rsa3072.der server-cert-chain.der server-cert.der server-cert.pem server-ecc-comp.der server-ecc-comp.pem server-ecc-rsa.der server-ecc-rsa.pem server-ecc-self.der server-ecc-self.pem server-ecc.der server-ecc.pem server-ecc384-cert.der server-ecc384-cert.pem server-ecc384-key.der server-ecc384-key.pem server-key.der server-key.pem server-keyEnc.pem server-keyPkcs8.der server-keyPkcs8.pem server-keyPkcs8Enc.der server-keyPkcs8Enc.pem server-keyPkcs8Enc12.pem server-keyPkcs8Enc2.pem server-keyPub.der server-keyPub.pem server-revoked-cert.pem server-revoked-key.pem taoCert.txt test-ber-exp02-05-2022.p7b test-degenerate.p7b test-multiple-recipients.p7b test-servercert-rc2.p12 test-servercert.p12 test-stream-dec.p7b test-stream-sign.p7b wolfssl-website-ca.pem x942dh2048.der x942dh2048.pem
cmake
consumer CMakeLists.txt README.md main.c
modules FindARIA.cmake FindOQS.cmake
Config.cmake.in README.md config.in functions.cmake include.am options.h.in wolfssl-config-version.cmake.in wolfssl-targets.cmake.in
debian
source format
changelog.in control.in copyright include.am libwolfssl-dev.install libwolfssl.install rules.in
doc
dox_comments
header_files aes.h arc4.h ascon.h asn.h asn_public.h blake2.h bn.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cryptocb.h curve25519.h curve448.h des3.h dh.h doxygen_groups.h doxygen_pages.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h evp.h hash.h hmac.h iotsafe.h kdf.h logging.h md2.h md4.h md5.h memory.h ocsp.h pem.h pkcs11.h pkcs7.h poly1305.h psa.h puf.h pwdbased.h quic.h random.h ripemd.h rsa.h sakke.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h srp.h ssl.h tfm.h types.h wc_encrypt.h wc_port.h wc_she.h wc_slhdsa.h wolfio.h
header_files-ja aes.h arc4.h ascon.h asn.h asn_public.h blake2.h bn.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cryptocb.h curve25519.h curve448.h des3.h dh.h doxygen_groups.h doxygen_pages.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h evp.h hash.h hmac.h iotsafe.h kdf.h logging.h md2.h md4.h md5.h memory.h ocsp.h pem.h pkcs11.h pkcs7.h poly1305.h psa.h pwdbased.h quic.h random.h ripemd.h rsa.h sakke.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h srp.h ssl.h tfm.h types.h wc_encrypt.h wc_port.h wolfio.h
formats
html
html_changes
search search.css search.js
customdoxygen.css doxygen.css menu.js menudata.js tabs.css
Doxyfile footer.html header.html mainpage.dox
pdf Doxyfile header.tex
images wolfssl_logo.png
QUIC.md README.txt README_DOXYGEN check_api.sh generate_documentation.sh include.am
examples
asn1 asn1.c dumpasn1.cfg gen_oid_names.rb include.am oid_names.h
async Makefile README.md async_client.c async_server.c async_tls.c async_tls.h include.am user_settings.h
benchmark include.am tls_bench.c tls_bench.h
client client.c client.h client.sln client.vcproj client.vcxproj include.am
configs README.md include.am user_settings_EBSnet.h user_settings_all.h user_settings_arduino.h user_settings_baremetal.h user_settings_ca.h user_settings_curve25519nonblock.h user_settings_dtls13.h user_settings_eccnonblock.h user_settings_espressif.h user_settings_fipsv2.h user_settings_fipsv5.h user_settings_min_ecc.h user_settings_openssl_compat.h user_settings_pkcs7.h user_settings_platformio.h user_settings_pq.h user_settings_rsa_only.h user_settings_stm32.h user_settings_template.h user_settings_tls12.h user_settings_tls13.h user_settings_wolfboot_keytools.h user_settings_wolfssh.h user_settings_wolftpm.h
crypto_policies
default wolfssl.txt
future wolfssl.txt
legacy wolfssl.txt
echoclient echoclient.c echoclient.h echoclient.sln echoclient.vcproj echoclient.vcxproj include.am quit
echoserver echoserver.c echoserver.h echoserver.sln echoserver.vcproj echoserver.vcxproj include.am
ocsp_responder include.am ocsp_responder.c ocsp_responder.h
pem include.am pem.c
sctp include.am sctp-client-dtls.c sctp-client.c sctp-server-dtls.c sctp-server.c
server include.am server.c server.h server.sln server.vcproj server.vcxproj
README.md include.am
linuxkm
patches
5.10.17 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v10v17.patch
5.10.236 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v10v236.patch
5.14.0-570.58.1.el9_6 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v14-570v58v1-el9_6.patch
5.15 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v15.patch
5.17 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v17.patch
5.17-ubuntu-jammy-tegra WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-5v17-ubuntu-jammy-tegra.patch
6.1.73 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v1v73.patch
6.12 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v12.patch
6.15 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-6v15.patch
7.0 WOLFSSL_LINUXKM_HAVE_GET_RANDOM_CALLBACKS-7v0.patch
regen-patches.sh
Kbuild Makefile README.md get_thread_size.c include.am linuxkm-fips-hash-wrapper.sh linuxkm-fips-hash.c linuxkm_memory.c linuxkm_memory.h linuxkm_wc_port.h lkcapi_aes_glue.c lkcapi_dh_glue.c lkcapi_ecdh_glue.c lkcapi_ecdsa_glue.c lkcapi_glue.c lkcapi_rsa_glue.c lkcapi_sha_glue.c module_exports.c.template module_hooks.c pie_redirect_table.c wolfcrypt.lds x86_vector_register_glue.c
m4 ax_add_am_macro.m4 ax_am_jobserver.m4 ax_am_macros.m4 ax_append_compile_flags.m4 ax_append_flag.m4 ax_append_link_flags.m4 ax_append_to_file.m4 ax_atomic.m4 ax_bsdkm.m4 ax_check_compile_flag.m4 ax_check_link_flag.m4 ax_compiler_version.m4 ax_count_cpus.m4 ax_create_generic_config.m4 ax_debug.m4 ax_file_escapes.m4 ax_harden_compiler_flags.m4 ax_linuxkm.m4 ax_print_to_file.m4 ax_pthread.m4 ax_require_defined.m4 ax_tls.m4 ax_vcs_checkout.m4 hexversion.m4 lib_socket_nsl.m4 visibility.m4
mcapi
wolfcrypt_mcapi.X
nbproject configurations.xml include.am project.xml
Makefile
wolfcrypt_test.X
nbproject configurations.xml include.am project.xml
Makefile
wolfssl.X
nbproject configurations.xml include.am project.xml
Makefile
zlib.X
nbproject configurations.xml include.am project.xml
Makefile
PIC32MZ-serial.h README crypto.c crypto.h include.am mcapi_test.c user_settings.h
mplabx
wolfcrypt_benchmark.X
nbproject configurations.xml include.am project.xml
Makefile
wolfcrypt_test.X
nbproject configurations.xml include.am project.xml
Makefile
wolfssl.X
nbproject configurations.xml include.am project.xml
Makefile
PIC32MZ-serial.h README benchmark_main.c include.am test_main.c user_settings.h
mqx
util_lib
Sources include.am util.c util.h
wolfcrypt_benchmark
Debugger K70FN1M0.mem init_kinetis.tcl mass_erase_kinetis.tcl
Sources include.am main.c main.h
ReferencedRSESystems.xml wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfcrypt_benchmark_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch
wolfcrypt_test
Debugger K70FN1M0.mem init_kinetis.tcl mass_erase_kinetis.tcl
Sources include.am main.c main.h
ReferencedRSESystems.xml wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfcrypt_test_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch
wolfssl include.am
wolfssl_client
Debugger K70FN1M0.mem init_kinetis.tcl mass_erase_kinetis.tcl
Sources include.am main.c main.h
ReferencedRSESystems.xml wolfssl_client_twrk70f120m_Int_Flash_DDRData_Debug_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_DDRData_Release_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.jlink wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_JTrace.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Debug_PnE_U-MultiLink.launch wolfssl_client_twrk70f120m_Int_Flash_SramData_Release_PnE_U-MultiLink.launch
README
rpm include.am spec.in
scripts
bench bench_functions.sh
aria-cmake-build-test.sh asn1_oid_sum.pl benchmark.test benchmark_compare.sh cleanup_testfiles.sh crl-gen-openssl.test crl-revoked.test dertoc.pl dtls.test dtlscid.test external.test google.test include.am makedistsmall.sh memtest.sh ocsp-responder-openssl-interop.test ocsp-stapling-with-ca-as-responder.test ocsp-stapling-with-wolfssl-responder.test ocsp-stapling.test ocsp-stapling2.test ocsp-stapling_tls13multi.test ocsp.test openssl.test openssl_srtp.test pem.test ping.test pkcallbacks.test psk.test resume.test rsapss.test sniffer-gen.sh sniffer-ipv6.pcap sniffer-static-rsa.pcap sniffer-testsuite.test sniffer-tls12-keylog.out sniffer-tls12-keylog.pcap sniffer-tls12-keylog.sslkeylog sniffer-tls13-dh-resume.pcap sniffer-tls13-dh.pcap sniffer-tls13-ecc-resume.pcap sniffer-tls13-ecc.pcap sniffer-tls13-hrr.pcap sniffer-tls13-keylog.out sniffer-tls13-keylog.pcap sniffer-tls13-keylog.sslkeylog sniffer-tls13-x25519-resume.pcap sniffer-tls13-x25519.pcap stm32l4-v4_0_1_build.sh tls13.test trusted_peer.test unit.test.in user_settings_asm.sh
src bio.c conf.c crl.c dtls.c dtls13.c include.am internal.c keys.c ocsp.c pk.c pk_ec.c pk_rsa.c quic.c sniffer.c ssl.c ssl_api_cert.c ssl_api_crl_ocsp.c ssl_api_pk.c ssl_asn1.c ssl_bn.c ssl_certman.c ssl_crypto.c ssl_ech.c ssl_load.c ssl_misc.c ssl_p7p12.c ssl_sess.c ssl_sk.c tls.c tls13.c wolfio.c x509.c x509_str.c
sslSniffer
sslSnifferTest README_WIN.md include.am snifftest.c sslSniffTest.vcproj sslSniffTest.vcxproj
README.md sslSniffer.vcproj sslSniffer.vcxproj
support gen-debug-trace-error-codes.sh include.am wolfssl.pc.in
tests
api api.h api_decl.h create_ocsp_test_blobs.py include.am test_aes.c test_aes.h test_arc4.c test_arc4.h test_ascon.c test_ascon.h test_ascon_kats.h test_asn.c test_asn.h test_blake2.c test_blake2.h test_camellia.c test_camellia.h test_certman.c test_certman.h test_chacha.c test_chacha.h test_chacha20_poly1305.c test_chacha20_poly1305.h test_cmac.c test_cmac.h test_curve25519.c test_curve25519.h test_curve448.c test_curve448.h test_des3.c test_des3.h test_dh.c test_dh.h test_digest.h test_dsa.c test_dsa.h test_dtls.c test_dtls.h test_ecc.c test_ecc.h test_ed25519.c test_ed25519.h test_ed448.c test_ed448.h test_evp.c test_evp.h test_evp_cipher.c test_evp_cipher.h test_evp_digest.c test_evp_digest.h test_evp_pkey.c test_evp_pkey.h test_hash.c test_hash.h test_hmac.c test_hmac.h test_md2.c test_md2.h test_md4.c test_md4.h test_md5.c test_md5.h test_mldsa.c test_mldsa.h test_mlkem.c test_mlkem.h test_ocsp.c test_ocsp.h test_ocsp_test_blobs.h test_ossl_asn1.c test_ossl_asn1.h test_ossl_bio.c test_ossl_bio.h test_ossl_bn.c test_ossl_bn.h test_ossl_cipher.c test_ossl_cipher.h test_ossl_dgst.c test_ossl_dgst.h test_ossl_dh.c test_ossl_dh.h test_ossl_dsa.c test_ossl_dsa.h test_ossl_ec.c test_ossl_ec.h test_ossl_ecx.c test_ossl_ecx.h test_ossl_mac.c test_ossl_mac.h test_ossl_obj.c test_ossl_obj.h test_ossl_p7p12.c test_ossl_p7p12.h test_ossl_pem.c test_ossl_pem.h test_ossl_rand.c test_ossl_rand.h test_ossl_rsa.c test_ossl_rsa.h test_ossl_sk.c test_ossl_sk.h test_ossl_x509.c test_ossl_x509.h test_ossl_x509_acert.c test_ossl_x509_acert.h test_ossl_x509_crypto.c test_ossl_x509_crypto.h test_ossl_x509_ext.c test_ossl_x509_ext.h test_ossl_x509_info.c test_ossl_x509_info.h test_ossl_x509_io.c test_ossl_x509_io.h test_ossl_x509_lu.c test_ossl_x509_lu.h test_ossl_x509_name.c test_ossl_x509_name.h test_ossl_x509_pk.c test_ossl_x509_pk.h test_ossl_x509_str.c test_ossl_x509_str.h test_ossl_x509_vp.c test_ossl_x509_vp.h test_pkcs12.c test_pkcs12.h test_pkcs7.c test_pkcs7.h test_poly1305.c test_poly1305.h test_random.c test_random.h test_rc2.c test_rc2.h test_ripemd.c test_ripemd.h test_rsa.c test_rsa.h test_sha.c test_sha.h test_sha256.c test_sha256.h test_sha3.c test_sha3.h test_sha512.c test_sha512.h test_she.c test_she.h test_signature.c test_signature.h test_slhdsa.c test_slhdsa.h test_sm2.c test_sm2.h test_sm3.c test_sm3.h test_sm4.c test_sm4.h test_tls.c test_tls.h test_tls13.c test_tls13.h test_tls_ext.c test_tls_ext.h test_wc_encrypt.c test_wc_encrypt.h test_wolfmath.c test_wolfmath.h test_x509.c test_x509.h
emnet
IP IP.h
Makefile emnet_nonblock_test.c emnet_shim.c
freertos-mem-track-repro FreeRTOS.h repro.c run.sh semphr.h task.h user_settings.h
swdev .gitignore Makefile README.md swdev.c swdev.h swdev_loader.c swdev_loader.h user_settings.h
CONF_FILES_README.md NCONF_test.cnf README TXT_DB.txt api.c include.am quic.c srp.c suites.c test-altchains.conf test-chains.conf test-dhprime.conf test-dtls-downgrade.conf test-dtls-fails-cipher.conf test-dtls-fails.conf test-dtls-group.conf test-dtls-mtu.conf test-dtls-reneg-client.conf test-dtls-reneg-server.conf test-dtls-resume.conf test-dtls-sha2.conf test-dtls-srtp-fails.conf test-dtls-srtp.conf test-dtls.conf test-dtls13-cid.conf test-dtls13-downgrade-fails.conf test-dtls13-downgrade.conf test-dtls13-pq-hybrid-extra-frag.conf test-dtls13-pq-hybrid-extra.conf test-dtls13-pq-hybrid-frag.conf test-dtls13-pq-standalone-frag.conf test-dtls13-pq-standalone.conf test-dtls13-psk.conf test-dtls13.conf test-ecc-cust-curves.conf test-ed25519.conf test-ed448.conf test-enckeys.conf test-fails.conf test-maxfrag-dtls.conf test-maxfrag.conf test-p521.conf test-psk-no-id-sha2.conf test-psk-no-id.conf test-psk.conf test-rsapss.conf test-sctp-sha2.conf test-sctp.conf test-sha2.conf test-sig.conf test-sm2.conf test-tls-downgrade.conf test-tls13-down.conf test-tls13-ecc.conf test-tls13-pq-hybrid-extra.conf test-tls13-pq-hybrid.conf test-tls13-pq-standalone.conf test-tls13-psk-certs.conf test-tls13-psk.conf test-tls13-slhdsa-fail.conf test-tls13-slhdsa-sha2.conf test-tls13-slhdsa-shake.conf test-tls13.conf test-trustpeer.conf test.conf unit.c unit.h utils.c utils.h w64wrapper.c
testsuite include.am testsuite.c testsuite.sln testsuite.vcproj testsuite.vcxproj utils.c utils.h
tirtos
packages
ti
net
wolfssl
tests
EK_TM4C1294XL
wolfcrypt
benchmark TM4C1294NC.icf benchmark.cfg main.c package.bld.hide package.xdc
test TM4C1294NC.icf main.c package.bld.hide package.xdc test.cfg
package.bld package.xdc package.xs
.gitignore README include.am products.mak wolfssl.bld wolfssl.mak
wolfcrypt
benchmark README.md benchmark-VS2022.sln benchmark-VS2022.vcxproj benchmark-VS2022.vcxproj.user benchmark.c benchmark.h benchmark.sln benchmark.vcproj benchmark.vcxproj include.am
src
port
Espressif
esp_crt_bundle README.md cacrt_all.pem cacrt_deprecated.pem cacrt_local.pem esp_crt_bundle.c gen_crt_bundle.py pio_install_cryptography.py
README.md esp32_aes.c esp32_mp.c esp32_sha.c esp32_util.c esp_sdk_mem_lib.c esp_sdk_time_lib.c esp_sdk_wifi_lib.c
Renesas README.md renesas_common.c renesas_fspsm_aes.c renesas_fspsm_rsa.c renesas_fspsm_sha.c renesas_fspsm_util.c renesas_rx64_hw_sha.c renesas_rx64_hw_util.c renesas_tsip_aes.c renesas_tsip_rsa.c renesas_tsip_sha.c renesas_tsip_util.c
af_alg afalg_aes.c afalg_hash.c wc_afalg.c
aria aria-crypt.c aria-cryptocb.c
arm armv8-32-aes-asm.S armv8-32-aes-asm_c.c armv8-32-chacha-asm.S armv8-32-chacha-asm_c.c armv8-32-curve25519.S armv8-32-curve25519_c.c armv8-32-mlkem-asm.S armv8-32-mlkem-asm_c.c armv8-32-poly1305-asm.S armv8-32-poly1305-asm_c.c armv8-32-sha256-asm.S armv8-32-sha256-asm_c.c armv8-32-sha3-asm.S armv8-32-sha3-asm_c.c armv8-32-sha512-asm.S armv8-32-sha512-asm_c.c armv8-aes-asm.S armv8-aes-asm_c.c armv8-aes.c armv8-chacha-asm.S armv8-chacha-asm_c.c armv8-curve25519.S armv8-curve25519_c.c armv8-mlkem-asm.S armv8-mlkem-asm_c.c armv8-poly1305-asm.S armv8-poly1305-asm_c.c armv8-sha256-asm.S armv8-sha256-asm_c.c armv8-sha256.c armv8-sha3-asm.S armv8-sha3-asm_c.c armv8-sha512-asm.S armv8-sha512-asm_c.c armv8-sha512.c cryptoCell.c cryptoCellHash.c thumb2-aes-asm.S thumb2-aes-asm_c.c thumb2-chacha-asm.S thumb2-chacha-asm_c.c thumb2-curve25519.S thumb2-curve25519_c.c thumb2-mlkem-asm.S thumb2-mlkem-asm_c.c thumb2-poly1305-asm.S thumb2-poly1305-asm_c.c thumb2-sha256-asm.S thumb2-sha256-asm_c.c thumb2-sha3-asm.S thumb2-sha3-asm_c.c thumb2-sha512-asm.S thumb2-sha512-asm_c.c
atmel README.md atmel.c
autosar README.md cryif.c crypto.c csm.c include.am test.c
caam README.md caam_aes.c caam_doc.pdf caam_driver.c caam_error.c caam_integrity.c caam_qnx.c caam_sha.c wolfcaam_aes.c wolfcaam_cmac.c wolfcaam_ecdsa.c wolfcaam_fsl_nxp.c wolfcaam_hash.c wolfcaam_hmac.c wolfcaam_init.c wolfcaam_qnx.c wolfcaam_rsa.c wolfcaam_seco.c wolfcaam_x25519.c
cavium README.md README_Octeon.md cavium_nitrox.c cavium_octeon_sync.c
cuda README.md aes-cuda.cu
cypress README.md psoc6_crypto.c
devcrypto README.md devcrypto_aes.c devcrypto_ecdsa.c devcrypto_hash.c devcrypto_hmac.c devcrypto_rsa.c devcrypto_x25519.c wc_devcrypto.c
intel README.md quickassist.c quickassist_mem.c quickassist_sync.c
iotsafe iotsafe.c
kcapi README.md kcapi_aes.c kcapi_dh.c kcapi_ecc.c kcapi_hash.c kcapi_hmac.c kcapi_rsa.c
liboqs liboqs.c
maxim README.md max3266x.c maxq10xx.c
mynewt mynewt_port.c
nxp README.md README_SE050.md casper_port.c dcp_port.c hashcrypt_port.c ksdk_port.c se050_port.c
pic32 pic32mz-crypt.c
ppc32 ppc32-sha256-asm.S ppc32-sha256-asm_c.c ppc32-sha256-asm_cr.c
psa README.md psa.c psa_aes.c psa_hash.c psa_pkcbs.c
riscv riscv-64-aes.c riscv-64-chacha.c riscv-64-poly1305.c riscv-64-sha256.c riscv-64-sha3.c riscv-64-sha512.c
rpi_pico README.md pico.c
silabs README.md silabs_aes.c silabs_ecc.c silabs_hash.c silabs_random.c
st README.md STM32MP13.md STM32MP25.md stm32.c stsafe.c
ti ti-aes.c ti-ccm.c ti-des3.c ti-hash.c
tropicsquare README.md tropic01.c
xilinx xil-aesgcm.c xil-sha3.c xil-versal-glue.c xil-versal-trng.c
nrf51.c
ASN_TEMPLATE.md aes.c aes_asm.S aes_asm.asm aes_gcm_asm.S aes_gcm_asm.asm aes_gcm_x86_asm.S aes_xts_asm.S aes_xts_asm.asm arc4.c ascon.c asm.c asn.c asn_orig.c async.c blake2b.c blake2s.c camellia.c chacha.c chacha20_poly1305.c chacha_asm.S chacha_asm.asm cmac.c coding.c compress.c cpuid.c cryptocb.c curve25519.c curve448.c des3.c dh.c dilithium.c dsa.c ecc.c ecc_fp.c eccsi.c ed25519.c ed448.c error.c evp.c evp_pk.c falcon.c fe_448.c fe_low_mem.c fe_operations.c fe_x25519_128.h fe_x25519_asm.S fp_mont_small.i fp_mul_comba_12.i fp_mul_comba_17.i fp_mul_comba_20.i fp_mul_comba_24.i fp_mul_comba_28.i fp_mul_comba_3.i fp_mul_comba_32.i fp_mul_comba_4.i fp_mul_comba_48.i fp_mul_comba_6.i fp_mul_comba_64.i fp_mul_comba_7.i fp_mul_comba_8.i fp_mul_comba_9.i fp_mul_comba_small_set.i fp_sqr_comba_12.i fp_sqr_comba_17.i fp_sqr_comba_20.i fp_sqr_comba_24.i fp_sqr_comba_28.i fp_sqr_comba_3.i fp_sqr_comba_32.i fp_sqr_comba_4.i fp_sqr_comba_48.i fp_sqr_comba_6.i fp_sqr_comba_64.i fp_sqr_comba_7.i fp_sqr_comba_8.i fp_sqr_comba_9.i fp_sqr_comba_small_set.i ge_448.c ge_low_mem.c ge_operations.c hash.c hmac.c hpke.c include.am integer.c kdf.c logging.c md2.c md4.c md5.c memory.c misc.c pkcs12.c pkcs7.c poly1305.c poly1305_asm.S poly1305_asm.asm puf.c pwdbased.c random.c rc2.c ripemd.c rng_bank.c rsa.c sakke.c sha.c sha256.c sha256_asm.S sha3.c sha3_asm.S sha512.c sha512_asm.S signature.c siphash.c sm2.c sm3.c sm3_asm.S sm4.c sp_arm32.c sp_arm64.c sp_armthumb.c sp_c32.c sp_c64.c sp_cortexm.c sp_dsp32.c sp_int.c sp_sm2_arm32.c sp_sm2_arm64.c sp_sm2_armthumb.c sp_sm2_c32.c sp_sm2_c64.c sp_sm2_cortexm.c sp_sm2_x86_64.c sp_sm2_x86_64_asm.S sp_x86_64.c sp_x86_64_asm.S sp_x86_64_asm.asm srp.c tfm.c wc_dsp.c wc_encrypt.c wc_lms.c wc_lms_impl.c wc_mldsa_asm.S wc_mlkem.c wc_mlkem_asm.S wc_mlkem_poly.c wc_pkcs11.c wc_port.c wc_she.c wc_slhdsa.c wc_xmss.c wc_xmss_impl.c wolfentropy.c wolfevent.c wolfmath.c
test README.md include.am test-VS2022.sln test-VS2022.vcxproj test-VS2022.vcxproj.user test.c test.h test.sln test.vcproj test_paths.h.in
wolfssl
openssl aes.h asn1.h asn1t.h bio.h bn.h buffer.h camellia.h cmac.h cms.h compat_types.h conf.h crypto.h des.h dh.h dsa.h ec.h ec25519.h ec448.h ecdh.h ecdsa.h ed25519.h ed448.h engine.h err.h evp.h fips_rand.h hmac.h include.am kdf.h lhash.h md4.h md5.h modes.h obj_mac.h objects.h ocsp.h opensslconf.h opensslv.h ossl_typ.h pem.h pkcs12.h pkcs7.h rand.h rc4.h ripemd.h rsa.h safestack.h sha.h sha3.h srp.h ssl.h ssl23.h stack.h tls1.h txt_db.h ui.h x509.h x509_vfy.h x509v3.h
wolfcrypt
port
Espressif esp-sdk-lib.h esp32-crypt.h esp_crt_bundle.h
Renesas renesas-fspsm-crypt.h renesas-fspsm-types.h renesas-rx64-hw-crypt.h renesas-tsip-crypt.h renesas_cmn.h renesas_fspsm_internal.h renesas_sync.h renesas_tsip_internal.h renesas_tsip_types.h
af_alg afalg_hash.h wc_afalg.h
aria aria-crypt.h aria-cryptocb.h
arm cryptoCell.h
atmel atmel.h
autosar CryIf.h Crypto.h Csm.h StandardTypes.h
caam caam_driver.h caam_error.h caam_qnx.h wolfcaam.h wolfcaam_aes.h wolfcaam_cmac.h wolfcaam_ecdsa.h wolfcaam_fsl_nxp.h wolfcaam_hash.h wolfcaam_qnx.h wolfcaam_rsa.h wolfcaam_seco.h wolfcaam_sha.h wolfcaam_x25519.h
cavium cavium_nitrox.h cavium_octeon_sync.h
cypress psoc6_crypto.h
devcrypto wc_devcrypto.h
intel quickassist.h quickassist_mem.h quickassist_sync.h
iotsafe iotsafe.h
kcapi kcapi_dh.h kcapi_ecc.h kcapi_hash.h kcapi_hmac.h kcapi_rsa.h wc_kcapi.h
liboqs liboqs.h
maxim max3266x-cryptocb.h max3266x.h maxq10xx.h
nxp casper_port.h dcp_port.h hashcrypt_port.h ksdk_port.h se050_port.h
pic32 pic32mz-crypt.h
psa psa.h
riscv riscv-64-asm.h
rpi_pico pico.h
silabs silabs_aes.h silabs_ecc.h silabs_hash.h silabs_random.h
st stm32.h stsafe.h
ti ti-ccm.h ti-hash.h
tropicsquare tropic01.h
xilinx xil-sha3.h xil-versal-glue.h xil-versal-trng.h
nrf51.h
aes.h arc4.h ascon.h asn.h asn_public.h async.h blake2-impl.h blake2-int.h blake2.h camellia.h chacha.h chacha20_poly1305.h cmac.h coding.h compress.h cpuid.h cryptocb.h curve25519.h curve448.h des3.h dh.h dilithium.h dsa.h ecc.h eccsi.h ed25519.h ed448.h error-crypt.h falcon.h fe_448.h fe_operations.h fips_test.h ge_448.h ge_operations.h hash.h hmac.h hpke.h include.am integer.h kdf.h libwolfssl_sources.h libwolfssl_sources_asm.h logging.h md2.h md4.h md5.h mem_track.h memory.h misc.h mpi_class.h mpi_superclass.h oid_sum.h pkcs11.h pkcs12.h pkcs7.h poly1305.h puf.h pwdbased.h random.h rc2.h ripemd.h rng_bank.h rsa.h sakke.h selftest.h settings.h sha.h sha256.h sha3.h sha512.h signature.h siphash.h sm2.h sm3.h sm4.h sp.h sp_int.h srp.h tfm.h types.h visibility.h wc_encrypt.h wc_lms.h wc_mlkem.h wc_pkcs11.h wc_port.h wc_she.h wc_slhdsa.h wc_xmss.h wolfentropy.h wolfevent.h wolfmath.h
callbacks.h certs_test.h certs_test_sm.h crl.h error-ssl.h include.am internal.h ocsp.h options.h.in quic.h sniffer.h sniffer_error.h sniffer_error.rc ssl.h test.h version.h version.h.in wolfio.h
wrapper
Ada
examples
src aes_verify_main.adb rsa_verify_main.adb sha256_main.adb spark_sockets.adb spark_sockets.ads spark_terminal.adb spark_terminal.ads tls_client.adb tls_client.ads tls_client_main.adb tls_server.adb tls_server.ads tls_server_main.adb
.gitignore alire.toml examples.gpr
tests
src
support test_support.adb test_support.ads tests_root_suite.adb tests_root_suite.ads
aes_bindings_tests.adb aes_bindings_tests.ads rsa_verify_bindings_tests.adb rsa_verify_bindings_tests.ads sha256_bindings_tests.adb sha256_bindings_tests.ads tests.adb
.gitignore README.md alire.toml tests.gpr valgrind.supp
.gitignore README.md ada_binding.c alire.toml default.gpr include.am restricted.adc user_settings.h wolfssl-full_runtime.adb wolfssl-full_runtime.ads wolfssl.adb wolfssl.ads wolfssl.gpr
CSharp
wolfCrypt-Test
Properties AssemblyInfo.cs
App.config wolfCrypt-Test.cs wolfCrypt-Test.csproj
wolfSSL-DTLS-PSK-Server
Properties AssemblyInfo.cs
App.config wolfSSL-DTLS-PSK-Server.cs wolfSSL-DTLS-PSK-Server.csproj
wolfSSL-DTLS-Server
Properties AssemblyInfo.cs
App.config wolfSSL-DTLS-Server.cs wolfSSL-DTLS-Server.csproj
wolfSSL-Example-IOCallbacks
Properties AssemblyInfo.cs
App.config wolfSSL-Example-IOCallbacks.cs wolfSSL-Example-IOCallbacks.csproj
wolfSSL-TLS-Client
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-Client.cs wolfSSL-TLS-Client.csproj
wolfSSL-TLS-PSK-Client
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-PSK-Client.cs wolfSSL-TLS-PSK-Client.csproj
wolfSSL-TLS-PSK-Server
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-PSK-Server.cs wolfSSL-TLS-PSK-Server.csproj
wolfSSL-TLS-Server
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-Server.cs wolfSSL-TLS-Server.csproj
wolfSSL-TLS-ServerThreaded
Properties AssemblyInfo.cs
App.config wolfSSL-TLS-ServerThreaded.cs wolfSSL-TLS-ServerThreaded.csproj
wolfSSL_CSharp
Properties AssemblyInfo.cs Resources.Designer.cs Resources.resx
X509.cs wolfCrypt.cs wolfSSL.cs wolfSSL_CSharp.csproj
README.md include.am user_settings.h wolfSSL_CSharp.sln wolfssl.vcxproj
python README.md
rust
wolfssl-wolfcrypt
src aes.rs blake2.rs chacha20_poly1305.rs cmac.rs cmac_mac.rs curve25519.rs dh.rs dilithium.rs ecc.rs ecdsa.rs ed25519.rs ed448.rs fips.rs hkdf.rs hmac.rs hmac_mac.rs kdf.rs lib.rs lms.rs mlkem.rs mlkem_kem.rs pbkdf2_password_hash.rs prf.rs random.rs rsa.rs rsa_pkcs1v15.rs sha.rs sha_digest.rs sys.rs
tests
common mod.rs
test_aes.rs test_blake2.rs test_chacha20_poly1305.rs test_cmac.rs test_cmac_mac.rs test_curve25519.rs test_dh.rs test_dilithium.rs test_ecc.rs test_ecdsa.rs test_ed25519.rs test_ed448.rs test_hkdf.rs test_hmac.rs test_hmac_mac.rs test_kdf.rs test_lms.rs test_mlkem.rs test_mlkem_kem.rs test_pbkdf2_password_hash.rs test_prf.rs test_random.rs test_rsa.rs test_rsa_pkcs1v15.rs test_sha.rs test_sha_digest.rs test_wolfcrypt.rs
CHANGELOG.md Cargo.lock Cargo.toml Makefile README.md build.rs headers.h
Makefile README.md include.am
include.am
zephyr
samples
wolfssl_benchmark
boards native_sim.conf nrf5340dk_nrf5340_cpuapp.conf nrf5340dk_nrf5340_cpuapp_ns.conf
CMakeLists.txt README install_test.sh prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl_test
boards native_sim.conf nrf5340dk_nrf5340_cpuapp.conf nrf5340dk_nrf5340_cpuapp_ns.conf
CMakeLists.txt README install_test.sh prj-no-malloc.conf prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl_tls_sock
boards native_sim.conf
src tls_sock.c
CMakeLists.txt README install_sample.sh prj-no-malloc.conf prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl_tls_thread
boards native_sim.conf nrf5340dk_nrf5340_cpuapp.conf nrf5340dk_nrf5340_cpuapp_ns.conf
src tls_threaded.c
CMakeLists.txt README install_sample.sh prj.conf sample.yaml zephyr_legacy.conf zephyr_v4.1.conf
wolfssl options.h
CMakeLists.txt Kconfig Kconfig.tls-generic README.md include.am module.yml user_settings-no-malloc.h user_settings.h zephyr_init.c
.codespellexcludelines .cyignore .editorconfig .gitignore .wolfssl_known_macro_extras AUTHORS CMakeLists.txt CMakePresets.json CMakeSettings.json COPYING ChangeLog.md INSTALL LICENSING LPCExpresso.cproject LPCExpresso.project Makefile.am README README-async.md README.md SCRIPTS-LIST SECURITY-POLICY.md SECURITY-REPORT-TEMPLATE.md Vagrantfile autogen.sh commit-tests.sh configure.ac fips-check.sh fips-hash.sh gencertbuf.pl input pull_to_vagrant.sh quit resource.h stamp-h.in valgrind-bash.supp valgrind-error.sh wnr-example.conf wolfssl-VS2022.vcxproj wolfssl.rc wolfssl.vcproj wolfssl.vcxproj wolfssl64.sln
.clangd .gitignore DOCS.md Makefile README.md assert.c core.c crypto.c env.c fs.c http.c ini.c json.c log.c luna.h main.c makext.mk path.c process.c request.c sqlite.c stash.c template.c util.c
luajit/src/host/minilua.c raw
   1/* This is a heavily customized and minimized copy of Lua 5.1.5. */
   2/* It's only used to build LuaJIT. It does NOT have all standard functions! */
   3/******************************************************************************
   4* Copyright (C) 1994-2012 Lua.org, PUC-Rio.  All rights reserved.
   5*
   6* Permission is hereby granted, free of charge, to any person obtaining
   7* a copy of this software and associated documentation files (the
   8* "Software"), to deal in the Software without restriction, including
   9* without limitation the rights to use, copy, modify, merge, publish,
  10* distribute, sublicense, and/or sell copies of the Software, and to
  11* permit persons to whom the Software is furnished to do so, subject to
  12* the following conditions:
  13*
  14* The above copyright notice and this permission notice shall be
  15* included in all copies or substantial portions of the Software.
  16*
  17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24******************************************************************************/
  25#ifdef _MSC_VER
  26typedef unsigned __int64 U64;
  27#else
  28typedef unsigned long long U64;
  29#endif
  30int _CRT_glob = 0;
  31#include <stddef.h>
  32#include <stdarg.h>
  33#include <limits.h>
  34#include <math.h>
  35#include <ctype.h>
  36#include <stdio.h>
  37#include <stdlib.h>
  38#include <string.h>
  39#include <setjmp.h>
  40#include <errno.h>
  41#include <time.h>
  42typedef enum{
  43TM_INDEX,
  44TM_NEWINDEX,
  45TM_GC,
  46TM_MODE,
  47TM_EQ,
  48TM_ADD,
  49TM_SUB,
  50TM_MUL,
  51TM_DIV,
  52TM_MOD,
  53TM_POW,
  54TM_UNM,
  55TM_LEN,
  56TM_LT,
  57TM_LE,
  58TM_CONCAT,
  59TM_CALL,
  60TM_N
  61}TMS;
  62enum OpMode{iABC,iABx,iAsBx};
  63typedef enum{
  64OP_MOVE,
  65OP_LOADK,
  66OP_LOADBOOL,
  67OP_LOADNIL,
  68OP_GETUPVAL,
  69OP_GETGLOBAL,
  70OP_GETTABLE,
  71OP_SETGLOBAL,
  72OP_SETUPVAL,
  73OP_SETTABLE,
  74OP_NEWTABLE,
  75OP_SELF,
  76OP_ADD,
  77OP_SUB,
  78OP_MUL,
  79OP_DIV,
  80OP_MOD,
  81OP_POW,
  82OP_UNM,
  83OP_NOT,
  84OP_LEN,
  85OP_CONCAT,
  86OP_JMP,
  87OP_EQ,
  88OP_LT,
  89OP_LE,
  90OP_TEST,
  91OP_TESTSET,
  92OP_CALL,
  93OP_TAILCALL,
  94OP_RETURN,
  95OP_FORLOOP,
  96OP_FORPREP,
  97OP_TFORLOOP,
  98OP_SETLIST,
  99OP_CLOSE,
 100OP_CLOSURE,
 101OP_VARARG
 102}OpCode;
 103enum OpArgMask{
 104OpArgN,
 105OpArgU,
 106OpArgR,
 107OpArgK
 108};
 109typedef enum{
 110VVOID,
 111VNIL,
 112VTRUE,
 113VFALSE,
 114VK,
 115VKNUM,
 116VLOCAL,
 117VUPVAL,
 118VGLOBAL,
 119VINDEXED,
 120VJMP,
 121VRELOCABLE,
 122VNONRELOC,
 123VCALL,
 124VVARARG
 125}expkind;
 126enum RESERVED{
 127TK_AND=257,TK_BREAK,
 128TK_DO,TK_ELSE,TK_ELSEIF,TK_END,TK_FALSE,TK_FOR,TK_FUNCTION,
 129TK_IF,TK_IN,TK_LOCAL,TK_NIL,TK_NOT,TK_OR,TK_REPEAT,
 130TK_RETURN,TK_THEN,TK_TRUE,TK_UNTIL,TK_WHILE,
 131TK_CONCAT,TK_DOTS,TK_EQ,TK_GE,TK_LE,TK_NE,TK_NUMBER,
 132TK_NAME,TK_STRING,TK_EOS
 133};
 134typedef enum BinOpr{
 135OPR_ADD,OPR_SUB,OPR_MUL,OPR_DIV,OPR_MOD,OPR_POW,
 136OPR_CONCAT,
 137OPR_NE,OPR_EQ,
 138OPR_LT,OPR_LE,OPR_GT,OPR_GE,
 139OPR_AND,OPR_OR,
 140OPR_NOBINOPR
 141}BinOpr;
 142typedef enum UnOpr{OPR_MINUS,OPR_NOT,OPR_LEN,OPR_NOUNOPR}UnOpr;
 143#define LUA_QL(x)"'"x"'"
 144#define luai_apicheck(L,o){(void)L;}
 145#define lua_number2str(s,n)sprintf((s),"%.14g",(n))
 146#define lua_str2number(s,p)strtod((s),(p))
 147#define luai_numadd(a,b)((a)+(b))
 148#define luai_numsub(a,b)((a)-(b))
 149#define luai_nummul(a,b)((a)*(b))
 150#define luai_numdiv(a,b)((a)/(b))
 151#define luai_nummod(a,b)((a)-floor((a)/(b))*(b))
 152#define luai_numpow(a,b)(pow(a,b))
 153#define luai_numunm(a)(-(a))
 154#define luai_numeq(a,b)((a)==(b))
 155#define luai_numlt(a,b)((a)<(b))
 156#define luai_numle(a,b)((a)<=(b))
 157#define luai_numisnan(a)(!luai_numeq((a),(a)))
 158#define lua_number2int(i,d)((i)=(int)(d))
 159#define lua_number2integer(i,d)((i)=(lua_Integer)(d))
 160#define LUAI_THROW(L,c)longjmp((c)->b,1)
 161#define LUAI_TRY(L,c,a)if(setjmp((c)->b)==0){a}
 162#define lua_pclose(L,file)((void)((void)L,file),0)
 163#define lua_upvalueindex(i)((-10002)-(i))
 164typedef struct lua_State lua_State;
 165typedef int(*lua_CFunction)(lua_State*L);
 166typedef const char*(*lua_Reader)(lua_State*L,void*ud,size_t*sz);
 167typedef void*(*lua_Alloc)(void*ud,void*ptr,size_t osize,size_t nsize);
 168typedef double lua_Number;
 169typedef ptrdiff_t lua_Integer;
 170static void lua_settop(lua_State*L,int idx);
 171static int lua_type(lua_State*L,int idx);
 172static const char* lua_tolstring(lua_State*L,int idx,size_t*len);
 173static size_t lua_objlen(lua_State*L,int idx);
 174static void lua_pushlstring(lua_State*L,const char*s,size_t l);
 175static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n);
 176static void lua_createtable(lua_State*L,int narr,int nrec);
 177static void lua_setfield(lua_State*L,int idx,const char*k);
 178#define lua_pop(L,n)lua_settop(L,-(n)-1)
 179#define lua_newtable(L)lua_createtable(L,0,0)
 180#define lua_pushcfunction(L,f)lua_pushcclosure(L,(f),0)
 181#define lua_strlen(L,i)lua_objlen(L,(i))
 182#define lua_isfunction(L,n)(lua_type(L,(n))==6)
 183#define lua_istable(L,n)(lua_type(L,(n))==5)
 184#define lua_isnil(L,n)(lua_type(L,(n))==0)
 185#define lua_isboolean(L,n)(lua_type(L,(n))==1)
 186#define lua_isnone(L,n)(lua_type(L,(n))==(-1))
 187#define lua_isnoneornil(L,n)(lua_type(L,(n))<=0)
 188#define lua_pushliteral(L,s)lua_pushlstring(L,""s,(sizeof(s)/sizeof(char))-1)
 189#define lua_setglobal(L,s)lua_setfield(L,(-10002),(s))
 190#define lua_tostring(L,i)lua_tolstring(L,(i),NULL)
 191typedef struct lua_Debug lua_Debug;
 192typedef void(*lua_Hook)(lua_State*L,lua_Debug*ar);
 193struct lua_Debug{
 194int event;
 195const char*name;
 196const char*namewhat;
 197const char*what;
 198const char*source;
 199int currentline;
 200int nups;
 201int linedefined;
 202int lastlinedefined;
 203char short_src[60];
 204int i_ci;
 205};
 206typedef unsigned int lu_int32;
 207typedef size_t lu_mem;
 208typedef ptrdiff_t l_mem;
 209typedef unsigned char lu_byte;
 210#define IntPoint(p)((unsigned int)(lu_mem)(p))
 211typedef union{double u;void*s;long l;}L_Umaxalign;
 212typedef double l_uacNumber;
 213#define check_exp(c,e)(e)
 214#define UNUSED(x)((void)(x))
 215#define cast(t,exp)((t)(exp))
 216#define cast_byte(i)cast(lu_byte,(i))
 217#define cast_num(i)cast(lua_Number,(i))
 218#define cast_int(i)cast(int,(i))
 219typedef lu_int32 Instruction;
 220#define condhardstacktests(x)((void)0)
 221typedef union GCObject GCObject;
 222typedef struct GCheader{
 223GCObject*next;lu_byte tt;lu_byte marked;
 224}GCheader;
 225typedef union{
 226GCObject*gc;
 227void*p;
 228lua_Number n;
 229int b;
 230}Value;
 231typedef struct lua_TValue{
 232Value value;int tt;
 233}TValue;
 234#define ttisnil(o)(ttype(o)==0)
 235#define ttisnumber(o)(ttype(o)==3)
 236#define ttisstring(o)(ttype(o)==4)
 237#define ttistable(o)(ttype(o)==5)
 238#define ttisfunction(o)(ttype(o)==6)
 239#define ttisboolean(o)(ttype(o)==1)
 240#define ttisuserdata(o)(ttype(o)==7)
 241#define ttisthread(o)(ttype(o)==8)
 242#define ttislightuserdata(o)(ttype(o)==2)
 243#define ttype(o)((o)->tt)
 244#define gcvalue(o)check_exp(iscollectable(o),(o)->value.gc)
 245#define pvalue(o)check_exp(ttislightuserdata(o),(o)->value.p)
 246#define nvalue(o)check_exp(ttisnumber(o),(o)->value.n)
 247#define rawtsvalue(o)check_exp(ttisstring(o),&(o)->value.gc->ts)
 248#define tsvalue(o)(&rawtsvalue(o)->tsv)
 249#define rawuvalue(o)check_exp(ttisuserdata(o),&(o)->value.gc->u)
 250#define uvalue(o)(&rawuvalue(o)->uv)
 251#define clvalue(o)check_exp(ttisfunction(o),&(o)->value.gc->cl)
 252#define hvalue(o)check_exp(ttistable(o),&(o)->value.gc->h)
 253#define bvalue(o)check_exp(ttisboolean(o),(o)->value.b)
 254#define thvalue(o)check_exp(ttisthread(o),&(o)->value.gc->th)
 255#define l_isfalse(o)(ttisnil(o)||(ttisboolean(o)&&bvalue(o)==0))
 256#define checkconsistency(obj)
 257#define checkliveness(g,obj)
 258#define setnilvalue(obj)((obj)->tt=0)
 259#define setnvalue(obj,x){TValue*i_o=(obj);i_o->value.n=(x);i_o->tt=3;}
 260#define setbvalue(obj,x){TValue*i_o=(obj);i_o->value.b=(x);i_o->tt=1;}
 261#define setsvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=4;checkliveness(G(L),i_o);}
 262#define setuvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=7;checkliveness(G(L),i_o);}
 263#define setthvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=8;checkliveness(G(L),i_o);}
 264#define setclvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=6;checkliveness(G(L),i_o);}
 265#define sethvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=5;checkliveness(G(L),i_o);}
 266#define setptvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=(8+1);checkliveness(G(L),i_o);}
 267#define setobj(L,obj1,obj2){const TValue*o2=(obj2);TValue*o1=(obj1);o1->value=o2->value;o1->tt=o2->tt;checkliveness(G(L),o1);}
 268#define setttype(obj,tt)(ttype(obj)=(tt))
 269#define iscollectable(o)(ttype(o)>=4)
 270typedef TValue*StkId;
 271typedef union TString{
 272L_Umaxalign dummy;
 273struct{
 274GCObject*next;lu_byte tt;lu_byte marked;
 275lu_byte reserved;
 276unsigned int hash;
 277size_t len;
 278}tsv;
 279}TString;
 280#define getstr(ts)cast(const char*,(ts)+1)
 281#define svalue(o)getstr(rawtsvalue(o))
 282typedef union Udata{
 283L_Umaxalign dummy;
 284struct{
 285GCObject*next;lu_byte tt;lu_byte marked;
 286struct Table*metatable;
 287struct Table*env;
 288size_t len;
 289}uv;
 290}Udata;
 291typedef struct Proto{
 292GCObject*next;lu_byte tt;lu_byte marked;
 293TValue*k;
 294Instruction*code;
 295struct Proto**p;
 296int*lineinfo;
 297struct LocVar*locvars;
 298TString**upvalues;
 299TString*source;
 300int sizeupvalues;
 301int sizek;
 302int sizecode;
 303int sizelineinfo;
 304int sizep;
 305int sizelocvars;
 306int linedefined;
 307int lastlinedefined;
 308GCObject*gclist;
 309lu_byte nups;
 310lu_byte numparams;
 311lu_byte is_vararg;
 312lu_byte maxstacksize;
 313}Proto;
 314typedef struct LocVar{
 315TString*varname;
 316int startpc;
 317int endpc;
 318}LocVar;
 319typedef struct UpVal{
 320GCObject*next;lu_byte tt;lu_byte marked;
 321TValue*v;
 322union{
 323TValue value;
 324struct{
 325struct UpVal*prev;
 326struct UpVal*next;
 327}l;
 328}u;
 329}UpVal;
 330typedef struct CClosure{
 331GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env;
 332lua_CFunction f;
 333TValue upvalue[1];
 334}CClosure;
 335typedef struct LClosure{
 336GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env;
 337struct Proto*p;
 338UpVal*upvals[1];
 339}LClosure;
 340typedef union Closure{
 341CClosure c;
 342LClosure l;
 343}Closure;
 344#define iscfunction(o)(ttype(o)==6&&clvalue(o)->c.isC)
 345typedef union TKey{
 346struct{
 347Value value;int tt;
 348struct Node*next;
 349}nk;
 350TValue tvk;
 351}TKey;
 352typedef struct Node{
 353TValue i_val;
 354TKey i_key;
 355}Node;
 356typedef struct Table{
 357GCObject*next;lu_byte tt;lu_byte marked;
 358lu_byte flags;
 359lu_byte lsizenode;
 360struct Table*metatable;
 361TValue*array;
 362Node*node;
 363Node*lastfree;
 364GCObject*gclist;
 365int sizearray;
 366}Table;
 367#define lmod(s,size)(check_exp((size&(size-1))==0,(cast(int,(s)&((size)-1)))))
 368#define twoto(x)((size_t)1<<(x))
 369#define sizenode(t)(twoto((t)->lsizenode))
 370static const TValue luaO_nilobject_;
 371#define ceillog2(x)(luaO_log2((x)-1)+1)
 372static int luaO_log2(unsigned int x);
 373#define gfasttm(g,et,e)((et)==NULL?NULL:((et)->flags&(1u<<(e)))?NULL:luaT_gettm(et,e,(g)->tmname[e]))
 374#define fasttm(l,et,e)gfasttm(G(l),et,e)
 375static const TValue*luaT_gettm(Table*events,TMS event,TString*ename);
 376#define luaM_reallocv(L,b,on,n,e)((cast(size_t,(n)+1)<=((size_t)(~(size_t)0)-2)/(e))?luaM_realloc_(L,(b),(on)*(e),(n)*(e)):luaM_toobig(L))
 377#define luaM_freemem(L,b,s)luaM_realloc_(L,(b),(s),0)
 378#define luaM_free(L,b)luaM_realloc_(L,(b),sizeof(*(b)),0)
 379#define luaM_freearray(L,b,n,t)luaM_reallocv(L,(b),n,0,sizeof(t))
 380#define luaM_malloc(L,t)luaM_realloc_(L,NULL,0,(t))
 381#define luaM_new(L,t)cast(t*,luaM_malloc(L,sizeof(t)))
 382#define luaM_newvector(L,n,t)cast(t*,luaM_reallocv(L,NULL,0,n,sizeof(t)))
 383#define luaM_growvector(L,v,nelems,size,t,limit,e)if((nelems)+1>(size))((v)=cast(t*,luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
 384#define luaM_reallocvector(L,v,oldn,n,t)((v)=cast(t*,luaM_reallocv(L,v,oldn,n,sizeof(t))))
 385static void*luaM_realloc_(lua_State*L,void*block,size_t oldsize,
 386size_t size);
 387static void*luaM_toobig(lua_State*L);
 388static void*luaM_growaux_(lua_State*L,void*block,int*size,
 389size_t size_elem,int limit,
 390const char*errormsg);
 391typedef struct Zio ZIO;
 392#define char2int(c)cast(int,cast(unsigned char,(c)))
 393#define zgetc(z)(((z)->n--)>0?char2int(*(z)->p++):luaZ_fill(z))
 394typedef struct Mbuffer{
 395char*buffer;
 396size_t n;
 397size_t buffsize;
 398}Mbuffer;
 399#define luaZ_initbuffer(L,buff)((buff)->buffer=NULL,(buff)->buffsize=0)
 400#define luaZ_buffer(buff)((buff)->buffer)
 401#define luaZ_sizebuffer(buff)((buff)->buffsize)
 402#define luaZ_bufflen(buff)((buff)->n)
 403#define luaZ_resetbuffer(buff)((buff)->n=0)
 404#define luaZ_resizebuffer(L,buff,size)(luaM_reallocvector(L,(buff)->buffer,(buff)->buffsize,size,char),(buff)->buffsize=size)
 405#define luaZ_freebuffer(L,buff)luaZ_resizebuffer(L,buff,0)
 406struct Zio{
 407size_t n;
 408const char*p;
 409lua_Reader reader;
 410void*data;
 411lua_State*L;
 412};
 413static int luaZ_fill(ZIO*z);
 414struct lua_longjmp;
 415#define gt(L)(&L->l_gt)
 416#define registry(L)(&G(L)->l_registry)
 417typedef struct stringtable{
 418GCObject**hash;
 419lu_int32 nuse;
 420int size;
 421}stringtable;
 422typedef struct CallInfo{
 423StkId base;
 424StkId func;
 425StkId top;
 426const Instruction*savedpc;
 427int nresults;
 428int tailcalls;
 429}CallInfo;
 430#define curr_func(L)(clvalue(L->ci->func))
 431#define ci_func(ci)(clvalue((ci)->func))
 432#define f_isLua(ci)(!ci_func(ci)->c.isC)
 433#define isLua(ci)(ttisfunction((ci)->func)&&f_isLua(ci))
 434typedef struct global_State{
 435stringtable strt;
 436lua_Alloc frealloc;
 437void*ud;
 438lu_byte currentwhite;
 439lu_byte gcstate;
 440int sweepstrgc;
 441GCObject*rootgc;
 442GCObject**sweepgc;
 443GCObject*gray;
 444GCObject*grayagain;
 445GCObject*weak;
 446GCObject*tmudata;
 447Mbuffer buff;
 448lu_mem GCthreshold;
 449lu_mem totalbytes;
 450lu_mem estimate;
 451lu_mem gcdept;
 452int gcpause;
 453int gcstepmul;
 454lua_CFunction panic;
 455TValue l_registry;
 456struct lua_State*mainthread;
 457UpVal uvhead;
 458struct Table*mt[(8+1)];
 459TString*tmname[TM_N];
 460}global_State;
 461struct lua_State{
 462GCObject*next;lu_byte tt;lu_byte marked;
 463lu_byte status;
 464StkId top;
 465StkId base;
 466global_State*l_G;
 467CallInfo*ci;
 468const Instruction*savedpc;
 469StkId stack_last;
 470StkId stack;
 471CallInfo*end_ci;
 472CallInfo*base_ci;
 473int stacksize;
 474int size_ci;
 475unsigned short nCcalls;
 476unsigned short baseCcalls;
 477lu_byte hookmask;
 478lu_byte allowhook;
 479int basehookcount;
 480int hookcount;
 481lua_Hook hook;
 482TValue l_gt;
 483TValue env;
 484GCObject*openupval;
 485GCObject*gclist;
 486struct lua_longjmp*errorJmp;
 487ptrdiff_t errfunc;
 488};
 489#define G(L)(L->l_G)
 490union GCObject{
 491GCheader gch;
 492union TString ts;
 493union Udata u;
 494union Closure cl;
 495struct Table h;
 496struct Proto p;
 497struct UpVal uv;
 498struct lua_State th;
 499};
 500#define rawgco2ts(o)check_exp((o)->gch.tt==4,&((o)->ts))
 501#define gco2ts(o)(&rawgco2ts(o)->tsv)
 502#define rawgco2u(o)check_exp((o)->gch.tt==7,&((o)->u))
 503#define gco2u(o)(&rawgco2u(o)->uv)
 504#define gco2cl(o)check_exp((o)->gch.tt==6,&((o)->cl))
 505#define gco2h(o)check_exp((o)->gch.tt==5,&((o)->h))
 506#define gco2p(o)check_exp((o)->gch.tt==(8+1),&((o)->p))
 507#define gco2uv(o)check_exp((o)->gch.tt==(8+2),&((o)->uv))
 508#define ngcotouv(o)check_exp((o)==NULL||(o)->gch.tt==(8+2),&((o)->uv))
 509#define gco2th(o)check_exp((o)->gch.tt==8,&((o)->th))
 510#define obj2gco(v)(cast(GCObject*,(v)))
 511static void luaE_freethread(lua_State*L,lua_State*L1);
 512#define pcRel(pc,p)(cast(int,(pc)-(p)->code)-1)
 513#define getline_(f,pc)(((f)->lineinfo)?(f)->lineinfo[pc]:0)
 514#define resethookcount(L)(L->hookcount=L->basehookcount)
 515static void luaG_typeerror(lua_State*L,const TValue*o,
 516const char*opname);
 517static void luaG_runerror(lua_State*L,const char*fmt,...);
 518#define luaD_checkstack(L,n)if((char*)L->stack_last-(char*)L->top<=(n)*(int)sizeof(TValue))luaD_growstack(L,n);else condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));
 519#define incr_top(L){luaD_checkstack(L,1);L->top++;}
 520#define savestack(L,p)((char*)(p)-(char*)L->stack)
 521#define restorestack(L,n)((TValue*)((char*)L->stack+(n)))
 522#define saveci(L,p)((char*)(p)-(char*)L->base_ci)
 523#define restoreci(L,n)((CallInfo*)((char*)L->base_ci+(n)))
 524typedef void(*Pfunc)(lua_State*L,void*ud);
 525static int luaD_poscall(lua_State*L,StkId firstResult);
 526static void luaD_reallocCI(lua_State*L,int newsize);
 527static void luaD_reallocstack(lua_State*L,int newsize);
 528static void luaD_growstack(lua_State*L,int n);
 529static void luaD_throw(lua_State*L,int errcode);
 530static void*luaM_growaux_(lua_State*L,void*block,int*size,size_t size_elems,
 531int limit,const char*errormsg){
 532void*newblock;
 533int newsize;
 534if(*size>=limit/2){
 535if(*size>=limit)
 536luaG_runerror(L,errormsg);
 537newsize=limit;
 538}
 539else{
 540newsize=(*size)*2;
 541if(newsize<4)
 542newsize=4;
 543}
 544newblock=luaM_reallocv(L,block,*size,newsize,size_elems);
 545*size=newsize;
 546return newblock;
 547}
 548static void*luaM_toobig(lua_State*L){
 549luaG_runerror(L,"memory allocation error: block too big");
 550return NULL;
 551}
 552static void*luaM_realloc_(lua_State*L,void*block,size_t osize,size_t nsize){
 553global_State*g=G(L);
 554block=(*g->frealloc)(g->ud,block,osize,nsize);
 555if(block==NULL&&nsize>0)
 556luaD_throw(L,4);
 557g->totalbytes=(g->totalbytes-osize)+nsize;
 558return block;
 559}
 560#define resetbits(x,m)((x)&=cast(lu_byte,~(m)))
 561#define setbits(x,m)((x)|=(m))
 562#define testbits(x,m)((x)&(m))
 563#define bitmask(b)(1<<(b))
 564#define bit2mask(b1,b2)(bitmask(b1)|bitmask(b2))
 565#define l_setbit(x,b)setbits(x,bitmask(b))
 566#define resetbit(x,b)resetbits(x,bitmask(b))
 567#define testbit(x,b)testbits(x,bitmask(b))
 568#define set2bits(x,b1,b2)setbits(x,(bit2mask(b1,b2)))
 569#define reset2bits(x,b1,b2)resetbits(x,(bit2mask(b1,b2)))
 570#define test2bits(x,b1,b2)testbits(x,(bit2mask(b1,b2)))
 571#define iswhite(x)test2bits((x)->gch.marked,0,1)
 572#define isblack(x)testbit((x)->gch.marked,2)
 573#define isgray(x)(!isblack(x)&&!iswhite(x))
 574#define otherwhite(g)(g->currentwhite^bit2mask(0,1))
 575#define isdead(g,v)((v)->gch.marked&otherwhite(g)&bit2mask(0,1))
 576#define changewhite(x)((x)->gch.marked^=bit2mask(0,1))
 577#define gray2black(x)l_setbit((x)->gch.marked,2)
 578#define valiswhite(x)(iscollectable(x)&&iswhite(gcvalue(x)))
 579#define luaC_white(g)cast(lu_byte,(g)->currentwhite&bit2mask(0,1))
 580#define luaC_checkGC(L){condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));if(G(L)->totalbytes>=G(L)->GCthreshold)luaC_step(L);}
 581#define luaC_barrier(L,p,v){if(valiswhite(v)&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),gcvalue(v));}
 582#define luaC_barriert(L,t,v){if(valiswhite(v)&&isblack(obj2gco(t)))luaC_barrierback(L,t);}
 583#define luaC_objbarrier(L,p,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),obj2gco(o));}
 584#define luaC_objbarriert(L,t,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(t)))luaC_barrierback(L,t);}
 585static void luaC_step(lua_State*L);
 586static void luaC_link(lua_State*L,GCObject*o,lu_byte tt);
 587static void luaC_linkupval(lua_State*L,UpVal*uv);
 588static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v);
 589static void luaC_barrierback(lua_State*L,Table*t);
 590#define sizestring(s)(sizeof(union TString)+((s)->len+1)*sizeof(char))
 591#define sizeudata(u)(sizeof(union Udata)+(u)->len)
 592#define luaS_new(L,s)(luaS_newlstr(L,s,strlen(s)))
 593#define luaS_newliteral(L,s)(luaS_newlstr(L,""s,(sizeof(s)/sizeof(char))-1))
 594#define luaS_fix(s)l_setbit((s)->tsv.marked,5)
 595static TString*luaS_newlstr(lua_State*L,const char*str,size_t l);
 596#define tostring(L,o)((ttype(o)==4)||(luaV_tostring(L,o)))
 597#define tonumber(o,n)(ttype(o)==3||(((o)=luaV_tonumber(o,n))!=NULL))
 598#define equalobj(L,o1,o2)(ttype(o1)==ttype(o2)&&luaV_equalval(L,o1,o2))
 599static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2);
 600static const TValue*luaV_tonumber(const TValue*obj,TValue*n);
 601static int luaV_tostring(lua_State*L,StkId obj);
 602static void luaV_execute(lua_State*L,int nexeccalls);
 603static void luaV_concat(lua_State*L,int total,int last);
 604static const TValue luaO_nilobject_={{NULL},0};
 605static int luaO_int2fb(unsigned int x){
 606int e=0;
 607while(x>=16){
 608x=(x+1)>>1;
 609e++;
 610}
 611if(x<8)return x;
 612else return((e+1)<<3)|(cast_int(x)-8);
 613}
 614static int luaO_fb2int(int x){
 615int e=(x>>3)&31;
 616if(e==0)return x;
 617else return((x&7)+8)<<(e-1);
 618}
 619static int luaO_log2(unsigned int x){
 620static const lu_byte log_2[256]={
 6210,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
 6226,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
 6237,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 6247,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 6258,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
 6268,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
 6278,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
 6288,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
 629};
 630int l=-1;
 631while(x>=256){l+=8;x>>=8;}
 632return l+log_2[x];
 633}
 634static int luaO_rawequalObj(const TValue*t1,const TValue*t2){
 635if(ttype(t1)!=ttype(t2))return 0;
 636else switch(ttype(t1)){
 637case 0:
 638return 1;
 639case 3:
 640return luai_numeq(nvalue(t1),nvalue(t2));
 641case 1:
 642return bvalue(t1)==bvalue(t2);
 643case 2:
 644return pvalue(t1)==pvalue(t2);
 645default:
 646return gcvalue(t1)==gcvalue(t2);
 647}
 648}
 649static int luaO_str2d(const char*s,lua_Number*result){
 650char*endptr;
 651*result=lua_str2number(s,&endptr);
 652if(endptr==s)return 0;
 653if(*endptr=='x'||*endptr=='X')
 654*result=cast_num(strtoul(s,&endptr,16));
 655if(*endptr=='\0')return 1;
 656while(isspace(cast(unsigned char,*endptr)))endptr++;
 657if(*endptr!='\0')return 0;
 658return 1;
 659}
 660static void pushstr(lua_State*L,const char*str){
 661setsvalue(L,L->top,luaS_new(L,str));
 662incr_top(L);
 663}
 664static const char*luaO_pushvfstring(lua_State*L,const char*fmt,va_list argp){
 665int n=1;
 666pushstr(L,"");
 667for(;;){
 668const char*e=strchr(fmt,'%');
 669if(e==NULL)break;
 670setsvalue(L,L->top,luaS_newlstr(L,fmt,e-fmt));
 671incr_top(L);
 672switch(*(e+1)){
 673case's':{
 674const char*s=va_arg(argp,char*);
 675if(s==NULL)s="(null)";
 676pushstr(L,s);
 677break;
 678}
 679case'c':{
 680char buff[2];
 681buff[0]=cast(char,va_arg(argp,int));
 682buff[1]='\0';
 683pushstr(L,buff);
 684break;
 685}
 686case'd':{
 687setnvalue(L->top,cast_num(va_arg(argp,int)));
 688incr_top(L);
 689break;
 690}
 691case'f':{
 692setnvalue(L->top,cast_num(va_arg(argp,l_uacNumber)));
 693incr_top(L);
 694break;
 695}
 696case'p':{
 697char buff[4*sizeof(void*)+8];
 698sprintf(buff,"%p",va_arg(argp,void*));
 699pushstr(L,buff);
 700break;
 701}
 702case'%':{
 703pushstr(L,"%");
 704break;
 705}
 706default:{
 707char buff[3];
 708buff[0]='%';
 709buff[1]=*(e+1);
 710buff[2]='\0';
 711pushstr(L,buff);
 712break;
 713}
 714}
 715n+=2;
 716fmt=e+2;
 717}
 718pushstr(L,fmt);
 719luaV_concat(L,n+1,cast_int(L->top-L->base)-1);
 720L->top-=n;
 721return svalue(L->top-1);
 722}
 723static const char*luaO_pushfstring(lua_State*L,const char*fmt,...){
 724const char*msg;
 725va_list argp;
 726va_start(argp,fmt);
 727msg=luaO_pushvfstring(L,fmt,argp);
 728va_end(argp);
 729return msg;
 730}
 731static void luaO_chunkid(char*out,const char*source,size_t bufflen){
 732if(*source=='='){
 733strncpy(out,source+1,bufflen);
 734out[bufflen-1]='\0';
 735}
 736else{
 737if(*source=='@'){
 738size_t l;
 739source++;
 740bufflen-=sizeof(" '...' ");
 741l=strlen(source);
 742strcpy(out,"");
 743if(l>bufflen){
 744source+=(l-bufflen);
 745strcat(out,"...");
 746}
 747strcat(out,source);
 748}
 749else{
 750size_t len=strcspn(source,"\n\r");
 751bufflen-=sizeof(" [string \"...\"] ");
 752if(len>bufflen)len=bufflen;
 753strcpy(out,"[string \"");
 754if(source[len]!='\0'){
 755strncat(out,source,len);
 756strcat(out,"...");
 757}
 758else
 759strcat(out,source);
 760strcat(out,"\"]");
 761}
 762}
 763}
 764#define gnode(t,i)(&(t)->node[i])
 765#define gkey(n)(&(n)->i_key.nk)
 766#define gval(n)(&(n)->i_val)
 767#define gnext(n)((n)->i_key.nk.next)
 768#define key2tval(n)(&(n)->i_key.tvk)
 769static TValue*luaH_setnum(lua_State*L,Table*t,int key);
 770static const TValue*luaH_getstr(Table*t,TString*key);
 771static TValue*luaH_set(lua_State*L,Table*t,const TValue*key);
 772static const char*const luaT_typenames[]={
 773"nil","boolean","userdata","number",
 774"string","table","function","userdata","thread",
 775"proto","upval"
 776};
 777static void luaT_init(lua_State*L){
 778static const char*const luaT_eventname[]={
 779"__index","__newindex",
 780"__gc","__mode","__eq",
 781"__add","__sub","__mul","__div","__mod",
 782"__pow","__unm","__len","__lt","__le",
 783"__concat","__call"
 784};
 785int i;
 786for(i=0;i<TM_N;i++){
 787G(L)->tmname[i]=luaS_new(L,luaT_eventname[i]);
 788luaS_fix(G(L)->tmname[i]);
 789}
 790}
 791static const TValue*luaT_gettm(Table*events,TMS event,TString*ename){
 792const TValue*tm=luaH_getstr(events,ename);
 793if(ttisnil(tm)){
 794events->flags|=cast_byte(1u<<event);
 795return NULL;
 796}
 797else return tm;
 798}
 799static const TValue*luaT_gettmbyobj(lua_State*L,const TValue*o,TMS event){
 800Table*mt;
 801switch(ttype(o)){
 802case 5:
 803mt=hvalue(o)->metatable;
 804break;
 805case 7:
 806mt=uvalue(o)->metatable;
 807break;
 808default:
 809mt=G(L)->mt[ttype(o)];
 810}
 811return(mt?luaH_getstr(mt,G(L)->tmname[event]):(&luaO_nilobject_));
 812}
 813#define sizeCclosure(n)(cast(int,sizeof(CClosure))+cast(int,sizeof(TValue)*((n)-1)))
 814#define sizeLclosure(n)(cast(int,sizeof(LClosure))+cast(int,sizeof(TValue*)*((n)-1)))
 815static Closure*luaF_newCclosure(lua_State*L,int nelems,Table*e){
 816Closure*c=cast(Closure*,luaM_malloc(L,sizeCclosure(nelems)));
 817luaC_link(L,obj2gco(c),6);
 818c->c.isC=1;
 819c->c.env=e;
 820c->c.nupvalues=cast_byte(nelems);
 821return c;
 822}
 823static Closure*luaF_newLclosure(lua_State*L,int nelems,Table*e){
 824Closure*c=cast(Closure*,luaM_malloc(L,sizeLclosure(nelems)));
 825luaC_link(L,obj2gco(c),6);
 826c->l.isC=0;
 827c->l.env=e;
 828c->l.nupvalues=cast_byte(nelems);
 829while(nelems--)c->l.upvals[nelems]=NULL;
 830return c;
 831}
 832static UpVal*luaF_newupval(lua_State*L){
 833UpVal*uv=luaM_new(L,UpVal);
 834luaC_link(L,obj2gco(uv),(8+2));
 835uv->v=&uv->u.value;
 836setnilvalue(uv->v);
 837return uv;
 838}
 839static UpVal*luaF_findupval(lua_State*L,StkId level){
 840global_State*g=G(L);
 841GCObject**pp=&L->openupval;
 842UpVal*p;
 843UpVal*uv;
 844while(*pp!=NULL&&(p=ngcotouv(*pp))->v>=level){
 845if(p->v==level){
 846if(isdead(g,obj2gco(p)))
 847changewhite(obj2gco(p));
 848return p;
 849}
 850pp=&p->next;
 851}
 852uv=luaM_new(L,UpVal);
 853uv->tt=(8+2);
 854uv->marked=luaC_white(g);
 855uv->v=level;
 856uv->next=*pp;
 857*pp=obj2gco(uv);
 858uv->u.l.prev=&g->uvhead;
 859uv->u.l.next=g->uvhead.u.l.next;
 860uv->u.l.next->u.l.prev=uv;
 861g->uvhead.u.l.next=uv;
 862return uv;
 863}
 864static void unlinkupval(UpVal*uv){
 865uv->u.l.next->u.l.prev=uv->u.l.prev;
 866uv->u.l.prev->u.l.next=uv->u.l.next;
 867}
 868static void luaF_freeupval(lua_State*L,UpVal*uv){
 869if(uv->v!=&uv->u.value)
 870unlinkupval(uv);
 871luaM_free(L,uv);
 872}
 873static void luaF_close(lua_State*L,StkId level){
 874UpVal*uv;
 875global_State*g=G(L);
 876while(L->openupval!=NULL&&(uv=ngcotouv(L->openupval))->v>=level){
 877GCObject*o=obj2gco(uv);
 878L->openupval=uv->next;
 879if(isdead(g,o))
 880luaF_freeupval(L,uv);
 881else{
 882unlinkupval(uv);
 883setobj(L,&uv->u.value,uv->v);
 884uv->v=&uv->u.value;
 885luaC_linkupval(L,uv);
 886}
 887}
 888}
 889static Proto*luaF_newproto(lua_State*L){
 890Proto*f=luaM_new(L,Proto);
 891luaC_link(L,obj2gco(f),(8+1));
 892f->k=NULL;
 893f->sizek=0;
 894f->p=NULL;
 895f->sizep=0;
 896f->code=NULL;
 897f->sizecode=0;
 898f->sizelineinfo=0;
 899f->sizeupvalues=0;
 900f->nups=0;
 901f->upvalues=NULL;
 902f->numparams=0;
 903f->is_vararg=0;
 904f->maxstacksize=0;
 905f->lineinfo=NULL;
 906f->sizelocvars=0;
 907f->locvars=NULL;
 908f->linedefined=0;
 909f->lastlinedefined=0;
 910f->source=NULL;
 911return f;
 912}
 913static void luaF_freeproto(lua_State*L,Proto*f){
 914luaM_freearray(L,f->code,f->sizecode,Instruction);
 915luaM_freearray(L,f->p,f->sizep,Proto*);
 916luaM_freearray(L,f->k,f->sizek,TValue);
 917luaM_freearray(L,f->lineinfo,f->sizelineinfo,int);
 918luaM_freearray(L,f->locvars,f->sizelocvars,struct LocVar);
 919luaM_freearray(L,f->upvalues,f->sizeupvalues,TString*);
 920luaM_free(L,f);
 921}
 922static void luaF_freeclosure(lua_State*L,Closure*c){
 923int size=(c->c.isC)?sizeCclosure(c->c.nupvalues):
 924sizeLclosure(c->l.nupvalues);
 925luaM_freemem(L,c,size);
 926}
 927#define MASK1(n,p)((~((~(Instruction)0)<<n))<<p)
 928#define MASK0(n,p)(~MASK1(n,p))
 929#define GET_OPCODE(i)(cast(OpCode,((i)>>0)&MASK1(6,0)))
 930#define SET_OPCODE(i,o)((i)=(((i)&MASK0(6,0))|((cast(Instruction,o)<<0)&MASK1(6,0))))
 931#define GETARG_A(i)(cast(int,((i)>>(0+6))&MASK1(8,0)))
 932#define SETARG_A(i,u)((i)=(((i)&MASK0(8,(0+6)))|((cast(Instruction,u)<<(0+6))&MASK1(8,(0+6)))))
 933#define GETARG_B(i)(cast(int,((i)>>(((0+6)+8)+9))&MASK1(9,0)))
 934#define SETARG_B(i,b)((i)=(((i)&MASK0(9,(((0+6)+8)+9)))|((cast(Instruction,b)<<(((0+6)+8)+9))&MASK1(9,(((0+6)+8)+9)))))
 935#define GETARG_C(i)(cast(int,((i)>>((0+6)+8))&MASK1(9,0)))
 936#define SETARG_C(i,b)((i)=(((i)&MASK0(9,((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1(9,((0+6)+8)))))
 937#define GETARG_Bx(i)(cast(int,((i)>>((0+6)+8))&MASK1((9+9),0)))
 938#define SETARG_Bx(i,b)((i)=(((i)&MASK0((9+9),((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1((9+9),((0+6)+8)))))
 939#define GETARG_sBx(i)(GETARG_Bx(i)-(((1<<(9+9))-1)>>1))
 940#define SETARG_sBx(i,b)SETARG_Bx((i),cast(unsigned int,(b)+(((1<<(9+9))-1)>>1)))
 941#define CREATE_ABC(o,a,b,c)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,b)<<(((0+6)+8)+9))|(cast(Instruction,c)<<((0+6)+8)))
 942#define CREATE_ABx(o,a,bc)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,bc)<<((0+6)+8)))
 943#define ISK(x)((x)&(1<<(9-1)))
 944#define INDEXK(r)((int)(r)&~(1<<(9-1)))
 945#define RKASK(x)((x)|(1<<(9-1)))
 946static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)];
 947#define getBMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>4)&3))
 948#define getCMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>2)&3))
 949#define testTMode(m)(luaP_opmodes[m]&(1<<7))
 950typedef struct expdesc{
 951expkind k;
 952union{
 953struct{int info,aux;}s;
 954lua_Number nval;
 955}u;
 956int t;
 957int f;
 958}expdesc;
 959typedef struct upvaldesc{
 960lu_byte k;
 961lu_byte info;
 962}upvaldesc;
 963struct BlockCnt;
 964typedef struct FuncState{
 965Proto*f;
 966Table*h;
 967struct FuncState*prev;
 968struct LexState*ls;
 969struct lua_State*L;
 970struct BlockCnt*bl;
 971int pc;
 972int lasttarget;
 973int jpc;
 974int freereg;
 975int nk;
 976int np;
 977short nlocvars;
 978lu_byte nactvar;
 979upvaldesc upvalues[60];
 980unsigned short actvar[200];
 981}FuncState;
 982static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,
 983const char*name);
 984struct lua_longjmp{
 985struct lua_longjmp*previous;
 986jmp_buf b;
 987volatile int status;
 988};
 989static void luaD_seterrorobj(lua_State*L,int errcode,StkId oldtop){
 990switch(errcode){
 991case 4:{
 992setsvalue(L,oldtop,luaS_newliteral(L,"not enough memory"));
 993break;
 994}
 995case 5:{
 996setsvalue(L,oldtop,luaS_newliteral(L,"error in error handling"));
 997break;
 998}
 999case 3:
1000case 2:{
1001setobj(L,oldtop,L->top-1);
1002break;
1003}
1004}
1005L->top=oldtop+1;
1006}
1007static void restore_stack_limit(lua_State*L){
1008if(L->size_ci>20000){
1009int inuse=cast_int(L->ci-L->base_ci);
1010if(inuse+1<20000)
1011luaD_reallocCI(L,20000);
1012}
1013}
1014static void resetstack(lua_State*L,int status){
1015L->ci=L->base_ci;
1016L->base=L->ci->base;
1017luaF_close(L,L->base);
1018luaD_seterrorobj(L,status,L->base);
1019L->nCcalls=L->baseCcalls;
1020L->allowhook=1;
1021restore_stack_limit(L);
1022L->errfunc=0;
1023L->errorJmp=NULL;
1024}
1025static void luaD_throw(lua_State*L,int errcode){
1026if(L->errorJmp){
1027L->errorJmp->status=errcode;
1028LUAI_THROW(L,L->errorJmp);
1029}
1030else{
1031L->status=cast_byte(errcode);
1032if(G(L)->panic){
1033resetstack(L,errcode);
1034G(L)->panic(L);
1035}
1036exit(EXIT_FAILURE);
1037}
1038}
1039static int luaD_rawrunprotected(lua_State*L,Pfunc f,void*ud){
1040struct lua_longjmp lj;
1041lj.status=0;
1042lj.previous=L->errorJmp;
1043L->errorJmp=&lj;
1044LUAI_TRY(L,&lj,
1045(*f)(L,ud);
1046);
1047L->errorJmp=lj.previous;
1048return lj.status;
1049}
1050static void correctstack(lua_State*L,TValue*oldstack){
1051CallInfo*ci;
1052GCObject*up;
1053L->top=(L->top-oldstack)+L->stack;
1054for(up=L->openupval;up!=NULL;up=up->gch.next)
1055gco2uv(up)->v=(gco2uv(up)->v-oldstack)+L->stack;
1056for(ci=L->base_ci;ci<=L->ci;ci++){
1057ci->top=(ci->top-oldstack)+L->stack;
1058ci->base=(ci->base-oldstack)+L->stack;
1059ci->func=(ci->func-oldstack)+L->stack;
1060}
1061L->base=(L->base-oldstack)+L->stack;
1062}
1063static void luaD_reallocstack(lua_State*L,int newsize){
1064TValue*oldstack=L->stack;
1065int realsize=newsize+1+5;
1066luaM_reallocvector(L,L->stack,L->stacksize,realsize,TValue);
1067L->stacksize=realsize;
1068L->stack_last=L->stack+newsize;
1069correctstack(L,oldstack);
1070}
1071static void luaD_reallocCI(lua_State*L,int newsize){
1072CallInfo*oldci=L->base_ci;
1073luaM_reallocvector(L,L->base_ci,L->size_ci,newsize,CallInfo);
1074L->size_ci=newsize;
1075L->ci=(L->ci-oldci)+L->base_ci;
1076L->end_ci=L->base_ci+L->size_ci-1;
1077}
1078static void luaD_growstack(lua_State*L,int n){
1079if(n<=L->stacksize)
1080luaD_reallocstack(L,2*L->stacksize);
1081else
1082luaD_reallocstack(L,L->stacksize+n);
1083}
1084static CallInfo*growCI(lua_State*L){
1085if(L->size_ci>20000)
1086luaD_throw(L,5);
1087else{
1088luaD_reallocCI(L,2*L->size_ci);
1089if(L->size_ci>20000)
1090luaG_runerror(L,"stack overflow");
1091}
1092return++L->ci;
1093}
1094static StkId adjust_varargs(lua_State*L,Proto*p,int actual){
1095int i;
1096int nfixargs=p->numparams;
1097Table*htab=NULL;
1098StkId base,fixed;
1099for(;actual<nfixargs;++actual)
1100setnilvalue(L->top++);
1101fixed=L->top-actual;
1102base=L->top;
1103for(i=0;i<nfixargs;i++){
1104setobj(L,L->top++,fixed+i);
1105setnilvalue(fixed+i);
1106}
1107if(htab){
1108sethvalue(L,L->top++,htab);
1109}
1110return base;
1111}
1112static StkId tryfuncTM(lua_State*L,StkId func){
1113const TValue*tm=luaT_gettmbyobj(L,func,TM_CALL);
1114StkId p;
1115ptrdiff_t funcr=savestack(L,func);
1116if(!ttisfunction(tm))
1117luaG_typeerror(L,func,"call");
1118for(p=L->top;p>func;p--)setobj(L,p,p-1);
1119incr_top(L);
1120func=restorestack(L,funcr);
1121setobj(L,func,tm);
1122return func;
1123}
1124#define inc_ci(L)((L->ci==L->end_ci)?growCI(L):(condhardstacktests(luaD_reallocCI(L,L->size_ci)),++L->ci))
1125static int luaD_precall(lua_State*L,StkId func,int nresults){
1126LClosure*cl;
1127ptrdiff_t funcr;
1128if(!ttisfunction(func))
1129func=tryfuncTM(L,func);
1130funcr=savestack(L,func);
1131cl=&clvalue(func)->l;
1132L->ci->savedpc=L->savedpc;
1133if(!cl->isC){
1134CallInfo*ci;
1135StkId st,base;
1136Proto*p=cl->p;
1137luaD_checkstack(L,p->maxstacksize+p->numparams);
1138func=restorestack(L,funcr);
1139if(!p->is_vararg){
1140base=func+1;
1141if(L->top>base+p->numparams)
1142L->top=base+p->numparams;
1143}
1144else{
1145int nargs=cast_int(L->top-func)-1;
1146base=adjust_varargs(L,p,nargs);
1147func=restorestack(L,funcr);
1148}
1149ci=inc_ci(L);
1150ci->func=func;
1151L->base=ci->base=base;
1152ci->top=L->base+p->maxstacksize;
1153L->savedpc=p->code;
1154ci->tailcalls=0;
1155ci->nresults=nresults;
1156for(st=L->top;st<ci->top;st++)
1157setnilvalue(st);
1158L->top=ci->top;
1159return 0;
1160}
1161else{
1162CallInfo*ci;
1163int n;
1164luaD_checkstack(L,20);
1165ci=inc_ci(L);
1166ci->func=restorestack(L,funcr);
1167L->base=ci->base=ci->func+1;
1168ci->top=L->top+20;
1169ci->nresults=nresults;
1170n=(*curr_func(L)->c.f)(L);
1171if(n<0)
1172return 2;
1173else{
1174luaD_poscall(L,L->top-n);
1175return 1;
1176}
1177}
1178}
1179static int luaD_poscall(lua_State*L,StkId firstResult){
1180StkId res;
1181int wanted,i;
1182CallInfo*ci;
1183ci=L->ci--;
1184res=ci->func;
1185wanted=ci->nresults;
1186L->base=(ci-1)->base;
1187L->savedpc=(ci-1)->savedpc;
1188for(i=wanted;i!=0&&firstResult<L->top;i--)
1189setobj(L,res++,firstResult++);
1190while(i-->0)
1191setnilvalue(res++);
1192L->top=res;
1193return(wanted-(-1));
1194}
1195static void luaD_call(lua_State*L,StkId func,int nResults){
1196if(++L->nCcalls>=200){
1197if(L->nCcalls==200)
1198luaG_runerror(L,"C stack overflow");
1199else if(L->nCcalls>=(200+(200>>3)))
1200luaD_throw(L,5);
1201}
1202if(luaD_precall(L,func,nResults)==0)
1203luaV_execute(L,1);
1204L->nCcalls--;
1205luaC_checkGC(L);
1206}
1207static int luaD_pcall(lua_State*L,Pfunc func,void*u,
1208ptrdiff_t old_top,ptrdiff_t ef){
1209int status;
1210unsigned short oldnCcalls=L->nCcalls;
1211ptrdiff_t old_ci=saveci(L,L->ci);
1212lu_byte old_allowhooks=L->allowhook;
1213ptrdiff_t old_errfunc=L->errfunc;
1214L->errfunc=ef;
1215status=luaD_rawrunprotected(L,func,u);
1216if(status!=0){
1217StkId oldtop=restorestack(L,old_top);
1218luaF_close(L,oldtop);
1219luaD_seterrorobj(L,status,oldtop);
1220L->nCcalls=oldnCcalls;
1221L->ci=restoreci(L,old_ci);
1222L->base=L->ci->base;
1223L->savedpc=L->ci->savedpc;
1224L->allowhook=old_allowhooks;
1225restore_stack_limit(L);
1226}
1227L->errfunc=old_errfunc;
1228return status;
1229}
1230struct SParser{
1231ZIO*z;
1232Mbuffer buff;
1233const char*name;
1234};
1235static void f_parser(lua_State*L,void*ud){
1236int i;
1237Proto*tf;
1238Closure*cl;
1239struct SParser*p=cast(struct SParser*,ud);
1240luaC_checkGC(L);
1241tf=luaY_parser(L,p->z,
1242&p->buff,p->name);
1243cl=luaF_newLclosure(L,tf->nups,hvalue(gt(L)));
1244cl->l.p=tf;
1245for(i=0;i<tf->nups;i++)
1246cl->l.upvals[i]=luaF_newupval(L);
1247setclvalue(L,L->top,cl);
1248incr_top(L);
1249}
1250static int luaD_protectedparser(lua_State*L,ZIO*z,const char*name){
1251struct SParser p;
1252int status;
1253p.z=z;p.name=name;
1254luaZ_initbuffer(L,&p.buff);
1255status=luaD_pcall(L,f_parser,&p,savestack(L,L->top),L->errfunc);
1256luaZ_freebuffer(L,&p.buff);
1257return status;
1258}
1259static void luaS_resize(lua_State*L,int newsize){
1260GCObject**newhash;
1261stringtable*tb;
1262int i;
1263if(G(L)->gcstate==2)
1264return;
1265newhash=luaM_newvector(L,newsize,GCObject*);
1266tb=&G(L)->strt;
1267for(i=0;i<newsize;i++)newhash[i]=NULL;
1268for(i=0;i<tb->size;i++){
1269GCObject*p=tb->hash[i];
1270while(p){
1271GCObject*next=p->gch.next;
1272unsigned int h=gco2ts(p)->hash;
1273int h1=lmod(h,newsize);
1274p->gch.next=newhash[h1];
1275newhash[h1]=p;
1276p=next;
1277}
1278}
1279luaM_freearray(L,tb->hash,tb->size,TString*);
1280tb->size=newsize;
1281tb->hash=newhash;
1282}
1283static TString*newlstr(lua_State*L,const char*str,size_t l,
1284unsigned int h){
1285TString*ts;
1286stringtable*tb;
1287if(l+1>(((size_t)(~(size_t)0)-2)-sizeof(TString))/sizeof(char))
1288luaM_toobig(L);
1289ts=cast(TString*,luaM_malloc(L,(l+1)*sizeof(char)+sizeof(TString)));
1290ts->tsv.len=l;
1291ts->tsv.hash=h;
1292ts->tsv.marked=luaC_white(G(L));
1293ts->tsv.tt=4;
1294ts->tsv.reserved=0;
1295memcpy(ts+1,str,l*sizeof(char));
1296((char*)(ts+1))[l]='\0';
1297tb=&G(L)->strt;
1298h=lmod(h,tb->size);
1299ts->tsv.next=tb->hash[h];
1300tb->hash[h]=obj2gco(ts);
1301tb->nuse++;
1302if(tb->nuse>cast(lu_int32,tb->size)&&tb->size<=(INT_MAX-2)/2)
1303luaS_resize(L,tb->size*2);
1304return ts;
1305}
1306static TString*luaS_newlstr(lua_State*L,const char*str,size_t l){
1307GCObject*o;
1308unsigned int h=cast(unsigned int,l);
1309size_t step=(l>>5)+1;
1310size_t l1;
1311for(l1=l;l1>=step;l1-=step)
1312h=h^((h<<5)+(h>>2)+cast(unsigned char,str[l1-1]));
1313for(o=G(L)->strt.hash[lmod(h,G(L)->strt.size)];
1314o!=NULL;
1315o=o->gch.next){
1316TString*ts=rawgco2ts(o);
1317if(ts->tsv.len==l&&(memcmp(str,getstr(ts),l)==0)){
1318if(isdead(G(L),o))changewhite(o);
1319return ts;
1320}
1321}
1322return newlstr(L,str,l,h);
1323}
1324static Udata*luaS_newudata(lua_State*L,size_t s,Table*e){
1325Udata*u;
1326if(s>((size_t)(~(size_t)0)-2)-sizeof(Udata))
1327luaM_toobig(L);
1328u=cast(Udata*,luaM_malloc(L,s+sizeof(Udata)));
1329u->uv.marked=luaC_white(G(L));
1330u->uv.tt=7;
1331u->uv.len=s;
1332u->uv.metatable=NULL;
1333u->uv.env=e;
1334u->uv.next=G(L)->mainthread->next;
1335G(L)->mainthread->next=obj2gco(u);
1336return u;
1337}
1338#define hashpow2(t,n)(gnode(t,lmod((n),sizenode(t))))
1339#define hashstr(t,str)hashpow2(t,(str)->tsv.hash)
1340#define hashboolean(t,p)hashpow2(t,p)
1341#define hashmod(t,n)(gnode(t,((n)%((sizenode(t)-1)|1))))
1342#define hashpointer(t,p)hashmod(t,IntPoint(p))
1343static const Node dummynode_={
1344{{NULL},0},
1345{{{NULL},0,NULL}}
1346};
1347static Node*hashnum(const Table*t,lua_Number n){
1348unsigned int a[cast_int(sizeof(lua_Number)/sizeof(int))];
1349int i;
1350if(luai_numeq(n,0))
1351return gnode(t,0);
1352memcpy(a,&n,sizeof(a));
1353for(i=1;i<cast_int(sizeof(lua_Number)/sizeof(int));i++)a[0]+=a[i];
1354return hashmod(t,a[0]);
1355}
1356static Node*mainposition(const Table*t,const TValue*key){
1357switch(ttype(key)){
1358case 3:
1359return hashnum(t,nvalue(key));
1360case 4:
1361return hashstr(t,rawtsvalue(key));
1362case 1:
1363return hashboolean(t,bvalue(key));
1364case 2:
1365return hashpointer(t,pvalue(key));
1366default:
1367return hashpointer(t,gcvalue(key));
1368}
1369}
1370static int arrayindex(const TValue*key){
1371if(ttisnumber(key)){
1372lua_Number n=nvalue(key);
1373int k;
1374lua_number2int(k,n);
1375if(luai_numeq(cast_num(k),n))
1376return k;
1377}
1378return-1;
1379}
1380static int findindex(lua_State*L,Table*t,StkId key){
1381int i;
1382if(ttisnil(key))return-1;
1383i=arrayindex(key);
1384if(0<i&&i<=t->sizearray)
1385return i-1;
1386else{
1387Node*n=mainposition(t,key);
1388do{
1389if(luaO_rawequalObj(key2tval(n),key)||
1390(ttype(gkey(n))==(8+3)&&iscollectable(key)&&
1391gcvalue(gkey(n))==gcvalue(key))){
1392i=cast_int(n-gnode(t,0));
1393return i+t->sizearray;
1394}
1395else n=gnext(n);
1396}while(n);
1397luaG_runerror(L,"invalid key to "LUA_QL("next"));
1398return 0;
1399}
1400}
1401static int luaH_next(lua_State*L,Table*t,StkId key){
1402int i=findindex(L,t,key);
1403for(i++;i<t->sizearray;i++){
1404if(!ttisnil(&t->array[i])){
1405setnvalue(key,cast_num(i+1));
1406setobj(L,key+1,&t->array[i]);
1407return 1;
1408}
1409}
1410for(i-=t->sizearray;i<(int)sizenode(t);i++){
1411if(!ttisnil(gval(gnode(t,i)))){
1412setobj(L,key,key2tval(gnode(t,i)));
1413setobj(L,key+1,gval(gnode(t,i)));
1414return 1;
1415}
1416}
1417return 0;
1418}
1419static int computesizes(int nums[],int*narray){
1420int i;
1421int twotoi;
1422int a=0;
1423int na=0;
1424int n=0;
1425for(i=0,twotoi=1;twotoi/2<*narray;i++,twotoi*=2){
1426if(nums[i]>0){
1427a+=nums[i];
1428if(a>twotoi/2){
1429n=twotoi;
1430na=a;
1431}
1432}
1433if(a==*narray)break;
1434}
1435*narray=n;
1436return na;
1437}
1438static int countint(const TValue*key,int*nums){
1439int k=arrayindex(key);
1440if(0<k&&k<=(1<<(32-2))){
1441nums[ceillog2(k)]++;
1442return 1;
1443}
1444else
1445return 0;
1446}
1447static int numusearray(const Table*t,int*nums){
1448int lg;
1449int ttlg;
1450int ause=0;
1451int i=1;
1452for(lg=0,ttlg=1;lg<=(32-2);lg++,ttlg*=2){
1453int lc=0;
1454int lim=ttlg;
1455if(lim>t->sizearray){
1456lim=t->sizearray;
1457if(i>lim)
1458break;
1459}
1460for(;i<=lim;i++){
1461if(!ttisnil(&t->array[i-1]))
1462lc++;
1463}
1464nums[lg]+=lc;
1465ause+=lc;
1466}
1467return ause;
1468}
1469static int numusehash(const Table*t,int*nums,int*pnasize){
1470int totaluse=0;
1471int ause=0;
1472int i=sizenode(t);
1473while(i--){
1474Node*n=&t->node[i];
1475if(!ttisnil(gval(n))){
1476ause+=countint(key2tval(n),nums);
1477totaluse++;
1478}
1479}
1480*pnasize+=ause;
1481return totaluse;
1482}
1483static void setarrayvector(lua_State*L,Table*t,int size){
1484int i;
1485luaM_reallocvector(L,t->array,t->sizearray,size,TValue);
1486for(i=t->sizearray;i<size;i++)
1487setnilvalue(&t->array[i]);
1488t->sizearray=size;
1489}
1490static void setnodevector(lua_State*L,Table*t,int size){
1491int lsize;
1492if(size==0){
1493t->node=cast(Node*,(&dummynode_));
1494lsize=0;
1495}
1496else{
1497int i;
1498lsize=ceillog2(size);
1499if(lsize>(32-2))
1500luaG_runerror(L,"table overflow");
1501size=twoto(lsize);
1502t->node=luaM_newvector(L,size,Node);
1503for(i=0;i<size;i++){
1504Node*n=gnode(t,i);
1505gnext(n)=NULL;
1506setnilvalue(gkey(n));
1507setnilvalue(gval(n));
1508}
1509}
1510t->lsizenode=cast_byte(lsize);
1511t->lastfree=gnode(t,size);
1512}
1513static void resize(lua_State*L,Table*t,int nasize,int nhsize){
1514int i;
1515int oldasize=t->sizearray;
1516int oldhsize=t->lsizenode;
1517Node*nold=t->node;
1518if(nasize>oldasize)
1519setarrayvector(L,t,nasize);
1520setnodevector(L,t,nhsize);
1521if(nasize<oldasize){
1522t->sizearray=nasize;
1523for(i=nasize;i<oldasize;i++){
1524if(!ttisnil(&t->array[i]))
1525setobj(L,luaH_setnum(L,t,i+1),&t->array[i]);
1526}
1527luaM_reallocvector(L,t->array,oldasize,nasize,TValue);
1528}
1529for(i=twoto(oldhsize)-1;i>=0;i--){
1530Node*old=nold+i;
1531if(!ttisnil(gval(old)))
1532setobj(L,luaH_set(L,t,key2tval(old)),gval(old));
1533}
1534if(nold!=(&dummynode_))
1535luaM_freearray(L,nold,twoto(oldhsize),Node);
1536}
1537static void luaH_resizearray(lua_State*L,Table*t,int nasize){
1538int nsize=(t->node==(&dummynode_))?0:sizenode(t);
1539resize(L,t,nasize,nsize);
1540}
1541static void rehash(lua_State*L,Table*t,const TValue*ek){
1542int nasize,na;
1543int nums[(32-2)+1];
1544int i;
1545int totaluse;
1546for(i=0;i<=(32-2);i++)nums[i]=0;
1547nasize=numusearray(t,nums);
1548totaluse=nasize;
1549totaluse+=numusehash(t,nums,&nasize);
1550nasize+=countint(ek,nums);
1551totaluse++;
1552na=computesizes(nums,&nasize);
1553resize(L,t,nasize,totaluse-na);
1554}
1555static Table*luaH_new(lua_State*L,int narray,int nhash){
1556Table*t=luaM_new(L,Table);
1557luaC_link(L,obj2gco(t),5);
1558t->metatable=NULL;
1559t->flags=cast_byte(~0);
1560t->array=NULL;
1561t->sizearray=0;
1562t->lsizenode=0;
1563t->node=cast(Node*,(&dummynode_));
1564setarrayvector(L,t,narray);
1565setnodevector(L,t,nhash);
1566return t;
1567}
1568static void luaH_free(lua_State*L,Table*t){
1569if(t->node!=(&dummynode_))
1570luaM_freearray(L,t->node,sizenode(t),Node);
1571luaM_freearray(L,t->array,t->sizearray,TValue);
1572luaM_free(L,t);
1573}
1574static Node*getfreepos(Table*t){
1575while(t->lastfree-->t->node){
1576if(ttisnil(gkey(t->lastfree)))
1577return t->lastfree;
1578}
1579return NULL;
1580}
1581static TValue*newkey(lua_State*L,Table*t,const TValue*key){
1582Node*mp=mainposition(t,key);
1583if(!ttisnil(gval(mp))||mp==(&dummynode_)){
1584Node*othern;
1585Node*n=getfreepos(t);
1586if(n==NULL){
1587rehash(L,t,key);
1588return luaH_set(L,t,key);
1589}
1590othern=mainposition(t,key2tval(mp));
1591if(othern!=mp){
1592while(gnext(othern)!=mp)othern=gnext(othern);
1593gnext(othern)=n;
1594*n=*mp;
1595gnext(mp)=NULL;
1596setnilvalue(gval(mp));
1597}
1598else{
1599gnext(n)=gnext(mp);
1600gnext(mp)=n;
1601mp=n;
1602}
1603}
1604gkey(mp)->value=key->value;gkey(mp)->tt=key->tt;
1605luaC_barriert(L,t,key);
1606return gval(mp);
1607}
1608static const TValue*luaH_getnum(Table*t,int key){
1609if(cast(unsigned int,key)-1<cast(unsigned int,t->sizearray))
1610return&t->array[key-1];
1611else{
1612lua_Number nk=cast_num(key);
1613Node*n=hashnum(t,nk);
1614do{
1615if(ttisnumber(gkey(n))&&luai_numeq(nvalue(gkey(n)),nk))
1616return gval(n);
1617else n=gnext(n);
1618}while(n);
1619return(&luaO_nilobject_);
1620}
1621}
1622static const TValue*luaH_getstr(Table*t,TString*key){
1623Node*n=hashstr(t,key);
1624do{
1625if(ttisstring(gkey(n))&&rawtsvalue(gkey(n))==key)
1626return gval(n);
1627else n=gnext(n);
1628}while(n);
1629return(&luaO_nilobject_);
1630}
1631static const TValue*luaH_get(Table*t,const TValue*key){
1632switch(ttype(key)){
1633case 0:return(&luaO_nilobject_);
1634case 4:return luaH_getstr(t,rawtsvalue(key));
1635case 3:{
1636int k;
1637lua_Number n=nvalue(key);
1638lua_number2int(k,n);
1639if(luai_numeq(cast_num(k),nvalue(key)))
1640return luaH_getnum(t,k);
1641}
1642/*fallthrough*/
1643default:{
1644Node*n=mainposition(t,key);
1645do{
1646if(luaO_rawequalObj(key2tval(n),key))
1647return gval(n);
1648else n=gnext(n);
1649}while(n);
1650return(&luaO_nilobject_);
1651}
1652}
1653}
1654static TValue*luaH_set(lua_State*L,Table*t,const TValue*key){
1655const TValue*p=luaH_get(t,key);
1656t->flags=0;
1657if(p!=(&luaO_nilobject_))
1658return cast(TValue*,p);
1659else{
1660if(ttisnil(key))luaG_runerror(L,"table index is nil");
1661else if(ttisnumber(key)&&luai_numisnan(nvalue(key)))
1662luaG_runerror(L,"table index is NaN");
1663return newkey(L,t,key);
1664}
1665}
1666static TValue*luaH_setnum(lua_State*L,Table*t,int key){
1667const TValue*p=luaH_getnum(t,key);
1668if(p!=(&luaO_nilobject_))
1669return cast(TValue*,p);
1670else{
1671TValue k;
1672setnvalue(&k,cast_num(key));
1673return newkey(L,t,&k);
1674}
1675}
1676static TValue*luaH_setstr(lua_State*L,Table*t,TString*key){
1677const TValue*p=luaH_getstr(t,key);
1678if(p!=(&luaO_nilobject_))
1679return cast(TValue*,p);
1680else{
1681TValue k;
1682setsvalue(L,&k,key);
1683return newkey(L,t,&k);
1684}
1685}
1686static int unbound_search(Table*t,unsigned int j){
1687unsigned int i=j;
1688j++;
1689while(!ttisnil(luaH_getnum(t,j))){
1690i=j;
1691j*=2;
1692if(j>cast(unsigned int,(INT_MAX-2))){
1693i=1;
1694while(!ttisnil(luaH_getnum(t,i)))i++;
1695return i-1;
1696}
1697}
1698while(j-i>1){
1699unsigned int m=(i+j)/2;
1700if(ttisnil(luaH_getnum(t,m)))j=m;
1701else i=m;
1702}
1703return i;
1704}
1705static int luaH_getn(Table*t){
1706unsigned int j=t->sizearray;
1707if(j>0&&ttisnil(&t->array[j-1])){
1708unsigned int i=0;
1709while(j-i>1){
1710unsigned int m=(i+j)/2;
1711if(ttisnil(&t->array[m-1]))j=m;
1712else i=m;
1713}
1714return i;
1715}
1716else if(t->node==(&dummynode_))
1717return j;
1718else return unbound_search(t,j);
1719}
1720#define makewhite(g,x)((x)->gch.marked=cast_byte(((x)->gch.marked&cast_byte(~(bitmask(2)|bit2mask(0,1))))|luaC_white(g)))
1721#define white2gray(x)reset2bits((x)->gch.marked,0,1)
1722#define black2gray(x)resetbit((x)->gch.marked,2)
1723#define stringmark(s)reset2bits((s)->tsv.marked,0,1)
1724#define isfinalized(u)testbit((u)->marked,3)
1725#define markfinalized(u)l_setbit((u)->marked,3)
1726#define markvalue(g,o){checkconsistency(o);if(iscollectable(o)&&iswhite(gcvalue(o)))reallymarkobject(g,gcvalue(o));}
1727#define markobject(g,t){if(iswhite(obj2gco(t)))reallymarkobject(g,obj2gco(t));}
1728#define setthreshold(g)(g->GCthreshold=(g->estimate/100)*g->gcpause)
1729static void removeentry(Node*n){
1730if(iscollectable(gkey(n)))
1731setttype(gkey(n),(8+3));
1732}
1733static void reallymarkobject(global_State*g,GCObject*o){
1734white2gray(o);
1735switch(o->gch.tt){
1736case 4:{
1737return;
1738}
1739case 7:{
1740Table*mt=gco2u(o)->metatable;
1741gray2black(o);
1742if(mt)markobject(g,mt);
1743markobject(g,gco2u(o)->env);
1744return;
1745}
1746case(8+2):{
1747UpVal*uv=gco2uv(o);
1748markvalue(g,uv->v);
1749if(uv->v==&uv->u.value)
1750gray2black(o);
1751return;
1752}
1753case 6:{
1754gco2cl(o)->c.gclist=g->gray;
1755g->gray=o;
1756break;
1757}
1758case 5:{
1759gco2h(o)->gclist=g->gray;
1760g->gray=o;
1761break;
1762}
1763case 8:{
1764gco2th(o)->gclist=g->gray;
1765g->gray=o;
1766break;
1767}
1768case(8+1):{
1769gco2p(o)->gclist=g->gray;
1770g->gray=o;
1771break;
1772}
1773default:;
1774}
1775}
1776static void marktmu(global_State*g){
1777GCObject*u=g->tmudata;
1778if(u){
1779do{
1780u=u->gch.next;
1781makewhite(g,u);
1782reallymarkobject(g,u);
1783}while(u!=g->tmudata);
1784}
1785}
1786static size_t luaC_separateudata(lua_State*L,int all){
1787global_State*g=G(L);
1788size_t deadmem=0;
1789GCObject**p=&g->mainthread->next;
1790GCObject*curr;
1791while((curr=*p)!=NULL){
1792if(!(iswhite(curr)||all)||isfinalized(gco2u(curr)))
1793p=&curr->gch.next;
1794else if(fasttm(L,gco2u(curr)->metatable,TM_GC)==NULL){
1795markfinalized(gco2u(curr));
1796p=&curr->gch.next;
1797}
1798else{
1799deadmem+=sizeudata(gco2u(curr));
1800markfinalized(gco2u(curr));
1801*p=curr->gch.next;
1802if(g->tmudata==NULL)
1803g->tmudata=curr->gch.next=curr;
1804else{
1805curr->gch.next=g->tmudata->gch.next;
1806g->tmudata->gch.next=curr;
1807g->tmudata=curr;
1808}
1809}
1810}
1811return deadmem;
1812}
1813static int traversetable(global_State*g,Table*h){
1814int i;
1815int weakkey=0;
1816int weakvalue=0;
1817const TValue*mode;
1818if(h->metatable)
1819markobject(g,h->metatable);
1820mode=gfasttm(g,h->metatable,TM_MODE);
1821if(mode&&ttisstring(mode)){
1822weakkey=(strchr(svalue(mode),'k')!=NULL);
1823weakvalue=(strchr(svalue(mode),'v')!=NULL);
1824if(weakkey||weakvalue){
1825h->marked&=~(bitmask(3)|bitmask(4));
1826h->marked|=cast_byte((weakkey<<3)|
1827(weakvalue<<4));
1828h->gclist=g->weak;
1829g->weak=obj2gco(h);
1830}
1831}
1832if(weakkey&&weakvalue)return 1;
1833if(!weakvalue){
1834i=h->sizearray;
1835while(i--)
1836markvalue(g,&h->array[i]);
1837}
1838i=sizenode(h);
1839while(i--){
1840Node*n=gnode(h,i);
1841if(ttisnil(gval(n)))
1842removeentry(n);
1843else{
1844if(!weakkey)markvalue(g,gkey(n));
1845if(!weakvalue)markvalue(g,gval(n));
1846}
1847}
1848return weakkey||weakvalue;
1849}
1850static void traverseproto(global_State*g,Proto*f){
1851int i;
1852if(f->source)stringmark(f->source);
1853for(i=0;i<f->sizek;i++)
1854markvalue(g,&f->k[i]);
1855for(i=0;i<f->sizeupvalues;i++){
1856if(f->upvalues[i])
1857stringmark(f->upvalues[i]);
1858}
1859for(i=0;i<f->sizep;i++){
1860if(f->p[i])
1861markobject(g,f->p[i]);
1862}
1863for(i=0;i<f->sizelocvars;i++){
1864if(f->locvars[i].varname)
1865stringmark(f->locvars[i].varname);
1866}
1867}
1868static void traverseclosure(global_State*g,Closure*cl){
1869markobject(g,cl->c.env);
1870if(cl->c.isC){
1871int i;
1872for(i=0;i<cl->c.nupvalues;i++)
1873markvalue(g,&cl->c.upvalue[i]);
1874}
1875else{
1876int i;
1877markobject(g,cl->l.p);
1878for(i=0;i<cl->l.nupvalues;i++)
1879markobject(g,cl->l.upvals[i]);
1880}
1881}
1882static void checkstacksizes(lua_State*L,StkId max){
1883int ci_used=cast_int(L->ci-L->base_ci);
1884int s_used=cast_int(max-L->stack);
1885if(L->size_ci>20000)
1886return;
1887if(4*ci_used<L->size_ci&&2*8<L->size_ci)
1888luaD_reallocCI(L,L->size_ci/2);
1889condhardstacktests(luaD_reallocCI(L,ci_used+1));
1890if(4*s_used<L->stacksize&&
18912*((2*20)+5)<L->stacksize)
1892luaD_reallocstack(L,L->stacksize/2);
1893condhardstacktests(luaD_reallocstack(L,s_used));
1894}
1895static void traversestack(global_State*g,lua_State*l){
1896StkId o,lim;
1897CallInfo*ci;
1898markvalue(g,gt(l));
1899lim=l->top;
1900for(ci=l->base_ci;ci<=l->ci;ci++){
1901if(lim<ci->top)lim=ci->top;
1902}
1903for(o=l->stack;o<l->top;o++)
1904markvalue(g,o);
1905for(;o<=lim;o++)
1906setnilvalue(o);
1907checkstacksizes(l,lim);
1908}
1909static l_mem propagatemark(global_State*g){
1910GCObject*o=g->gray;
1911gray2black(o);
1912switch(o->gch.tt){
1913case 5:{
1914Table*h=gco2h(o);
1915g->gray=h->gclist;
1916if(traversetable(g,h))
1917black2gray(o);
1918return sizeof(Table)+sizeof(TValue)*h->sizearray+
1919sizeof(Node)*sizenode(h);
1920}
1921case 6:{
1922Closure*cl=gco2cl(o);
1923g->gray=cl->c.gclist;
1924traverseclosure(g,cl);
1925return(cl->c.isC)?sizeCclosure(cl->c.nupvalues):
1926sizeLclosure(cl->l.nupvalues);
1927}
1928case 8:{
1929lua_State*th=gco2th(o);
1930g->gray=th->gclist;
1931th->gclist=g->grayagain;
1932g->grayagain=o;
1933black2gray(o);
1934traversestack(g,th);
1935return sizeof(lua_State)+sizeof(TValue)*th->stacksize+
1936sizeof(CallInfo)*th->size_ci;
1937}
1938case(8+1):{
1939Proto*p=gco2p(o);
1940g->gray=p->gclist;
1941traverseproto(g,p);
1942return sizeof(Proto)+sizeof(Instruction)*p->sizecode+
1943sizeof(Proto*)*p->sizep+
1944sizeof(TValue)*p->sizek+
1945sizeof(int)*p->sizelineinfo+
1946sizeof(LocVar)*p->sizelocvars+
1947sizeof(TString*)*p->sizeupvalues;
1948}
1949default:return 0;
1950}
1951}
1952static size_t propagateall(global_State*g){
1953size_t m=0;
1954while(g->gray)m+=propagatemark(g);
1955return m;
1956}
1957static int iscleared(const TValue*o,int iskey){
1958if(!iscollectable(o))return 0;
1959if(ttisstring(o)){
1960stringmark(rawtsvalue(o));
1961return 0;
1962}
1963return iswhite(gcvalue(o))||
1964(ttisuserdata(o)&&(!iskey&&isfinalized(uvalue(o))));
1965}
1966static void cleartable(GCObject*l){
1967while(l){
1968Table*h=gco2h(l);
1969int i=h->sizearray;
1970if(testbit(h->marked,4)){
1971while(i--){
1972TValue*o=&h->array[i];
1973if(iscleared(o,0))
1974setnilvalue(o);
1975}
1976}
1977i=sizenode(h);
1978while(i--){
1979Node*n=gnode(h,i);
1980if(!ttisnil(gval(n))&&
1981(iscleared(key2tval(n),1)||iscleared(gval(n),0))){
1982setnilvalue(gval(n));
1983removeentry(n);
1984}
1985}
1986l=h->gclist;
1987}
1988}
1989static void freeobj(lua_State*L,GCObject*o){
1990switch(o->gch.tt){
1991case(8+1):luaF_freeproto(L,gco2p(o));break;
1992case 6:luaF_freeclosure(L,gco2cl(o));break;
1993case(8+2):luaF_freeupval(L,gco2uv(o));break;
1994case 5:luaH_free(L,gco2h(o));break;
1995case 8:{
1996luaE_freethread(L,gco2th(o));
1997break;
1998}
1999case 4:{
2000G(L)->strt.nuse--;
2001luaM_freemem(L,o,sizestring(gco2ts(o)));
2002break;
2003}
2004case 7:{
2005luaM_freemem(L,o,sizeudata(gco2u(o)));
2006break;
2007}
2008default:;
2009}
2010}
2011#define sweepwholelist(L,p)sweeplist(L,p,((lu_mem)(~(lu_mem)0)-2))
2012static GCObject**sweeplist(lua_State*L,GCObject**p,lu_mem count){
2013GCObject*curr;
2014global_State*g=G(L);
2015int deadmask=otherwhite(g);
2016while((curr=*p)!=NULL&&count-->0){
2017if(curr->gch.tt==8)
2018sweepwholelist(L,&gco2th(curr)->openupval);
2019if((curr->gch.marked^bit2mask(0,1))&deadmask){
2020makewhite(g,curr);
2021p=&curr->gch.next;
2022}
2023else{
2024*p=curr->gch.next;
2025if(curr==g->rootgc)
2026g->rootgc=curr->gch.next;
2027freeobj(L,curr);
2028}
2029}
2030return p;
2031}
2032static void checkSizes(lua_State*L){
2033global_State*g=G(L);
2034if(g->strt.nuse<cast(lu_int32,g->strt.size/4)&&
2035g->strt.size>32*2)
2036luaS_resize(L,g->strt.size/2);
2037if(luaZ_sizebuffer(&g->buff)>32*2){
2038size_t newsize=luaZ_sizebuffer(&g->buff)/2;
2039luaZ_resizebuffer(L,&g->buff,newsize);
2040}
2041}
2042static void GCTM(lua_State*L){
2043global_State*g=G(L);
2044GCObject*o=g->tmudata->gch.next;
2045Udata*udata=rawgco2u(o);
2046const TValue*tm;
2047if(o==g->tmudata)
2048g->tmudata=NULL;
2049else
2050g->tmudata->gch.next=udata->uv.next;
2051udata->uv.next=g->mainthread->next;
2052g->mainthread->next=o;
2053makewhite(g,o);
2054tm=fasttm(L,udata->uv.metatable,TM_GC);
2055if(tm!=NULL){
2056lu_byte oldah=L->allowhook;
2057lu_mem oldt=g->GCthreshold;
2058L->allowhook=0;
2059g->GCthreshold=2*g->totalbytes;
2060setobj(L,L->top,tm);
2061setuvalue(L,L->top+1,udata);
2062L->top+=2;
2063luaD_call(L,L->top-2,0);
2064L->allowhook=oldah;
2065g->GCthreshold=oldt;
2066}
2067}
2068static void luaC_callGCTM(lua_State*L){
2069while(G(L)->tmudata)
2070GCTM(L);
2071}
2072static void luaC_freeall(lua_State*L){
2073global_State*g=G(L);
2074int i;
2075g->currentwhite=bit2mask(0,1)|bitmask(6);
2076sweepwholelist(L,&g->rootgc);
2077for(i=0;i<g->strt.size;i++)
2078sweepwholelist(L,&g->strt.hash[i]);
2079}
2080static void markmt(global_State*g){
2081int i;
2082for(i=0;i<(8+1);i++)
2083if(g->mt[i])markobject(g,g->mt[i]);
2084}
2085static void markroot(lua_State*L){
2086global_State*g=G(L);
2087g->gray=NULL;
2088g->grayagain=NULL;
2089g->weak=NULL;
2090markobject(g,g->mainthread);
2091markvalue(g,gt(g->mainthread));
2092markvalue(g,registry(L));
2093markmt(g);
2094g->gcstate=1;
2095}
2096static void remarkupvals(global_State*g){
2097UpVal*uv;
2098for(uv=g->uvhead.u.l.next;uv!=&g->uvhead;uv=uv->u.l.next){
2099if(isgray(obj2gco(uv)))
2100markvalue(g,uv->v);
2101}
2102}
2103static void atomic(lua_State*L){
2104global_State*g=G(L);
2105size_t udsize;
2106remarkupvals(g);
2107propagateall(g);
2108g->gray=g->weak;
2109g->weak=NULL;
2110markobject(g,L);
2111markmt(g);
2112propagateall(g);
2113g->gray=g->grayagain;
2114g->grayagain=NULL;
2115propagateall(g);
2116udsize=luaC_separateudata(L,0);
2117marktmu(g);
2118udsize+=propagateall(g);
2119cleartable(g->weak);
2120g->currentwhite=cast_byte(otherwhite(g));
2121g->sweepstrgc=0;
2122g->sweepgc=&g->rootgc;
2123g->gcstate=2;
2124g->estimate=g->totalbytes-udsize;
2125}
2126static l_mem singlestep(lua_State*L){
2127global_State*g=G(L);
2128switch(g->gcstate){
2129case 0:{
2130markroot(L);
2131return 0;
2132}
2133case 1:{
2134if(g->gray)
2135return propagatemark(g);
2136else{
2137atomic(L);
2138return 0;
2139}
2140}
2141case 2:{
2142lu_mem old=g->totalbytes;
2143sweepwholelist(L,&g->strt.hash[g->sweepstrgc++]);
2144if(g->sweepstrgc>=g->strt.size)
2145g->gcstate=3;
2146g->estimate-=old-g->totalbytes;
2147return 10;
2148}
2149case 3:{
2150lu_mem old=g->totalbytes;
2151g->sweepgc=sweeplist(L,g->sweepgc,40);
2152if(*g->sweepgc==NULL){
2153checkSizes(L);
2154g->gcstate=4;
2155}
2156g->estimate-=old-g->totalbytes;
2157return 40*10;
2158}
2159case 4:{
2160if(g->tmudata){
2161GCTM(L);
2162if(g->estimate>100)
2163g->estimate-=100;
2164return 100;
2165}
2166else{
2167g->gcstate=0;
2168g->gcdept=0;
2169return 0;
2170}
2171}
2172default:return 0;
2173}
2174}
2175static void luaC_step(lua_State*L){
2176global_State*g=G(L);
2177l_mem lim=(1024u/100)*g->gcstepmul;
2178if(lim==0)
2179lim=(((lu_mem)(~(lu_mem)0)-2)-1)/2;
2180g->gcdept+=g->totalbytes-g->GCthreshold;
2181do{
2182lim-=singlestep(L);
2183if(g->gcstate==0)
2184break;
2185}while(lim>0);
2186if(g->gcstate!=0){
2187if(g->gcdept<1024u)
2188g->GCthreshold=g->totalbytes+1024u;
2189else{
2190g->gcdept-=1024u;
2191g->GCthreshold=g->totalbytes;
2192}
2193}
2194else{
2195setthreshold(g);
2196}
2197}
2198static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v){
2199global_State*g=G(L);
2200if(g->gcstate==1)
2201reallymarkobject(g,v);
2202else
2203makewhite(g,o);
2204}
2205static void luaC_barrierback(lua_State*L,Table*t){
2206global_State*g=G(L);
2207GCObject*o=obj2gco(t);
2208black2gray(o);
2209t->gclist=g->grayagain;
2210g->grayagain=o;
2211}
2212static void luaC_link(lua_State*L,GCObject*o,lu_byte tt){
2213global_State*g=G(L);
2214o->gch.next=g->rootgc;
2215g->rootgc=o;
2216o->gch.marked=luaC_white(g);
2217o->gch.tt=tt;
2218}
2219static void luaC_linkupval(lua_State*L,UpVal*uv){
2220global_State*g=G(L);
2221GCObject*o=obj2gco(uv);
2222o->gch.next=g->rootgc;
2223g->rootgc=o;
2224if(isgray(o)){
2225if(g->gcstate==1){
2226gray2black(o);
2227luaC_barrier(L,uv,uv->v);
2228}
2229else{
2230makewhite(g,o);
2231}
2232}
2233}
2234typedef union{
2235lua_Number r;
2236TString*ts;
2237}SemInfo;
2238typedef struct Token{
2239int token;
2240SemInfo seminfo;
2241}Token;
2242typedef struct LexState{
2243int current;
2244int linenumber;
2245int lastline;
2246Token t;
2247Token lookahead;
2248struct FuncState*fs;
2249struct lua_State*L;
2250ZIO*z;
2251Mbuffer*buff;
2252TString*source;
2253char decpoint;
2254}LexState;
2255static void luaX_init(lua_State*L);
2256static void luaX_lexerror(LexState*ls,const char*msg,int token);
2257#define state_size(x)(sizeof(x)+0)
2258#define fromstate(l)(cast(lu_byte*,(l))-0)
2259#define tostate(l)(cast(lua_State*,cast(lu_byte*,l)+0))
2260typedef struct LG{
2261lua_State l;
2262global_State g;
2263}LG;
2264static void stack_init(lua_State*L1,lua_State*L){
2265L1->base_ci=luaM_newvector(L,8,CallInfo);
2266L1->ci=L1->base_ci;
2267L1->size_ci=8;
2268L1->end_ci=L1->base_ci+L1->size_ci-1;
2269L1->stack=luaM_newvector(L,(2*20)+5,TValue);
2270L1->stacksize=(2*20)+5;
2271L1->top=L1->stack;
2272L1->stack_last=L1->stack+(L1->stacksize-5)-1;
2273L1->ci->func=L1->top;
2274setnilvalue(L1->top++);
2275L1->base=L1->ci->base=L1->top;
2276L1->ci->top=L1->top+20;
2277}
2278static void freestack(lua_State*L,lua_State*L1){
2279luaM_freearray(L,L1->base_ci,L1->size_ci,CallInfo);
2280luaM_freearray(L,L1->stack,L1->stacksize,TValue);
2281}
2282static void f_luaopen(lua_State*L,void*ud){
2283global_State*g=G(L);
2284UNUSED(ud);
2285stack_init(L,L);
2286sethvalue(L,gt(L),luaH_new(L,0,2));
2287sethvalue(L,registry(L),luaH_new(L,0,2));
2288luaS_resize(L,32);
2289luaT_init(L);
2290luaX_init(L);
2291luaS_fix(luaS_newliteral(L,"not enough memory"));
2292g->GCthreshold=4*g->totalbytes;
2293}
2294static void preinit_state(lua_State*L,global_State*g){
2295G(L)=g;
2296L->stack=NULL;
2297L->stacksize=0;
2298L->errorJmp=NULL;
2299L->hook=NULL;
2300L->hookmask=0;
2301L->basehookcount=0;
2302L->allowhook=1;
2303resethookcount(L);
2304L->openupval=NULL;
2305L->size_ci=0;
2306L->nCcalls=L->baseCcalls=0;
2307L->status=0;
2308L->base_ci=L->ci=NULL;
2309L->savedpc=NULL;
2310L->errfunc=0;
2311setnilvalue(gt(L));
2312}
2313static void close_state(lua_State*L){
2314global_State*g=G(L);
2315luaF_close(L,L->stack);
2316luaC_freeall(L);
2317luaM_freearray(L,G(L)->strt.hash,G(L)->strt.size,TString*);
2318luaZ_freebuffer(L,&g->buff);
2319freestack(L,L);
2320(*g->frealloc)(g->ud,fromstate(L),state_size(LG),0);
2321}
2322static void luaE_freethread(lua_State*L,lua_State*L1){
2323luaF_close(L1,L1->stack);
2324freestack(L,L1);
2325luaM_freemem(L,fromstate(L1),state_size(lua_State));
2326}
2327static lua_State*lua_newstate(lua_Alloc f,void*ud){
2328int i;
2329lua_State*L;
2330global_State*g;
2331void*l=(*f)(ud,NULL,0,state_size(LG));
2332if(l==NULL)return NULL;
2333L=tostate(l);
2334g=&((LG*)L)->g;
2335L->next=NULL;
2336L->tt=8;
2337g->currentwhite=bit2mask(0,5);
2338L->marked=luaC_white(g);
2339set2bits(L->marked,5,6);
2340preinit_state(L,g);
2341g->frealloc=f;
2342g->ud=ud;
2343g->mainthread=L;
2344g->uvhead.u.l.prev=&g->uvhead;
2345g->uvhead.u.l.next=&g->uvhead;
2346g->GCthreshold=0;
2347g->strt.size=0;
2348g->strt.nuse=0;
2349g->strt.hash=NULL;
2350setnilvalue(registry(L));
2351luaZ_initbuffer(L,&g->buff);
2352g->panic=NULL;
2353g->gcstate=0;
2354g->rootgc=obj2gco(L);
2355g->sweepstrgc=0;
2356g->sweepgc=&g->rootgc;
2357g->gray=NULL;
2358g->grayagain=NULL;
2359g->weak=NULL;
2360g->tmudata=NULL;
2361g->totalbytes=sizeof(LG);
2362g->gcpause=200;
2363g->gcstepmul=200;
2364g->gcdept=0;
2365for(i=0;i<(8+1);i++)g->mt[i]=NULL;
2366if(luaD_rawrunprotected(L,f_luaopen,NULL)!=0){
2367close_state(L);
2368L=NULL;
2369}
2370else
2371{}
2372return L;
2373}
2374static void callallgcTM(lua_State*L,void*ud){
2375UNUSED(ud);
2376luaC_callGCTM(L);
2377}
2378static void lua_close(lua_State*L){
2379L=G(L)->mainthread;
2380luaF_close(L,L->stack);
2381luaC_separateudata(L,1);
2382L->errfunc=0;
2383do{
2384L->ci=L->base_ci;
2385L->base=L->top=L->ci->base;
2386L->nCcalls=L->baseCcalls=0;
2387}while(luaD_rawrunprotected(L,callallgcTM,NULL)!=0);
2388close_state(L);
2389}
2390#define getcode(fs,e)((fs)->f->code[(e)->u.s.info])
2391#define luaK_codeAsBx(fs,o,A,sBx)luaK_codeABx(fs,o,A,(sBx)+(((1<<(9+9))-1)>>1))
2392#define luaK_setmultret(fs,e)luaK_setreturns(fs,e,(-1))
2393static int luaK_codeABx(FuncState*fs,OpCode o,int A,unsigned int Bx);
2394static int luaK_codeABC(FuncState*fs,OpCode o,int A,int B,int C);
2395static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults);
2396static void luaK_patchtohere(FuncState*fs,int list);
2397static void luaK_concat(FuncState*fs,int*l1,int l2);
2398static int currentpc(lua_State*L,CallInfo*ci){
2399if(!isLua(ci))return-1;
2400if(ci==L->ci)
2401ci->savedpc=L->savedpc;
2402return pcRel(ci->savedpc,ci_func(ci)->l.p);
2403}
2404static int currentline(lua_State*L,CallInfo*ci){
2405int pc=currentpc(L,ci);
2406if(pc<0)
2407return-1;
2408else
2409return getline_(ci_func(ci)->l.p,pc);
2410}
2411static int lua_getstack(lua_State*L,int level,lua_Debug*ar){
2412int status;
2413CallInfo*ci;
2414for(ci=L->ci;level>0&&ci>L->base_ci;ci--){
2415level--;
2416if(f_isLua(ci))
2417level-=ci->tailcalls;
2418}
2419if(level==0&&ci>L->base_ci){
2420status=1;
2421ar->i_ci=cast_int(ci-L->base_ci);
2422}
2423else if(level<0){
2424status=1;
2425ar->i_ci=0;
2426}
2427else status=0;
2428return status;
2429}
2430static Proto*getluaproto(CallInfo*ci){
2431return(isLua(ci)?ci_func(ci)->l.p:NULL);
2432}
2433static void funcinfo(lua_Debug*ar,Closure*cl){
2434if(cl->c.isC){
2435ar->source="=[C]";
2436ar->linedefined=-1;
2437ar->lastlinedefined=-1;
2438ar->what="C";
2439}
2440else{
2441ar->source=getstr(cl->l.p->source);
2442ar->linedefined=cl->l.p->linedefined;
2443ar->lastlinedefined=cl->l.p->lastlinedefined;
2444ar->what=(ar->linedefined==0)?"main":"Lua";
2445}
2446luaO_chunkid(ar->short_src,ar->source,60);
2447}
2448static void info_tailcall(lua_Debug*ar){
2449ar->name=ar->namewhat="";
2450ar->what="tail";
2451ar->lastlinedefined=ar->linedefined=ar->currentline=-1;
2452ar->source="=(tail call)";
2453luaO_chunkid(ar->short_src,ar->source,60);
2454ar->nups=0;
2455}
2456static void collectvalidlines(lua_State*L,Closure*f){
2457if(f==NULL||f->c.isC){
2458setnilvalue(L->top);
2459}
2460else{
2461Table*t=luaH_new(L,0,0);
2462int*lineinfo=f->l.p->lineinfo;
2463int i;
2464for(i=0;i<f->l.p->sizelineinfo;i++)
2465setbvalue(luaH_setnum(L,t,lineinfo[i]),1);
2466sethvalue(L,L->top,t);
2467}
2468incr_top(L);
2469}
2470static int auxgetinfo(lua_State*L,const char*what,lua_Debug*ar,
2471Closure*f,CallInfo*ci){
2472int status=1;
2473if(f==NULL){
2474info_tailcall(ar);
2475return status;
2476}
2477for(;*what;what++){
2478switch(*what){
2479case'S':{
2480funcinfo(ar,f);
2481break;
2482}
2483case'l':{
2484ar->currentline=(ci)?currentline(L,ci):-1;
2485break;
2486}
2487case'u':{
2488ar->nups=f->c.nupvalues;
2489break;
2490}
2491case'n':{
2492ar->namewhat=(ci)?NULL:NULL;
2493if(ar->namewhat==NULL){
2494ar->namewhat="";
2495ar->name=NULL;
2496}
2497break;
2498}
2499case'L':
2500case'f':
2501break;
2502default:status=0;
2503}
2504}
2505return status;
2506}
2507static int lua_getinfo(lua_State*L,const char*what,lua_Debug*ar){
2508int status;
2509Closure*f=NULL;
2510CallInfo*ci=NULL;
2511if(*what=='>'){
2512StkId func=L->top-1;
2513luai_apicheck(L,ttisfunction(func));
2514what++;
2515f=clvalue(func);
2516L->top--;
2517}
2518else if(ar->i_ci!=0){
2519ci=L->base_ci+ar->i_ci;
2520f=clvalue(ci->func);
2521}
2522status=auxgetinfo(L,what,ar,f,ci);
2523if(strchr(what,'f')){
2524if(f==NULL)setnilvalue(L->top);
2525else setclvalue(L,L->top,f);
2526incr_top(L);
2527}
2528if(strchr(what,'L'))
2529collectvalidlines(L,f);
2530return status;
2531}
2532static int isinstack(CallInfo*ci,const TValue*o){
2533StkId p;
2534for(p=ci->base;p<ci->top;p++)
2535if(o==p)return 1;
2536return 0;
2537}
2538static void luaG_typeerror(lua_State*L,const TValue*o,const char*op){
2539const char*name=NULL;
2540const char*t=luaT_typenames[ttype(o)];
2541const char*kind=(isinstack(L->ci,o))?
2542NULL:
2543NULL;
2544if(kind)
2545luaG_runerror(L,"attempt to %s %s "LUA_QL("%s")" (a %s value)",
2546op,kind,name,t);
2547else
2548luaG_runerror(L,"attempt to %s a %s value",op,t);
2549}
2550static void luaG_concaterror(lua_State*L,StkId p1,StkId p2){
2551if(ttisstring(p1)||ttisnumber(p1))p1=p2;
2552luaG_typeerror(L,p1,"concatenate");
2553}
2554static void luaG_aritherror(lua_State*L,const TValue*p1,const TValue*p2){
2555TValue temp;
2556if(luaV_tonumber(p1,&temp)==NULL)
2557p2=p1;
2558luaG_typeerror(L,p2,"perform arithmetic on");
2559}
2560static int luaG_ordererror(lua_State*L,const TValue*p1,const TValue*p2){
2561const char*t1=luaT_typenames[ttype(p1)];
2562const char*t2=luaT_typenames[ttype(p2)];
2563if(t1[2]==t2[2])
2564luaG_runerror(L,"attempt to compare two %s values",t1);
2565else
2566luaG_runerror(L,"attempt to compare %s with %s",t1,t2);
2567return 0;
2568}
2569static void addinfo(lua_State*L,const char*msg){
2570CallInfo*ci=L->ci;
2571if(isLua(ci)){
2572char buff[60];
2573int line=currentline(L,ci);
2574luaO_chunkid(buff,getstr(getluaproto(ci)->source),60);
2575luaO_pushfstring(L,"%s:%d: %s",buff,line,msg);
2576}
2577}
2578static void luaG_errormsg(lua_State*L){
2579if(L->errfunc!=0){
2580StkId errfunc=restorestack(L,L->errfunc);
2581if(!ttisfunction(errfunc))luaD_throw(L,5);
2582setobj(L,L->top,L->top-1);
2583setobj(L,L->top-1,errfunc);
2584incr_top(L);
2585luaD_call(L,L->top-2,1);
2586}
2587luaD_throw(L,2);
2588}
2589static void luaG_runerror(lua_State*L,const char*fmt,...){
2590va_list argp;
2591va_start(argp,fmt);
2592addinfo(L,luaO_pushvfstring(L,fmt,argp));
2593va_end(argp);
2594luaG_errormsg(L);
2595}
2596static int luaZ_fill(ZIO*z){
2597size_t size;
2598lua_State*L=z->L;
2599const char*buff;
2600buff=z->reader(L,z->data,&size);
2601if(buff==NULL||size==0)return(-1);
2602z->n=size-1;
2603z->p=buff;
2604return char2int(*(z->p++));
2605}
2606static void luaZ_init(lua_State*L,ZIO*z,lua_Reader reader,void*data){
2607z->L=L;
2608z->reader=reader;
2609z->data=data;
2610z->n=0;
2611z->p=NULL;
2612}
2613static char*luaZ_openspace(lua_State*L,Mbuffer*buff,size_t n){
2614if(n>buff->buffsize){
2615if(n<32)n=32;
2616luaZ_resizebuffer(L,buff,n);
2617}
2618return buff->buffer;
2619}
2620#define opmode(t,a,b,c,m)(((t)<<7)|((a)<<6)|((b)<<4)|((c)<<2)|(m))
2621static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]={
2622opmode(0,1,OpArgR,OpArgN,iABC)
2623,opmode(0,1,OpArgK,OpArgN,iABx)
2624,opmode(0,1,OpArgU,OpArgU,iABC)
2625,opmode(0,1,OpArgR,OpArgN,iABC)
2626,opmode(0,1,OpArgU,OpArgN,iABC)
2627,opmode(0,1,OpArgK,OpArgN,iABx)
2628,opmode(0,1,OpArgR,OpArgK,iABC)
2629,opmode(0,0,OpArgK,OpArgN,iABx)
2630,opmode(0,0,OpArgU,OpArgN,iABC)
2631,opmode(0,0,OpArgK,OpArgK,iABC)
2632,opmode(0,1,OpArgU,OpArgU,iABC)
2633,opmode(0,1,OpArgR,OpArgK,iABC)
2634,opmode(0,1,OpArgK,OpArgK,iABC)
2635,opmode(0,1,OpArgK,OpArgK,iABC)
2636,opmode(0,1,OpArgK,OpArgK,iABC)
2637,opmode(0,1,OpArgK,OpArgK,iABC)
2638,opmode(0,1,OpArgK,OpArgK,iABC)
2639,opmode(0,1,OpArgK,OpArgK,iABC)
2640,opmode(0,1,OpArgR,OpArgN,iABC)
2641,opmode(0,1,OpArgR,OpArgN,iABC)
2642,opmode(0,1,OpArgR,OpArgN,iABC)
2643,opmode(0,1,OpArgR,OpArgR,iABC)
2644,opmode(0,0,OpArgR,OpArgN,iAsBx)
2645,opmode(1,0,OpArgK,OpArgK,iABC)
2646,opmode(1,0,OpArgK,OpArgK,iABC)
2647,opmode(1,0,OpArgK,OpArgK,iABC)
2648,opmode(1,1,OpArgR,OpArgU,iABC)
2649,opmode(1,1,OpArgR,OpArgU,iABC)
2650,opmode(0,1,OpArgU,OpArgU,iABC)
2651,opmode(0,1,OpArgU,OpArgU,iABC)
2652,opmode(0,0,OpArgU,OpArgN,iABC)
2653,opmode(0,1,OpArgR,OpArgN,iAsBx)
2654,opmode(0,1,OpArgR,OpArgN,iAsBx)
2655,opmode(1,0,OpArgN,OpArgU,iABC)
2656,opmode(0,0,OpArgU,OpArgU,iABC)
2657,opmode(0,0,OpArgN,OpArgN,iABC)
2658,opmode(0,1,OpArgU,OpArgN,iABx)
2659,opmode(0,1,OpArgU,OpArgN,iABC)
2660};
2661#define next(ls)(ls->current=zgetc(ls->z))
2662#define currIsNewline(ls)(ls->current=='\n'||ls->current=='\r')
2663static const char*const luaX_tokens[]={
2664"and","break","do","else","elseif",
2665"end","false","for","function","if",
2666"in","local","nil","not","or","repeat",
2667"return","then","true","until","while",
2668"..","...","==",">=","<=","~=",
2669"<number>","<name>","<string>","<eof>",
2670NULL
2671};
2672#define save_and_next(ls)(save(ls,ls->current),next(ls))
2673static void save(LexState*ls,int c){
2674Mbuffer*b=ls->buff;
2675if(b->n+1>b->buffsize){
2676size_t newsize;
2677if(b->buffsize>=((size_t)(~(size_t)0)-2)/2)
2678luaX_lexerror(ls,"lexical element too long",0);
2679newsize=b->buffsize*2;
2680luaZ_resizebuffer(ls->L,b,newsize);
2681}
2682b->buffer[b->n++]=cast(char,c);
2683}
2684static void luaX_init(lua_State*L){
2685int i;
2686for(i=0;i<(cast(int,TK_WHILE-257+1));i++){
2687TString*ts=luaS_new(L,luaX_tokens[i]);
2688luaS_fix(ts);
2689ts->tsv.reserved=cast_byte(i+1);
2690}
2691}
2692static const char*luaX_token2str(LexState*ls,int token){
2693if(token<257){
2694return(iscntrl(token))?luaO_pushfstring(ls->L,"char(%d)",token):
2695luaO_pushfstring(ls->L,"%c",token);
2696}
2697else
2698return luaX_tokens[token-257];
2699}
2700static const char*txtToken(LexState*ls,int token){
2701switch(token){
2702case TK_NAME:
2703case TK_STRING:
2704case TK_NUMBER:
2705save(ls,'\0');
2706return luaZ_buffer(ls->buff);
2707default:
2708return luaX_token2str(ls,token);
2709}
2710}
2711static void luaX_lexerror(LexState*ls,const char*msg,int token){
2712char buff[80];
2713luaO_chunkid(buff,getstr(ls->source),80);
2714msg=luaO_pushfstring(ls->L,"%s:%d: %s",buff,ls->linenumber,msg);
2715if(token)
2716luaO_pushfstring(ls->L,"%s near "LUA_QL("%s"),msg,txtToken(ls,token));
2717luaD_throw(ls->L,3);
2718}
2719static void luaX_syntaxerror(LexState*ls,const char*msg){
2720luaX_lexerror(ls,msg,ls->t.token);
2721}
2722static TString*luaX_newstring(LexState*ls,const char*str,size_t l){
2723lua_State*L=ls->L;
2724TString*ts=luaS_newlstr(L,str,l);
2725TValue*o=luaH_setstr(L,ls->fs->h,ts);
2726if(ttisnil(o)){
2727setbvalue(o,1);
2728luaC_checkGC(L);
2729}
2730return ts;
2731}
2732static void inclinenumber(LexState*ls){
2733int old=ls->current;
2734next(ls);
2735if(currIsNewline(ls)&&ls->current!=old)
2736next(ls);
2737if(++ls->linenumber>=(INT_MAX-2))
2738luaX_syntaxerror(ls,"chunk has too many lines");
2739}
2740static void luaX_setinput(lua_State*L,LexState*ls,ZIO*z,TString*source){
2741ls->decpoint='.';
2742ls->L=L;
2743ls->lookahead.token=TK_EOS;
2744ls->z=z;
2745ls->fs=NULL;
2746ls->linenumber=1;
2747ls->lastline=1;
2748ls->source=source;
2749luaZ_resizebuffer(ls->L,ls->buff,32);
2750next(ls);
2751}
2752static int check_next(LexState*ls,const char*set){
2753if(!strchr(set,ls->current))
2754return 0;
2755save_and_next(ls);
2756return 1;
2757}
2758static void buffreplace(LexState*ls,char from,char to){
2759size_t n=luaZ_bufflen(ls->buff);
2760char*p=luaZ_buffer(ls->buff);
2761while(n--)
2762if(p[n]==from)p[n]=to;
2763}
2764static void read_numeral(LexState*ls,SemInfo*seminfo){
2765do{
2766save_and_next(ls);
2767}while(isdigit(ls->current)||ls->current=='.');
2768if(check_next(ls,"Ee"))
2769check_next(ls,"+-");
2770while(isalnum(ls->current)||ls->current=='_')
2771save_and_next(ls);
2772save(ls,'\0');
2773buffreplace(ls,'.',ls->decpoint);
2774if(!luaO_str2d(luaZ_buffer(ls->buff),&seminfo->r))
2775luaX_lexerror(ls,"malformed number",TK_NUMBER);
2776}
2777static int skip_sep(LexState*ls){
2778int count=0;
2779int s=ls->current;
2780save_and_next(ls);
2781while(ls->current=='='){
2782save_and_next(ls);
2783count++;
2784}
2785return(ls->current==s)?count:(-count)-1;
2786}
2787static void read_long_string(LexState*ls,SemInfo*seminfo,int sep){
2788int cont=0;
2789(void)(cont);
2790save_and_next(ls);
2791if(currIsNewline(ls))
2792inclinenumber(ls);
2793for(;;){
2794switch(ls->current){
2795case(-1):
2796luaX_lexerror(ls,(seminfo)?"unfinished long string":
2797"unfinished long comment",TK_EOS);
2798break;
2799case']':{
2800if(skip_sep(ls)==sep){
2801save_and_next(ls);
2802goto endloop;
2803}
2804break;
2805}
2806case'\n':
2807case'\r':{
2808save(ls,'\n');
2809inclinenumber(ls);
2810if(!seminfo)luaZ_resetbuffer(ls->buff);
2811break;
2812}
2813default:{
2814if(seminfo)save_and_next(ls);
2815else next(ls);
2816}
2817}
2818}endloop:
2819if(seminfo)
2820seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+(2+sep),
2821luaZ_bufflen(ls->buff)-2*(2+sep));
2822}
2823static void read_string(LexState*ls,int del,SemInfo*seminfo){
2824save_and_next(ls);
2825while(ls->current!=del){
2826switch(ls->current){
2827case(-1):
2828luaX_lexerror(ls,"unfinished string",TK_EOS);
2829continue;
2830case'\n':
2831case'\r':
2832luaX_lexerror(ls,"unfinished string",TK_STRING);
2833continue;
2834case'\\':{
2835int c;
2836next(ls);
2837switch(ls->current){
2838case'a':c='\a';break;
2839case'b':c='\b';break;
2840case'f':c='\f';break;
2841case'n':c='\n';break;
2842case'r':c='\r';break;
2843case't':c='\t';break;
2844case'v':c='\v';break;
2845case'\n':
2846case'\r':save(ls,'\n');inclinenumber(ls);continue;
2847case(-1):continue;
2848default:{
2849if(!isdigit(ls->current))
2850save_and_next(ls);
2851else{
2852int i=0;
2853c=0;
2854do{
2855c=10*c+(ls->current-'0');
2856next(ls);
2857}while(++i<3&&isdigit(ls->current));
2858if(c>UCHAR_MAX)
2859luaX_lexerror(ls,"escape sequence too large",TK_STRING);
2860save(ls,c);
2861}
2862continue;
2863}
2864}
2865save(ls,c);
2866next(ls);
2867continue;
2868}
2869default:
2870save_and_next(ls);
2871}
2872}
2873save_and_next(ls);
2874seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+1,
2875luaZ_bufflen(ls->buff)-2);
2876}
2877static int llex(LexState*ls,SemInfo*seminfo){
2878luaZ_resetbuffer(ls->buff);
2879for(;;){
2880switch(ls->current){
2881case'\n':
2882case'\r':{
2883inclinenumber(ls);
2884continue;
2885}
2886case'-':{
2887next(ls);
2888if(ls->current!='-')return'-';
2889next(ls);
2890if(ls->current=='['){
2891int sep=skip_sep(ls);
2892luaZ_resetbuffer(ls->buff);
2893if(sep>=0){
2894read_long_string(ls,NULL,sep);
2895luaZ_resetbuffer(ls->buff);
2896continue;
2897}
2898}
2899while(!currIsNewline(ls)&&ls->current!=(-1))
2900next(ls);
2901continue;
2902}
2903case'[':{
2904int sep=skip_sep(ls);
2905if(sep>=0){
2906read_long_string(ls,seminfo,sep);
2907return TK_STRING;
2908}
2909else if (sep!=-1)luaX_lexerror(ls,"invalid long string delimiter",TK_STRING);
2910return'[';
2911}
2912case'=':{
2913next(ls);
2914if(ls->current!='=')return'=';
2915else{next(ls);return TK_EQ;}
2916}
2917case'<':{
2918next(ls);
2919if(ls->current!='=')return'<';
2920else{next(ls);return TK_LE;}
2921}
2922case'>':{
2923next(ls);
2924if(ls->current!='=')return'>';
2925else{next(ls);return TK_GE;}
2926}
2927case'~':{
2928next(ls);
2929if(ls->current!='=')return'~';
2930else{next(ls);return TK_NE;}
2931}
2932case'"':
2933case'\'':{
2934read_string(ls,ls->current,seminfo);
2935return TK_STRING;
2936}
2937case'.':{
2938save_and_next(ls);
2939if(check_next(ls,".")){
2940if(check_next(ls,"."))
2941return TK_DOTS;
2942else return TK_CONCAT;
2943}
2944else if(!isdigit(ls->current))return'.';
2945else{
2946read_numeral(ls,seminfo);
2947return TK_NUMBER;
2948}
2949}
2950case(-1):{
2951return TK_EOS;
2952}
2953default:{
2954if(isspace(ls->current)){
2955next(ls);
2956continue;
2957}
2958else if(isdigit(ls->current)){
2959read_numeral(ls,seminfo);
2960return TK_NUMBER;
2961}
2962else if(isalpha(ls->current)||ls->current=='_'){
2963TString*ts;
2964do{
2965save_and_next(ls);
2966}while(isalnum(ls->current)||ls->current=='_');
2967ts=luaX_newstring(ls,luaZ_buffer(ls->buff),
2968luaZ_bufflen(ls->buff));
2969if(ts->tsv.reserved>0)
2970return ts->tsv.reserved-1+257;
2971else{
2972seminfo->ts=ts;
2973return TK_NAME;
2974}
2975}
2976else{
2977int c=ls->current;
2978next(ls);
2979return c;
2980}
2981}
2982}
2983}
2984}
2985static void luaX_next(LexState*ls){
2986ls->lastline=ls->linenumber;
2987if(ls->lookahead.token!=TK_EOS){
2988ls->t=ls->lookahead;
2989ls->lookahead.token=TK_EOS;
2990}
2991else
2992ls->t.token=llex(ls,&ls->t.seminfo);
2993}
2994static void luaX_lookahead(LexState*ls){
2995ls->lookahead.token=llex(ls,&ls->lookahead.seminfo);
2996}
2997#define hasjumps(e)((e)->t!=(e)->f)
2998static int isnumeral(expdesc*e){
2999return(e->k==VKNUM&&e->t==(-1)&&e->f==(-1));
3000}
3001static void luaK_nil(FuncState*fs,int from,int n){
3002Instruction*previous;
3003if(fs->pc>fs->lasttarget){
3004if(fs->pc==0){
3005if(from>=fs->nactvar)
3006return;
3007}
3008else{
3009previous=&fs->f->code[fs->pc-1];
3010if(GET_OPCODE(*previous)==OP_LOADNIL){
3011int pfrom=GETARG_A(*previous);
3012int pto=GETARG_B(*previous);
3013if(pfrom<=from&&from<=pto+1){
3014if(from+n-1>pto)
3015SETARG_B(*previous,from+n-1);
3016return;
3017}
3018}
3019}
3020}
3021luaK_codeABC(fs,OP_LOADNIL,from,from+n-1,0);
3022}
3023static int luaK_jump(FuncState*fs){
3024int jpc=fs->jpc;
3025int j;
3026fs->jpc=(-1);
3027j=luaK_codeAsBx(fs,OP_JMP,0,(-1));
3028luaK_concat(fs,&j,jpc);
3029return j;
3030}
3031static void luaK_ret(FuncState*fs,int first,int nret){
3032luaK_codeABC(fs,OP_RETURN,first,nret+1,0);
3033}
3034static int condjump(FuncState*fs,OpCode op,int A,int B,int C){
3035luaK_codeABC(fs,op,A,B,C);
3036return luaK_jump(fs);
3037}
3038static void fixjump(FuncState*fs,int pc,int dest){
3039Instruction*jmp=&fs->f->code[pc];
3040int offset=dest-(pc+1);
3041if(abs(offset)>(((1<<(9+9))-1)>>1))
3042luaX_syntaxerror(fs->ls,"control structure too long");
3043SETARG_sBx(*jmp,offset);
3044}
3045static int luaK_getlabel(FuncState*fs){
3046fs->lasttarget=fs->pc;
3047return fs->pc;
3048}
3049static int getjump(FuncState*fs,int pc){
3050int offset=GETARG_sBx(fs->f->code[pc]);
3051if(offset==(-1))
3052return(-1);
3053else
3054return(pc+1)+offset;
3055}
3056static Instruction*getjumpcontrol(FuncState*fs,int pc){
3057Instruction*pi=&fs->f->code[pc];
3058if(pc>=1&&testTMode(GET_OPCODE(*(pi-1))))
3059return pi-1;
3060else
3061return pi;
3062}
3063static int need_value(FuncState*fs,int list){
3064for(;list!=(-1);list=getjump(fs,list)){
3065Instruction i=*getjumpcontrol(fs,list);
3066if(GET_OPCODE(i)!=OP_TESTSET)return 1;
3067}
3068return 0;
3069}
3070static int patchtestreg(FuncState*fs,int node,int reg){
3071Instruction*i=getjumpcontrol(fs,node);
3072if(GET_OPCODE(*i)!=OP_TESTSET)
3073return 0;
3074if(reg!=((1<<8)-1)&&reg!=GETARG_B(*i))
3075SETARG_A(*i,reg);
3076else
3077*i=CREATE_ABC(OP_TEST,GETARG_B(*i),0,GETARG_C(*i));
3078return 1;
3079}
3080static void removevalues(FuncState*fs,int list){
3081for(;list!=(-1);list=getjump(fs,list))
3082patchtestreg(fs,list,((1<<8)-1));
3083}
3084static void patchlistaux(FuncState*fs,int list,int vtarget,int reg,
3085int dtarget){
3086while(list!=(-1)){
3087int next=getjump(fs,list);
3088if(patchtestreg(fs,list,reg))
3089fixjump(fs,list,vtarget);
3090else
3091fixjump(fs,list,dtarget);
3092list=next;
3093}
3094}
3095static void dischargejpc(FuncState*fs){
3096patchlistaux(fs,fs->jpc,fs->pc,((1<<8)-1),fs->pc);
3097fs->jpc=(-1);
3098}
3099static void luaK_patchlist(FuncState*fs,int list,int target){
3100if(target==fs->pc)
3101luaK_patchtohere(fs,list);
3102else{
3103patchlistaux(fs,list,target,((1<<8)-1),target);
3104}
3105}
3106static void luaK_patchtohere(FuncState*fs,int list){
3107luaK_getlabel(fs);
3108luaK_concat(fs,&fs->jpc,list);
3109}
3110static void luaK_concat(FuncState*fs,int*l1,int l2){
3111if(l2==(-1))return;
3112else if(*l1==(-1))
3113*l1=l2;
3114else{
3115int list=*l1;
3116int next;
3117while((next=getjump(fs,list))!=(-1))
3118list=next;
3119fixjump(fs,list,l2);
3120}
3121}
3122static void luaK_checkstack(FuncState*fs,int n){
3123int newstack=fs->freereg+n;
3124if(newstack>fs->f->maxstacksize){
3125if(newstack>=250)
3126luaX_syntaxerror(fs->ls,"function or expression too complex");
3127fs->f->maxstacksize=cast_byte(newstack);
3128}
3129}
3130static void luaK_reserveregs(FuncState*fs,int n){
3131luaK_checkstack(fs,n);
3132fs->freereg+=n;
3133}
3134static void freereg(FuncState*fs,int reg){
3135if(!ISK(reg)&&reg>=fs->nactvar){
3136fs->freereg--;
3137}
3138}
3139static void freeexp(FuncState*fs,expdesc*e){
3140if(e->k==VNONRELOC)
3141freereg(fs,e->u.s.info);
3142}
3143static int addk(FuncState*fs,TValue*k,TValue*v){
3144lua_State*L=fs->L;
3145TValue*idx=luaH_set(L,fs->h,k);
3146Proto*f=fs->f;
3147int oldsize=f->sizek;
3148if(ttisnumber(idx)){
3149return cast_int(nvalue(idx));
3150}
3151else{
3152setnvalue(idx,cast_num(fs->nk));
3153luaM_growvector(L,f->k,fs->nk,f->sizek,TValue,
3154((1<<(9+9))-1),"constant table overflow");
3155while(oldsize<f->sizek)setnilvalue(&f->k[oldsize++]);
3156setobj(L,&f->k[fs->nk],v);
3157luaC_barrier(L,f,v);
3158return fs->nk++;
3159}
3160}
3161static int luaK_stringK(FuncState*fs,TString*s){
3162TValue o;
3163setsvalue(fs->L,&o,s);
3164return addk(fs,&o,&o);
3165}
3166static int luaK_numberK(FuncState*fs,lua_Number r){
3167TValue o;
3168setnvalue(&o,r);
3169return addk(fs,&o,&o);
3170}
3171static int boolK(FuncState*fs,int b){
3172TValue o;
3173setbvalue(&o,b);
3174return addk(fs,&o,&o);
3175}
3176static int nilK(FuncState*fs){
3177TValue k,v;
3178setnilvalue(&v);
3179sethvalue(fs->L,&k,fs->h);
3180return addk(fs,&k,&v);
3181}
3182static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults){
3183if(e->k==VCALL){
3184SETARG_C(getcode(fs,e),nresults+1);
3185}
3186else if(e->k==VVARARG){
3187SETARG_B(getcode(fs,e),nresults+1);
3188SETARG_A(getcode(fs,e),fs->freereg);
3189luaK_reserveregs(fs,1);
3190}
3191}
3192static void luaK_setoneret(FuncState*fs,expdesc*e){
3193if(e->k==VCALL){
3194e->k=VNONRELOC;
3195e->u.s.info=GETARG_A(getcode(fs,e));
3196}
3197else if(e->k==VVARARG){
3198SETARG_B(getcode(fs,e),2);
3199e->k=VRELOCABLE;
3200}
3201}
3202static void luaK_dischargevars(FuncState*fs,expdesc*e){
3203switch(e->k){
3204case VLOCAL:{
3205e->k=VNONRELOC;
3206break;
3207}
3208case VUPVAL:{
3209e->u.s.info=luaK_codeABC(fs,OP_GETUPVAL,0,e->u.s.info,0);
3210e->k=VRELOCABLE;
3211break;
3212}
3213case VGLOBAL:{
3214e->u.s.info=luaK_codeABx(fs,OP_GETGLOBAL,0,e->u.s.info);
3215e->k=VRELOCABLE;
3216break;
3217}
3218case VINDEXED:{
3219freereg(fs,e->u.s.aux);
3220freereg(fs,e->u.s.info);
3221e->u.s.info=luaK_codeABC(fs,OP_GETTABLE,0,e->u.s.info,e->u.s.aux);
3222e->k=VRELOCABLE;
3223break;
3224}
3225case VVARARG:
3226case VCALL:{
3227luaK_setoneret(fs,e);
3228break;
3229}
3230default:break;
3231}
3232}
3233static int code_label(FuncState*fs,int A,int b,int jump){
3234luaK_getlabel(fs);
3235return luaK_codeABC(fs,OP_LOADBOOL,A,b,jump);
3236}
3237static void discharge2reg(FuncState*fs,expdesc*e,int reg){
3238luaK_dischargevars(fs,e);
3239switch(e->k){
3240case VNIL:{
3241luaK_nil(fs,reg,1);
3242break;
3243}
3244case VFALSE:case VTRUE:{
3245luaK_codeABC(fs,OP_LOADBOOL,reg,e->k==VTRUE,0);
3246break;
3247}
3248case VK:{
3249luaK_codeABx(fs,OP_LOADK,reg,e->u.s.info);
3250break;
3251}
3252case VKNUM:{
3253luaK_codeABx(fs,OP_LOADK,reg,luaK_numberK(fs,e->u.nval));
3254break;
3255}
3256case VRELOCABLE:{
3257Instruction*pc=&getcode(fs,e);
3258SETARG_A(*pc,reg);
3259break;
3260}
3261case VNONRELOC:{
3262if(reg!=e->u.s.info)
3263luaK_codeABC(fs,OP_MOVE,reg,e->u.s.info,0);
3264break;
3265}
3266default:{
3267return;
3268}
3269}
3270e->u.s.info=reg;
3271e->k=VNONRELOC;
3272}
3273static void discharge2anyreg(FuncState*fs,expdesc*e){
3274if(e->k!=VNONRELOC){
3275luaK_reserveregs(fs,1);
3276discharge2reg(fs,e,fs->freereg-1);
3277}
3278}
3279static void exp2reg(FuncState*fs,expdesc*e,int reg){
3280discharge2reg(fs,e,reg);
3281if(e->k==VJMP)
3282luaK_concat(fs,&e->t,e->u.s.info);
3283if(hasjumps(e)){
3284int final;
3285int p_f=(-1);
3286int p_t=(-1);
3287if(need_value(fs,e->t)||need_value(fs,e->f)){
3288int fj=(e->k==VJMP)?(-1):luaK_jump(fs);
3289p_f=code_label(fs,reg,0,1);
3290p_t=code_label(fs,reg,1,0);
3291luaK_patchtohere(fs,fj);
3292}
3293final=luaK_getlabel(fs);
3294patchlistaux(fs,e->f,final,reg,p_f);
3295patchlistaux(fs,e->t,final,reg,p_t);
3296}
3297e->f=e->t=(-1);
3298e->u.s.info=reg;
3299e->k=VNONRELOC;
3300}
3301static void luaK_exp2nextreg(FuncState*fs,expdesc*e){
3302luaK_dischargevars(fs,e);
3303freeexp(fs,e);
3304luaK_reserveregs(fs,1);
3305exp2reg(fs,e,fs->freereg-1);
3306}
3307static int luaK_exp2anyreg(FuncState*fs,expdesc*e){
3308luaK_dischargevars(fs,e);
3309if(e->k==VNONRELOC){
3310if(!hasjumps(e))return e->u.s.info;
3311if(e->u.s.info>=fs->nactvar){
3312exp2reg(fs,e,e->u.s.info);
3313return e->u.s.info;
3314}
3315}
3316luaK_exp2nextreg(fs,e);
3317return e->u.s.info;
3318}
3319static void luaK_exp2val(FuncState*fs,expdesc*e){
3320if(hasjumps(e))
3321luaK_exp2anyreg(fs,e);
3322else
3323luaK_dischargevars(fs,e);
3324}
3325static int luaK_exp2RK(FuncState*fs,expdesc*e){
3326luaK_exp2val(fs,e);
3327switch(e->k){
3328case VKNUM:
3329case VTRUE:
3330case VFALSE:
3331case VNIL:{
3332if(fs->nk<=((1<<(9-1))-1)){
3333e->u.s.info=(e->k==VNIL)?nilK(fs):
3334(e->k==VKNUM)?luaK_numberK(fs,e->u.nval):
3335boolK(fs,(e->k==VTRUE));
3336e->k=VK;
3337return RKASK(e->u.s.info);
3338}
3339else break;
3340}
3341case VK:{
3342if(e->u.s.info<=((1<<(9-1))-1))
3343return RKASK(e->u.s.info);
3344else break;
3345}
3346default:break;
3347}
3348return luaK_exp2anyreg(fs,e);
3349}
3350static void luaK_storevar(FuncState*fs,expdesc*var,expdesc*ex){
3351switch(var->k){
3352case VLOCAL:{
3353freeexp(fs,ex);
3354exp2reg(fs,ex,var->u.s.info);
3355return;
3356}
3357case VUPVAL:{
3358int e=luaK_exp2anyreg(fs,ex);
3359luaK_codeABC(fs,OP_SETUPVAL,e,var->u.s.info,0);
3360break;
3361}
3362case VGLOBAL:{
3363int e=luaK_exp2anyreg(fs,ex);
3364luaK_codeABx(fs,OP_SETGLOBAL,e,var->u.s.info);
3365break;
3366}
3367case VINDEXED:{
3368int e=luaK_exp2RK(fs,ex);
3369luaK_codeABC(fs,OP_SETTABLE,var->u.s.info,var->u.s.aux,e);
3370break;
3371}
3372default:{
3373break;
3374}
3375}
3376freeexp(fs,ex);
3377}
3378static void luaK_self(FuncState*fs,expdesc*e,expdesc*key){
3379int func;
3380luaK_exp2anyreg(fs,e);
3381freeexp(fs,e);
3382func=fs->freereg;
3383luaK_reserveregs(fs,2);
3384luaK_codeABC(fs,OP_SELF,func,e->u.s.info,luaK_exp2RK(fs,key));
3385freeexp(fs,key);
3386e->u.s.info=func;
3387e->k=VNONRELOC;
3388}
3389static void invertjump(FuncState*fs,expdesc*e){
3390Instruction*pc=getjumpcontrol(fs,e->u.s.info);
3391SETARG_A(*pc,!(GETARG_A(*pc)));
3392}
3393static int jumponcond(FuncState*fs,expdesc*e,int cond){
3394if(e->k==VRELOCABLE){
3395Instruction ie=getcode(fs,e);
3396if(GET_OPCODE(ie)==OP_NOT){
3397fs->pc--;
3398return condjump(fs,OP_TEST,GETARG_B(ie),0,!cond);
3399}
3400}
3401discharge2anyreg(fs,e);
3402freeexp(fs,e);
3403return condjump(fs,OP_TESTSET,((1<<8)-1),e->u.s.info,cond);
3404}
3405static void luaK_goiftrue(FuncState*fs,expdesc*e){
3406int pc;
3407luaK_dischargevars(fs,e);
3408switch(e->k){
3409case VK:case VKNUM:case VTRUE:{
3410pc=(-1);
3411break;
3412}
3413case VJMP:{
3414invertjump(fs,e);
3415pc=e->u.s.info;
3416break;
3417}
3418default:{
3419pc=jumponcond(fs,e,0);
3420break;
3421}
3422}
3423luaK_concat(fs,&e->f,pc);
3424luaK_patchtohere(fs,e->t);
3425e->t=(-1);
3426}
3427static void luaK_goiffalse(FuncState*fs,expdesc*e){
3428int pc;
3429luaK_dischargevars(fs,e);
3430switch(e->k){
3431case VNIL:case VFALSE:{
3432pc=(-1);
3433break;
3434}
3435case VJMP:{
3436pc=e->u.s.info;
3437break;
3438}
3439default:{
3440pc=jumponcond(fs,e,1);
3441break;
3442}
3443}
3444luaK_concat(fs,&e->t,pc);
3445luaK_patchtohere(fs,e->f);
3446e->f=(-1);
3447}
3448static void codenot(FuncState*fs,expdesc*e){
3449luaK_dischargevars(fs,e);
3450switch(e->k){
3451case VNIL:case VFALSE:{
3452e->k=VTRUE;
3453break;
3454}
3455case VK:case VKNUM:case VTRUE:{
3456e->k=VFALSE;
3457break;
3458}
3459case VJMP:{
3460invertjump(fs,e);
3461break;
3462}
3463case VRELOCABLE:
3464case VNONRELOC:{
3465discharge2anyreg(fs,e);
3466freeexp(fs,e);
3467e->u.s.info=luaK_codeABC(fs,OP_NOT,0,e->u.s.info,0);
3468e->k=VRELOCABLE;
3469break;
3470}
3471default:{
3472break;
3473}
3474}
3475{int temp=e->f;e->f=e->t;e->t=temp;}
3476removevalues(fs,e->f);
3477removevalues(fs,e->t);
3478}
3479static void luaK_indexed(FuncState*fs,expdesc*t,expdesc*k){
3480t->u.s.aux=luaK_exp2RK(fs,k);
3481t->k=VINDEXED;
3482}
3483static int constfolding(OpCode op,expdesc*e1,expdesc*e2){
3484lua_Number v1,v2,r;
3485if(!isnumeral(e1)||!isnumeral(e2))return 0;
3486v1=e1->u.nval;
3487v2=e2->u.nval;
3488switch(op){
3489case OP_ADD:r=luai_numadd(v1,v2);break;
3490case OP_SUB:r=luai_numsub(v1,v2);break;
3491case OP_MUL:r=luai_nummul(v1,v2);break;
3492case OP_DIV:
3493if(v2==0)return 0;
3494r=luai_numdiv(v1,v2);break;
3495case OP_MOD:
3496if(v2==0)return 0;
3497r=luai_nummod(v1,v2);break;
3498case OP_POW:r=luai_numpow(v1,v2);break;
3499case OP_UNM:r=luai_numunm(v1);break;
3500case OP_LEN:return 0;
3501default:r=0;break;
3502}
3503if(luai_numisnan(r))return 0;
3504e1->u.nval=r;
3505return 1;
3506}
3507static void codearith(FuncState*fs,OpCode op,expdesc*e1,expdesc*e2){
3508if(constfolding(op,e1,e2))
3509return;
3510else{
3511int o2=(op!=OP_UNM&&op!=OP_LEN)?luaK_exp2RK(fs,e2):0;
3512int o1=luaK_exp2RK(fs,e1);
3513if(o1>o2){
3514freeexp(fs,e1);
3515freeexp(fs,e2);
3516}
3517else{
3518freeexp(fs,e2);
3519freeexp(fs,e1);
3520}
3521e1->u.s.info=luaK_codeABC(fs,op,0,o1,o2);
3522e1->k=VRELOCABLE;
3523}
3524}
3525static void codecomp(FuncState*fs,OpCode op,int cond,expdesc*e1,
3526expdesc*e2){
3527int o1=luaK_exp2RK(fs,e1);
3528int o2=luaK_exp2RK(fs,e2);
3529freeexp(fs,e2);
3530freeexp(fs,e1);
3531if(cond==0&&op!=OP_EQ){
3532int temp;
3533temp=o1;o1=o2;o2=temp;
3534cond=1;
3535}
3536e1->u.s.info=condjump(fs,op,cond,o1,o2);
3537e1->k=VJMP;
3538}
3539static void luaK_prefix(FuncState*fs,UnOpr op,expdesc*e){
3540expdesc e2;
3541e2.t=e2.f=(-1);e2.k=VKNUM;e2.u.nval=0;
3542switch(op){
3543case OPR_MINUS:{
3544if(!isnumeral(e))
3545luaK_exp2anyreg(fs,e);
3546codearith(fs,OP_UNM,e,&e2);
3547break;
3548}
3549case OPR_NOT:codenot(fs,e);break;
3550case OPR_LEN:{
3551luaK_exp2anyreg(fs,e);
3552codearith(fs,OP_LEN,e,&e2);
3553break;
3554}
3555default:;
3556}
3557}
3558static void luaK_infix(FuncState*fs,BinOpr op,expdesc*v){
3559switch(op){
3560case OPR_AND:{
3561luaK_goiftrue(fs,v);
3562break;
3563}
3564case OPR_OR:{
3565luaK_goiffalse(fs,v);
3566break;
3567}
3568case OPR_CONCAT:{
3569luaK_exp2nextreg(fs,v);
3570break;
3571}
3572case OPR_ADD:case OPR_SUB:case OPR_MUL:case OPR_DIV:
3573case OPR_MOD:case OPR_POW:{
3574if(!isnumeral(v))luaK_exp2RK(fs,v);
3575break;
3576}
3577default:{
3578luaK_exp2RK(fs,v);
3579break;
3580}
3581}
3582}
3583static void luaK_posfix(FuncState*fs,BinOpr op,expdesc*e1,expdesc*e2){
3584switch(op){
3585case OPR_AND:{
3586luaK_dischargevars(fs,e2);
3587luaK_concat(fs,&e2->f,e1->f);
3588*e1=*e2;
3589break;
3590}
3591case OPR_OR:{
3592luaK_dischargevars(fs,e2);
3593luaK_concat(fs,&e2->t,e1->t);
3594*e1=*e2;
3595break;
3596}
3597case OPR_CONCAT:{
3598luaK_exp2val(fs,e2);
3599if(e2->k==VRELOCABLE&&GET_OPCODE(getcode(fs,e2))==OP_CONCAT){
3600freeexp(fs,e1);
3601SETARG_B(getcode(fs,e2),e1->u.s.info);
3602e1->k=VRELOCABLE;e1->u.s.info=e2->u.s.info;
3603}
3604else{
3605luaK_exp2nextreg(fs,e2);
3606codearith(fs,OP_CONCAT,e1,e2);
3607}
3608break;
3609}
3610case OPR_ADD:codearith(fs,OP_ADD,e1,e2);break;
3611case OPR_SUB:codearith(fs,OP_SUB,e1,e2);break;
3612case OPR_MUL:codearith(fs,OP_MUL,e1,e2);break;
3613case OPR_DIV:codearith(fs,OP_DIV,e1,e2);break;
3614case OPR_MOD:codearith(fs,OP_MOD,e1,e2);break;
3615case OPR_POW:codearith(fs,OP_POW,e1,e2);break;
3616case OPR_EQ:codecomp(fs,OP_EQ,1,e1,e2);break;
3617case OPR_NE:codecomp(fs,OP_EQ,0,e1,e2);break;
3618case OPR_LT:codecomp(fs,OP_LT,1,e1,e2);break;
3619case OPR_LE:codecomp(fs,OP_LE,1,e1,e2);break;
3620case OPR_GT:codecomp(fs,OP_LT,0,e1,e2);break;
3621case OPR_GE:codecomp(fs,OP_LE,0,e1,e2);break;
3622default:;
3623}
3624}
3625static void luaK_fixline(FuncState*fs,int line){
3626fs->f->lineinfo[fs->pc-1]=line;
3627}
3628static int luaK_code(FuncState*fs,Instruction i,int line){
3629Proto*f=fs->f;
3630dischargejpc(fs);
3631luaM_growvector(fs->L,f->code,fs->pc,f->sizecode,Instruction,
3632(INT_MAX-2),"code size overflow");
3633f->code[fs->pc]=i;
3634luaM_growvector(fs->L,f->lineinfo,fs->pc,f->sizelineinfo,int,
3635(INT_MAX-2),"code size overflow");
3636f->lineinfo[fs->pc]=line;
3637return fs->pc++;
3638}
3639static int luaK_codeABC(FuncState*fs,OpCode o,int a,int b,int c){
3640return luaK_code(fs,CREATE_ABC(o,a,b,c),fs->ls->lastline);
3641}
3642static int luaK_codeABx(FuncState*fs,OpCode o,int a,unsigned int bc){
3643return luaK_code(fs,CREATE_ABx(o,a,bc),fs->ls->lastline);
3644}
3645static void luaK_setlist(FuncState*fs,int base,int nelems,int tostore){
3646int c=(nelems-1)/50+1;
3647int b=(tostore==(-1))?0:tostore;
3648if(c<=((1<<9)-1))
3649luaK_codeABC(fs,OP_SETLIST,base,b,c);
3650else{
3651luaK_codeABC(fs,OP_SETLIST,base,b,0);
3652luaK_code(fs,cast(Instruction,c),fs->ls->lastline);
3653}
3654fs->freereg=base+1;
3655}
3656#define hasmultret(k)((k)==VCALL||(k)==VVARARG)
3657#define getlocvar(fs,i)((fs)->f->locvars[(fs)->actvar[i]])
3658#define luaY_checklimit(fs,v,l,m)if((v)>(l))errorlimit(fs,l,m)
3659typedef struct BlockCnt{
3660struct BlockCnt*previous;
3661int breaklist;
3662lu_byte nactvar;
3663lu_byte upval;
3664lu_byte isbreakable;
3665}BlockCnt;
3666static void chunk(LexState*ls);
3667static void expr(LexState*ls,expdesc*v);
3668static void anchor_token(LexState*ls){
3669if(ls->t.token==TK_NAME||ls->t.token==TK_STRING){
3670TString*ts=ls->t.seminfo.ts;
3671luaX_newstring(ls,getstr(ts),ts->tsv.len);
3672}
3673}
3674static void error_expected(LexState*ls,int token){
3675luaX_syntaxerror(ls,
3676luaO_pushfstring(ls->L,LUA_QL("%s")" expected",luaX_token2str(ls,token)));
3677}
3678static void errorlimit(FuncState*fs,int limit,const char*what){
3679const char*msg=(fs->f->linedefined==0)?
3680luaO_pushfstring(fs->L,"main function has more than %d %s",limit,what):
3681luaO_pushfstring(fs->L,"function at line %d has more than %d %s",
3682fs->f->linedefined,limit,what);
3683luaX_lexerror(fs->ls,msg,0);
3684}
3685static int testnext(LexState*ls,int c){
3686if(ls->t.token==c){
3687luaX_next(ls);
3688return 1;
3689}
3690else return 0;
3691}
3692static void check(LexState*ls,int c){
3693if(ls->t.token!=c)
3694error_expected(ls,c);
3695}
3696static void checknext(LexState*ls,int c){
3697check(ls,c);
3698luaX_next(ls);
3699}
3700#define check_condition(ls,c,msg){if(!(c))luaX_syntaxerror(ls,msg);}
3701static void check_match(LexState*ls,int what,int who,int where){
3702if(!testnext(ls,what)){
3703if(where==ls->linenumber)
3704error_expected(ls,what);
3705else{
3706luaX_syntaxerror(ls,luaO_pushfstring(ls->L,
3707LUA_QL("%s")" expected (to close "LUA_QL("%s")" at line %d)",
3708luaX_token2str(ls,what),luaX_token2str(ls,who),where));
3709}
3710}
3711}
3712static TString*str_checkname(LexState*ls){
3713TString*ts;
3714check(ls,TK_NAME);
3715ts=ls->t.seminfo.ts;
3716luaX_next(ls);
3717return ts;
3718}
3719static void init_exp(expdesc*e,expkind k,int i){
3720e->f=e->t=(-1);
3721e->k=k;
3722e->u.s.info=i;
3723}
3724static void codestring(LexState*ls,expdesc*e,TString*s){
3725init_exp(e,VK,luaK_stringK(ls->fs,s));
3726}
3727static void checkname(LexState*ls,expdesc*e){
3728codestring(ls,e,str_checkname(ls));
3729}
3730static int registerlocalvar(LexState*ls,TString*varname){
3731FuncState*fs=ls->fs;
3732Proto*f=fs->f;
3733int oldsize=f->sizelocvars;
3734luaM_growvector(ls->L,f->locvars,fs->nlocvars,f->sizelocvars,
3735LocVar,SHRT_MAX,"too many local variables");
3736while(oldsize<f->sizelocvars)f->locvars[oldsize++].varname=NULL;
3737f->locvars[fs->nlocvars].varname=varname;
3738luaC_objbarrier(ls->L,f,varname);
3739return fs->nlocvars++;
3740}
3741#define new_localvarliteral(ls,v,n)new_localvar(ls,luaX_newstring(ls,""v,(sizeof(v)/sizeof(char))-1),n)
3742static void new_localvar(LexState*ls,TString*name,int n){
3743FuncState*fs=ls->fs;
3744luaY_checklimit(fs,fs->nactvar+n+1,200,"local variables");
3745fs->actvar[fs->nactvar+n]=cast(unsigned short,registerlocalvar(ls,name));
3746}
3747static void adjustlocalvars(LexState*ls,int nvars){
3748FuncState*fs=ls->fs;
3749fs->nactvar=cast_byte(fs->nactvar+nvars);
3750for(;nvars;nvars--){
3751getlocvar(fs,fs->nactvar-nvars).startpc=fs->pc;
3752}
3753}
3754static void removevars(LexState*ls,int tolevel){
3755FuncState*fs=ls->fs;
3756while(fs->nactvar>tolevel)
3757getlocvar(fs,--fs->nactvar).endpc=fs->pc;
3758}
3759static int indexupvalue(FuncState*fs,TString*name,expdesc*v){
3760int i;
3761Proto*f=fs->f;
3762int oldsize=f->sizeupvalues;
3763for(i=0;i<f->nups;i++){
3764if(fs->upvalues[i].k==v->k&&fs->upvalues[i].info==v->u.s.info){
3765return i;
3766}
3767}
3768luaY_checklimit(fs,f->nups+1,60,"upvalues");
3769luaM_growvector(fs->L,f->upvalues,f->nups,f->sizeupvalues,
3770TString*,(INT_MAX-2),"");
3771while(oldsize<f->sizeupvalues)f->upvalues[oldsize++]=NULL;
3772f->upvalues[f->nups]=name;
3773luaC_objbarrier(fs->L,f,name);
3774fs->upvalues[f->nups].k=cast_byte(v->k);
3775fs->upvalues[f->nups].info=cast_byte(v->u.s.info);
3776return f->nups++;
3777}
3778static int searchvar(FuncState*fs,TString*n){
3779int i;
3780for(i=fs->nactvar-1;i>=0;i--){
3781if(n==getlocvar(fs,i).varname)
3782return i;
3783}
3784return-1;
3785}
3786static void markupval(FuncState*fs,int level){
3787BlockCnt*bl=fs->bl;
3788while(bl&&bl->nactvar>level)bl=bl->previous;
3789if(bl)bl->upval=1;
3790}
3791static int singlevaraux(FuncState*fs,TString*n,expdesc*var,int base){
3792if(fs==NULL){
3793init_exp(var,VGLOBAL,((1<<8)-1));
3794return VGLOBAL;
3795}
3796else{
3797int v=searchvar(fs,n);
3798if(v>=0){
3799init_exp(var,VLOCAL,v);
3800if(!base)
3801markupval(fs,v);
3802return VLOCAL;
3803}
3804else{
3805if(singlevaraux(fs->prev,n,var,0)==VGLOBAL)
3806return VGLOBAL;
3807var->u.s.info=indexupvalue(fs,n,var);
3808var->k=VUPVAL;
3809return VUPVAL;
3810}
3811}
3812}
3813static void singlevar(LexState*ls,expdesc*var){
3814TString*varname=str_checkname(ls);
3815FuncState*fs=ls->fs;
3816if(singlevaraux(fs,varname,var,1)==VGLOBAL)
3817var->u.s.info=luaK_stringK(fs,varname);
3818}
3819static void adjust_assign(LexState*ls,int nvars,int nexps,expdesc*e){
3820FuncState*fs=ls->fs;
3821int extra=nvars-nexps;
3822if(hasmultret(e->k)){
3823extra++;
3824if(extra<0)extra=0;
3825luaK_setreturns(fs,e,extra);
3826if(extra>1)luaK_reserveregs(fs,extra-1);
3827}
3828else{
3829if(e->k!=VVOID)luaK_exp2nextreg(fs,e);
3830if(extra>0){
3831int reg=fs->freereg;
3832luaK_reserveregs(fs,extra);
3833luaK_nil(fs,reg,extra);
3834}
3835}
3836}
3837static void enterlevel(LexState*ls){
3838if(++ls->L->nCcalls>200)
3839luaX_lexerror(ls,"chunk has too many syntax levels",0);
3840}
3841#define leavelevel(ls)((ls)->L->nCcalls--)
3842static void enterblock(FuncState*fs,BlockCnt*bl,lu_byte isbreakable){
3843bl->breaklist=(-1);
3844bl->isbreakable=isbreakable;
3845bl->nactvar=fs->nactvar;
3846bl->upval=0;
3847bl->previous=fs->bl;
3848fs->bl=bl;
3849}
3850static void leaveblock(FuncState*fs){
3851BlockCnt*bl=fs->bl;
3852fs->bl=bl->previous;
3853removevars(fs->ls,bl->nactvar);
3854if(bl->upval)
3855luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0);
3856fs->freereg=fs->nactvar;
3857luaK_patchtohere(fs,bl->breaklist);
3858}
3859static void pushclosure(LexState*ls,FuncState*func,expdesc*v){
3860FuncState*fs=ls->fs;
3861Proto*f=fs->f;
3862int oldsize=f->sizep;
3863int i;
3864luaM_growvector(ls->L,f->p,fs->np,f->sizep,Proto*,
3865((1<<(9+9))-1),"constant table overflow");
3866while(oldsize<f->sizep)f->p[oldsize++]=NULL;
3867f->p[fs->np++]=func->f;
3868luaC_objbarrier(ls->L,f,func->f);
3869init_exp(v,VRELOCABLE,luaK_codeABx(fs,OP_CLOSURE,0,fs->np-1));
3870for(i=0;i<func->f->nups;i++){
3871OpCode o=(func->upvalues[i].k==VLOCAL)?OP_MOVE:OP_GETUPVAL;
3872luaK_codeABC(fs,o,0,func->upvalues[i].info,0);
3873}
3874}
3875static void open_func(LexState*ls,FuncState*fs){
3876lua_State*L=ls->L;
3877Proto*f=luaF_newproto(L);
3878fs->f=f;
3879fs->prev=ls->fs;
3880fs->ls=ls;
3881fs->L=L;
3882ls->fs=fs;
3883fs->pc=0;
3884fs->lasttarget=-1;
3885fs->jpc=(-1);
3886fs->freereg=0;
3887fs->nk=0;
3888fs->np=0;
3889fs->nlocvars=0;
3890fs->nactvar=0;
3891fs->bl=NULL;
3892f->source=ls->source;
3893f->maxstacksize=2;
3894fs->h=luaH_new(L,0,0);
3895sethvalue(L,L->top,fs->h);
3896incr_top(L);
3897setptvalue(L,L->top,f);
3898incr_top(L);
3899}
3900static void close_func(LexState*ls){
3901lua_State*L=ls->L;
3902FuncState*fs=ls->fs;
3903Proto*f=fs->f;
3904removevars(ls,0);
3905luaK_ret(fs,0,0);
3906luaM_reallocvector(L,f->code,f->sizecode,fs->pc,Instruction);
3907f->sizecode=fs->pc;
3908luaM_reallocvector(L,f->lineinfo,f->sizelineinfo,fs->pc,int);
3909f->sizelineinfo=fs->pc;
3910luaM_reallocvector(L,f->k,f->sizek,fs->nk,TValue);
3911f->sizek=fs->nk;
3912luaM_reallocvector(L,f->p,f->sizep,fs->np,Proto*);
3913f->sizep=fs->np;
3914luaM_reallocvector(L,f->locvars,f->sizelocvars,fs->nlocvars,LocVar);
3915f->sizelocvars=fs->nlocvars;
3916luaM_reallocvector(L,f->upvalues,f->sizeupvalues,f->nups,TString*);
3917f->sizeupvalues=f->nups;
3918ls->fs=fs->prev;
3919if(fs)anchor_token(ls);
3920L->top-=2;
3921}
3922static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,const char*name){
3923struct LexState lexstate;
3924struct FuncState funcstate;
3925lexstate.buff=buff;
3926luaX_setinput(L,&lexstate,z,luaS_new(L,name));
3927open_func(&lexstate,&funcstate);
3928funcstate.f->is_vararg=2;
3929luaX_next(&lexstate);
3930chunk(&lexstate);
3931check(&lexstate,TK_EOS);
3932close_func(&lexstate);
3933return funcstate.f;
3934}
3935static void field(LexState*ls,expdesc*v){
3936FuncState*fs=ls->fs;
3937expdesc key;
3938luaK_exp2anyreg(fs,v);
3939luaX_next(ls);
3940checkname(ls,&key);
3941luaK_indexed(fs,v,&key);
3942}
3943static void yindex(LexState*ls,expdesc*v){
3944luaX_next(ls);
3945expr(ls,v);
3946luaK_exp2val(ls->fs,v);
3947checknext(ls,']');
3948}
3949struct ConsControl{
3950expdesc v;
3951expdesc*t;
3952int nh;
3953int na;
3954int tostore;
3955};
3956static void recfield(LexState*ls,struct ConsControl*cc){
3957FuncState*fs=ls->fs;
3958int reg=ls->fs->freereg;
3959expdesc key,val;
3960int rkkey;
3961if(ls->t.token==TK_NAME){
3962luaY_checklimit(fs,cc->nh,(INT_MAX-2),"items in a constructor");
3963checkname(ls,&key);
3964}
3965else
3966yindex(ls,&key);
3967cc->nh++;
3968checknext(ls,'=');
3969rkkey=luaK_exp2RK(fs,&key);
3970expr(ls,&val);
3971luaK_codeABC(fs,OP_SETTABLE,cc->t->u.s.info,rkkey,luaK_exp2RK(fs,&val));
3972fs->freereg=reg;
3973}
3974static void closelistfield(FuncState*fs,struct ConsControl*cc){
3975if(cc->v.k==VVOID)return;
3976luaK_exp2nextreg(fs,&cc->v);
3977cc->v.k=VVOID;
3978if(cc->tostore==50){
3979luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore);
3980cc->tostore=0;
3981}
3982}
3983static void lastlistfield(FuncState*fs,struct ConsControl*cc){
3984if(cc->tostore==0)return;
3985if(hasmultret(cc->v.k)){
3986luaK_setmultret(fs,&cc->v);
3987luaK_setlist(fs,cc->t->u.s.info,cc->na,(-1));
3988cc->na--;
3989}
3990else{
3991if(cc->v.k!=VVOID)
3992luaK_exp2nextreg(fs,&cc->v);
3993luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore);
3994}
3995}
3996static void listfield(LexState*ls,struct ConsControl*cc){
3997expr(ls,&cc->v);
3998luaY_checklimit(ls->fs,cc->na,(INT_MAX-2),"items in a constructor");
3999cc->na++;
4000cc->tostore++;
4001}
4002static void constructor(LexState*ls,expdesc*t){
4003FuncState*fs=ls->fs;
4004int line=ls->linenumber;
4005int pc=luaK_codeABC(fs,OP_NEWTABLE,0,0,0);
4006struct ConsControl cc;
4007cc.na=cc.nh=cc.tostore=0;
4008cc.t=t;
4009init_exp(t,VRELOCABLE,pc);
4010init_exp(&cc.v,VVOID,0);
4011luaK_exp2nextreg(ls->fs,t);
4012checknext(ls,'{');
4013do{
4014if(ls->t.token=='}')break;
4015closelistfield(fs,&cc);
4016switch(ls->t.token){
4017case TK_NAME:{
4018luaX_lookahead(ls);
4019if(ls->lookahead.token!='=')
4020listfield(ls,&cc);
4021else
4022recfield(ls,&cc);
4023break;
4024}
4025case'[':{
4026recfield(ls,&cc);
4027break;
4028}
4029default:{
4030listfield(ls,&cc);
4031break;
4032}
4033}
4034}while(testnext(ls,',')||testnext(ls,';'));
4035check_match(ls,'}','{',line);
4036lastlistfield(fs,&cc);
4037SETARG_B(fs->f->code[pc],luaO_int2fb(cc.na));
4038SETARG_C(fs->f->code[pc],luaO_int2fb(cc.nh));
4039}
4040static void parlist(LexState*ls){
4041FuncState*fs=ls->fs;
4042Proto*f=fs->f;
4043int nparams=0;
4044f->is_vararg=0;
4045if(ls->t.token!=')'){
4046do{
4047switch(ls->t.token){
4048case TK_NAME:{
4049new_localvar(ls,str_checkname(ls),nparams++);
4050break;
4051}
4052case TK_DOTS:{
4053luaX_next(ls);
4054f->is_vararg|=2;
4055break;
4056}
4057default:luaX_syntaxerror(ls,"<name> or "LUA_QL("...")" expected");
4058}
4059}while(!f->is_vararg&&testnext(ls,','));
4060}
4061adjustlocalvars(ls,nparams);
4062f->numparams=cast_byte(fs->nactvar-(f->is_vararg&1));
4063luaK_reserveregs(fs,fs->nactvar);
4064}
4065static void body(LexState*ls,expdesc*e,int needself,int line){
4066FuncState new_fs;
4067open_func(ls,&new_fs);
4068new_fs.f->linedefined=line;
4069checknext(ls,'(');
4070if(needself){
4071new_localvarliteral(ls,"self",0);
4072adjustlocalvars(ls,1);
4073}
4074parlist(ls);
4075checknext(ls,')');
4076chunk(ls);
4077new_fs.f->lastlinedefined=ls->linenumber;
4078check_match(ls,TK_END,TK_FUNCTION,line);
4079close_func(ls);
4080pushclosure(ls,&new_fs,e);
4081}
4082static int explist1(LexState*ls,expdesc*v){
4083int n=1;
4084expr(ls,v);
4085while(testnext(ls,',')){
4086luaK_exp2nextreg(ls->fs,v);
4087expr(ls,v);
4088n++;
4089}
4090return n;
4091}
4092static void funcargs(LexState*ls,expdesc*f){
4093FuncState*fs=ls->fs;
4094expdesc args;
4095int base,nparams;
4096int line=ls->linenumber;
4097switch(ls->t.token){
4098case'(':{
4099if(line!=ls->lastline)
4100luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
4101luaX_next(ls);
4102if(ls->t.token==')')
4103args.k=VVOID;
4104else{
4105explist1(ls,&args);
4106luaK_setmultret(fs,&args);
4107}
4108check_match(ls,')','(',line);
4109break;
4110}
4111case'{':{
4112constructor(ls,&args);
4113break;
4114}
4115case TK_STRING:{
4116codestring(ls,&args,ls->t.seminfo.ts);
4117luaX_next(ls);
4118break;
4119}
4120default:{
4121luaX_syntaxerror(ls,"function arguments expected");
4122return;
4123}
4124}
4125base=f->u.s.info;
4126if(hasmultret(args.k))
4127nparams=(-1);
4128else{
4129if(args.k!=VVOID)
4130luaK_exp2nextreg(fs,&args);
4131nparams=fs->freereg-(base+1);
4132}
4133init_exp(f,VCALL,luaK_codeABC(fs,OP_CALL,base,nparams+1,2));
4134luaK_fixline(fs,line);
4135fs->freereg=base+1;
4136}
4137static void prefixexp(LexState*ls,expdesc*v){
4138switch(ls->t.token){
4139case'(':{
4140int line=ls->linenumber;
4141luaX_next(ls);
4142expr(ls,v);
4143check_match(ls,')','(',line);
4144luaK_dischargevars(ls->fs,v);
4145return;
4146}
4147case TK_NAME:{
4148singlevar(ls,v);
4149return;
4150}
4151default:{
4152luaX_syntaxerror(ls,"unexpected symbol");
4153return;
4154}
4155}
4156}
4157static void primaryexp(LexState*ls,expdesc*v){
4158FuncState*fs=ls->fs;
4159prefixexp(ls,v);
4160for(;;){
4161switch(ls->t.token){
4162case'.':{
4163field(ls,v);
4164break;
4165}
4166case'[':{
4167expdesc key;
4168luaK_exp2anyreg(fs,v);
4169yindex(ls,&key);
4170luaK_indexed(fs,v,&key);
4171break;
4172}
4173case':':{
4174expdesc key;
4175luaX_next(ls);
4176checkname(ls,&key);
4177luaK_self(fs,v,&key);
4178funcargs(ls,v);
4179break;
4180}
4181case'(':case TK_STRING:case'{':{
4182luaK_exp2nextreg(fs,v);
4183funcargs(ls,v);
4184break;
4185}
4186default:return;
4187}
4188}
4189}
4190static void simpleexp(LexState*ls,expdesc*v){
4191switch(ls->t.token){
4192case TK_NUMBER:{
4193init_exp(v,VKNUM,0);
4194v->u.nval=ls->t.seminfo.r;
4195break;
4196}
4197case TK_STRING:{
4198codestring(ls,v,ls->t.seminfo.ts);
4199break;
4200}
4201case TK_NIL:{
4202init_exp(v,VNIL,0);
4203break;
4204}
4205case TK_TRUE:{
4206init_exp(v,VTRUE,0);
4207break;
4208}
4209case TK_FALSE:{
4210init_exp(v,VFALSE,0);
4211break;
4212}
4213case TK_DOTS:{
4214FuncState*fs=ls->fs;
4215check_condition(ls,fs->f->is_vararg,
4216"cannot use "LUA_QL("...")" outside a vararg function");
4217fs->f->is_vararg&=~4;
4218init_exp(v,VVARARG,luaK_codeABC(fs,OP_VARARG,0,1,0));
4219break;
4220}
4221case'{':{
4222constructor(ls,v);
4223return;
4224}
4225case TK_FUNCTION:{
4226luaX_next(ls);
4227body(ls,v,0,ls->linenumber);
4228return;
4229}
4230default:{
4231primaryexp(ls,v);
4232return;
4233}
4234}
4235luaX_next(ls);
4236}
4237static UnOpr getunopr(int op){
4238switch(op){
4239case TK_NOT:return OPR_NOT;
4240case'-':return OPR_MINUS;
4241case'#':return OPR_LEN;
4242default:return OPR_NOUNOPR;
4243}
4244}
4245static BinOpr getbinopr(int op){
4246switch(op){
4247case'+':return OPR_ADD;
4248case'-':return OPR_SUB;
4249case'*':return OPR_MUL;
4250case'/':return OPR_DIV;
4251case'%':return OPR_MOD;
4252case'^':return OPR_POW;
4253case TK_CONCAT:return OPR_CONCAT;
4254case TK_NE:return OPR_NE;
4255case TK_EQ:return OPR_EQ;
4256case'<':return OPR_LT;
4257case TK_LE:return OPR_LE;
4258case'>':return OPR_GT;
4259case TK_GE:return OPR_GE;
4260case TK_AND:return OPR_AND;
4261case TK_OR:return OPR_OR;
4262default:return OPR_NOBINOPR;
4263}
4264}
4265static const struct{
4266lu_byte left;
4267lu_byte right;
4268}priority[]={
4269{6,6},{6,6},{7,7},{7,7},{7,7},
4270{10,9},{5,4},
4271{3,3},{3,3},
4272{3,3},{3,3},{3,3},{3,3},
4273{2,2},{1,1}
4274};
4275static BinOpr subexpr(LexState*ls,expdesc*v,unsigned int limit){
4276BinOpr op;
4277UnOpr uop;
4278enterlevel(ls);
4279uop=getunopr(ls->t.token);
4280if(uop!=OPR_NOUNOPR){
4281luaX_next(ls);
4282subexpr(ls,v,8);
4283luaK_prefix(ls->fs,uop,v);
4284}
4285else simpleexp(ls,v);
4286op=getbinopr(ls->t.token);
4287while(op!=OPR_NOBINOPR&&priority[op].left>limit){
4288expdesc v2;
4289BinOpr nextop;
4290luaX_next(ls);
4291luaK_infix(ls->fs,op,v);
4292nextop=subexpr(ls,&v2,priority[op].right);
4293luaK_posfix(ls->fs,op,v,&v2);
4294op=nextop;
4295}
4296leavelevel(ls);
4297return op;
4298}
4299static void expr(LexState*ls,expdesc*v){
4300subexpr(ls,v,0);
4301}
4302static int block_follow(int token){
4303switch(token){
4304case TK_ELSE:case TK_ELSEIF:case TK_END:
4305case TK_UNTIL:case TK_EOS:
4306return 1;
4307default:return 0;
4308}
4309}
4310static void block(LexState*ls){
4311FuncState*fs=ls->fs;
4312BlockCnt bl;
4313enterblock(fs,&bl,0);
4314chunk(ls);
4315leaveblock(fs);
4316}
4317struct LHS_assign{
4318struct LHS_assign*prev;
4319expdesc v;
4320};
4321static void check_conflict(LexState*ls,struct LHS_assign*lh,expdesc*v){
4322FuncState*fs=ls->fs;
4323int extra=fs->freereg;
4324int conflict=0;
4325for(;lh;lh=lh->prev){
4326if(lh->v.k==VINDEXED){
4327if(lh->v.u.s.info==v->u.s.info){
4328conflict=1;
4329lh->v.u.s.info=extra;
4330}
4331if(lh->v.u.s.aux==v->u.s.info){
4332conflict=1;
4333lh->v.u.s.aux=extra;
4334}
4335}
4336}
4337if(conflict){
4338luaK_codeABC(fs,OP_MOVE,fs->freereg,v->u.s.info,0);
4339luaK_reserveregs(fs,1);
4340}
4341}
4342static void assignment(LexState*ls,struct LHS_assign*lh,int nvars){
4343expdesc e;
4344check_condition(ls,VLOCAL<=lh->v.k&&lh->v.k<=VINDEXED,
4345"syntax error");
4346if(testnext(ls,',')){
4347struct LHS_assign nv;
4348nv.prev=lh;
4349primaryexp(ls,&nv.v);
4350if(nv.v.k==VLOCAL)
4351check_conflict(ls,lh,&nv.v);
4352luaY_checklimit(ls->fs,nvars,200-ls->L->nCcalls,
4353"variables in assignment");
4354assignment(ls,&nv,nvars+1);
4355}
4356else{
4357int nexps;
4358checknext(ls,'=');
4359nexps=explist1(ls,&e);
4360if(nexps!=nvars){
4361adjust_assign(ls,nvars,nexps,&e);
4362if(nexps>nvars)
4363ls->fs->freereg-=nexps-nvars;
4364}
4365else{
4366luaK_setoneret(ls->fs,&e);
4367luaK_storevar(ls->fs,&lh->v,&e);
4368return;
4369}
4370}
4371init_exp(&e,VNONRELOC,ls->fs->freereg-1);
4372luaK_storevar(ls->fs,&lh->v,&e);
4373}
4374static int cond(LexState*ls){
4375expdesc v;
4376expr(ls,&v);
4377if(v.k==VNIL)v.k=VFALSE;
4378luaK_goiftrue(ls->fs,&v);
4379return v.f;
4380}
4381static void breakstat(LexState*ls){
4382FuncState*fs=ls->fs;
4383BlockCnt*bl=fs->bl;
4384int upval=0;
4385while(bl&&!bl->isbreakable){
4386upval|=bl->upval;
4387bl=bl->previous;
4388}
4389if(!bl)
4390luaX_syntaxerror(ls,"no loop to break");
4391if(upval)
4392luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0);
4393luaK_concat(fs,&bl->breaklist,luaK_jump(fs));
4394}
4395static void whilestat(LexState*ls,int line){
4396FuncState*fs=ls->fs;
4397int whileinit;
4398int condexit;
4399BlockCnt bl;
4400luaX_next(ls);
4401whileinit=luaK_getlabel(fs);
4402condexit=cond(ls);
4403enterblock(fs,&bl,1);
4404checknext(ls,TK_DO);
4405block(ls);
4406luaK_patchlist(fs,luaK_jump(fs),whileinit);
4407check_match(ls,TK_END,TK_WHILE,line);
4408leaveblock(fs);
4409luaK_patchtohere(fs,condexit);
4410}
4411static void repeatstat(LexState*ls,int line){
4412int condexit;
4413FuncState*fs=ls->fs;
4414int repeat_init=luaK_getlabel(fs);
4415BlockCnt bl1,bl2;
4416enterblock(fs,&bl1,1);
4417enterblock(fs,&bl2,0);
4418luaX_next(ls);
4419chunk(ls);
4420check_match(ls,TK_UNTIL,TK_REPEAT,line);
4421condexit=cond(ls);
4422if(!bl2.upval){
4423leaveblock(fs);
4424luaK_patchlist(ls->fs,condexit,repeat_init);
4425}
4426else{
4427breakstat(ls);
4428luaK_patchtohere(ls->fs,condexit);
4429leaveblock(fs);
4430luaK_patchlist(ls->fs,luaK_jump(fs),repeat_init);
4431}
4432leaveblock(fs);
4433}
4434static int exp1(LexState*ls){
4435expdesc e;
4436int k;
4437expr(ls,&e);
4438k=e.k;
4439luaK_exp2nextreg(ls->fs,&e);
4440return k;
4441}
4442static void forbody(LexState*ls,int base,int line,int nvars,int isnum){
4443BlockCnt bl;
4444FuncState*fs=ls->fs;
4445int prep,endfor;
4446adjustlocalvars(ls,3);
4447checknext(ls,TK_DO);
4448prep=isnum?luaK_codeAsBx(fs,OP_FORPREP,base,(-1)):luaK_jump(fs);
4449enterblock(fs,&bl,0);
4450adjustlocalvars(ls,nvars);
4451luaK_reserveregs(fs,nvars);
4452block(ls);
4453leaveblock(fs);
4454luaK_patchtohere(fs,prep);
4455endfor=(isnum)?luaK_codeAsBx(fs,OP_FORLOOP,base,(-1)):
4456luaK_codeABC(fs,OP_TFORLOOP,base,0,nvars);
4457luaK_fixline(fs,line);
4458luaK_patchlist(fs,(isnum?endfor:luaK_jump(fs)),prep+1);
4459}
4460static void fornum(LexState*ls,TString*varname,int line){
4461FuncState*fs=ls->fs;
4462int base=fs->freereg;
4463new_localvarliteral(ls,"(for index)",0);
4464new_localvarliteral(ls,"(for limit)",1);
4465new_localvarliteral(ls,"(for step)",2);
4466new_localvar(ls,varname,3);
4467checknext(ls,'=');
4468exp1(ls);
4469checknext(ls,',');
4470exp1(ls);
4471if(testnext(ls,','))
4472exp1(ls);
4473else{
4474luaK_codeABx(fs,OP_LOADK,fs->freereg,luaK_numberK(fs,1));
4475luaK_reserveregs(fs,1);
4476}
4477forbody(ls,base,line,1,1);
4478}
4479static void forlist(LexState*ls,TString*indexname){
4480FuncState*fs=ls->fs;
4481expdesc e;
4482int nvars=0;
4483int line;
4484int base=fs->freereg;
4485new_localvarliteral(ls,"(for generator)",nvars++);
4486new_localvarliteral(ls,"(for state)",nvars++);
4487new_localvarliteral(ls,"(for control)",nvars++);
4488new_localvar(ls,indexname,nvars++);
4489while(testnext(ls,','))
4490new_localvar(ls,str_checkname(ls),nvars++);
4491checknext(ls,TK_IN);
4492line=ls->linenumber;
4493adjust_assign(ls,3,explist1(ls,&e),&e);
4494luaK_checkstack(fs,3);
4495forbody(ls,base,line,nvars-3,0);
4496}
4497static void forstat(LexState*ls,int line){
4498FuncState*fs=ls->fs;
4499TString*varname;
4500BlockCnt bl;
4501enterblock(fs,&bl,1);
4502luaX_next(ls);
4503varname=str_checkname(ls);
4504switch(ls->t.token){
4505case'=':fornum(ls,varname,line);break;
4506case',':case TK_IN:forlist(ls,varname);break;
4507default:luaX_syntaxerror(ls,LUA_QL("=")" or "LUA_QL("in")" expected");
4508}
4509check_match(ls,TK_END,TK_FOR,line);
4510leaveblock(fs);
4511}
4512static int test_then_block(LexState*ls){
4513int condexit;
4514luaX_next(ls);
4515condexit=cond(ls);
4516checknext(ls,TK_THEN);
4517block(ls);
4518return condexit;
4519}
4520static void ifstat(LexState*ls,int line){
4521FuncState*fs=ls->fs;
4522int flist;
4523int escapelist=(-1);
4524flist=test_then_block(ls);
4525while(ls->t.token==TK_ELSEIF){
4526luaK_concat(fs,&escapelist,luaK_jump(fs));
4527luaK_patchtohere(fs,flist);
4528flist=test_then_block(ls);
4529}
4530if(ls->t.token==TK_ELSE){
4531luaK_concat(fs,&escapelist,luaK_jump(fs));
4532luaK_patchtohere(fs,flist);
4533luaX_next(ls);
4534block(ls);
4535}
4536else
4537luaK_concat(fs,&escapelist,flist);
4538luaK_patchtohere(fs,escapelist);
4539check_match(ls,TK_END,TK_IF,line);
4540}
4541static void localfunc(LexState*ls){
4542expdesc v,b;
4543FuncState*fs=ls->fs;
4544new_localvar(ls,str_checkname(ls),0);
4545init_exp(&v,VLOCAL,fs->freereg);
4546luaK_reserveregs(fs,1);
4547adjustlocalvars(ls,1);
4548body(ls,&b,0,ls->linenumber);
4549luaK_storevar(fs,&v,&b);
4550getlocvar(fs,fs->nactvar-1).startpc=fs->pc;
4551}
4552static void localstat(LexState*ls){
4553int nvars=0;
4554int nexps;
4555expdesc e;
4556do{
4557new_localvar(ls,str_checkname(ls),nvars++);
4558}while(testnext(ls,','));
4559if(testnext(ls,'='))
4560nexps=explist1(ls,&e);
4561else{
4562e.k=VVOID;
4563nexps=0;
4564}
4565adjust_assign(ls,nvars,nexps,&e);
4566adjustlocalvars(ls,nvars);
4567}
4568static int funcname(LexState*ls,expdesc*v){
4569int needself=0;
4570singlevar(ls,v);
4571while(ls->t.token=='.')
4572field(ls,v);
4573if(ls->t.token==':'){
4574needself=1;
4575field(ls,v);
4576}
4577return needself;
4578}
4579static void funcstat(LexState*ls,int line){
4580int needself;
4581expdesc v,b;
4582luaX_next(ls);
4583needself=funcname(ls,&v);
4584body(ls,&b,needself,line);
4585luaK_storevar(ls->fs,&v,&b);
4586luaK_fixline(ls->fs,line);
4587}
4588static void exprstat(LexState*ls){
4589FuncState*fs=ls->fs;
4590struct LHS_assign v;
4591primaryexp(ls,&v.v);
4592if(v.v.k==VCALL)
4593SETARG_C(getcode(fs,&v.v),1);
4594else{
4595v.prev=NULL;
4596assignment(ls,&v,1);
4597}
4598}
4599static void retstat(LexState*ls){
4600FuncState*fs=ls->fs;
4601expdesc e;
4602int first,nret;
4603luaX_next(ls);
4604if(block_follow(ls->t.token)||ls->t.token==';')
4605first=nret=0;
4606else{
4607nret=explist1(ls,&e);
4608if(hasmultret(e.k)){
4609luaK_setmultret(fs,&e);
4610if(e.k==VCALL&&nret==1){
4611SET_OPCODE(getcode(fs,&e),OP_TAILCALL);
4612}
4613first=fs->nactvar;
4614nret=(-1);
4615}
4616else{
4617if(nret==1)
4618first=luaK_exp2anyreg(fs,&e);
4619else{
4620luaK_exp2nextreg(fs,&e);
4621first=fs->nactvar;
4622}
4623}
4624}
4625luaK_ret(fs,first,nret);
4626}
4627static int statement(LexState*ls){
4628int line=ls->linenumber;
4629switch(ls->t.token){
4630case TK_IF:{
4631ifstat(ls,line);
4632return 0;
4633}
4634case TK_WHILE:{
4635whilestat(ls,line);
4636return 0;
4637}
4638case TK_DO:{
4639luaX_next(ls);
4640block(ls);
4641check_match(ls,TK_END,TK_DO,line);
4642return 0;
4643}
4644case TK_FOR:{
4645forstat(ls,line);
4646return 0;
4647}
4648case TK_REPEAT:{
4649repeatstat(ls,line);
4650return 0;
4651}
4652case TK_FUNCTION:{
4653funcstat(ls,line);
4654return 0;
4655}
4656case TK_LOCAL:{
4657luaX_next(ls);
4658if(testnext(ls,TK_FUNCTION))
4659localfunc(ls);
4660else
4661localstat(ls);
4662return 0;
4663}
4664case TK_RETURN:{
4665retstat(ls);
4666return 1;
4667}
4668case TK_BREAK:{
4669luaX_next(ls);
4670breakstat(ls);
4671return 1;
4672}
4673default:{
4674exprstat(ls);
4675return 0;
4676}
4677}
4678}
4679static void chunk(LexState*ls){
4680int islast=0;
4681enterlevel(ls);
4682while(!islast&&!block_follow(ls->t.token)){
4683islast=statement(ls);
4684testnext(ls,';');
4685ls->fs->freereg=ls->fs->nactvar;
4686}
4687leavelevel(ls);
4688}
4689static const TValue*luaV_tonumber(const TValue*obj,TValue*n){
4690lua_Number num;
4691if(ttisnumber(obj))return obj;
4692if(ttisstring(obj)&&luaO_str2d(svalue(obj),&num)){
4693setnvalue(n,num);
4694return n;
4695}
4696else
4697return NULL;
4698}
4699static int luaV_tostring(lua_State*L,StkId obj){
4700if(!ttisnumber(obj))
4701return 0;
4702else{
4703char s[32];
4704lua_Number n=nvalue(obj);
4705lua_number2str(s,n);
4706setsvalue(L,obj,luaS_new(L,s));
4707return 1;
4708}
4709}
4710static void callTMres(lua_State*L,StkId res,const TValue*f,
4711const TValue*p1,const TValue*p2){
4712ptrdiff_t result=savestack(L,res);
4713setobj(L,L->top,f);
4714setobj(L,L->top+1,p1);
4715setobj(L,L->top+2,p2);
4716luaD_checkstack(L,3);
4717L->top+=3;
4718luaD_call(L,L->top-3,1);
4719res=restorestack(L,result);
4720L->top--;
4721setobj(L,res,L->top);
4722}
4723static void callTM(lua_State*L,const TValue*f,const TValue*p1,
4724const TValue*p2,const TValue*p3){
4725setobj(L,L->top,f);
4726setobj(L,L->top+1,p1);
4727setobj(L,L->top+2,p2);
4728setobj(L,L->top+3,p3);
4729luaD_checkstack(L,4);
4730L->top+=4;
4731luaD_call(L,L->top-4,0);
4732}
4733static void luaV_gettable(lua_State*L,const TValue*t,TValue*key,StkId val){
4734int loop;
4735for(loop=0;loop<100;loop++){
4736const TValue*tm;
4737if(ttistable(t)){
4738Table*h=hvalue(t);
4739const TValue*res=luaH_get(h,key);
4740if(!ttisnil(res)||
4741(tm=fasttm(L,h->metatable,TM_INDEX))==NULL){
4742setobj(L,val,res);
4743return;
4744}
4745}
4746else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_INDEX)))
4747luaG_typeerror(L,t,"index");
4748if(ttisfunction(tm)){
4749callTMres(L,val,tm,t,key);
4750return;
4751}
4752t=tm;
4753}
4754luaG_runerror(L,"loop in gettable");
4755}
4756static void luaV_settable(lua_State*L,const TValue*t,TValue*key,StkId val){
4757int loop;
4758TValue temp;
4759for(loop=0;loop<100;loop++){
4760const TValue*tm;
4761if(ttistable(t)){
4762Table*h=hvalue(t);
4763TValue*oldval=luaH_set(L,h,key);
4764if(!ttisnil(oldval)||
4765(tm=fasttm(L,h->metatable,TM_NEWINDEX))==NULL){
4766setobj(L,oldval,val);
4767h->flags=0;
4768luaC_barriert(L,h,val);
4769return;
4770}
4771}
4772else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_NEWINDEX)))
4773luaG_typeerror(L,t,"index");
4774if(ttisfunction(tm)){
4775callTM(L,tm,t,key,val);
4776return;
4777}
4778setobj(L,&temp,tm);
4779t=&temp;
4780}
4781luaG_runerror(L,"loop in settable");
4782}
4783static int call_binTM(lua_State*L,const TValue*p1,const TValue*p2,
4784StkId res,TMS event){
4785const TValue*tm=luaT_gettmbyobj(L,p1,event);
4786if(ttisnil(tm))
4787tm=luaT_gettmbyobj(L,p2,event);
4788if(ttisnil(tm))return 0;
4789callTMres(L,res,tm,p1,p2);
4790return 1;
4791}
4792static const TValue*get_compTM(lua_State*L,Table*mt1,Table*mt2,
4793TMS event){
4794const TValue*tm1=fasttm(L,mt1,event);
4795const TValue*tm2;
4796if(tm1==NULL)return NULL;
4797if(mt1==mt2)return tm1;
4798tm2=fasttm(L,mt2,event);
4799if(tm2==NULL)return NULL;
4800if(luaO_rawequalObj(tm1,tm2))
4801return tm1;
4802return NULL;
4803}
4804static int call_orderTM(lua_State*L,const TValue*p1,const TValue*p2,
4805TMS event){
4806const TValue*tm1=luaT_gettmbyobj(L,p1,event);
4807const TValue*tm2;
4808if(ttisnil(tm1))return-1;
4809tm2=luaT_gettmbyobj(L,p2,event);
4810if(!luaO_rawequalObj(tm1,tm2))
4811return-1;
4812callTMres(L,L->top,tm1,p1,p2);
4813return!l_isfalse(L->top);
4814}
4815static int l_strcmp(const TString*ls,const TString*rs){
4816const char*l=getstr(ls);
4817size_t ll=ls->tsv.len;
4818const char*r=getstr(rs);
4819size_t lr=rs->tsv.len;
4820for(;;){
4821int temp=strcoll(l,r);
4822if(temp!=0)return temp;
4823else{
4824size_t len=strlen(l);
4825if(len==lr)
4826return(len==ll)?0:1;
4827else if(len==ll)
4828return-1;
4829len++;
4830l+=len;ll-=len;r+=len;lr-=len;
4831}
4832}
4833}
4834static int luaV_lessthan(lua_State*L,const TValue*l,const TValue*r){
4835int res;
4836if(ttype(l)!=ttype(r))
4837return luaG_ordererror(L,l,r);
4838else if(ttisnumber(l))
4839return luai_numlt(nvalue(l),nvalue(r));
4840else if(ttisstring(l))
4841return l_strcmp(rawtsvalue(l),rawtsvalue(r))<0;
4842else if((res=call_orderTM(L,l,r,TM_LT))!=-1)
4843return res;
4844return luaG_ordererror(L,l,r);
4845}
4846static int lessequal(lua_State*L,const TValue*l,const TValue*r){
4847int res;
4848if(ttype(l)!=ttype(r))
4849return luaG_ordererror(L,l,r);
4850else if(ttisnumber(l))
4851return luai_numle(nvalue(l),nvalue(r));
4852else if(ttisstring(l))
4853return l_strcmp(rawtsvalue(l),rawtsvalue(r))<=0;
4854else if((res=call_orderTM(L,l,r,TM_LE))!=-1)
4855return res;
4856else if((res=call_orderTM(L,r,l,TM_LT))!=-1)
4857return!res;
4858return luaG_ordererror(L,l,r);
4859}
4860static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2){
4861const TValue*tm;
4862switch(ttype(t1)){
4863case 0:return 1;
4864case 3:return luai_numeq(nvalue(t1),nvalue(t2));
4865case 1:return bvalue(t1)==bvalue(t2);
4866case 2:return pvalue(t1)==pvalue(t2);
4867case 7:{
4868if(uvalue(t1)==uvalue(t2))return 1;
4869tm=get_compTM(L,uvalue(t1)->metatable,uvalue(t2)->metatable,
4870TM_EQ);
4871break;
4872}
4873case 5:{
4874if(hvalue(t1)==hvalue(t2))return 1;
4875tm=get_compTM(L,hvalue(t1)->metatable,hvalue(t2)->metatable,TM_EQ);
4876break;
4877}
4878default:return gcvalue(t1)==gcvalue(t2);
4879}
4880if(tm==NULL)return 0;
4881callTMres(L,L->top,tm,t1,t2);
4882return!l_isfalse(L->top);
4883}
4884static void luaV_concat(lua_State*L,int total,int last){
4885do{
4886StkId top=L->base+last+1;
4887int n=2;
4888if(!(ttisstring(top-2)||ttisnumber(top-2))||!tostring(L,top-1)){
4889if(!call_binTM(L,top-2,top-1,top-2,TM_CONCAT))
4890luaG_concaterror(L,top-2,top-1);
4891}else if(tsvalue(top-1)->len==0)
4892(void)tostring(L,top-2);
4893else{
4894size_t tl=tsvalue(top-1)->len;
4895char*buffer;
4896int i;
4897for(n=1;n<total&&tostring(L,top-n-1);n++){
4898size_t l=tsvalue(top-n-1)->len;
4899if(l>=((size_t)(~(size_t)0)-2)-tl)luaG_runerror(L,"string length overflow");
4900tl+=l;
4901}
4902buffer=luaZ_openspace(L,&G(L)->buff,tl);
4903tl=0;
4904for(i=n;i>0;i--){
4905size_t l=tsvalue(top-i)->len;
4906memcpy(buffer+tl,svalue(top-i),l);
4907tl+=l;
4908}
4909setsvalue(L,top-n,luaS_newlstr(L,buffer,tl));
4910}
4911total-=n-1;
4912last-=n-1;
4913}while(total>1);
4914}
4915static void Arith(lua_State*L,StkId ra,const TValue*rb,
4916const TValue*rc,TMS op){
4917TValue tempb,tempc;
4918const TValue*b,*c;
4919if((b=luaV_tonumber(rb,&tempb))!=NULL&&
4920(c=luaV_tonumber(rc,&tempc))!=NULL){
4921lua_Number nb=nvalue(b),nc=nvalue(c);
4922switch(op){
4923case TM_ADD:setnvalue(ra,luai_numadd(nb,nc));break;
4924case TM_SUB:setnvalue(ra,luai_numsub(nb,nc));break;
4925case TM_MUL:setnvalue(ra,luai_nummul(nb,nc));break;
4926case TM_DIV:setnvalue(ra,luai_numdiv(nb,nc));break;
4927case TM_MOD:setnvalue(ra,luai_nummod(nb,nc));break;
4928case TM_POW:setnvalue(ra,luai_numpow(nb,nc));break;
4929case TM_UNM:setnvalue(ra,luai_numunm(nb));break;
4930default:break;
4931}
4932}
4933else if(!call_binTM(L,rb,rc,ra,op))
4934luaG_aritherror(L,rb,rc);
4935}
4936#define runtime_check(L,c){if(!(c))break;}
4937#define RA(i)(base+GETARG_A(i))
4938#define RB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgR,base+GETARG_B(i))
4939#define RKB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_B(i))?k+INDEXK(GETARG_B(i)):base+GETARG_B(i))
4940#define RKC(i)check_exp(getCMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_C(i))?k+INDEXK(GETARG_C(i)):base+GETARG_C(i))
4941#define KBx(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,k+GETARG_Bx(i))
4942#define dojump(L,pc,i){(pc)+=(i);}
4943#define Protect(x){L->savedpc=pc;{x;};base=L->base;}
4944#define arith_op(op,tm){TValue*rb=RKB(i);TValue*rc=RKC(i);if(ttisnumber(rb)&&ttisnumber(rc)){lua_Number nb=nvalue(rb),nc=nvalue(rc);setnvalue(ra,op(nb,nc));}else Protect(Arith(L,ra,rb,rc,tm));}
4945static void luaV_execute(lua_State*L,int nexeccalls){
4946LClosure*cl;
4947StkId base;
4948TValue*k;
4949const Instruction*pc;
4950reentry:
4951pc=L->savedpc;
4952cl=&clvalue(L->ci->func)->l;
4953base=L->base;
4954k=cl->p->k;
4955for(;;){
4956const Instruction i=*pc++;
4957StkId ra;
4958ra=RA(i);
4959switch(GET_OPCODE(i)){
4960case OP_MOVE:{
4961setobj(L,ra,RB(i));
4962continue;
4963}
4964case OP_LOADK:{
4965setobj(L,ra,KBx(i));
4966continue;
4967}
4968case OP_LOADBOOL:{
4969setbvalue(ra,GETARG_B(i));
4970if(GETARG_C(i))pc++;
4971continue;
4972}
4973case OP_LOADNIL:{
4974TValue*rb=RB(i);
4975do{
4976setnilvalue(rb--);
4977}while(rb>=ra);
4978continue;
4979}
4980case OP_GETUPVAL:{
4981int b=GETARG_B(i);
4982setobj(L,ra,cl->upvals[b]->v);
4983continue;
4984}
4985case OP_GETGLOBAL:{
4986TValue g;
4987TValue*rb=KBx(i);
4988sethvalue(L,&g,cl->env);
4989Protect(luaV_gettable(L,&g,rb,ra));
4990continue;
4991}
4992case OP_GETTABLE:{
4993Protect(luaV_gettable(L,RB(i),RKC(i),ra));
4994continue;
4995}
4996case OP_SETGLOBAL:{
4997TValue g;
4998sethvalue(L,&g,cl->env);
4999Protect(luaV_settable(L,&g,KBx(i),ra));
5000continue;
5001}
5002case OP_SETUPVAL:{
5003UpVal*uv=cl->upvals[GETARG_B(i)];
5004setobj(L,uv->v,ra);
5005luaC_barrier(L,uv,ra);
5006continue;
5007}
5008case OP_SETTABLE:{
5009Protect(luaV_settable(L,ra,RKB(i),RKC(i)));
5010continue;
5011}
5012case OP_NEWTABLE:{
5013int b=GETARG_B(i);
5014int c=GETARG_C(i);
5015sethvalue(L,ra,luaH_new(L,luaO_fb2int(b),luaO_fb2int(c)));
5016Protect(luaC_checkGC(L));
5017continue;
5018}
5019case OP_SELF:{
5020StkId rb=RB(i);
5021setobj(L,ra+1,rb);
5022Protect(luaV_gettable(L,rb,RKC(i),ra));
5023continue;
5024}
5025case OP_ADD:{
5026arith_op(luai_numadd,TM_ADD);
5027continue;
5028}
5029case OP_SUB:{
5030arith_op(luai_numsub,TM_SUB);
5031continue;
5032}
5033case OP_MUL:{
5034arith_op(luai_nummul,TM_MUL);
5035continue;
5036}
5037case OP_DIV:{
5038arith_op(luai_numdiv,TM_DIV);
5039continue;
5040}
5041case OP_MOD:{
5042arith_op(luai_nummod,TM_MOD);
5043continue;
5044}
5045case OP_POW:{
5046arith_op(luai_numpow,TM_POW);
5047continue;
5048}
5049case OP_UNM:{
5050TValue*rb=RB(i);
5051if(ttisnumber(rb)){
5052lua_Number nb=nvalue(rb);
5053setnvalue(ra,luai_numunm(nb));
5054}
5055else{
5056Protect(Arith(L,ra,rb,rb,TM_UNM));
5057}
5058continue;
5059}
5060case OP_NOT:{
5061int res=l_isfalse(RB(i));
5062setbvalue(ra,res);
5063continue;
5064}
5065case OP_LEN:{
5066const TValue*rb=RB(i);
5067switch(ttype(rb)){
5068case 5:{
5069setnvalue(ra,cast_num(luaH_getn(hvalue(rb))));
5070break;
5071}
5072case 4:{
5073setnvalue(ra,cast_num(tsvalue(rb)->len));
5074break;
5075}
5076default:{
5077Protect(
5078if(!call_binTM(L,rb,(&luaO_nilobject_),ra,TM_LEN))
5079luaG_typeerror(L,rb,"get length of");
5080)
5081}
5082}
5083continue;
5084}
5085case OP_CONCAT:{
5086int b=GETARG_B(i);
5087int c=GETARG_C(i);
5088Protect(luaV_concat(L,c-b+1,c);luaC_checkGC(L));
5089setobj(L,RA(i),base+b);
5090continue;
5091}
5092case OP_JMP:{
5093dojump(L,pc,GETARG_sBx(i));
5094continue;
5095}
5096case OP_EQ:{
5097TValue*rb=RKB(i);
5098TValue*rc=RKC(i);
5099Protect(
5100if(equalobj(L,rb,rc)==GETARG_A(i))
5101dojump(L,pc,GETARG_sBx(*pc));
5102)
5103pc++;
5104continue;
5105}
5106case OP_LT:{
5107Protect(
5108if(luaV_lessthan(L,RKB(i),RKC(i))==GETARG_A(i))
5109dojump(L,pc,GETARG_sBx(*pc));
5110)
5111pc++;
5112continue;
5113}
5114case OP_LE:{
5115Protect(
5116if(lessequal(L,RKB(i),RKC(i))==GETARG_A(i))
5117dojump(L,pc,GETARG_sBx(*pc));
5118)
5119pc++;
5120continue;
5121}
5122case OP_TEST:{
5123if(l_isfalse(ra)!=GETARG_C(i))
5124dojump(L,pc,GETARG_sBx(*pc));
5125pc++;
5126continue;
5127}
5128case OP_TESTSET:{
5129TValue*rb=RB(i);
5130if(l_isfalse(rb)!=GETARG_C(i)){
5131setobj(L,ra,rb);
5132dojump(L,pc,GETARG_sBx(*pc));
5133}
5134pc++;
5135continue;
5136}
5137case OP_CALL:{
5138int b=GETARG_B(i);
5139int nresults=GETARG_C(i)-1;
5140if(b!=0)L->top=ra+b;
5141L->savedpc=pc;
5142switch(luaD_precall(L,ra,nresults)){
5143case 0:{
5144nexeccalls++;
5145goto reentry;
5146}
5147case 1:{
5148if(nresults>=0)L->top=L->ci->top;
5149base=L->base;
5150continue;
5151}
5152default:{
5153return;
5154}
5155}
5156}
5157case OP_TAILCALL:{
5158int b=GETARG_B(i);
5159if(b!=0)L->top=ra+b;
5160L->savedpc=pc;
5161switch(luaD_precall(L,ra,(-1))){
5162case 0:{
5163CallInfo*ci=L->ci-1;
5164int aux;
5165StkId func=ci->func;
5166StkId pfunc=(ci+1)->func;
5167if(L->openupval)luaF_close(L,ci->base);
5168L->base=ci->base=ci->func+((ci+1)->base-pfunc);
5169for(aux=0;pfunc+aux<L->top;aux++)
5170setobj(L,func+aux,pfunc+aux);
5171ci->top=L->top=func+aux;
5172ci->savedpc=L->savedpc;
5173ci->tailcalls++;
5174L->ci--;
5175goto reentry;
5176}
5177case 1:{
5178base=L->base;
5179continue;
5180}
5181default:{
5182return;
5183}
5184}
5185}
5186case OP_RETURN:{
5187int b=GETARG_B(i);
5188if(b!=0)L->top=ra+b-1;
5189if(L->openupval)luaF_close(L,base);
5190L->savedpc=pc;
5191b=luaD_poscall(L,ra);
5192if(--nexeccalls==0)
5193return;
5194else{
5195if(b)L->top=L->ci->top;
5196goto reentry;
5197}
5198}
5199case OP_FORLOOP:{
5200lua_Number step=nvalue(ra+2);
5201lua_Number idx=luai_numadd(nvalue(ra),step);
5202lua_Number limit=nvalue(ra+1);
5203if(luai_numlt(0,step)?luai_numle(idx,limit)
5204:luai_numle(limit,idx)){
5205dojump(L,pc,GETARG_sBx(i));
5206setnvalue(ra,idx);
5207setnvalue(ra+3,idx);
5208}
5209continue;
5210}
5211case OP_FORPREP:{
5212const TValue*init=ra;
5213const TValue*plimit=ra+1;
5214const TValue*pstep=ra+2;
5215L->savedpc=pc;
5216if(!tonumber(init,ra))
5217luaG_runerror(L,LUA_QL("for")" initial value must be a number");
5218else if(!tonumber(plimit,ra+1))
5219luaG_runerror(L,LUA_QL("for")" limit must be a number");
5220else if(!tonumber(pstep,ra+2))
5221luaG_runerror(L,LUA_QL("for")" step must be a number");
5222setnvalue(ra,luai_numsub(nvalue(ra),nvalue(pstep)));
5223dojump(L,pc,GETARG_sBx(i));
5224continue;
5225}
5226case OP_TFORLOOP:{
5227StkId cb=ra+3;
5228setobj(L,cb+2,ra+2);
5229setobj(L,cb+1,ra+1);
5230setobj(L,cb,ra);
5231L->top=cb+3;
5232Protect(luaD_call(L,cb,GETARG_C(i)));
5233L->top=L->ci->top;
5234cb=RA(i)+3;
5235if(!ttisnil(cb)){
5236setobj(L,cb-1,cb);
5237dojump(L,pc,GETARG_sBx(*pc));
5238}
5239pc++;
5240continue;
5241}
5242case OP_SETLIST:{
5243int n=GETARG_B(i);
5244int c=GETARG_C(i);
5245int last;
5246Table*h;
5247if(n==0){
5248n=cast_int(L->top-ra)-1;
5249L->top=L->ci->top;
5250}
5251if(c==0)c=cast_int(*pc++);
5252runtime_check(L,ttistable(ra));
5253h=hvalue(ra);
5254last=((c-1)*50)+n;
5255if(last>h->sizearray)
5256luaH_resizearray(L,h,last);
5257for(;n>0;n--){
5258TValue*val=ra+n;
5259setobj(L,luaH_setnum(L,h,last--),val);
5260luaC_barriert(L,h,val);
5261}
5262continue;
5263}
5264case OP_CLOSE:{
5265luaF_close(L,ra);
5266continue;
5267}
5268case OP_CLOSURE:{
5269Proto*p;
5270Closure*ncl;
5271int nup,j;
5272p=cl->p->p[GETARG_Bx(i)];
5273nup=p->nups;
5274ncl=luaF_newLclosure(L,nup,cl->env);
5275ncl->l.p=p;
5276for(j=0;j<nup;j++,pc++){
5277if(GET_OPCODE(*pc)==OP_GETUPVAL)
5278ncl->l.upvals[j]=cl->upvals[GETARG_B(*pc)];
5279else{
5280ncl->l.upvals[j]=luaF_findupval(L,base+GETARG_B(*pc));
5281}
5282}
5283setclvalue(L,ra,ncl);
5284Protect(luaC_checkGC(L));
5285continue;
5286}
5287case OP_VARARG:{
5288int b=GETARG_B(i)-1;
5289int j;
5290CallInfo*ci=L->ci;
5291int n=cast_int(ci->base-ci->func)-cl->p->numparams-1;
5292if(b==(-1)){
5293Protect(luaD_checkstack(L,n));
5294ra=RA(i);
5295b=n;
5296L->top=ra+n;
5297}
5298for(j=0;j<b;j++){
5299if(j<n){
5300setobj(L,ra+j,ci->base-n+j);
5301}
5302else{
5303setnilvalue(ra+j);
5304}
5305}
5306continue;
5307}
5308}
5309}
5310}
5311#define api_checknelems(L,n)luai_apicheck(L,(n)<=(L->top-L->base))
5312#define api_checkvalidindex(L,i)luai_apicheck(L,(i)!=(&luaO_nilobject_))
5313#define api_incr_top(L){luai_apicheck(L,L->top<L->ci->top);L->top++;}
5314static TValue*index2adr(lua_State*L,int idx){
5315if(idx>0){
5316TValue*o=L->base+(idx-1);
5317luai_apicheck(L,idx<=L->ci->top-L->base);
5318if(o>=L->top)return cast(TValue*,(&luaO_nilobject_));
5319else return o;
5320}
5321else if(idx>(-10000)){
5322luai_apicheck(L,idx!=0&&-idx<=L->top-L->base);
5323return L->top+idx;
5324}
5325else switch(idx){
5326case(-10000):return registry(L);
5327case(-10001):{
5328Closure*func=curr_func(L);
5329sethvalue(L,&L->env,func->c.env);
5330return&L->env;
5331}
5332case(-10002):return gt(L);
5333default:{
5334Closure*func=curr_func(L);
5335idx=(-10002)-idx;
5336return(idx<=func->c.nupvalues)
5337?&func->c.upvalue[idx-1]
5338:cast(TValue*,(&luaO_nilobject_));
5339}
5340}
5341}
5342static Table*getcurrenv(lua_State*L){
5343if(L->ci==L->base_ci)
5344return hvalue(gt(L));
5345else{
5346Closure*func=curr_func(L);
5347return func->c.env;
5348}
5349}
5350static int lua_checkstack(lua_State*L,int size){
5351int res=1;
5352if(size>8000||(L->top-L->base+size)>8000)
5353res=0;
5354else if(size>0){
5355luaD_checkstack(L,size);
5356if(L->ci->top<L->top+size)
5357L->ci->top=L->top+size;
5358}
5359return res;
5360}
5361static lua_CFunction lua_atpanic(lua_State*L,lua_CFunction panicf){
5362lua_CFunction old;
5363old=G(L)->panic;
5364G(L)->panic=panicf;
5365return old;
5366}
5367static int lua_gettop(lua_State*L){
5368return cast_int(L->top-L->base);
5369}
5370static void lua_settop(lua_State*L,int idx){
5371if(idx>=0){
5372luai_apicheck(L,idx<=L->stack_last-L->base);
5373while(L->top<L->base+idx)
5374setnilvalue(L->top++);
5375L->top=L->base+idx;
5376}
5377else{
5378luai_apicheck(L,-(idx+1)<=(L->top-L->base));
5379L->top+=idx+1;
5380}
5381}
5382static void lua_remove(lua_State*L,int idx){
5383StkId p;
5384p=index2adr(L,idx);
5385api_checkvalidindex(L,p);
5386while(++p<L->top)setobj(L,p-1,p);
5387L->top--;
5388}
5389static void lua_insert(lua_State*L,int idx){
5390StkId p;
5391StkId q;
5392p=index2adr(L,idx);
5393api_checkvalidindex(L,p);
5394for(q=L->top;q>p;q--)setobj(L,q,q-1);
5395setobj(L,p,L->top);
5396}
5397static void lua_replace(lua_State*L,int idx){
5398StkId o;
5399if(idx==(-10001)&&L->ci==L->base_ci)
5400luaG_runerror(L,"no calling environment");
5401api_checknelems(L,1);
5402o=index2adr(L,idx);
5403api_checkvalidindex(L,o);
5404if(idx==(-10001)){
5405Closure*func=curr_func(L);
5406luai_apicheck(L,ttistable(L->top-1));
5407func->c.env=hvalue(L->top-1);
5408luaC_barrier(L,func,L->top-1);
5409}
5410else{
5411setobj(L,o,L->top-1);
5412if(idx<(-10002))
5413luaC_barrier(L,curr_func(L),L->top-1);
5414}
5415L->top--;
5416}
5417static void lua_pushvalue(lua_State*L,int idx){
5418setobj(L,L->top,index2adr(L,idx));
5419api_incr_top(L);
5420}
5421static int lua_type(lua_State*L,int idx){
5422StkId o=index2adr(L,idx);
5423return(o==(&luaO_nilobject_))?(-1):ttype(o);
5424}
5425static const char*lua_typename(lua_State*L,int t){
5426UNUSED(L);
5427return(t==(-1))?"no value":luaT_typenames[t];
5428}
5429static int lua_iscfunction(lua_State*L,int idx){
5430StkId o=index2adr(L,idx);
5431return iscfunction(o);
5432}
5433static int lua_isnumber(lua_State*L,int idx){
5434TValue n;
5435const TValue*o=index2adr(L,idx);
5436return tonumber(o,&n);
5437}
5438static int lua_isstring(lua_State*L,int idx){
5439int t=lua_type(L,idx);
5440return(t==4||t==3);
5441}
5442static int lua_rawequal(lua_State*L,int index1,int index2){
5443StkId o1=index2adr(L,index1);
5444StkId o2=index2adr(L,index2);
5445return(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0
5446:luaO_rawequalObj(o1,o2);
5447}
5448static int lua_lessthan(lua_State*L,int index1,int index2){
5449StkId o1,o2;
5450int i;
5451o1=index2adr(L,index1);
5452o2=index2adr(L,index2);
5453i=(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0
5454:luaV_lessthan(L,o1,o2);
5455return i;
5456}
5457static lua_Number lua_tonumber(lua_State*L,int idx){
5458TValue n;
5459const TValue*o=index2adr(L,idx);
5460if(tonumber(o,&n))
5461return nvalue(o);
5462else
5463return 0;
5464}
5465static lua_Integer lua_tointeger(lua_State*L,int idx){
5466TValue n;
5467const TValue*o=index2adr(L,idx);
5468if(tonumber(o,&n)){
5469lua_Integer res;
5470lua_Number num=nvalue(o);
5471lua_number2integer(res,num);
5472return res;
5473}
5474else
5475return 0;
5476}
5477static int lua_toboolean(lua_State*L,int idx){
5478const TValue*o=index2adr(L,idx);
5479return!l_isfalse(o);
5480}
5481static const char*lua_tolstring(lua_State*L,int idx,size_t*len){
5482StkId o=index2adr(L,idx);
5483if(!ttisstring(o)){
5484if(!luaV_tostring(L,o)){
5485if(len!=NULL)*len=0;
5486return NULL;
5487}
5488luaC_checkGC(L);
5489o=index2adr(L,idx);
5490}
5491if(len!=NULL)*len=tsvalue(o)->len;
5492return svalue(o);
5493}
5494static size_t lua_objlen(lua_State*L,int idx){
5495StkId o=index2adr(L,idx);
5496switch(ttype(o)){
5497case 4:return tsvalue(o)->len;
5498case 7:return uvalue(o)->len;
5499case 5:return luaH_getn(hvalue(o));
5500case 3:{
5501size_t l;
5502l=(luaV_tostring(L,o)?tsvalue(o)->len:0);
5503return l;
5504}
5505default:return 0;
5506}
5507}
5508static lua_CFunction lua_tocfunction(lua_State*L,int idx){
5509StkId o=index2adr(L,idx);
5510return(!iscfunction(o))?NULL:clvalue(o)->c.f;
5511}
5512static void*lua_touserdata(lua_State*L,int idx){
5513StkId o=index2adr(L,idx);
5514switch(ttype(o)){
5515case 7:return(rawuvalue(o)+1);
5516case 2:return pvalue(o);
5517default:return NULL;
5518}
5519}
5520static void lua_pushnil(lua_State*L){
5521setnilvalue(L->top);
5522api_incr_top(L);
5523}
5524static void lua_pushnumber(lua_State*L,lua_Number n){
5525setnvalue(L->top,n);
5526api_incr_top(L);
5527}
5528static void lua_pushinteger(lua_State*L,lua_Integer n){
5529setnvalue(L->top,cast_num(n));
5530api_incr_top(L);
5531}
5532static void lua_pushlstring(lua_State*L,const char*s,size_t len){
5533luaC_checkGC(L);
5534setsvalue(L,L->top,luaS_newlstr(L,s,len));
5535api_incr_top(L);
5536}
5537static void lua_pushstring(lua_State*L,const char*s){
5538if(s==NULL)
5539lua_pushnil(L);
5540else
5541lua_pushlstring(L,s,strlen(s));
5542}
5543static const char*lua_pushvfstring(lua_State*L,const char*fmt,
5544va_list argp){
5545const char*ret;
5546luaC_checkGC(L);
5547ret=luaO_pushvfstring(L,fmt,argp);
5548return ret;
5549}
5550static const char*lua_pushfstring(lua_State*L,const char*fmt,...){
5551const char*ret;
5552va_list argp;
5553luaC_checkGC(L);
5554va_start(argp,fmt);
5555ret=luaO_pushvfstring(L,fmt,argp);
5556va_end(argp);
5557return ret;
5558}
5559static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n){
5560Closure*cl;
5561luaC_checkGC(L);
5562api_checknelems(L,n);
5563cl=luaF_newCclosure(L,n,getcurrenv(L));
5564cl->c.f=fn;
5565L->top-=n;
5566while(n--)
5567setobj(L,&cl->c.upvalue[n],L->top+n);
5568setclvalue(L,L->top,cl);
5569api_incr_top(L);
5570}
5571static void lua_pushboolean(lua_State*L,int b){
5572setbvalue(L->top,(b!=0));
5573api_incr_top(L);
5574}
5575static int lua_pushthread(lua_State*L){
5576setthvalue(L,L->top,L);
5577api_incr_top(L);
5578return(G(L)->mainthread==L);
5579}
5580static void lua_gettable(lua_State*L,int idx){
5581StkId t;
5582t=index2adr(L,idx);
5583api_checkvalidindex(L,t);
5584luaV_gettable(L,t,L->top-1,L->top-1);
5585}
5586static void lua_getfield(lua_State*L,int idx,const char*k){
5587StkId t;
5588TValue key;
5589t=index2adr(L,idx);
5590api_checkvalidindex(L,t);
5591setsvalue(L,&key,luaS_new(L,k));
5592luaV_gettable(L,t,&key,L->top);
5593api_incr_top(L);
5594}
5595static void lua_rawget(lua_State*L,int idx){
5596StkId t;
5597t=index2adr(L,idx);
5598luai_apicheck(L,ttistable(t));
5599setobj(L,L->top-1,luaH_get(hvalue(t),L->top-1));
5600}
5601static void lua_rawgeti(lua_State*L,int idx,int n){
5602StkId o;
5603o=index2adr(L,idx);
5604luai_apicheck(L,ttistable(o));
5605setobj(L,L->top,luaH_getnum(hvalue(o),n));
5606api_incr_top(L);
5607}
5608static void lua_createtable(lua_State*L,int narray,int nrec){
5609luaC_checkGC(L);
5610sethvalue(L,L->top,luaH_new(L,narray,nrec));
5611api_incr_top(L);
5612}
5613static int lua_getmetatable(lua_State*L,int objindex){
5614const TValue*obj;
5615Table*mt=NULL;
5616int res;
5617obj=index2adr(L,objindex);
5618switch(ttype(obj)){
5619case 5:
5620mt=hvalue(obj)->metatable;
5621break;
5622case 7:
5623mt=uvalue(obj)->metatable;
5624break;
5625default:
5626mt=G(L)->mt[ttype(obj)];
5627break;
5628}
5629if(mt==NULL)
5630res=0;
5631else{
5632sethvalue(L,L->top,mt);
5633api_incr_top(L);
5634res=1;
5635}
5636return res;
5637}
5638static void lua_getfenv(lua_State*L,int idx){
5639StkId o;
5640o=index2adr(L,idx);
5641api_checkvalidindex(L,o);
5642switch(ttype(o)){
5643case 6:
5644sethvalue(L,L->top,clvalue(o)->c.env);
5645break;
5646case 7:
5647sethvalue(L,L->top,uvalue(o)->env);
5648break;
5649case 8:
5650setobj(L,L->top,gt(thvalue(o)));
5651break;
5652default:
5653setnilvalue(L->top);
5654break;
5655}
5656api_incr_top(L);
5657}
5658static void lua_settable(lua_State*L,int idx){
5659StkId t;
5660api_checknelems(L,2);
5661t=index2adr(L,idx);
5662api_checkvalidindex(L,t);
5663luaV_settable(L,t,L->top-2,L->top-1);
5664L->top-=2;
5665}
5666static void lua_setfield(lua_State*L,int idx,const char*k){
5667StkId t;
5668TValue key;
5669api_checknelems(L,1);
5670t=index2adr(L,idx);
5671api_checkvalidindex(L,t);
5672setsvalue(L,&key,luaS_new(L,k));
5673luaV_settable(L,t,&key,L->top-1);
5674L->top--;
5675}
5676static void lua_rawset(lua_State*L,int idx){
5677StkId t;
5678api_checknelems(L,2);
5679t=index2adr(L,idx);
5680luai_apicheck(L,ttistable(t));
5681setobj(L,luaH_set(L,hvalue(t),L->top-2),L->top-1);
5682luaC_barriert(L,hvalue(t),L->top-1);
5683L->top-=2;
5684}
5685static void lua_rawseti(lua_State*L,int idx,int n){
5686StkId o;
5687api_checknelems(L,1);
5688o=index2adr(L,idx);
5689luai_apicheck(L,ttistable(o));
5690setobj(L,luaH_setnum(L,hvalue(o),n),L->top-1);
5691luaC_barriert(L,hvalue(o),L->top-1);
5692L->top--;
5693}
5694static int lua_setmetatable(lua_State*L,int objindex){
5695TValue*obj;
5696Table*mt;
5697api_checknelems(L,1);
5698obj=index2adr(L,objindex);
5699api_checkvalidindex(L,obj);
5700if(ttisnil(L->top-1))
5701mt=NULL;
5702else{
5703luai_apicheck(L,ttistable(L->top-1));
5704mt=hvalue(L->top-1);
5705}
5706switch(ttype(obj)){
5707case 5:{
5708hvalue(obj)->metatable=mt;
5709if(mt)
5710luaC_objbarriert(L,hvalue(obj),mt);
5711break;
5712}
5713case 7:{
5714uvalue(obj)->metatable=mt;
5715if(mt)
5716luaC_objbarrier(L,rawuvalue(obj),mt);
5717break;
5718}
5719default:{
5720G(L)->mt[ttype(obj)]=mt;
5721break;
5722}
5723}
5724L->top--;
5725return 1;
5726}
5727static int lua_setfenv(lua_State*L,int idx){
5728StkId o;
5729int res=1;
5730api_checknelems(L,1);
5731o=index2adr(L,idx);
5732api_checkvalidindex(L,o);
5733luai_apicheck(L,ttistable(L->top-1));
5734switch(ttype(o)){
5735case 6:
5736clvalue(o)->c.env=hvalue(L->top-1);
5737break;
5738case 7:
5739uvalue(o)->env=hvalue(L->top-1);
5740break;
5741case 8:
5742sethvalue(L,gt(thvalue(o)),hvalue(L->top-1));
5743break;
5744default:
5745res=0;
5746break;
5747}
5748if(res)luaC_objbarrier(L,gcvalue(o),hvalue(L->top-1));
5749L->top--;
5750return res;
5751}
5752#define adjustresults(L,nres){if(nres==(-1)&&L->top>=L->ci->top)L->ci->top=L->top;}
5753#define checkresults(L,na,nr)luai_apicheck(L,(nr)==(-1)||(L->ci->top-L->top>=(nr)-(na)))
5754static void lua_call(lua_State*L,int nargs,int nresults){
5755StkId func;
5756api_checknelems(L,nargs+1);
5757checkresults(L,nargs,nresults);
5758func=L->top-(nargs+1);
5759luaD_call(L,func,nresults);
5760adjustresults(L,nresults);
5761}
5762struct CallS{
5763StkId func;
5764int nresults;
5765};
5766static void f_call(lua_State*L,void*ud){
5767struct CallS*c=cast(struct CallS*,ud);
5768luaD_call(L,c->func,c->nresults);
5769}
5770static int lua_pcall(lua_State*L,int nargs,int nresults,int errfunc){
5771struct CallS c;
5772int status;
5773ptrdiff_t func;
5774api_checknelems(L,nargs+1);
5775checkresults(L,nargs,nresults);
5776if(errfunc==0)
5777func=0;
5778else{
5779StkId o=index2adr(L,errfunc);
5780api_checkvalidindex(L,o);
5781func=savestack(L,o);
5782}
5783c.func=L->top-(nargs+1);
5784c.nresults=nresults;
5785status=luaD_pcall(L,f_call,&c,savestack(L,c.func),func);
5786adjustresults(L,nresults);
5787return status;
5788}
5789static int lua_load(lua_State*L,lua_Reader reader,void*data,
5790const char*chunkname){
5791ZIO z;
5792int status;
5793if(!chunkname)chunkname="?";
5794luaZ_init(L,&z,reader,data);
5795status=luaD_protectedparser(L,&z,chunkname);
5796return status;
5797}
5798static int lua_error(lua_State*L){
5799api_checknelems(L,1);
5800luaG_errormsg(L);
5801return 0;
5802}
5803static int lua_next(lua_State*L,int idx){
5804StkId t;
5805int more;
5806t=index2adr(L,idx);
5807luai_apicheck(L,ttistable(t));
5808more=luaH_next(L,hvalue(t),L->top-1);
5809if(more){
5810api_incr_top(L);
5811}
5812else
5813L->top-=1;
5814return more;
5815}
5816static void lua_concat(lua_State*L,int n){
5817api_checknelems(L,n);
5818if(n>=2){
5819luaC_checkGC(L);
5820luaV_concat(L,n,cast_int(L->top-L->base)-1);
5821L->top-=(n-1);
5822}
5823else if(n==0){
5824setsvalue(L,L->top,luaS_newlstr(L,"",0));
5825api_incr_top(L);
5826}
5827}
5828static void*lua_newuserdata(lua_State*L,size_t size){
5829Udata*u;
5830luaC_checkGC(L);
5831u=luaS_newudata(L,size,getcurrenv(L));
5832setuvalue(L,L->top,u);
5833api_incr_top(L);
5834return u+1;
5835}
5836#define luaL_getn(L,i)((int)lua_objlen(L,i))
5837#define luaL_setn(L,i,j)((void)0)
5838typedef struct luaL_Reg{
5839const char*name;
5840lua_CFunction func;
5841}luaL_Reg;
5842static void luaI_openlib(lua_State*L,const char*libname,
5843const luaL_Reg*l,int nup);
5844static int luaL_argerror(lua_State*L,int numarg,const char*extramsg);
5845static const char* luaL_checklstring(lua_State*L,int numArg,
5846size_t*l);
5847static const char* luaL_optlstring(lua_State*L,int numArg,
5848const char*def,size_t*l);
5849static lua_Integer luaL_checkinteger(lua_State*L,int numArg);
5850static lua_Integer luaL_optinteger(lua_State*L,int nArg,
5851lua_Integer def);
5852static int luaL_error(lua_State*L,const char*fmt,...);
5853static const char* luaL_findtable(lua_State*L,int idx,
5854const char*fname,int szhint);
5855#define luaL_argcheck(L,cond,numarg,extramsg)((void)((cond)||luaL_argerror(L,(numarg),(extramsg))))
5856#define luaL_checkstring(L,n)(luaL_checklstring(L,(n),NULL))
5857#define luaL_optstring(L,n,d)(luaL_optlstring(L,(n),(d),NULL))
5858#define luaL_checkint(L,n)((int)luaL_checkinteger(L,(n)))
5859#define luaL_optint(L,n,d)((int)luaL_optinteger(L,(n),(d)))
5860#define luaL_typename(L,i)lua_typename(L,lua_type(L,(i)))
5861#define luaL_getmetatable(L,n)(lua_getfield(L,(-10000),(n)))
5862#define luaL_opt(L,f,n,d)(lua_isnoneornil(L,(n))?(d):f(L,(n)))
5863typedef struct luaL_Buffer{
5864char*p;
5865int lvl;
5866lua_State*L;
5867char buffer[BUFSIZ];
5868}luaL_Buffer;
5869#define luaL_addchar(B,c)((void)((B)->p<((B)->buffer+BUFSIZ)||luaL_prepbuffer(B)),(*(B)->p++=(char)(c)))
5870#define luaL_addsize(B,n)((B)->p+=(n))
5871static char* luaL_prepbuffer(luaL_Buffer*B);
5872static int luaL_argerror(lua_State*L,int narg,const char*extramsg){
5873lua_Debug ar;
5874if(!lua_getstack(L,0,&ar))
5875return luaL_error(L,"bad argument #%d (%s)",narg,extramsg);
5876lua_getinfo(L,"n",&ar);
5877if(strcmp(ar.namewhat,"method")==0){
5878narg--;
5879if(narg==0)
5880return luaL_error(L,"calling "LUA_QL("%s")" on bad self (%s)",
5881ar.name,extramsg);
5882}
5883if(ar.name==NULL)
5884ar.name="?";
5885return luaL_error(L,"bad argument #%d to "LUA_QL("%s")" (%s)",
5886narg,ar.name,extramsg);
5887}
5888static int luaL_typerror(lua_State*L,int narg,const char*tname){
5889const char*msg=lua_pushfstring(L,"%s expected, got %s",
5890tname,luaL_typename(L,narg));
5891return luaL_argerror(L,narg,msg);
5892}
5893static void tag_error(lua_State*L,int narg,int tag){
5894luaL_typerror(L,narg,lua_typename(L,tag));
5895}
5896static void luaL_where(lua_State*L,int level){
5897lua_Debug ar;
5898if(lua_getstack(L,level,&ar)){
5899lua_getinfo(L,"Sl",&ar);
5900if(ar.currentline>0){
5901lua_pushfstring(L,"%s:%d: ",ar.short_src,ar.currentline);
5902return;
5903}
5904}
5905lua_pushliteral(L,"");
5906}
5907static int luaL_error(lua_State*L,const char*fmt,...){
5908va_list argp;
5909va_start(argp,fmt);
5910luaL_where(L,1);
5911lua_pushvfstring(L,fmt,argp);
5912va_end(argp);
5913lua_concat(L,2);
5914return lua_error(L);
5915}
5916static int luaL_newmetatable(lua_State*L,const char*tname){
5917lua_getfield(L,(-10000),tname);
5918if(!lua_isnil(L,-1))
5919return 0;
5920lua_pop(L,1);
5921lua_newtable(L);
5922lua_pushvalue(L,-1);
5923lua_setfield(L,(-10000),tname);
5924return 1;
5925}
5926static void*luaL_checkudata(lua_State*L,int ud,const char*tname){
5927void*p=lua_touserdata(L,ud);
5928if(p!=NULL){
5929if(lua_getmetatable(L,ud)){
5930lua_getfield(L,(-10000),tname);
5931if(lua_rawequal(L,-1,-2)){
5932lua_pop(L,2);
5933return p;
5934}
5935}
5936}
5937luaL_typerror(L,ud,tname);
5938return NULL;
5939}
5940static void luaL_checkstack(lua_State*L,int space,const char*mes){
5941if(!lua_checkstack(L,space))
5942luaL_error(L,"stack overflow (%s)",mes);
5943}
5944static void luaL_checktype(lua_State*L,int narg,int t){
5945if(lua_type(L,narg)!=t)
5946tag_error(L,narg,t);
5947}
5948static void luaL_checkany(lua_State*L,int narg){
5949if(lua_type(L,narg)==(-1))
5950luaL_argerror(L,narg,"value expected");
5951}
5952static const char*luaL_checklstring(lua_State*L,int narg,size_t*len){
5953const char*s=lua_tolstring(L,narg,len);
5954if(!s)tag_error(L,narg,4);
5955return s;
5956}
5957static const char*luaL_optlstring(lua_State*L,int narg,
5958const char*def,size_t*len){
5959if(lua_isnoneornil(L,narg)){
5960if(len)
5961*len=(def?strlen(def):0);
5962return def;
5963}
5964else return luaL_checklstring(L,narg,len);
5965}
5966static lua_Number luaL_checknumber(lua_State*L,int narg){
5967lua_Number d=lua_tonumber(L,narg);
5968if(d==0&&!lua_isnumber(L,narg))
5969tag_error(L,narg,3);
5970return d;
5971}
5972static lua_Integer luaL_checkinteger(lua_State*L,int narg){
5973lua_Integer d=lua_tointeger(L,narg);
5974if(d==0&&!lua_isnumber(L,narg))
5975tag_error(L,narg,3);
5976return d;
5977}
5978static lua_Integer luaL_optinteger(lua_State*L,int narg,
5979lua_Integer def){
5980return luaL_opt(L,luaL_checkinteger,narg,def);
5981}
5982static int luaL_getmetafield(lua_State*L,int obj,const char*event){
5983if(!lua_getmetatable(L,obj))
5984return 0;
5985lua_pushstring(L,event);
5986lua_rawget(L,-2);
5987if(lua_isnil(L,-1)){
5988lua_pop(L,2);
5989return 0;
5990}
5991else{
5992lua_remove(L,-2);
5993return 1;
5994}
5995}
5996static void luaL_register(lua_State*L,const char*libname,
5997const luaL_Reg*l){
5998luaI_openlib(L,libname,l,0);
5999}
6000static int libsize(const luaL_Reg*l){
6001int size=0;
6002for(;l->name;l++)size++;
6003return size;
6004}
6005static void luaI_openlib(lua_State*L,const char*libname,
6006const luaL_Reg*l,int nup){
6007if(libname){
6008int size=libsize(l);
6009luaL_findtable(L,(-10000),"_LOADED",1);
6010lua_getfield(L,-1,libname);
6011if(!lua_istable(L,-1)){
6012lua_pop(L,1);
6013if(luaL_findtable(L,(-10002),libname,size)!=NULL)
6014luaL_error(L,"name conflict for module "LUA_QL("%s"),libname);
6015lua_pushvalue(L,-1);
6016lua_setfield(L,-3,libname);
6017}
6018lua_remove(L,-2);
6019lua_insert(L,-(nup+1));
6020}
6021for(;l->name;l++){
6022int i;
6023for(i=0;i<nup;i++)
6024lua_pushvalue(L,-nup);
6025lua_pushcclosure(L,l->func,nup);
6026lua_setfield(L,-(nup+2),l->name);
6027}
6028lua_pop(L,nup);
6029}
6030static const char*luaL_findtable(lua_State*L,int idx,
6031const char*fname,int szhint){
6032const char*e;
6033lua_pushvalue(L,idx);
6034do{
6035e=strchr(fname,'.');
6036if(e==NULL)e=fname+strlen(fname);
6037lua_pushlstring(L,fname,e-fname);
6038lua_rawget(L,-2);
6039if(lua_isnil(L,-1)){
6040lua_pop(L,1);
6041lua_createtable(L,0,(*e=='.'?1:szhint));
6042lua_pushlstring(L,fname,e-fname);
6043lua_pushvalue(L,-2);
6044lua_settable(L,-4);
6045}
6046else if(!lua_istable(L,-1)){
6047lua_pop(L,2);
6048return fname;
6049}
6050lua_remove(L,-2);
6051fname=e+1;
6052}while(*e=='.');
6053return NULL;
6054}
6055#define bufflen(B)((B)->p-(B)->buffer)
6056#define bufffree(B)((size_t)(BUFSIZ-bufflen(B)))
6057static int emptybuffer(luaL_Buffer*B){
6058size_t l=bufflen(B);
6059if(l==0)return 0;
6060else{
6061lua_pushlstring(B->L,B->buffer,l);
6062B->p=B->buffer;
6063B->lvl++;
6064return 1;
6065}
6066}
6067static void adjuststack(luaL_Buffer*B){
6068if(B->lvl>1){
6069lua_State*L=B->L;
6070int toget=1;
6071size_t toplen=lua_strlen(L,-1);
6072do{
6073size_t l=lua_strlen(L,-(toget+1));
6074if(B->lvl-toget+1>=(20/2)||toplen>l){
6075toplen+=l;
6076toget++;
6077}
6078else break;
6079}while(toget<B->lvl);
6080lua_concat(L,toget);
6081B->lvl=B->lvl-toget+1;
6082}
6083}
6084static char*luaL_prepbuffer(luaL_Buffer*B){
6085if(emptybuffer(B))
6086adjuststack(B);
6087return B->buffer;
6088}
6089static void luaL_addlstring(luaL_Buffer*B,const char*s,size_t l){
6090while(l--)
6091luaL_addchar(B,*s++);
6092}
6093static void luaL_pushresult(luaL_Buffer*B){
6094emptybuffer(B);
6095lua_concat(B->L,B->lvl);
6096B->lvl=1;
6097}
6098static void luaL_addvalue(luaL_Buffer*B){
6099lua_State*L=B->L;
6100size_t vl;
6101const char*s=lua_tolstring(L,-1,&vl);
6102if(vl<=bufffree(B)){
6103memcpy(B->p,s,vl);
6104B->p+=vl;
6105lua_pop(L,1);
6106}
6107else{
6108if(emptybuffer(B))
6109lua_insert(L,-2);
6110B->lvl++;
6111adjuststack(B);
6112}
6113}
6114static void luaL_buffinit(lua_State*L,luaL_Buffer*B){
6115B->L=L;
6116B->p=B->buffer;
6117B->lvl=0;
6118}
6119typedef struct LoadF{
6120int extraline;
6121FILE*f;
6122char buff[BUFSIZ];
6123}LoadF;
6124static const char*getF(lua_State*L,void*ud,size_t*size){
6125LoadF*lf=(LoadF*)ud;
6126(void)L;
6127if(lf->extraline){
6128lf->extraline=0;
6129*size=1;
6130return"\n";
6131}
6132if(feof(lf->f))return NULL;
6133*size=fread(lf->buff,1,sizeof(lf->buff),lf->f);
6134return(*size>0)?lf->buff:NULL;
6135}
6136static int errfile(lua_State*L,const char*what,int fnameindex){
6137const char*serr=strerror(errno);
6138const char*filename=lua_tostring(L,fnameindex)+1;
6139lua_pushfstring(L,"cannot %s %s: %s",what,filename,serr);
6140lua_remove(L,fnameindex);
6141return(5+1);
6142}
6143static int luaL_loadfile(lua_State*L,const char*filename){
6144LoadF lf;
6145int status,readstatus;
6146int c;
6147int fnameindex=lua_gettop(L)+1;
6148lf.extraline=0;
6149if(filename==NULL){
6150lua_pushliteral(L,"=stdin");
6151lf.f=stdin;
6152}
6153else{
6154lua_pushfstring(L,"@%s",filename);
6155lf.f=fopen(filename,"r");
6156if(lf.f==NULL)return errfile(L,"open",fnameindex);
6157}
6158c=getc(lf.f);
6159if(c=='#'){
6160lf.extraline=1;
6161while((c=getc(lf.f))!=EOF&&c!='\n');
6162if(c=='\n')c=getc(lf.f);
6163}
6164if(c=="\033Lua"[0]&&filename){
6165lf.f=freopen(filename,"rb",lf.f);
6166if(lf.f==NULL)return errfile(L,"reopen",fnameindex);
6167while((c=getc(lf.f))!=EOF&&c!="\033Lua"[0]);
6168lf.extraline=0;
6169}
6170ungetc(c,lf.f);
6171status=lua_load(L,getF,&lf,lua_tostring(L,-1));
6172readstatus=ferror(lf.f);
6173if(filename)fclose(lf.f);
6174if(readstatus){
6175lua_settop(L,fnameindex);
6176return errfile(L,"read",fnameindex);
6177}
6178lua_remove(L,fnameindex);
6179return status;
6180}
6181typedef struct LoadS{
6182const char*s;
6183size_t size;
6184}LoadS;
6185static const char*getS(lua_State*L,void*ud,size_t*size){
6186LoadS*ls=(LoadS*)ud;
6187(void)L;
6188if(ls->size==0)return NULL;
6189*size=ls->size;
6190ls->size=0;
6191return ls->s;
6192}
6193static int luaL_loadbuffer(lua_State*L,const char*buff,size_t size,
6194const char*name){
6195LoadS ls;
6196ls.s=buff;
6197ls.size=size;
6198return lua_load(L,getS,&ls,name);
6199}
6200static void*l_alloc(void*ud,void*ptr,size_t osize,size_t nsize){
6201(void)ud;
6202(void)osize;
6203if(nsize==0){
6204free(ptr);
6205return NULL;
6206}
6207else
6208return realloc(ptr,nsize);
6209}
6210static int panic(lua_State*L){
6211(void)L;
6212fprintf(stderr,"PANIC: unprotected error in call to Lua API (%s)\n",
6213lua_tostring(L,-1));
6214return 0;
6215}
6216static lua_State*luaL_newstate(void){
6217lua_State*L=lua_newstate(l_alloc,NULL);
6218if(L)lua_atpanic(L,&panic);
6219return L;
6220}
6221static int luaB_tonumber(lua_State*L){
6222int base=luaL_optint(L,2,10);
6223if(base==10){
6224luaL_checkany(L,1);
6225if(lua_isnumber(L,1)){
6226lua_pushnumber(L,lua_tonumber(L,1));
6227return 1;
6228}
6229}
6230else{
6231const char*s1=luaL_checkstring(L,1);
6232char*s2;
6233unsigned long n;
6234luaL_argcheck(L,2<=base&&base<=36,2,"base out of range");
6235n=strtoul(s1,&s2,base);
6236if(s1!=s2){
6237while(isspace((unsigned char)(*s2)))s2++;
6238if(*s2=='\0'){
6239lua_pushnumber(L,(lua_Number)n);
6240return 1;
6241}
6242}
6243}
6244lua_pushnil(L);
6245return 1;
6246}
6247static int luaB_error(lua_State*L){
6248int level=luaL_optint(L,2,1);
6249lua_settop(L,1);
6250if(lua_isstring(L,1)&&level>0){
6251luaL_where(L,level);
6252lua_pushvalue(L,1);
6253lua_concat(L,2);
6254}
6255return lua_error(L);
6256}
6257static int luaB_setmetatable(lua_State*L){
6258int t=lua_type(L,2);
6259luaL_checktype(L,1,5);
6260luaL_argcheck(L,t==0||t==5,2,
6261"nil or table expected");
6262if(luaL_getmetafield(L,1,"__metatable"))
6263luaL_error(L,"cannot change a protected metatable");
6264lua_settop(L,2);
6265lua_setmetatable(L,1);
6266return 1;
6267}
6268static void getfunc(lua_State*L,int opt){
6269if(lua_isfunction(L,1))lua_pushvalue(L,1);
6270else{
6271lua_Debug ar;
6272int level=opt?luaL_optint(L,1,1):luaL_checkint(L,1);
6273luaL_argcheck(L,level>=0,1,"level must be non-negative");
6274if(lua_getstack(L,level,&ar)==0)
6275luaL_argerror(L,1,"invalid level");
6276lua_getinfo(L,"f",&ar);
6277if(lua_isnil(L,-1))
6278luaL_error(L,"no function environment for tail call at level %d",
6279level);
6280}
6281}
6282static int luaB_setfenv(lua_State*L){
6283luaL_checktype(L,2,5);
6284getfunc(L,0);
6285lua_pushvalue(L,2);
6286if(lua_isnumber(L,1)&&lua_tonumber(L,1)==0){
6287lua_pushthread(L);
6288lua_insert(L,-2);
6289lua_setfenv(L,-2);
6290return 0;
6291}
6292else if(lua_iscfunction(L,-2)||lua_setfenv(L,-2)==0)
6293luaL_error(L,
6294LUA_QL("setfenv")" cannot change environment of given object");
6295return 1;
6296}
6297static int luaB_rawget(lua_State*L){
6298luaL_checktype(L,1,5);
6299luaL_checkany(L,2);
6300lua_settop(L,2);
6301lua_rawget(L,1);
6302return 1;
6303}
6304static int luaB_type(lua_State*L){
6305luaL_checkany(L,1);
6306lua_pushstring(L,luaL_typename(L,1));
6307return 1;
6308}
6309static int luaB_next(lua_State*L){
6310luaL_checktype(L,1,5);
6311lua_settop(L,2);
6312if(lua_next(L,1))
6313return 2;
6314else{
6315lua_pushnil(L);
6316return 1;
6317}
6318}
6319static int luaB_pairs(lua_State*L){
6320luaL_checktype(L,1,5);
6321lua_pushvalue(L,lua_upvalueindex(1));
6322lua_pushvalue(L,1);
6323lua_pushnil(L);
6324return 3;
6325}
6326static int ipairsaux(lua_State*L){
6327int i=luaL_checkint(L,2);
6328luaL_checktype(L,1,5);
6329i++;
6330lua_pushinteger(L,i);
6331lua_rawgeti(L,1,i);
6332return(lua_isnil(L,-1))?0:2;
6333}
6334static int luaB_ipairs(lua_State*L){
6335luaL_checktype(L,1,5);
6336lua_pushvalue(L,lua_upvalueindex(1));
6337lua_pushvalue(L,1);
6338lua_pushinteger(L,0);
6339return 3;
6340}
6341static int load_aux(lua_State*L,int status){
6342if(status==0)
6343return 1;
6344else{
6345lua_pushnil(L);
6346lua_insert(L,-2);
6347return 2;
6348}
6349}
6350static int luaB_loadstring(lua_State*L){
6351size_t l;
6352const char*s=luaL_checklstring(L,1,&l);
6353const char*chunkname=luaL_optstring(L,2,s);
6354return load_aux(L,luaL_loadbuffer(L,s,l,chunkname));
6355}
6356static int luaB_loadfile(lua_State*L){
6357const char*fname=luaL_optstring(L,1,NULL);
6358return load_aux(L,luaL_loadfile(L,fname));
6359}
6360static int luaB_assert(lua_State*L){
6361luaL_checkany(L,1);
6362if(!lua_toboolean(L,1))
6363return luaL_error(L,"%s",luaL_optstring(L,2,"assertion failed!"));
6364return lua_gettop(L);
6365}
6366static int luaB_unpack(lua_State*L){
6367int i,e,n;
6368luaL_checktype(L,1,5);
6369i=luaL_optint(L,2,1);
6370e=luaL_opt(L,luaL_checkint,3,luaL_getn(L,1));
6371if(i>e)return 0;
6372n=e-i+1;
6373if(n<=0||!lua_checkstack(L,n))
6374return luaL_error(L,"too many results to unpack");
6375lua_rawgeti(L,1,i);
6376while(i++<e)
6377lua_rawgeti(L,1,i);
6378return n;
6379}
6380static int luaB_pcall(lua_State*L){
6381int status;
6382luaL_checkany(L,1);
6383status=lua_pcall(L,lua_gettop(L)-1,(-1),0);
6384lua_pushboolean(L,(status==0));
6385lua_insert(L,1);
6386return lua_gettop(L);
6387}
6388static int luaB_newproxy(lua_State*L){
6389lua_settop(L,1);
6390lua_newuserdata(L,0);
6391if(lua_toboolean(L,1)==0)
6392return 1;
6393else if(lua_isboolean(L,1)){
6394lua_newtable(L);
6395lua_pushvalue(L,-1);
6396lua_pushboolean(L,1);
6397lua_rawset(L,lua_upvalueindex(1));
6398}
6399else{
6400int validproxy=0;
6401if(lua_getmetatable(L,1)){
6402lua_rawget(L,lua_upvalueindex(1));
6403validproxy=lua_toboolean(L,-1);
6404lua_pop(L,1);
6405}
6406luaL_argcheck(L,validproxy,1,"boolean or proxy expected");
6407lua_getmetatable(L,1);
6408}
6409lua_setmetatable(L,2);
6410return 1;
6411}
6412static const luaL_Reg base_funcs[]={
6413{"assert",luaB_assert},
6414{"error",luaB_error},
6415{"loadfile",luaB_loadfile},
6416{"loadstring",luaB_loadstring},
6417{"next",luaB_next},
6418{"pcall",luaB_pcall},
6419{"rawget",luaB_rawget},
6420{"setfenv",luaB_setfenv},
6421{"setmetatable",luaB_setmetatable},
6422{"tonumber",luaB_tonumber},
6423{"type",luaB_type},
6424{"unpack",luaB_unpack},
6425{NULL,NULL}
6426};
6427static void auxopen(lua_State*L,const char*name,
6428lua_CFunction f,lua_CFunction u){
6429lua_pushcfunction(L,u);
6430lua_pushcclosure(L,f,1);
6431lua_setfield(L,-2,name);
6432}
6433static void base_open(lua_State*L){
6434lua_pushvalue(L,(-10002));
6435lua_setglobal(L,"_G");
6436luaL_register(L,"_G",base_funcs);
6437lua_pushliteral(L,"Lua 5.1");
6438lua_setglobal(L,"_VERSION");
6439auxopen(L,"ipairs",luaB_ipairs,ipairsaux);
6440auxopen(L,"pairs",luaB_pairs,luaB_next);
6441lua_createtable(L,0,1);
6442lua_pushvalue(L,-1);
6443lua_setmetatable(L,-2);
6444lua_pushliteral(L,"kv");
6445lua_setfield(L,-2,"__mode");
6446lua_pushcclosure(L,luaB_newproxy,1);
6447lua_setglobal(L,"newproxy");
6448}
6449static int luaopen_base(lua_State*L){
6450base_open(L);
6451return 1;
6452}
6453#define aux_getn(L,n)(luaL_checktype(L,n,5),luaL_getn(L,n))
6454static int tinsert(lua_State*L){
6455int e=aux_getn(L,1)+1;
6456int pos;
6457switch(lua_gettop(L)){
6458case 2:{
6459pos=e;
6460break;
6461}
6462case 3:{
6463int i;
6464pos=luaL_checkint(L,2);
6465if(pos>e)e=pos;
6466for(i=e;i>pos;i--){
6467lua_rawgeti(L,1,i-1);
6468lua_rawseti(L,1,i);
6469}
6470break;
6471}
6472default:{
6473return luaL_error(L,"wrong number of arguments to "LUA_QL("insert"));
6474}
6475}
6476luaL_setn(L,1,e);
6477lua_rawseti(L,1,pos);
6478return 0;
6479}
6480static int tremove(lua_State*L){
6481int e=aux_getn(L,1);
6482int pos=luaL_optint(L,2,e);
6483if(!(1<=pos&&pos<=e))
6484return 0;
6485luaL_setn(L,1,e-1);
6486lua_rawgeti(L,1,pos);
6487for(;pos<e;pos++){
6488lua_rawgeti(L,1,pos+1);
6489lua_rawseti(L,1,pos);
6490}
6491lua_pushnil(L);
6492lua_rawseti(L,1,e);
6493return 1;
6494}
6495static void addfield(lua_State*L,luaL_Buffer*b,int i){
6496lua_rawgeti(L,1,i);
6497if(!lua_isstring(L,-1))
6498luaL_error(L,"invalid value (%s) at index %d in table for "
6499LUA_QL("concat"),luaL_typename(L,-1),i);
6500luaL_addvalue(b);
6501}
6502static int tconcat(lua_State*L){
6503luaL_Buffer b;
6504size_t lsep;
6505int i,last;
6506const char*sep=luaL_optlstring(L,2,"",&lsep);
6507luaL_checktype(L,1,5);
6508i=luaL_optint(L,3,1);
6509last=luaL_opt(L,luaL_checkint,4,luaL_getn(L,1));
6510luaL_buffinit(L,&b);
6511for(;i<last;i++){
6512addfield(L,&b,i);
6513luaL_addlstring(&b,sep,lsep);
6514}
6515if(i==last)
6516addfield(L,&b,i);
6517luaL_pushresult(&b);
6518return 1;
6519}
6520static void set2(lua_State*L,int i,int j){
6521lua_rawseti(L,1,i);
6522lua_rawseti(L,1,j);
6523}
6524static int sort_comp(lua_State*L,int a,int b){
6525if(!lua_isnil(L,2)){
6526int res;
6527lua_pushvalue(L,2);
6528lua_pushvalue(L,a-1);
6529lua_pushvalue(L,b-2);
6530lua_call(L,2,1);
6531res=lua_toboolean(L,-1);
6532lua_pop(L,1);
6533return res;
6534}
6535else
6536return lua_lessthan(L,a,b);
6537}
6538static void auxsort(lua_State*L,int l,int u){
6539while(l<u){
6540int i,j;
6541lua_rawgeti(L,1,l);
6542lua_rawgeti(L,1,u);
6543if(sort_comp(L,-1,-2))
6544set2(L,l,u);
6545else
6546lua_pop(L,2);
6547if(u-l==1)break;
6548i=(l+u)/2;
6549lua_rawgeti(L,1,i);
6550lua_rawgeti(L,1,l);
6551if(sort_comp(L,-2,-1))
6552set2(L,i,l);
6553else{
6554lua_pop(L,1);
6555lua_rawgeti(L,1,u);
6556if(sort_comp(L,-1,-2))
6557set2(L,i,u);
6558else
6559lua_pop(L,2);
6560}
6561if(u-l==2)break;
6562lua_rawgeti(L,1,i);
6563lua_pushvalue(L,-1);
6564lua_rawgeti(L,1,u-1);
6565set2(L,i,u-1);
6566i=l;j=u-1;
6567for(;;){
6568while(lua_rawgeti(L,1,++i),sort_comp(L,-1,-2)){
6569if(i>u)luaL_error(L,"invalid order function for sorting");
6570lua_pop(L,1);
6571}
6572while(lua_rawgeti(L,1,--j),sort_comp(L,-3,-1)){
6573if(j<l)luaL_error(L,"invalid order function for sorting");
6574lua_pop(L,1);
6575}
6576if(j<i){
6577lua_pop(L,3);
6578break;
6579}
6580set2(L,i,j);
6581}
6582lua_rawgeti(L,1,u-1);
6583lua_rawgeti(L,1,i);
6584set2(L,u-1,i);
6585if(i-l<u-i){
6586j=l;i=i-1;l=i+2;
6587}
6588else{
6589j=i+1;i=u;u=j-2;
6590}
6591auxsort(L,j,i);
6592}
6593}
6594static int sort(lua_State*L){
6595int n=aux_getn(L,1);
6596luaL_checkstack(L,40,"");
6597if(!lua_isnoneornil(L,2))
6598luaL_checktype(L,2,6);
6599lua_settop(L,2);
6600auxsort(L,1,n);
6601return 0;
6602}
6603static const luaL_Reg tab_funcs[]={
6604{"concat",tconcat},
6605{"insert",tinsert},
6606{"remove",tremove},
6607{"sort",sort},
6608{NULL,NULL}
6609};
6610static int luaopen_table(lua_State*L){
6611luaL_register(L,"table",tab_funcs);
6612return 1;
6613}
6614static const char*const fnames[]={"input","output"};
6615static int pushresult(lua_State*L,int i,const char*filename){
6616int en=errno;
6617if(i){
6618lua_pushboolean(L,1);
6619return 1;
6620}
6621else{
6622lua_pushnil(L);
6623if(filename)
6624lua_pushfstring(L,"%s: %s",filename,strerror(en));
6625else
6626lua_pushfstring(L,"%s",strerror(en));
6627lua_pushinteger(L,en);
6628return 3;
6629}
6630}
6631static void fileerror(lua_State*L,int arg,const char*filename){
6632lua_pushfstring(L,"%s: %s",filename,strerror(errno));
6633luaL_argerror(L,arg,lua_tostring(L,-1));
6634}
6635#define tofilep(L)((FILE**)luaL_checkudata(L,1,"FILE*"))
6636static int io_type(lua_State*L){
6637void*ud;
6638luaL_checkany(L,1);
6639ud=lua_touserdata(L,1);
6640lua_getfield(L,(-10000),"FILE*");
6641if(ud==NULL||!lua_getmetatable(L,1)||!lua_rawequal(L,-2,-1))
6642lua_pushnil(L);
6643else if(*((FILE**)ud)==NULL)
6644lua_pushliteral(L,"closed file");
6645else
6646lua_pushliteral(L,"file");
6647return 1;
6648}
6649static FILE*tofile(lua_State*L){
6650FILE**f=tofilep(L);
6651if(*f==NULL)
6652luaL_error(L,"attempt to use a closed file");
6653return*f;
6654}
6655static FILE**newfile(lua_State*L){
6656FILE**pf=(FILE**)lua_newuserdata(L,sizeof(FILE*));
6657*pf=NULL;
6658luaL_getmetatable(L,"FILE*");
6659lua_setmetatable(L,-2);
6660return pf;
6661}
6662static int io_noclose(lua_State*L){
6663lua_pushnil(L);
6664lua_pushliteral(L,"cannot close standard file");
6665return 2;
6666}
6667static int io_pclose(lua_State*L){
6668FILE**p=tofilep(L);
6669int ok=lua_pclose(L,*p);
6670*p=NULL;
6671return pushresult(L,ok,NULL);
6672}
6673static int io_fclose(lua_State*L){
6674FILE**p=tofilep(L);
6675int ok=(fclose(*p)==0);
6676*p=NULL;
6677return pushresult(L,ok,NULL);
6678}
6679static int aux_close(lua_State*L){
6680lua_getfenv(L,1);
6681lua_getfield(L,-1,"__close");
6682return(lua_tocfunction(L,-1))(L);
6683}
6684static int io_close(lua_State*L){
6685if(lua_isnone(L,1))
6686lua_rawgeti(L,(-10001),2);
6687tofile(L);
6688return aux_close(L);
6689}
6690static int io_gc(lua_State*L){
6691FILE*f=*tofilep(L);
6692if(f!=NULL)
6693aux_close(L);
6694return 0;
6695}
6696static int io_open(lua_State*L){
6697const char*filename=luaL_checkstring(L,1);
6698const char*mode=luaL_optstring(L,2,"r");
6699FILE**pf=newfile(L);
6700*pf=fopen(filename,mode);
6701return(*pf==NULL)?pushresult(L,0,filename):1;
6702}
6703static FILE*getiofile(lua_State*L,int findex){
6704FILE*f;
6705lua_rawgeti(L,(-10001),findex);
6706f=*(FILE**)lua_touserdata(L,-1);
6707if(f==NULL)
6708luaL_error(L,"standard %s file is closed",fnames[findex-1]);
6709return f;
6710}
6711static int g_iofile(lua_State*L,int f,const char*mode){
6712if(!lua_isnoneornil(L,1)){
6713const char*filename=lua_tostring(L,1);
6714if(filename){
6715FILE**pf=newfile(L);
6716*pf=fopen(filename,mode);
6717if(*pf==NULL)
6718fileerror(L,1,filename);
6719}
6720else{
6721tofile(L);
6722lua_pushvalue(L,1);
6723}
6724lua_rawseti(L,(-10001),f);
6725}
6726lua_rawgeti(L,(-10001),f);
6727return 1;
6728}
6729static int io_input(lua_State*L){
6730return g_iofile(L,1,"r");
6731}
6732static int io_output(lua_State*L){
6733return g_iofile(L,2,"w");
6734}
6735static int io_readline(lua_State*L);
6736static void aux_lines(lua_State*L,int idx,int toclose){
6737lua_pushvalue(L,idx);
6738lua_pushboolean(L,toclose);
6739lua_pushcclosure(L,io_readline,2);
6740}
6741static int f_lines(lua_State*L){
6742tofile(L);
6743aux_lines(L,1,0);
6744return 1;
6745}
6746static int io_lines(lua_State*L){
6747if(lua_isnoneornil(L,1)){
6748lua_rawgeti(L,(-10001),1);
6749return f_lines(L);
6750}
6751else{
6752const char*filename=luaL_checkstring(L,1);
6753FILE**pf=newfile(L);
6754*pf=fopen(filename,"r");
6755if(*pf==NULL)
6756fileerror(L,1,filename);
6757aux_lines(L,lua_gettop(L),1);
6758return 1;
6759}
6760}
6761static int read_number(lua_State*L,FILE*f){
6762lua_Number d;
6763if(fscanf(f,"%lf",&d)==1){
6764lua_pushnumber(L,d);
6765return 1;
6766}
6767else{
6768lua_pushnil(L);
6769return 0;
6770}
6771}
6772static int test_eof(lua_State*L,FILE*f){
6773int c=getc(f);
6774ungetc(c,f);
6775lua_pushlstring(L,NULL,0);
6776return(c!=EOF);
6777}
6778static int read_line(lua_State*L,FILE*f){
6779luaL_Buffer b;
6780luaL_buffinit(L,&b);
6781for(;;){
6782size_t l;
6783char*p=luaL_prepbuffer(&b);
6784if(fgets(p,BUFSIZ,f)==NULL){
6785luaL_pushresult(&b);
6786return(lua_objlen(L,-1)>0);
6787}
6788l=strlen(p);
6789if(l==0||p[l-1]!='\n')
6790luaL_addsize(&b,l);
6791else{
6792luaL_addsize(&b,l-1);
6793luaL_pushresult(&b);
6794return 1;
6795}
6796}
6797}
6798static int read_chars(lua_State*L,FILE*f,size_t n){
6799size_t rlen;
6800size_t nr;
6801luaL_Buffer b;
6802luaL_buffinit(L,&b);
6803rlen=BUFSIZ;
6804do{
6805char*p=luaL_prepbuffer(&b);
6806if(rlen>n)rlen=n;
6807nr=fread(p,sizeof(char),rlen,f);
6808luaL_addsize(&b,nr);
6809n-=nr;
6810}while(n>0&&nr==rlen);
6811luaL_pushresult(&b);
6812return(n==0||lua_objlen(L,-1)>0);
6813}
6814static int g_read(lua_State*L,FILE*f,int first){
6815int nargs=lua_gettop(L)-1;
6816int success;
6817int n;
6818clearerr(f);
6819if(nargs==0){
6820success=read_line(L,f);
6821n=first+1;
6822}
6823else{
6824luaL_checkstack(L,nargs+20,"too many arguments");
6825success=1;
6826for(n=first;nargs--&&success;n++){
6827if(lua_type(L,n)==3){
6828size_t l=(size_t)lua_tointeger(L,n);
6829success=(l==0)?test_eof(L,f):read_chars(L,f,l);
6830}
6831else{
6832const char*p=lua_tostring(L,n);
6833luaL_argcheck(L,p&&p[0]=='*',n,"invalid option");
6834switch(p[1]){
6835case'n':
6836success=read_number(L,f);
6837break;
6838case'l':
6839success=read_line(L,f);
6840break;
6841case'a':
6842read_chars(L,f,~((size_t)0));
6843success=1;
6844break;
6845default:
6846return luaL_argerror(L,n,"invalid format");
6847}
6848}
6849}
6850}
6851if(ferror(f))
6852return pushresult(L,0,NULL);
6853if(!success){
6854lua_pop(L,1);
6855lua_pushnil(L);
6856}
6857return n-first;
6858}
6859static int io_read(lua_State*L){
6860return g_read(L,getiofile(L,1),1);
6861}
6862static int f_read(lua_State*L){
6863return g_read(L,tofile(L),2);
6864}
6865static int io_readline(lua_State*L){
6866FILE*f=*(FILE**)lua_touserdata(L,lua_upvalueindex(1));
6867int sucess;
6868if(f==NULL)
6869luaL_error(L,"file is already closed");
6870sucess=read_line(L,f);
6871if(ferror(f))
6872return luaL_error(L,"%s",strerror(errno));
6873if(sucess)return 1;
6874else{
6875if(lua_toboolean(L,lua_upvalueindex(2))){
6876lua_settop(L,0);
6877lua_pushvalue(L,lua_upvalueindex(1));
6878aux_close(L);
6879}
6880return 0;
6881}
6882}
6883static int g_write(lua_State*L,FILE*f,int arg){
6884int nargs=lua_gettop(L)-1;
6885int status=1;
6886for(;nargs--;arg++){
6887if(lua_type(L,arg)==3){
6888status=status&&
6889fprintf(f,"%.14g",lua_tonumber(L,arg))>0;
6890}
6891else{
6892size_t l;
6893const char*s=luaL_checklstring(L,arg,&l);
6894status=status&&(fwrite(s,sizeof(char),l,f)==l);
6895}
6896}
6897return pushresult(L,status,NULL);
6898}
6899static int io_write(lua_State*L){
6900return g_write(L,getiofile(L,2),1);
6901}
6902static int f_write(lua_State*L){
6903return g_write(L,tofile(L),2);
6904}
6905static int io_flush(lua_State*L){
6906return pushresult(L,fflush(getiofile(L,2))==0,NULL);
6907}
6908static int f_flush(lua_State*L){
6909return pushresult(L,fflush(tofile(L))==0,NULL);
6910}
6911static const luaL_Reg iolib[]={
6912{"close",io_close},
6913{"flush",io_flush},
6914{"input",io_input},
6915{"lines",io_lines},
6916{"open",io_open},
6917{"output",io_output},
6918{"read",io_read},
6919{"type",io_type},
6920{"write",io_write},
6921{NULL,NULL}
6922};
6923static const luaL_Reg flib[]={
6924{"close",io_close},
6925{"flush",f_flush},
6926{"lines",f_lines},
6927{"read",f_read},
6928{"write",f_write},
6929{"__gc",io_gc},
6930{NULL,NULL}
6931};
6932static void createmeta(lua_State*L){
6933luaL_newmetatable(L,"FILE*");
6934lua_pushvalue(L,-1);
6935lua_setfield(L,-2,"__index");
6936luaL_register(L,NULL,flib);
6937}
6938static void createstdfile(lua_State*L,FILE*f,int k,const char*fname){
6939*newfile(L)=f;
6940if(k>0){
6941lua_pushvalue(L,-1);
6942lua_rawseti(L,(-10001),k);
6943}
6944lua_pushvalue(L,-2);
6945lua_setfenv(L,-2);
6946lua_setfield(L,-3,fname);
6947}
6948static void newfenv(lua_State*L,lua_CFunction cls){
6949lua_createtable(L,0,1);
6950lua_pushcfunction(L,cls);
6951lua_setfield(L,-2,"__close");
6952}
6953static int luaopen_io(lua_State*L){
6954createmeta(L);
6955newfenv(L,io_fclose);
6956lua_replace(L,(-10001));
6957luaL_register(L,"io",iolib);
6958newfenv(L,io_noclose);
6959createstdfile(L,stdin,1,"stdin");
6960createstdfile(L,stdout,2,"stdout");
6961createstdfile(L,stderr,0,"stderr");
6962lua_pop(L,1);
6963lua_getfield(L,-1,"popen");
6964newfenv(L,io_pclose);
6965lua_setfenv(L,-2);
6966lua_pop(L,1);
6967return 1;
6968}
6969static int os_pushresult(lua_State*L,int i,const char*filename){
6970int en=errno;
6971if(i){
6972lua_pushboolean(L,1);
6973return 1;
6974}
6975else{
6976lua_pushnil(L);
6977lua_pushfstring(L,"%s: %s",filename,strerror(en));
6978lua_pushinteger(L,en);
6979return 3;
6980}
6981}
6982static int os_remove(lua_State*L){
6983const char*filename=luaL_checkstring(L,1);
6984return os_pushresult(L,remove(filename)==0,filename);
6985}
6986static int os_exit(lua_State*L){
6987exit(luaL_optint(L,1,EXIT_SUCCESS));
6988}
6989static const luaL_Reg syslib[]={
6990{"exit",os_exit},
6991{"remove",os_remove},
6992{NULL,NULL}
6993};
6994static int luaopen_os(lua_State*L){
6995luaL_register(L,"os",syslib);
6996return 1;
6997}
6998#define uchar(c)((unsigned char)(c))
6999static ptrdiff_t posrelat(ptrdiff_t pos,size_t len){
7000if(pos<0)pos+=(ptrdiff_t)len+1;
7001return(pos>=0)?pos:0;
7002}
7003static int str_sub(lua_State*L){
7004size_t l;
7005const char*s=luaL_checklstring(L,1,&l);
7006ptrdiff_t start=posrelat(luaL_checkinteger(L,2),l);
7007ptrdiff_t end=posrelat(luaL_optinteger(L,3,-1),l);
7008if(start<1)start=1;
7009if(end>(ptrdiff_t)l)end=(ptrdiff_t)l;
7010if(start<=end)
7011lua_pushlstring(L,s+start-1,end-start+1);
7012else lua_pushliteral(L,"");
7013return 1;
7014}
7015static int str_lower(lua_State*L){
7016size_t l;
7017size_t i;
7018luaL_Buffer b;
7019const char*s=luaL_checklstring(L,1,&l);
7020luaL_buffinit(L,&b);
7021for(i=0;i<l;i++)
7022luaL_addchar(&b,tolower(uchar(s[i])));
7023luaL_pushresult(&b);
7024return 1;
7025}
7026static int str_upper(lua_State*L){
7027size_t l;
7028size_t i;
7029luaL_Buffer b;
7030const char*s=luaL_checklstring(L,1,&l);
7031luaL_buffinit(L,&b);
7032for(i=0;i<l;i++)
7033luaL_addchar(&b,toupper(uchar(s[i])));
7034luaL_pushresult(&b);
7035return 1;
7036}
7037static int str_rep(lua_State*L){
7038size_t l;
7039luaL_Buffer b;
7040const char*s=luaL_checklstring(L,1,&l);
7041int n=luaL_checkint(L,2);
7042luaL_buffinit(L,&b);
7043while(n-->0)
7044luaL_addlstring(&b,s,l);
7045luaL_pushresult(&b);
7046return 1;
7047}
7048static int str_byte(lua_State*L){
7049size_t l;
7050const char*s=luaL_checklstring(L,1,&l);
7051ptrdiff_t posi=posrelat(luaL_optinteger(L,2,1),l);
7052ptrdiff_t pose=posrelat(luaL_optinteger(L,3,posi),l);
7053int n,i;
7054if(posi<=0)posi=1;
7055if((size_t)pose>l)pose=l;
7056if(posi>pose)return 0;
7057n=(int)(pose-posi+1);
7058if(posi+n<=pose)
7059luaL_error(L,"string slice too long");
7060luaL_checkstack(L,n,"string slice too long");
7061for(i=0;i<n;i++)
7062lua_pushinteger(L,uchar(s[posi+i-1]));
7063return n;
7064}
7065static int str_char(lua_State*L){
7066int n=lua_gettop(L);
7067int i;
7068luaL_Buffer b;
7069luaL_buffinit(L,&b);
7070for(i=1;i<=n;i++){
7071int c=luaL_checkint(L,i);
7072luaL_argcheck(L,uchar(c)==c,i,"invalid value");
7073luaL_addchar(&b,uchar(c));
7074}
7075luaL_pushresult(&b);
7076return 1;
7077}
7078typedef struct MatchState{
7079const char*src_init;
7080const char*src_end;
7081lua_State*L;
7082int level;
7083struct{
7084const char*init;
7085ptrdiff_t len;
7086}capture[32];
7087}MatchState;
7088static int check_capture(MatchState*ms,int l){
7089l-='1';
7090if(l<0||l>=ms->level||ms->capture[l].len==(-1))
7091return luaL_error(ms->L,"invalid capture index");
7092return l;
7093}
7094static int capture_to_close(MatchState*ms){
7095int level=ms->level;
7096for(level--;level>=0;level--)
7097if(ms->capture[level].len==(-1))return level;
7098return luaL_error(ms->L,"invalid pattern capture");
7099}
7100static const char*classend(MatchState*ms,const char*p){
7101switch(*p++){
7102case'%':{
7103if(*p=='\0')
7104luaL_error(ms->L,"malformed pattern (ends with "LUA_QL("%%")")");
7105return p+1;
7106}
7107case'[':{
7108if(*p=='^')p++;
7109do{
7110if(*p=='\0')
7111luaL_error(ms->L,"malformed pattern (missing "LUA_QL("]")")");
7112if(*(p++)=='%'&&*p!='\0')
7113p++;
7114}while(*p!=']');
7115return p+1;
7116}
7117default:{
7118return p;
7119}
7120}
7121}
7122static int match_class(int c,int cl){
7123int res;
7124switch(tolower(cl)){
7125case'a':res=isalpha(c);break;
7126case'c':res=iscntrl(c);break;
7127case'd':res=isdigit(c);break;
7128case'l':res=islower(c);break;
7129case'p':res=ispunct(c);break;
7130case's':res=isspace(c);break;
7131case'u':res=isupper(c);break;
7132case'w':res=isalnum(c);break;
7133case'x':res=isxdigit(c);break;
7134case'z':res=(c==0);break;
7135default:return(cl==c);
7136}
7137return(islower(cl)?res:!res);
7138}
7139static int matchbracketclass(int c,const char*p,const char*ec){
7140int sig=1;
7141if(*(p+1)=='^'){
7142sig=0;
7143p++;
7144}
7145while(++p<ec){
7146if(*p=='%'){
7147p++;
7148if(match_class(c,uchar(*p)))
7149return sig;
7150}
7151else if((*(p+1)=='-')&&(p+2<ec)){
7152p+=2;
7153if(uchar(*(p-2))<=c&&c<=uchar(*p))
7154return sig;
7155}
7156else if(uchar(*p)==c)return sig;
7157}
7158return!sig;
7159}
7160static int singlematch(int c,const char*p,const char*ep){
7161switch(*p){
7162case'.':return 1;
7163case'%':return match_class(c,uchar(*(p+1)));
7164case'[':return matchbracketclass(c,p,ep-1);
7165default:return(uchar(*p)==c);
7166}
7167}
7168static const char*match(MatchState*ms,const char*s,const char*p);
7169static const char*matchbalance(MatchState*ms,const char*s,
7170const char*p){
7171if(*p==0||*(p+1)==0)
7172luaL_error(ms->L,"unbalanced pattern");
7173if(*s!=*p)return NULL;
7174else{
7175int b=*p;
7176int e=*(p+1);
7177int cont=1;
7178while(++s<ms->src_end){
7179if(*s==e){
7180if(--cont==0)return s+1;
7181}
7182else if(*s==b)cont++;
7183}
7184}
7185return NULL;
7186}
7187static const char*max_expand(MatchState*ms,const char*s,
7188const char*p,const char*ep){
7189ptrdiff_t i=0;
7190while((s+i)<ms->src_end&&singlematch(uchar(*(s+i)),p,ep))
7191i++;
7192while(i>=0){
7193const char*res=match(ms,(s+i),ep+1);
7194if(res)return res;
7195i--;
7196}
7197return NULL;
7198}
7199static const char*min_expand(MatchState*ms,const char*s,
7200const char*p,const char*ep){
7201for(;;){
7202const char*res=match(ms,s,ep+1);
7203if(res!=NULL)
7204return res;
7205else if(s<ms->src_end&&singlematch(uchar(*s),p,ep))
7206s++;
7207else return NULL;
7208}
7209}
7210static const char*start_capture(MatchState*ms,const char*s,
7211const char*p,int what){
7212const char*res;
7213int level=ms->level;
7214if(level>=32)luaL_error(ms->L,"too many captures");
7215ms->capture[level].init=s;
7216ms->capture[level].len=what;
7217ms->level=level+1;
7218if((res=match(ms,s,p))==NULL)
7219ms->level--;
7220return res;
7221}
7222static const char*end_capture(MatchState*ms,const char*s,
7223const char*p){
7224int l=capture_to_close(ms);
7225const char*res;
7226ms->capture[l].len=s-ms->capture[l].init;
7227if((res=match(ms,s,p))==NULL)
7228ms->capture[l].len=(-1);
7229return res;
7230}
7231static const char*match_capture(MatchState*ms,const char*s,int l){
7232size_t len;
7233l=check_capture(ms,l);
7234len=ms->capture[l].len;
7235if((size_t)(ms->src_end-s)>=len&&
7236memcmp(ms->capture[l].init,s,len)==0)
7237return s+len;
7238else return NULL;
7239}
7240static const char*match(MatchState*ms,const char*s,const char*p){
7241init:
7242switch(*p){
7243case'(':{
7244if(*(p+1)==')')
7245return start_capture(ms,s,p+2,(-2));
7246else
7247return start_capture(ms,s,p+1,(-1));
7248}
7249case')':{
7250return end_capture(ms,s,p+1);
7251}
7252case'%':{
7253switch(*(p+1)){
7254case'b':{
7255s=matchbalance(ms,s,p+2);
7256if(s==NULL)return NULL;
7257p+=4;goto init;
7258}
7259case'f':{
7260const char*ep;char previous;
7261p+=2;
7262if(*p!='[')
7263luaL_error(ms->L,"missing "LUA_QL("[")" after "
7264LUA_QL("%%f")" in pattern");
7265ep=classend(ms,p);
7266previous=(s==ms->src_init)?'\0':*(s-1);
7267if(matchbracketclass(uchar(previous),p,ep-1)||
7268!matchbracketclass(uchar(*s),p,ep-1))return NULL;
7269p=ep;goto init;
7270}
7271default:{
7272if(isdigit(uchar(*(p+1)))){
7273s=match_capture(ms,s,uchar(*(p+1)));
7274if(s==NULL)return NULL;
7275p+=2;goto init;
7276}
7277goto dflt;
7278}
7279}
7280}
7281case'\0':{
7282return s;
7283}
7284case'$':{
7285if(*(p+1)=='\0')
7286return(s==ms->src_end)?s:NULL;
7287else goto dflt;
7288}
7289default:dflt:{
7290const char*ep=classend(ms,p);
7291int m=s<ms->src_end&&singlematch(uchar(*s),p,ep);
7292switch(*ep){
7293case'?':{
7294const char*res;
7295if(m&&((res=match(ms,s+1,ep+1))!=NULL))
7296return res;
7297p=ep+1;goto init;
7298}
7299case'*':{
7300return max_expand(ms,s,p,ep);
7301}
7302case'+':{
7303return(m?max_expand(ms,s+1,p,ep):NULL);
7304}
7305case'-':{
7306return min_expand(ms,s,p,ep);
7307}
7308default:{
7309if(!m)return NULL;
7310s++;p=ep;goto init;
7311}
7312}
7313}
7314}
7315}
7316static const char*lmemfind(const char*s1,size_t l1,
7317const char*s2,size_t l2){
7318if(l2==0)return s1;
7319else if(l2>l1)return NULL;
7320else{
7321const char*init;
7322l2--;
7323l1=l1-l2;
7324while(l1>0&&(init=(const char*)memchr(s1,*s2,l1))!=NULL){
7325init++;
7326if(memcmp(init,s2+1,l2)==0)
7327return init-1;
7328else{
7329l1-=init-s1;
7330s1=init;
7331}
7332}
7333return NULL;
7334}
7335}
7336static void push_onecapture(MatchState*ms,int i,const char*s,
7337const char*e){
7338if(i>=ms->level){
7339if(i==0)
7340lua_pushlstring(ms->L,s,e-s);
7341else
7342luaL_error(ms->L,"invalid capture index");
7343}
7344else{
7345ptrdiff_t l=ms->capture[i].len;
7346if(l==(-1))luaL_error(ms->L,"unfinished capture");
7347if(l==(-2))
7348lua_pushinteger(ms->L,ms->capture[i].init-ms->src_init+1);
7349else
7350lua_pushlstring(ms->L,ms->capture[i].init,l);
7351}
7352}
7353static int push_captures(MatchState*ms,const char*s,const char*e){
7354int i;
7355int nlevels=(ms->level==0&&s)?1:ms->level;
7356luaL_checkstack(ms->L,nlevels,"too many captures");
7357for(i=0;i<nlevels;i++)
7358push_onecapture(ms,i,s,e);
7359return nlevels;
7360}
7361static int str_find_aux(lua_State*L,int find){
7362size_t l1,l2;
7363const char*s=luaL_checklstring(L,1,&l1);
7364const char*p=luaL_checklstring(L,2,&l2);
7365ptrdiff_t init=posrelat(luaL_optinteger(L,3,1),l1)-1;
7366if(init<0)init=0;
7367else if((size_t)(init)>l1)init=(ptrdiff_t)l1;
7368if(find&&(lua_toboolean(L,4)||
7369strpbrk(p,"^$*+?.([%-")==NULL)){
7370const char*s2=lmemfind(s+init,l1-init,p,l2);
7371if(s2){
7372lua_pushinteger(L,s2-s+1);
7373lua_pushinteger(L,s2-s+l2);
7374return 2;
7375}
7376}
7377else{
7378MatchState ms;
7379int anchor=(*p=='^')?(p++,1):0;
7380const char*s1=s+init;
7381ms.L=L;
7382ms.src_init=s;
7383ms.src_end=s+l1;
7384do{
7385const char*res;
7386ms.level=0;
7387if((res=match(&ms,s1,p))!=NULL){
7388if(find){
7389lua_pushinteger(L,s1-s+1);
7390lua_pushinteger(L,res-s);
7391return push_captures(&ms,NULL,0)+2;
7392}
7393else
7394return push_captures(&ms,s1,res);
7395}
7396}while(s1++<ms.src_end&&!anchor);
7397}
7398lua_pushnil(L);
7399return 1;
7400}
7401static int str_find(lua_State*L){
7402return str_find_aux(L,1);
7403}
7404static int str_match(lua_State*L){
7405return str_find_aux(L,0);
7406}
7407static int gmatch_aux(lua_State*L){
7408MatchState ms;
7409size_t ls;
7410const char*s=lua_tolstring(L,lua_upvalueindex(1),&ls);
7411const char*p=lua_tostring(L,lua_upvalueindex(2));
7412const char*src;
7413ms.L=L;
7414ms.src_init=s;
7415ms.src_end=s+ls;
7416for(src=s+(size_t)lua_tointeger(L,lua_upvalueindex(3));
7417src<=ms.src_end;
7418src++){
7419const char*e;
7420ms.level=0;
7421if((e=match(&ms,src,p))!=NULL){
7422lua_Integer newstart=e-s;
7423if(e==src)newstart++;
7424lua_pushinteger(L,newstart);
7425lua_replace(L,lua_upvalueindex(3));
7426return push_captures(&ms,src,e);
7427}
7428}
7429return 0;
7430}
7431static int gmatch(lua_State*L){
7432luaL_checkstring(L,1);
7433luaL_checkstring(L,2);
7434lua_settop(L,2);
7435lua_pushinteger(L,0);
7436lua_pushcclosure(L,gmatch_aux,3);
7437return 1;
7438}
7439static void add_s(MatchState*ms,luaL_Buffer*b,const char*s,
7440const char*e){
7441size_t l,i;
7442const char*news=lua_tolstring(ms->L,3,&l);
7443for(i=0;i<l;i++){
7444if(news[i]!='%')
7445luaL_addchar(b,news[i]);
7446else{
7447i++;
7448if(!isdigit(uchar(news[i])))
7449luaL_addchar(b,news[i]);
7450else if(news[i]=='0')
7451luaL_addlstring(b,s,e-s);
7452else{
7453push_onecapture(ms,news[i]-'1',s,e);
7454luaL_addvalue(b);
7455}
7456}
7457}
7458}
7459static void add_value(MatchState*ms,luaL_Buffer*b,const char*s,
7460const char*e){
7461lua_State*L=ms->L;
7462switch(lua_type(L,3)){
7463case 3:
7464case 4:{
7465add_s(ms,b,s,e);
7466return;
7467}
7468case 6:{
7469int n;
7470lua_pushvalue(L,3);
7471n=push_captures(ms,s,e);
7472lua_call(L,n,1);
7473break;
7474}
7475case 5:{
7476push_onecapture(ms,0,s,e);
7477lua_gettable(L,3);
7478break;
7479}
7480}
7481if(!lua_toboolean(L,-1)){
7482lua_pop(L,1);
7483lua_pushlstring(L,s,e-s);
7484}
7485else if(!lua_isstring(L,-1))
7486luaL_error(L,"invalid replacement value (a %s)",luaL_typename(L,-1));
7487luaL_addvalue(b);
7488}
7489static int str_gsub(lua_State*L){
7490size_t srcl;
7491const char*src=luaL_checklstring(L,1,&srcl);
7492const char*p=luaL_checkstring(L,2);
7493int tr=lua_type(L,3);
7494int max_s=luaL_optint(L,4,srcl+1);
7495int anchor=(*p=='^')?(p++,1):0;
7496int n=0;
7497MatchState ms;
7498luaL_Buffer b;
7499luaL_argcheck(L,tr==3||tr==4||
7500tr==6||tr==5,3,
7501"string/function/table expected");
7502luaL_buffinit(L,&b);
7503ms.L=L;
7504ms.src_init=src;
7505ms.src_end=src+srcl;
7506while(n<max_s){
7507const char*e;
7508ms.level=0;
7509e=match(&ms,src,p);
7510if(e){
7511n++;
7512add_value(&ms,&b,src,e);
7513}
7514if(e&&e>src)
7515src=e;
7516else if(src<ms.src_end)
7517luaL_addchar(&b,*src++);
7518else break;
7519if(anchor)break;
7520}
7521luaL_addlstring(&b,src,ms.src_end-src);
7522luaL_pushresult(&b);
7523lua_pushinteger(L,n);
7524return 2;
7525}
7526static void addquoted(lua_State*L,luaL_Buffer*b,int arg){
7527size_t l;
7528const char*s=luaL_checklstring(L,arg,&l);
7529luaL_addchar(b,'"');
7530while(l--){
7531switch(*s){
7532case'"':case'\\':case'\n':{
7533luaL_addchar(b,'\\');
7534luaL_addchar(b,*s);
7535break;
7536}
7537case'\r':{
7538luaL_addlstring(b,"\\r",2);
7539break;
7540}
7541case'\0':{
7542luaL_addlstring(b,"\\000",4);
7543break;
7544}
7545default:{
7546luaL_addchar(b,*s);
7547break;
7548}
7549}
7550s++;
7551}
7552luaL_addchar(b,'"');
7553}
7554static const char*scanformat(lua_State*L,const char*strfrmt,char*form){
7555const char*p=strfrmt;
7556while(*p!='\0'&&strchr("-+ #0",*p)!=NULL)p++;
7557if((size_t)(p-strfrmt)>=sizeof("-+ #0"))
7558luaL_error(L,"invalid format (repeated flags)");
7559if(isdigit(uchar(*p)))p++;
7560if(isdigit(uchar(*p)))p++;
7561if(*p=='.'){
7562p++;
7563if(isdigit(uchar(*p)))p++;
7564if(isdigit(uchar(*p)))p++;
7565}
7566if(isdigit(uchar(*p)))
7567luaL_error(L,"invalid format (width or precision too long)");
7568*(form++)='%';
7569strncpy(form,strfrmt,p-strfrmt+1);
7570form+=p-strfrmt+1;
7571*form='\0';
7572return p;
7573}
7574static void addintlen(char*form){
7575size_t l=strlen(form);
7576char spec=form[l-1];
7577strcpy(form+l-1,"l");
7578form[l+sizeof("l")-2]=spec;
7579form[l+sizeof("l")-1]='\0';
7580}
7581static int str_format(lua_State*L){
7582int top=lua_gettop(L);
7583int arg=1;
7584size_t sfl;
7585const char*strfrmt=luaL_checklstring(L,arg,&sfl);
7586const char*strfrmt_end=strfrmt+sfl;
7587luaL_Buffer b;
7588luaL_buffinit(L,&b);
7589while(strfrmt<strfrmt_end){
7590if(*strfrmt!='%')
7591luaL_addchar(&b,*strfrmt++);
7592else if(*++strfrmt=='%')
7593luaL_addchar(&b,*strfrmt++);
7594else{
7595char form[(sizeof("-+ #0")+sizeof("l")+10)];
7596char buff[512];
7597if(++arg>top)
7598luaL_argerror(L,arg,"no value");
7599strfrmt=scanformat(L,strfrmt,form);
7600switch(*strfrmt++){
7601case'c':{
7602sprintf(buff,form,(int)luaL_checknumber(L,arg));
7603break;
7604}
7605case'd':case'i':{
7606addintlen(form);
7607sprintf(buff,form,(long)luaL_checknumber(L,arg));
7608break;
7609}
7610case'o':case'u':case'x':case'X':{
7611addintlen(form);
7612sprintf(buff,form,(unsigned long)luaL_checknumber(L,arg));
7613break;
7614}
7615case'e':case'E':case'f':
7616case'g':case'G':{
7617sprintf(buff,form,(double)luaL_checknumber(L,arg));
7618break;
7619}
7620case'q':{
7621addquoted(L,&b,arg);
7622continue;
7623}
7624case's':{
7625size_t l;
7626const char*s=luaL_checklstring(L,arg,&l);
7627if(!strchr(form,'.')&&l>=100){
7628lua_pushvalue(L,arg);
7629luaL_addvalue(&b);
7630continue;
7631}
7632else{
7633sprintf(buff,form,s);
7634break;
7635}
7636}
7637default:{
7638return luaL_error(L,"invalid option "LUA_QL("%%%c")" to "
7639LUA_QL("format"),*(strfrmt-1));
7640}
7641}
7642luaL_addlstring(&b,buff,strlen(buff));
7643}
7644}
7645luaL_pushresult(&b);
7646return 1;
7647}
7648static const luaL_Reg strlib[]={
7649{"byte",str_byte},
7650{"char",str_char},
7651{"find",str_find},
7652{"format",str_format},
7653{"gmatch",gmatch},
7654{"gsub",str_gsub},
7655{"lower",str_lower},
7656{"match",str_match},
7657{"rep",str_rep},
7658{"sub",str_sub},
7659{"upper",str_upper},
7660{NULL,NULL}
7661};
7662static void createmetatable(lua_State*L){
7663lua_createtable(L,0,1);
7664lua_pushliteral(L,"");
7665lua_pushvalue(L,-2);
7666lua_setmetatable(L,-2);
7667lua_pop(L,1);
7668lua_pushvalue(L,-2);
7669lua_setfield(L,-2,"__index");
7670lua_pop(L,1);
7671}
7672static int luaopen_string(lua_State*L){
7673luaL_register(L,"string",strlib);
7674createmetatable(L);
7675return 1;
7676}
7677static const luaL_Reg lualibs[]={
7678{"",luaopen_base},
7679{"table",luaopen_table},
7680{"io",luaopen_io},
7681{"os",luaopen_os},
7682{"string",luaopen_string},
7683{NULL,NULL}
7684};
7685static void luaL_openlibs(lua_State*L){
7686const luaL_Reg*lib=lualibs;
7687for(;lib->func;lib++){
7688lua_pushcfunction(L,lib->func);
7689lua_pushstring(L,lib->name);
7690lua_call(L,1,0);
7691}
7692}
7693typedef unsigned int UB;
7694static UB barg(lua_State*L,int idx){
7695union{lua_Number n;U64 b;}bn;
7696bn.n=lua_tonumber(L,idx)+6755399441055744.0;
7697if(bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,"number");
7698return(UB)bn.b;
7699}
7700#define BRET(b)lua_pushnumber(L,(lua_Number)(int)(b));return 1;
7701static int tobit(lua_State*L){
7702BRET(barg(L,1))}
7703static int bnot(lua_State*L){
7704BRET(~barg(L,1))}
7705static int band(lua_State*L){
7706int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)}
7707static int bor(lua_State*L){
7708int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)}
7709static int bxor(lua_State*L){
7710int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)}
7711static int lshift(lua_State*L){
7712UB b=barg(L,1),n=barg(L,2)&31;BRET(b<<n)}
7713static int rshift(lua_State*L){
7714UB b=barg(L,1),n=barg(L,2)&31;BRET(b>>n)}
7715static int arshift(lua_State*L){
7716UB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)}
7717static int rol(lua_State*L){
7718UB b=barg(L,1),n=barg(L,2)&31;BRET((b<<n)|(b>>(32-n)))}
7719static int ror(lua_State*L){
7720UB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))}
7721static int bswap(lua_State*L){
7722UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)}
7723static int tohex(lua_State*L){
7724UB b=barg(L,1);
7725UB n=lua_isnone(L,2)?8:barg(L,2);
7726const char*hexdigits="0123456789abcdef";
7727char buf[8];
7728int i;
7729if((int)n<0){n=~n+1;hexdigits="0123456789ABCDEF";}
7730if(n>8)n=8;
7731for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;}
7732lua_pushlstring(L,buf,(size_t)n);
7733return 1;
7734}
7735static const struct luaL_Reg bitlib[]={
7736{"tobit",tobit},
7737{"bnot",bnot},
7738{"band",band},
7739{"bor",bor},
7740{"bxor",bxor},
7741{"lshift",lshift},
7742{"rshift",rshift},
7743{"arshift",arshift},
7744{"rol",rol},
7745{"ror",ror},
7746{"bswap",bswap},
7747{"tohex",tohex},
7748{NULL,NULL}
7749};
7750int main(int argc,char**argv){
7751lua_State*L=luaL_newstate();
7752int i;
7753luaL_openlibs(L);
7754luaL_register(L,"bit",bitlib);
7755if(argc<2)return sizeof(void*);
7756lua_createtable(L,0,1);
7757lua_pushstring(L,argv[1]);
7758lua_rawseti(L,-2,0);
7759lua_setglobal(L,"arg");
7760if(luaL_loadfile(L,argv[1]))
7761goto err;
7762for(i=2;i<argc;i++)
7763lua_pushstring(L,argv[i]);
7764if(lua_pcall(L,argc-2,0,0)){
7765err:
7766fprintf(stderr,"Error: %s\n",lua_tostring(L,-1));
7767return 1;
7768}
7769lua_close(L);
7770return 0;
7771}