mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
document requirecontext
This commit is contained in:
parent
3d9bb89255
commit
eaa1c4d16b
1 changed files with 30 additions and 1 deletions
|
@ -22,9 +22,18 @@ struct RequireContextData<'a> {
|
||||||
pub struct RequireContext {}
|
pub struct RequireContext {}
|
||||||
|
|
||||||
impl RequireContext {
|
impl RequireContext {
|
||||||
|
/**
|
||||||
|
|
||||||
|
# Errors
|
||||||
|
|
||||||
|
- when `RequireContext::init` is called more than once on the same `Lua` instance
|
||||||
|
|
||||||
|
*/
|
||||||
pub fn init(lua: &Lua) -> LuaResult<()> {
|
pub fn init(lua: &Lua) -> LuaResult<()> {
|
||||||
if lua.set_app_data(RequireContextData::default()).is_some() {
|
if lua.set_app_data(RequireContextData::default()).is_some() {
|
||||||
Err(LuaError::runtime("RequireContext::init got called twice"))
|
Err(LuaError::runtime(
|
||||||
|
"RequireContext::init got called twice on the same Lua instance",
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -172,6 +181,26 @@ impl RequireContext {
|
||||||
Ok(multi)
|
Ok(multi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
add a standard library into the require function
|
||||||
|
|
||||||
|
# Example
|
||||||
|
|
||||||
|
```rs
|
||||||
|
inject_std(lua, "lune", LuneStandardLibrary::Task)?;
|
||||||
|
```
|
||||||
|
|
||||||
|
```luau
|
||||||
|
-- luau
|
||||||
|
local task = require("@lune/task")
|
||||||
|
```
|
||||||
|
|
||||||
|
# Errors
|
||||||
|
|
||||||
|
- when `RequireStorage::init` isn't called
|
||||||
|
|
||||||
|
*/
|
||||||
pub fn inject_std(
|
pub fn inject_std(
|
||||||
lua: &Lua,
|
lua: &Lua,
|
||||||
alias: &'static str,
|
alias: &'static str,
|
||||||
|
|
Loading…
Add table
Reference in a new issue