diff --git a/CHANGELOG.md b/CHANGELOG.md index 64e1fea..e816252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,13 +10,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added a new `luau` built-in library for manually compiling and loading Luau source code. ([#82]) + + Example usage: + + ```lua + local luau = require("@lune/luau") + + local bytecode = luau.compile("print('Hello, World!')") + local callableFn = luau.load(bytecode) + + callableFn() + + -- Additionally, we can skip the bytecode generation and + -- load a callable function directly from the code itself. + local callableFn2 = luau.load("print('Hello, World!')") + + callableFn2() + ``` + +[#82]: https://github.com/filiptibell/lune/pull/82 + +## `0.7.6` - August 9th, 2023 + ### Changed +- Update to Luau version `0.588` - Enabled Luau JIT backend for potential performance improvements 🚀
If you run into any strange behavior please open an issue! ### Fixed +- Fixed publishing of the Lune library to `crates.io` - Fixed `serde.decode` deserializing `null` values as `userdata` instead of `nil`. - Fixed not being able to require files with multiple extensions, eg. `module.spec.luau` was not require-able using `require("module.spec")`. - Fixed instances and `roblox` built-in library APIs erroring when used asynchronously/concurrently. diff --git a/Cargo.lock b/Cargo.lock index e5ee426..597ad3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,15 +41,6 @@ dependencies = [ "alloc-no-stdlib", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anstream" version = "0.3.2" @@ -91,9 +82,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" dependencies = [ "anstyle", "windows-sys 0.48.0", @@ -145,18 +136,7 @@ checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", + "syn 2.0.28", ] [[package]] @@ -301,9 +281,12 @@ checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -313,24 +296,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "2.34.0" +version = "4.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", -] - -[[package]] -name = "clap" -version = "4.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd304a20bff958a57f04c4e96a2e7594cc4490a0e809cbd48bb6437edaa452d" +checksum = "c27cdf28c0f604ba3f512b0c9a409f8de8513e4816705deb0498b627e7c3a3fd" dependencies = [ "clap_builder", "clap_derive", @@ -339,14 +307,14 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.3.19" +version = "4.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c6a3f08f1fe5662a35cfe393aec09c4df95f60ee93b7556505260f75eee9e1" +checksum = "08a9f1ab5e9f01a9b81f202e8562eb9a10de70abf9eaeac1be465c28b75aa4aa" dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.10.0", + "strsim", ] [[package]] @@ -358,7 +326,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.28", ] [[package]] @@ -468,6 +436,12 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +[[package]] +name = "deranged" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" + [[package]] name = "dialoguer" version = "0.10.4" @@ -562,19 +536,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" -[[package]] -name = "env_logger" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.10.0" @@ -605,9 +566,9 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" dependencies = [ "errno-dragonfly", "libc", @@ -699,7 +660,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.28", ] [[package]] @@ -816,15 +777,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.2" @@ -897,7 +849,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -993,16 +945,16 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi", "rustix", "windows-sys 0.48.0", ] [[package]] name = "itertools" -version = "0.10.5" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ "either", ] @@ -1045,9 +997,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "lock_api" @@ -1067,26 +1019,26 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "luau0-src" -version = "0.5.11+luau583" +version = "0.6.0+luau588" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a7183d0a3eaa387403dd4ac7b449536af82c1545b7a48247af1652ca66926d5" +checksum = "4c628f5525cc62a89a2d478b2ee619c77b35da55c8e3231752f3b8fe528a6c49" dependencies = [ "cc", ] [[package]] name = "lune" -version = "0.7.5" +version = "0.7.6" dependencies = [ "anyhow", "async-compression", "async-trait", - "clap 4.3.19", + "clap", "console", "dialoguer", "directories", "dunce", - "env_logger 0.10.0", + "env_logger", "futures-util", "glam", "home", @@ -1182,9 +1134,9 @@ dependencies = [ [[package]] name = "mlua" -version = "0.9.0-rc.1" +version = "0.9.0-rc.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5369212118d0f115c9adbe7f7905e36fb3ef2994266039c51fc3e96374d705d" +checksum = "01a6500a9fb74b519a85ac206cd57f9f91b270ce39d6cb12ab06a8ed29c3563d" dependencies = [ "bstr", "erased-serde", @@ -1198,9 +1150,9 @@ dependencies = [ [[package]] name = "mlua-sys" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3daecc55a656cae8e54fc599701ab597b67cdde68f780cac8c1c49b9cfff2f5" +checksum = "aa5b61f6c943d77dd6ab5f670865670f65b978400127c8bf31c2df7d6e76289a" dependencies = [ "cc", "cfg-if", @@ -1244,7 +1196,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi", "libc", ] @@ -1324,29 +1276,29 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pin-project" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" +checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" +checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.28", ] [[package]] name = "pin-project-lite" -version = "0.2.10" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" +checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" [[package]] name = "pin-utils" @@ -1371,7 +1323,7 @@ dependencies = [ "line-wrap", "quick-xml", "serde", - "time 0.3.23", + "time 0.3.25", ] [[package]] @@ -1397,21 +1349,21 @@ dependencies = [ [[package]] name = "profiling" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "332cd62e95873ea4f41f3dfd6bbbfc5b52aec892d7e8d534197c4720a0bbbab2" +checksum = "46b2164ebdb1dfeec5e337be164292351e11daf63a05174c6776b2f47460f0c9" dependencies = [ "profiling-procmacros", ] [[package]] name = "profiling-procmacros" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a10adb8d151bb1280afb8bed41ae5db26be1b056964947133c7525b0bf39c0b0" +checksum = "097bf8b99121dfb8c75eed54dfbdbdb1d53e372c53d2353e8a15aad2a479249d" dependencies = [ "quote", - "syn 1.0.109", + "syn 2.0.28", ] [[package]] @@ -1425,9 +1377,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.31" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" dependencies = [ "proc-macro2", ] @@ -1474,8 +1426,9 @@ dependencies = [ [[package]] name = "rbx_binary" -version = "0.7.0" -source = "git+https://github.com/rojo-rbx/rbx-dom?rev=e7a813d569c3f8a54be8a8873c33f8976c37b8b1#e7a813d569c3f8a54be8a8873c33f8976c37b8b1" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e50573021d04b680018955662eba7dc4aac3de92219231798f6c9b41e38ab01" dependencies = [ "log", "lz4", @@ -1488,15 +1441,13 @@ dependencies = [ [[package]] name = "rbx_cookie" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d909d60469944842c9d204fa44afc90d9cb1e1f3f30a29bd1def490edd525a96" +checksum = "6716fd418196130f1dd19947608b94bda942d096b514be9b441409d262bf5e59" dependencies = [ "byteorder 0.5.3", - "clap 2.34.0", "cookie", "dirs", - "env_logger 0.9.3", "log", "plist", "winapi", @@ -1505,8 +1456,9 @@ dependencies = [ [[package]] name = "rbx_dom_weak" -version = "2.4.0" -source = "git+https://github.com/rojo-rbx/rbx-dom?rev=e7a813d569c3f8a54be8a8873c33f8976c37b8b1#e7a813d569c3f8a54be8a8873c33f8976c37b8b1" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "161729449bbb0cfa657ce7bcca6a160d0af06d8b8d9efdc9abe14735dccacdb9" dependencies = [ "rbx_types", "serde", @@ -1514,8 +1466,9 @@ dependencies = [ [[package]] name = "rbx_reflection" -version = "4.2.0" -source = "git+https://github.com/rojo-rbx/rbx-dom?rev=e7a813d569c3f8a54be8a8873c33f8976c37b8b1#e7a813d569c3f8a54be8a8873c33f8976c37b8b1" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08bd48487192046fec8f805f3fa29f3d7d5beb9890b0859b1a92bd8aff580343" dependencies = [ "rbx_types", "serde", @@ -1524,8 +1477,9 @@ dependencies = [ [[package]] name = "rbx_reflection_database" -version = "0.2.6+roblox-572" -source = "git+https://github.com/rojo-rbx/rbx-dom?rev=e7a813d569c3f8a54be8a8873c33f8976c37b8b1#e7a813d569c3f8a54be8a8873c33f8976c37b8b1" +version = "0.2.7+roblox-588" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1be6cf674182806f11ad4899dd1feafe977591f1ae035ae05a58d4b74e487276" dependencies = [ "lazy_static", "rbx_reflection", @@ -1535,8 +1489,9 @@ dependencies = [ [[package]] name = "rbx_types" -version = "1.5.0" -source = "git+https://github.com/rojo-rbx/rbx-dom?rev=e7a813d569c3f8a54be8a8873c33f8976c37b8b1#e7a813d569c3f8a54be8a8873c33f8976c37b8b1" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "070106e926b8ae54c7bc443e5db4d868d7f0af51c1d7cfd7efe1364c1753d8a3" dependencies = [ "base64 0.13.1", "bitflags 1.3.2", @@ -1549,8 +1504,9 @@ dependencies = [ [[package]] name = "rbx_xml" -version = "0.13.0" -source = "git+https://github.com/rojo-rbx/rbx-dom?rev=e7a813d569c3f8a54be8a8873c33f8976c37b8b1#e7a813d569c3f8a54be8a8873c33f8976c37b8b1" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bc65b70827519fdc4ab47416d1085b912f087fadab9ed415471b6daba635574" dependencies = [ "base64 0.13.1", "log", @@ -1608,9 +1564,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" dependencies = [ "aho-corasick", "memchr", @@ -1620,9 +1576,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.3" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" +checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" dependencies = [ "aho-corasick", "memchr", @@ -1746,9 +1702,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.4" +version = "0.38.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399" dependencies = [ "bitflags 2.3.3", "errno", @@ -1759,13 +1715,13 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.5" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79ea77c539259495ce8ca47f53e66ae0330a8819f67e23ac96ca02f50e7b7d36" +checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" dependencies = [ "log", "ring", - "rustls-webpki 0.101.1", + "rustls-webpki 0.101.3", "sct", ] @@ -1790,9 +1746,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.101.1" +version = "0.101.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f36a6828982f422756984e47912a7a51dcbc2a197aa791158f8ca61cd8204e" +checksum = "261e9e0888cba427c3316e6322805653c9425240b6fd96cee7cb671ab70ab8d0" dependencies = [ "ring", "untrusted", @@ -1866,9 +1822,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.174" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b88756493a5bd5e5395d53baa70b194b05764ab85b59e43e4b8f4e1192fa9b1" +checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" dependencies = [ "serde_derive", ] @@ -1885,20 +1841,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.174" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e5c3a298c7f978e53536f95a63bdc4c4a64550582f31a0359a9afda6aede62e" +checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.28", ] [[package]] name = "serde_json" -version = "1.0.103" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b" +checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" dependencies = [ "indexmap 2.0.0", "itoa", @@ -2006,6 +1962,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "spin" version = "0.5.2" @@ -2082,12 +2048,6 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" @@ -2113,9 +2073,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.27" +version = "2.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" +checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" dependencies = [ "proc-macro2", "quote", @@ -2124,9 +2084,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.7.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" +checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" dependencies = [ "cfg-if", "fastrand", @@ -2144,15 +2104,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.44" @@ -2170,7 +2121,7 @@ checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.28", ] [[package]] @@ -2190,14 +2141,15 @@ dependencies = [ [[package]] name = "time" -version = "0.3.23" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" dependencies = [ + "deranged", "itoa", "serde", "time-core", - "time-macros 0.2.10", + "time-macros 0.2.11", ] [[package]] @@ -2218,9 +2170,9 @@ dependencies = [ [[package]] name = "time-macros" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96ba15a897f3c86766b757e5ac7221554c6750054d74d5b28844fce5fb36a6c4" +checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" dependencies = [ "time-core", ] @@ -2255,11 +2207,10 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.29.1" +version = "1.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +checksum = "2d3ce25f50619af8b0aec2eb23deebe84249e19e2ddd393a6e16e3300a6dadfd" dependencies = [ - "autocfg", "backtrace", "bytes", "libc", @@ -2268,7 +2219,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.3", "tokio-macros", "windows-sys 0.48.0", ] @@ -2281,7 +2232,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.28", ] [[package]] @@ -2500,12 +2451,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" @@ -2554,7 +2499,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.28", "wasm-bindgen-shared", ] @@ -2588,7 +2533,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.28", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2802,9 +2747,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.5.0" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fac9742fd1ad1bd9643b991319f72dd031016d44b77039a26977eb667141e7" +checksum = "acaaa1190073b2b101e15083c38ee8ec891b5e05cbee516521e94ec008f61e64" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 092677d..14e5a12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune" -version = "0.7.5" +version = "0.7.6" edition = "2021" license = "MPL-2.0" repository = "https://github.com/filiptibell/lune" @@ -124,7 +124,7 @@ tokio-tungstenite = { version = "0.20", features = ["rustls-tls-webpki-roots"] } anyhow = { optional = true, version = "1.0" } env_logger = { optional = true, version = "0.10" } -itertools = { optional = true, version = "0.10" } +itertools = { optional = true, version = "0.11" } clap = { optional = true, version = "4.1", features = ["derive"] } include_dir = { optional = true, version = "0.7.3", features = ["glob"] } @@ -139,10 +139,10 @@ rustyline = "12.0.0" glam = { optional = true, version = "0.24" } rand = { optional = true, version = "0.8" } -rbx_cookie = { optional = true, version = "0.1.2" } +rbx_cookie = { optional = true, version = "0.1.3", default-features = false } -rbx_binary = { optional = true, git = "https://github.com/rojo-rbx/rbx-dom", rev = "e7a813d569c3f8a54be8a8873c33f8976c37b8b1" } -rbx_dom_weak = { optional = true, git = "https://github.com/rojo-rbx/rbx-dom", rev = "e7a813d569c3f8a54be8a8873c33f8976c37b8b1" } -rbx_reflection = { optional = true, git = "https://github.com/rojo-rbx/rbx-dom", rev = "e7a813d569c3f8a54be8a8873c33f8976c37b8b1" } -rbx_reflection_database = { optional = true, git = "https://github.com/rojo-rbx/rbx-dom", rev = "e7a813d569c3f8a54be8a8873c33f8976c37b8b1" } -rbx_xml = { optional = true, git = "https://github.com/rojo-rbx/rbx-dom", rev = "e7a813d569c3f8a54be8a8873c33f8976c37b8b1" } +rbx_binary = { optional = true, version = "0.7.1" } +rbx_dom_weak = { optional = true, version = "2.5.0" } +rbx_reflection = { optional = true, version = "4.3.0" } +rbx_reflection_database = { optional = true, version = "0.2.7" } +rbx_xml = { optional = true, version = "0.13.1" } diff --git a/src/lib.rs b/src/lib.rs index 3895d59..55ce4f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ mod lune; -mod roblox; + +#[cfg(feature = "roblox")] +pub mod roblox; #[cfg(test)] mod tests; diff --git a/src/lune/builtins/luau.rs b/src/lune/builtins/luau.rs new file mode 100644 index 0000000..c80a630 --- /dev/null +++ b/src/lune/builtins/luau.rs @@ -0,0 +1,39 @@ +use mlua::prelude::*; + +use crate::lune::lua::{ + luau::{LuauCompileOptions, LuauLoadOptions}, + table::TableBuilder, +}; + +const BYTECODE_ERROR_BYTE: u8 = 0; + +pub fn create(lua: &'static Lua) -> LuaResult { + TableBuilder::new(lua)? + .with_function("compile", compile_source)? + .with_function("load", load_source)? + .build_readonly() +} + +fn compile_source<'lua>( + lua: &'lua Lua, + (source, options): (LuaString<'lua>, LuauCompileOptions), +) -> LuaResult> { + let bytecode = options.into_compiler().compile(source); + + match bytecode.first() { + Some(&BYTECODE_ERROR_BYTE) => Err(LuaError::RuntimeError( + String::from_utf8_lossy(&bytecode).into_owned(), + )), + Some(_) => lua.create_string(bytecode), + None => panic!("Compiling resulted in empty bytecode"), + } +} + +fn load_source<'a>( + lua: &'static Lua, + (source, options): (LuaString<'a>, LuauLoadOptions), +) -> LuaResult> { + lua.load(source.as_bytes()) + .set_name(options.debug_name) + .into_function() +} diff --git a/src/lune/builtins/mod.rs b/src/lune/builtins/mod.rs index 20b13a4..46aefbe 100644 --- a/src/lune/builtins/mod.rs +++ b/src/lune/builtins/mod.rs @@ -1,4 +1,5 @@ pub mod fs; +pub mod luau; pub mod net; pub mod process; pub mod serde; diff --git a/src/lune/importer/mod.rs b/src/lune/importer/mod.rs index c0658d1..de3cdf6 100644 --- a/src/lune/importer/mod.rs +++ b/src/lune/importer/mod.rs @@ -14,6 +14,7 @@ pub fn create(lua: &'static Lua, args: Vec) -> LuaResult<()> { ("serde", builtins::serde::create(lua)?), ("stdio", builtins::stdio::create(lua)?), ("task", builtins::task::create(lua)?), + ("luau", builtins::luau::create(lua)?), #[cfg(feature = "roblox")] ("roblox", builtins::roblox::create(lua)?), ]; diff --git a/src/lune/lua/luau/mod.rs b/src/lune/lua/luau/mod.rs new file mode 100644 index 0000000..bf42f1f --- /dev/null +++ b/src/lune/lua/luau/mod.rs @@ -0,0 +1,3 @@ +mod options; + +pub use options::{LuauCompileOptions, LuauLoadOptions}; diff --git a/src/lune/lua/luau/options.rs b/src/lune/lua/luau/options.rs new file mode 100644 index 0000000..a3c0cc0 --- /dev/null +++ b/src/lune/lua/luau/options.rs @@ -0,0 +1,106 @@ +use mlua::prelude::*; +use mlua::Compiler as LuaCompiler; + +const DEFAULT_DEBUG_NAME: &str = "luau.load(...)"; + +pub struct LuauCompileOptions { + pub(crate) optimization_level: u8, + pub(crate) coverage_level: u8, + pub(crate) debug_level: u8, +} + +impl LuauCompileOptions { + pub fn into_compiler(self) -> LuaCompiler { + LuaCompiler::default() + .set_optimization_level(self.optimization_level) + .set_coverage_level(self.coverage_level) + .set_debug_level(self.debug_level) + } +} + +impl Default for LuauCompileOptions { + fn default() -> Self { + // NOTE: This is the same as LuaCompiler::default() values, but they are + // not accessible from outside of mlua so we need to recreate them here. + Self { + optimization_level: 1, + coverage_level: 0, + debug_level: 1, + } + } +} + +impl<'lua> FromLua<'lua> for LuauCompileOptions { + fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult { + Ok(match value { + LuaValue::Nil => Self::default(), + LuaValue::Table(t) => { + let mut options = Self::default(); + + if let Some(optimization_level) = t.get("optimizationLevel")? { + options.optimization_level = optimization_level; + } + if let Some(coverage_level) = t.get("coverageLevel")? { + options.coverage_level = coverage_level; + } + if let Some(debug_level) = t.get("debugLevel")? { + options.debug_level = debug_level; + } + + options + } + _ => { + return Err(LuaError::FromLuaConversionError { + from: value.type_name(), + to: "CompileOptions", + message: Some(format!( + "Invalid compile options - expected table, got {}", + value.type_name() + )), + }) + } + }) + } +} + +pub struct LuauLoadOptions { + pub(crate) debug_name: String, +} + +impl Default for LuauLoadOptions { + fn default() -> Self { + Self { + debug_name: DEFAULT_DEBUG_NAME.to_string(), + } + } +} + +impl<'lua> FromLua<'lua> for LuauLoadOptions { + fn from_lua(value: LuaValue<'lua>, _: &'lua Lua) -> LuaResult { + Ok(match value { + LuaValue::Nil => Self::default(), + LuaValue::Table(t) => { + let mut options = Self::default(); + + if let Some(debug_name) = t.get("debugName")? { + options.debug_name = debug_name; + } + + options + } + LuaValue::String(s) => Self { + debug_name: s.to_string_lossy().to_string(), + }, + _ => { + return Err(LuaError::FromLuaConversionError { + from: value.type_name(), + to: "LoadOptions", + message: Some(format!( + "Invalid load options - expected string or table, got {}", + value.type_name() + )), + }) + } + }) + } +} diff --git a/src/lune/lua/mod.rs b/src/lune/lua/mod.rs index 12c39cd..944ea44 100644 --- a/src/lune/lua/mod.rs +++ b/src/lune/lua/mod.rs @@ -2,6 +2,7 @@ mod create; pub mod async_ext; pub mod fs; +pub mod luau; pub mod net; pub mod process; pub mod serde; diff --git a/src/roblox/datatypes/extension.rs b/src/roblox/datatypes/extension.rs index 1aa0d20..aea0b59 100644 --- a/src/roblox/datatypes/extension.rs +++ b/src/roblox/datatypes/extension.rs @@ -29,6 +29,7 @@ impl DomValueExt for DomType { Font => "Font", Int32 => "Int32", Int64 => "Int64", + MaterialColors => "MaterialColors", NumberRange => "NumberRange", NumberSequence => "NumberSequence", PhysicalProperties => "PhysicalProperties", diff --git a/src/roblox/reflection/mod.rs b/src/roblox/reflection/mod.rs index f8db49a..3b59200 100644 --- a/src/roblox/reflection/mod.rs +++ b/src/roblox/reflection/mod.rs @@ -31,7 +31,7 @@ impl Database { Creates a new database struct, referencing the bundled reflection database. */ pub fn new() -> Self { - Self(rbx_reflection_database::get()) + Self::default() } /** @@ -125,6 +125,12 @@ impl LuaUserData for Database { } } +impl Default for Database { + fn default() -> Self { + Self(rbx_reflection_database::get()) + } +} + impl PartialEq for Database { fn eq(&self, _other: &Self) -> bool { true // All database userdatas refer to the same underlying rbx-dom database diff --git a/src/tests.rs b/src/tests.rs index 96a840c..270de16 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -101,6 +101,9 @@ create_tests! { task_delay: "task/delay", task_spawn: "task/spawn", task_wait: "task/wait", + + luau_compile: "luau/compile", + luau_load: "luau/load", } #[cfg(feature = "roblox")] diff --git a/tests/luau/compile.luau b/tests/luau/compile.luau new file mode 100644 index 0000000..a949d23 --- /dev/null +++ b/tests/luau/compile.luau @@ -0,0 +1,17 @@ +local luau = require("@lune/luau") + +local EMPTY_LUAU_CODE_BLOCK = "do end" +local BROKEN_LUAU_CODE_BLOCK = "do" + +assert(type(luau.compile) == "function", "expected `luau.compile` to be a function") + +assert( + type(luau.compile(EMPTY_LUAU_CODE_BLOCK)) == "string", + "expected `luau.compile` to return bytecode string" +) + +local success = pcall(function() + luau.compile(BROKEN_LUAU_CODE_BLOCK) +end) + +assert(success == false, "expected 'BROKEN_LUAU_CODE_BLOCK' to fail to compile into bytecode.") diff --git a/tests/luau/load.luau b/tests/luau/load.luau new file mode 100644 index 0000000..6a28b8e --- /dev/null +++ b/tests/luau/load.luau @@ -0,0 +1,33 @@ +local luau = require("@lune/luau") + +local RETURN_VALUE = 1 + +local EMPTY_LUAU_CODE_BLOCK = "do end" +local RETURN_LUAU_CODE_BLOCK = "return " .. tostring(RETURN_VALUE) + +local CUSTOM_SOURCE_BLOCK_NAME = "test" + +assert(type(luau.load) == "function", "expected `luau.compile` to be a function") + +assert( + type(luau.load(EMPTY_LUAU_CODE_BLOCK)) == "function", + "expected 'luau.load' to return a function" +) +assert( + luau.load(RETURN_LUAU_CODE_BLOCK)() == RETURN_VALUE, + "expected 'luau.load' to return a value" +) + +local sourceFunction = luau.load(EMPTY_LUAU_CODE_BLOCK, { debugName = CUSTOM_SOURCE_BLOCK_NAME }) +local sourceFunctionDebugName = debug.info(sourceFunction, "s") + +assert( + string.find(sourceFunctionDebugName, CUSTOM_SOURCE_BLOCK_NAME), + "expected source block name for 'luau.load' to return a custom debug name" +) + +local success = pcall(function() + luau.load(luau.compile(RETURN_LUAU_CODE_BLOCK)) +end) + +assert(success, "expected `luau.load` to be able to process the result of `luau.compile`") diff --git a/types/Luau.luau b/types/Luau.luau new file mode 100644 index 0000000..d57aee9 --- /dev/null +++ b/types/Luau.luau @@ -0,0 +1,116 @@ +--[=[ + @interface CompileOptions + @within Luau + + The Luau compiler options used in generating luau bytecode + + This is a dictionary that may contain one or more of the following values: + + * `optimizationLevel` - Sets the compiler option "optimizationLevel". Defaults to `1` + * `coverageLevel` - Sets the compiler option "coverageLevel". Defaults to `0` + * `debugLevel` - Sets the compiler option "debugLevel". Defaults to `1` + + Documentation regarding what these values represent can be found here; + * https://github.com/Roblox/luau/blob/bd229816c0a82a8590395416c81c333087f541fd/Compiler/include/luacode.h#L13 +]=] +export type CompileOptions = { + optimizationLevel: number, + coverageLevel: number, + debugLevel: number, +} + +--[=[ + @interface LoadOptions + @within Luau + + The Luau load options are used for generating a lua function from either bytecode or sourcecode + + This is a dictionary that may contain one or more of the following values: + + * `debugName` - The debug name of the closure. Defaults to `string ["..."]` +]=] +export type LoadOptions = { + debugName: string, +} + +--[=[ + @class Luau + + Built-in library for generating luau bytecode & functions. + + ### Example usage + + ```lua + local luau = require("@lune/luau") + + local bytecode = luau.compile("print('Hello, World!')") + local callableFn = luau.load(bytecode) + + -- Additionally, we can skip the bytecode generation and load a callable function directly from the code itself. + -- local callableFn = luau.load("print('Hello, World!')") + + callableFn() + ``` +]=] +local luau = {} + +--[=[ + @within Luau + + Compiles sourcecode into Luau bytecode + + An error will be thrown if the sourcecode given isn't valid Luau code. + + ### Example usage + + ```lua + local luau = require("@lune/luau") + + local bytecode = luau.compile("print('Hello, World!')", { + optimizationLevel: 1, + coverageLevel: 0, + debugLevel: 1, + }) + + ... + ``` + + @param source The string that'll be compiled into bytecode + @param CompileOptions The luau compiler options used when compiling the source string + + @return luau bytecode +]=] +function luau.compile(source: string, CompileOptions: CompileOptions): string + return nil :: any +end + +--[=[ + @within Luau + + Generates a function from either bytecode or sourcecode + + An error will be thrown if the sourcecode given isn't valid luau code. + + ### Example usage + + ```lua + local luau = require("@lune/luau") + + local bytecode = luau.compile("print('Hello, World!')") + local callableFn = luau.load(bytecode, { + debugName = "'Hello, World'" + }) + + callableFn() + ``` + + @param source Either bytecode or sourcecode + @param loadOptions The load options used when creating a callbable function + + @return luau function +]=] +function luau.load(source: string, loadOptions: LoadOptions): string + return nil :: any +end + +return luau