vfox/hooks/
backend_list_versions.rs1use crate::{Plugin, error::Result};
2use mlua::{FromLua, IntoLua, Lua, Value, prelude::LuaError};
3
4#[derive(Debug, Clone)]
5pub struct BackendListVersionsContext {
6 pub tool: String,
7}
8
9#[derive(Debug, Clone)]
10pub struct BackendListVersionsResponse {
11 pub versions: Vec<String>,
12}
13
14impl Plugin {
15 pub async fn backend_list_versions(
16 &self,
17 ctx: BackendListVersionsContext,
18 ) -> Result<BackendListVersionsResponse> {
19 debug!("[vfox:{}] backend_list_versions", &self.name);
20 self.eval_async(chunk! {
21 require "hooks/backend_list_versions"
22 return PLUGIN:BackendListVersions($ctx)
23 })
24 .await
25 }
26}
27
28impl IntoLua for BackendListVersionsContext {
29 fn into_lua(self, lua: &mlua::Lua) -> mlua::Result<Value> {
30 let table = lua.create_table()?;
31 table.set("tool", self.tool)?;
32 Ok(Value::Table(table))
33 }
34}
35
36impl FromLua for BackendListVersionsResponse {
37 fn from_lua(value: Value, _: &Lua) -> std::result::Result<Self, LuaError> {
38 match value {
39 Value::Table(table) => Ok(BackendListVersionsResponse {
40 versions: table.get::<Vec<String>>("versions")?,
41 }),
42 _ => Err(LuaError::FromLuaConversionError {
43 from: value.type_name(),
44 to: "BackendListVersionsResponse".to_string(),
45 message: Some("Expected table".to_string()),
46 }),
47 }
48 }
49}