Compare commits

...

3 Commits

12 changed files with 190 additions and 216 deletions

247
Cargo.lock generated
View File

@ -75,9 +75,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.71"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854"
[[package]]
name = "anymap2"
@ -138,9 +138,9 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -149,9 +149,9 @@ version = "0.1.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -415,6 +415,15 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
[[package]]
name = "convert_case"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
@ -547,8 +556,8 @@ checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
dependencies = [
"fnv",
"ident_case",
"proc-macro2 1.0.64",
"quote 1.0.29",
"proc-macro2 1.0.66",
"quote 1.0.31",
"strsim",
"syn 1.0.109",
]
@ -560,18 +569,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
dependencies = [
"darling_core",
"quote 1.0.29",
"quote 1.0.31",
"syn 1.0.109",
]
[[package]]
name = "dashmap"
version = "5.4.0"
version = "5.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
checksum = "6943ae99c34386c84a470c499d3414f66502a41340aa895406e0d2e4a207b91d"
dependencies = [
"cfg-if",
"hashbrown 0.12.3",
"hashbrown 0.14.0",
"lock_api",
"once_cell",
"parking_lot_core 0.9.8",
@ -602,8 +611,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4"
dependencies = [
"darling",
"proc-macro2 1.0.64",
"quote 1.0.29",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 1.0.109",
]
@ -649,9 +658,9 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -696,9 +705,9 @@ dependencies = [
[[package]]
name = "equivalent"
version = "1.0.0"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
@ -848,9 +857,9 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -1213,9 +1222,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.8"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "js-sys"
@ -1291,9 +1300,10 @@ dependencies = [
name = "lua_macros"
version = "0.1.0"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"convert_case",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -1523,6 +1533,23 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "mlua"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07366ed2cd22a3b000aed076e2b68896fb46f06f1f5786c5962da73c0af01577"
dependencies = [
"bstr",
"cc",
"futures-core",
"futures-task",
"futures-util",
"num-traits",
"once_cell",
"pkg-config",
"rustc-hash",
]
[[package]]
name = "native-tls"
version = "0.2.11"
@ -1602,9 +1629,9 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -1717,9 +1744,9 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -1788,9 +1815,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.64"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
dependencies = [
"unicode-ident",
]
@ -1822,8 +1849,8 @@ checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4"
dependencies = [
"anyhow",
"itertools",
"proc-macro2 1.0.64",
"quote 1.0.29",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 1.0.109",
]
@ -1838,11 +1865,11 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.29"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105"
checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0"
dependencies = [
"proc-macro2 1.0.64",
"proc-macro2 1.0.66",
]
[[package]]
@ -2063,9 +2090,9 @@ dependencies = [
[[package]]
name = "regex-automata"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83d3daa6976cffb758ec878f108ba0e062a45b2d6ca3a2cca965338855476caf"
checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310"
dependencies = [
"aho-corasick",
"memchr",
@ -2074,9 +2101,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.7.3"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846"
checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"
[[package]]
name = "reqwest"
@ -2115,30 +2142,6 @@ dependencies = [
"winreg",
]
[[package]]
name = "rlua"
version = "0.19.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d33e5ba15c3d43178f283ed5863d4531e292fc0e56fb773f3bea45f18e3a42a"
dependencies = [
"bitflags",
"bstr",
"libc",
"num-traits",
"rlua-lua54-sys",
]
[[package]]
name = "rlua-lua54-sys"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7aafabafe1895cb4a2be81a56d7ff3d46bf4b5d2f9cfdbea2ed404cdabe96474"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]]
name = "ruma"
version = "0.7.4"
@ -2230,8 +2233,8 @@ checksum = "0f82e91eb61cd86d9287303133ee55b54618eccb75a522cc22a42c15f5bda340"
dependencies = [
"once_cell",
"proc-macro-crate",
"proc-macro2 1.0.64",
"quote 1.0.29",
"proc-macro2 1.0.66",
"quote 1.0.31",
"ruma-identifiers-validation",
"serde",
"syn 1.0.109",
@ -2244,6 +2247,12 @@ version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustix"
version = "0.37.23"
@ -2260,9 +2269,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.14"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "schannel"
@ -2304,38 +2313,38 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.169"
version = "1.0.171"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd51c3db8f9500d531e6c12dd0fd4ad13d133e9117f5aebac3cdbb8b6d9824b0"
checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_bytes"
version = "0.11.11"
version = "0.11.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a16be4fe5320ade08736447e3198294a5ea9a6d44dde6f35f0a5e06859c427a"
checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff"
dependencies = [
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.169"
version = "1.0.171"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27738cfea0d944ab72c3ed01f3d5f23ec4322af8a1431e40ce630e4c01ea74fd"
checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
name = "serde_json"
version = "1.0.100"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c"
checksum = "d03b412469450d4404fe8499a268edd7f8b79fecb074b0d812ad64ca21f4031b"
dependencies = [
"itoa",
"ryu",
@ -2380,9 +2389,9 @@ dependencies = [
[[package]]
name = "signal-hook"
version = "0.3.15"
version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9"
checksum = "b824b6e687aff278cdbf3b36f07aa52d4bd4099699324d5da86a2ebce3aa00b3"
dependencies = [
"libc",
"signal-hook-registry",
@ -2493,19 +2502,19 @@ version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"proc-macro2 1.0.66",
"quote 1.0.31",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.25"
version = "2.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2"
checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"proc-macro2 1.0.66",
"quote 1.0.31",
"unicode-ident",
]
@ -2538,9 +2547,9 @@ version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -2593,9 +2602,9 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -2639,9 +2648,9 @@ checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
[[package]]
name = "toml_edit"
version = "0.19.12"
version = "0.19.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c500344a19072298cd05a7224b3c0c629348b78692bf48466c5238656e315a78"
checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a"
dependencies = [
"indexmap 2.0.0",
"toml_datetime",
@ -2672,9 +2681,9 @@ version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]
[[package]]
@ -2696,7 +2705,7 @@ dependencies = [
"indexmap 2.0.0",
"lua_macros",
"matrix-sdk",
"rlua",
"mlua",
"serde",
"tokio",
"tokio-util",
@ -2747,9 +2756,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
[[package]]
name = "unicode-ident"
version = "1.0.10"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
[[package]]
name = "unicode-normalization"
@ -2912,9 +2921,9 @@ dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
"wasm-bindgen-shared",
]
@ -2936,7 +2945,7 @@ version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
dependencies = [
"quote 1.0.29",
"quote 1.0.31",
"wasm-bindgen-macro-support",
]
@ -2946,9 +2955,9 @@ version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -3089,9 +3098,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "winnow"
version = "0.4.9"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81a2094c43cc94775293eaa0e499fbc30048a6d824ac82c0351a8c0bf9112529"
checksum = "81fac9742fd1ad1bd9643b991319f72dd031016d44b77039a26977eb667141e7"
dependencies = [
"memchr",
]
@ -3132,7 +3141,7 @@ version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [
"proc-macro2 1.0.64",
"quote 1.0.29",
"syn 2.0.25",
"proc-macro2 1.0.66",
"quote 1.0.31",
"syn 2.0.26",
]

View File

@ -18,4 +18,4 @@ tokio-util = "0.7"
serde = "1.0"
cli-log = "2.0"
indexmap = "2.0.0"
rlua = "0.19.7"
mlua = { version = "0.8.9", features = ["lua54", "async"] }

View File

@ -50,11 +50,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1687709756,
"narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=",
"lastModified": 1689068808,
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7",
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github"
},
"original": {
@ -65,11 +65,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1688829822,
"narHash": "sha256-hv56yK1fPHPt7SU2DboxBtdSbIuv9nym7Dss7Cn2jic=",
"lastModified": 1689449371,
"narHash": "sha256-sK3Oi8uEFrFPL83wKPV6w0+96NrmwqIpw9YFffMifVg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ed6afb10dfdfc97b6bcf0703f1bad8118e9e961b",
"rev": "29bcead8405cfe4c00085843eb372cc43837bb9d",
"type": "github"
},
"original": {
@ -98,11 +98,11 @@
]
},
"locked": {
"lastModified": 1688870171,
"narHash": "sha256-8tD8fheWPa7TaJoxzcU3iHkCrQQpOpdMN+HYqgZ1N5A=",
"lastModified": 1689561325,
"narHash": "sha256-+UABrHUXtWJSc9mM7oEKPIYQEhTzUVVNy2IPG9Lfrj0=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "5a932f10ac4bd59047d6e8b5780750ec76ea988a",
"rev": "d8a38aea13c67dc2ce10cff93eb274dcf455753f",
"type": "github"
},
"original": {

View File

@ -55,6 +55,7 @@
];
buildInputs = with pkgs; [
openssl
lua54Packages.stdlib
];
craneBuild = craneLib.buildPackage {

View File

@ -1,11 +0,0 @@
use proc_macro2::TokenStream as TokenStream2;
use quote::ToTokens;
// TODO: Do we need this noop?
pub fn generate_default_lua_function(input: &syn::Field) -> TokenStream2 {
let output: TokenStream2 = syn::parse(input.into_token_stream().into())
.expect("This is generated from valid rust code, it should stay that way.");
output
}

View File

@ -1,8 +1,6 @@
mod generate_noop_lua_function;
mod mark_as_ci_command;
mod struct_to_ci_enum;
use generate_noop_lua_function::generate_default_lua_function;
use mark_as_ci_command::generate_final_function;
use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
@ -30,21 +28,18 @@ pub fn turn_struct_to_ci_commands(_attrs: TokenStream, input: TokenStream) -> To
}
/// Generate a default lua function implementation.
// TODO: Is this needed?
#[proc_macro_attribute]
pub fn gen_lua_function(_attrs: TokenStream, input: TokenStream) -> TokenStream {
// Construct a representation of Rust code as a syntax tree
// that we can manipulate
//
let parser = Field::parse_named;
let input = parser.parse(input)
.expect("This is only defined for named fileds.");
// Build the trait implementation
let default_lua_function: TokenStream2 = generate_default_lua_function(&input);
quote! {
#default_lua_function
#input
}
.into()
}

View File

@ -26,21 +26,7 @@ fn append_tx_send_code(input: &mut syn::ItemFn) -> &mut syn::ItemFn {
let tx_send = match &input.sig.output {
syn::ReturnType::Default => {
todo!(
"Does this case even trigger? All functions should have a output of (Result<$type, rlua::Error>)"
);
quote! {
{
let tx: std::sync::mpsc::Sender<crate::app::events::event_types::Event> =
context
.named_registry_value("sender_for_ci_commands")
.expect("This exists, it was set before");
tx
.send(Event::CommandEvent(Command::#function_name_pascal))
.expect("This should work, as the reciever is not dropped");
}
}
unreachable!("All functions should have a output of (Result<$type, rlua::Error>)");
}
syn::ReturnType::Type(_, ret_type) => {
let return_type = match *(ret_type.clone()) {
@ -111,35 +97,38 @@ fn append_tx_send_code(input: &mut syn::ItemFn) -> &mut syn::ItemFn {
}
_ => unimplemented!("Only for path types"),
};
match return_type {
let send_data = match return_type {
ReturnType::Default => {
quote! {
{
let tx: std::sync::mpsc::Sender<crate::app::events::event_types::Event> =
context
.named_registry_value("sender_for_ci_commands")
.expect("This exists, it was set before");
tx
.send(Event::CommandEvent(Command::#function_name_pascal))
.expect("This should work, as the reciever is not dropped");
Event::CommandEvent(Command::#function_name_pascal)
}
}
}
ReturnType::Type(_, _) => {
quote! {
{
let tx: std::sync::mpsc::Sender<crate::app::events::event_types::Event> =
context
.named_registry_value("sender_for_ci_commands")
.expect("This exists, it was set before");
tx
.send(Event::CommandEvent(Command::#function_name_pascal(input_str)))
.expect("This should work, as the reciever is not dropped");
Event::CommandEvent(Command::#function_name_pascal(input_str))
}
}
}
};
quote! {
{
let tx: std::sync::Arc<std::sync::Mutex<tokio::sync::mpsc::Sender<crate::app::events::event_types::Event>>> =
lua
.named_registry_value("sender_for_ci_commands")
.expect("This exists, it was set before");
tx
// FIXME: This is sync code, it needs to be run in a blocking allowed
// executor
.lock()
.expect("This should work, as only one function is executed. It wil however fail, when concurrency is added");
.send(#send_data)
.await
.expect("This should work, as the reciever is not dropped");
}
}
}
};

View File

@ -22,10 +22,10 @@ pub fn generate_generate_ci_function(input: &syn::DeriveInput) -> TokenStream2 {
.expect("These are only the named field, thus they all should have a name.");
functions_to_generate.push(quote! {
#[ci_command]
fn #function_name(context: Context, input_str: String) -> Result<(), rlua::Error> {
async fn #function_name(lua: &mlua::Lua, input_str: String) -> Result<(), mlua::Error> {
Ok(())
}
});
});
generate_ci_part(field)
} else {
generate_ci_part(field)
@ -41,11 +41,11 @@ pub fn generate_generate_ci_function(input: &syn::DeriveInput) -> TokenStream2 {
let functions_to_generate: TokenStream2 = functions_to_generate.into_iter().collect();
let gen = quote! {
pub fn generate_ci_functions(
context: &mut rlua::Context,
tx: std::sync::mpsc::Sender<crate::app::events::event_types::Event>)
lua: &mut mlua::Lua,
tx: tokio::sync::mpsc::Sender<crate::app::events::event_types::Event>)
{
context.set_named_registry_value("sender_for_ci_commands", tx).expect("This should always work, as the value is added before all else");
let globals = context.globals();
lua.set_named_registry_value("sender_for_ci_commands", std::sync::Arc::new(std::sync::Mutex::new(tx))).expect("This should always work, as the value is added before all else");
let globals = lua.globals();
#input_tokens
}
#functions_to_generate
@ -61,7 +61,7 @@ fn generate_ci_part(field: &syn::Field) -> TokenStream2 {
let function_name_ident = format_ident!("fun_{}", field_ident);
let function_name = format!("{}", field_ident);
quote! {
let #function_name_ident = context.create_function(#field_ident).expect(
let #function_name_ident = lua.create_async_function(#field_ident).expect(
&format!(
"The function: `{}` should be defined",
#function_name

View File

@ -1,4 +1,5 @@
// FIXME: This file needs documentation with examples of how the proc macros work.
// for now use `cargo expand app::command_interface` for an overview
use lua_macros::{ci_command, turn_struct_to_ci_commands};
use rlua::Context;
@ -21,7 +22,7 @@ use super::events::event_types::Event;
/// where $return_type is the type returned by the function (the only supported ones are right now
/// `String` and `()`).
#[turn_struct_to_ci_commands]
struct Commands<'lua> {
struct Commands {
greet: fn(usize) -> String,
// Closes the application
@ -42,11 +43,11 @@ struct Commands<'lua> {
}
#[ci_command]
fn greet(context: Context, input_str: String) -> Result<String, rlua::Error> {
async fn greet(lua: &mlua::Lua, input_str: String) -> Result<String, mlua::Error> {
Ok(format!("Name is {}", input_str))
}
#[ci_command]
fn room_message_send(context: Context, input_str: String) -> Result<String, rlua::Error> {
async fn room_message_send(lua: &mlua::Lua, input_str: String) -> Result<String, mlua::Error> {
Ok(format!("Sent message: {}", input_str))
}

View File

@ -1,20 +1,22 @@
use anyhow::{Context, Result};
use cli_log::info;
use crate::app::{App, events::event_types::{EventStatus, Event}};
use crate::app::{
events::event_types::{Event, EventStatus},
App,
};
pub async fn handle(app: &mut App<'_>, command: &str) -> Result<EventStatus> {
info!("Recieved ci command: `{command}`; executing..");
// TODO: Should the ci support more than strings?
let output = app.lua.context(|context| -> Result<String> {
let output = context
.load(&command)
.eval::<String>()
.with_context(|| format!("Failed to execute: `{command}`"))?;
info!("Function evaluated to: `{output}`");
Ok(output)
})?;
let output = app
.lua
.load(command)
.eval_async::<String>()
.await
.with_context(|| format!("Failed to execute: `{command}`"))?;
info!("Function evaluated to: `{output}`");
app.transmitter.send(Event::CiOutput(output));

View File

@ -3,13 +3,14 @@ pub mod events;
pub mod status;
pub mod transmitter;
use std::{path::Path, sync::mpsc::Sender as StdSender};
use std::path::Path;
use anyhow::{Context, Error, Result};
use cli_log::info;
use matrix_sdk::Client;
use rlua::Lua;
use mlua::Lua;
use status::{State, Status};
use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken;
use crate::{
@ -34,12 +35,10 @@ pub struct App<'ui> {
impl App<'_> {
pub fn new() -> Result<Self> {
fn set_up_lua(tx: StdSender<Event>) -> Lua {
fn set_up_lua(tx: mpsc::Sender<Event>) -> Lua {
let lua = Lua::new();
lua.context(|mut lua_context| {
generate_ci_functions(&mut lua_context, tx);
});
generate_ci_functions(&mut lua, tx);
lua
}
@ -61,7 +60,7 @@ impl App<'_> {
input_listener_killer: CancellationToken::new(),
matrix_listener_killer: CancellationToken::new(),
lua: set_up_lua(transmitter.std_tx()),
lua: set_up_lua(transmitter.tx()),
})
}

View File

@ -1,5 +1,3 @@
use std::sync::mpsc as StdMpsc;
use anyhow::{bail, Context, Result};
use tokio::sync::mpsc;
@ -8,29 +6,20 @@ use super::events::event_types::Event;
pub struct Transmitter {
tx: mpsc::Sender<Event>,
rx: mpsc::Receiver<Event>,
std_tx: StdMpsc::Sender<Event>,
std_rx: StdMpsc::Receiver<Event>,
}
impl Transmitter {
pub fn new() -> Transmitter {
let (std_tx, std_rx) = StdMpsc::channel();
let (tx, rx) = mpsc::channel(256);
Transmitter {
tx,
rx,
std_tx,
std_rx,
}
}
pub fn tx(&self) -> mpsc::Sender<Event> {
self.tx.to_owned()
}
pub fn std_tx(&self) -> StdMpsc::Sender<Event> {
self.std_tx.to_owned()
}
pub async fn recv(&mut self) -> Result<Event> {
match self.rx.recv().await {
Some(event) => Ok(event),