Include lb_tasklib::spawn in globals

This commit is contained in:
lumi 2025-06-26 17:52:31 +10:00
parent 0cafac0948
commit 24c5e9edc2
Signed by: luaneko
GPG Key ID: 406809B8763FF07A
3 changed files with 9 additions and 2 deletions

6
crates/lb/src/task.lua Normal file
View File

@ -0,0 +1,6 @@
local task = require("lb:task")
-- include `lb_tasklib::spawn` in the global scope
function spawn(f, ...)
return task:spawn(f, ...)
end

View File

@ -7,6 +7,7 @@ use tokio::task::JoinHandle;
pub struct lb_tasklib;
#[metatype]
#[include("task.lua")]
impl lb_tasklib {
#[new]
extern "Lua-C" fn new() -> Self {

View File

@ -62,12 +62,12 @@ fn generate_impls(_args: &Args, imp: &mut ItemImpl) -> Result<TokenStream> {
imp.attrs.retain(|attr| {
if attr.path().is_ident("include") {
if let Ok(path) = attr.parse_args::<LitStr>() {
registry.build.push(quote_spanned!(attr.span() =>
registry.build.push(quote_spanned!(path.span() =>
b.include_lua(::std::include_str!(#path));
));
return false;
} else if let Ok(chunk) = attr.parse_args::<Block>() {
registry.build.push(quote_spanned!(attr.span() =>
registry.build.push(quote_spanned!(chunk.span() =>
b.include_lua(#ffi::__internal::luaify_chunk!(#chunk));
));
return false;