lune icon indicating copy to clipboard operation
lune copied to clipboard

Rewrite require and luaurc in lune-std

Open FlowGnarly opened this issue 1 year ago • 0 comments

Highlights of this PR

  • doesn't mutably borrow the app container for the entire require process (Fixes #236)
  • allows custom libraries that impl the StandardLibrary trait to be added to the require envrionment (Fixes #197)
     context::RequireContext::inject_std(lua, "custom", CustomStandardLibrary::Timer)?;
    
     local timer = require("@custom/timer")
    
  • the luaurc parser has better error handling and doesnt fail silently when it fails to parse a .luaurc file (Fixes #210)
    Failed to parse /path/to/.luaurc
    ParserError: trailing comma at line 16 column 1
    [Stack Begin]
            Script '[C]'
            Script '__mlua_async_poll', Line 4
            Script 'REPL', Line 1
    [Stack End]
    

API Changes

for the existing crates that use lune-std nothing has to be changed, since this pr only changes the internal code and adds 2 new items which are totally optional and can be accessed by other crates, which are:

pub trait StandardLibrary
where
    Self: Debug,
{
    fn name(&self) -> &'static str;
    fn module<'lua>(&self, lua: &'lua Lua) -> LuaResult<LuaMultiValue<'lua>>;
}
pub struct RequireContext {}

impl RequireContext {
    pub fn inject_std(
        lua: &Lua,
        alias: &'static str,
        std: impl StandardLibrary + 'static,
    ) -> Result<(), RequireError>;
}

FlowGnarly avatar Aug 25 '24 18:08 FlowGnarly