- 
                Notifications
    You must be signed in to change notification settings 
- Fork 28
stdlib: loadbypath #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    stdlib: loadbypath #461
Changes from 11 commits
      Commits
    
    
            Show all changes
          
          
            14 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      634caf5
              
                path join shouldn't mutate argument objects
              
              
                skberkeley 843db08
              
                require by path
              
              
                skberkeley c650639
              
                ariel comments
              
              
                skberkeley 71105d7
              
                create @std wrapper for luau around @lute/luau
              
              
                skberkeley 3419596
              
                require takes a pathlike
              
              
                skberkeley 97ce393
              
                move loadbypath into std/luau
              
              
                skberkeley 58c0abf
              
                update load_luau to reflect new signature
              
              
                skberkeley 16a8385
              
                Merge branch 'primary' into skanosue/requirebypath
              
              
                skberkeley 88fb11a
              
                rare useful copilot feedback
              
              
                skberkeley 7c1b88f
              
                Merge branch 'primary' into skanosue/requirebypath
              
              
                skberkeley 6ad70b4
              
                Merge branch 'primary' into skanosue/requirebypath
              
              
                skberkeley cf5279e
              
                Merge branch 'primary' into skanosue/requirebypath
              
              
                skberkeley 7fd1d72
              
                varun comments
              
              
                skberkeley aefedab
              
                Merge branch 'primary' into skanosue/requirebypath
              
              
                skberkeley File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| local luau = require("@lute/luau") | ||
| local luau = require("@std/luau") | ||
|  | ||
| local pretty = require("@batteries/pp") | ||
|  | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| local luteLuau = require("@lute/luau") | ||
|  | ||
| local fs = require("@lute/fs") | ||
| local path = require("@std/path") | ||
|  | ||
| local luau = {} | ||
|  | ||
| -- Export all types from luteLuau | ||
| export type Position = luteLuau.Position | ||
| export type Location = luteLuau.Location | ||
|  | ||
| export type Whitespace = luteLuau.Whitespace | ||
| export type SingleLineComment = luteLuau.SingleLineComment | ||
| export type MultiLineComment = luteLuau.MultiLineComment | ||
|  | ||
| export type Trivia = luteLuau.Trivia | ||
|  | ||
| export type Token<Kind = string> = luteLuau.Token<Kind> | ||
|  | ||
| export type Eof = luteLuau.Eof | ||
|  | ||
| export type Pair<T, Separator> = luteLuau.Pair<T, Separator> | ||
| export type Punctuated<T, Separator = ","> = luteLuau.Punctuated<T, Separator> | ||
|  | ||
| export type AstLocal = luteLuau.AstLocal | ||
|  | ||
| export type AstExprGroup = luteLuau.AstExprGroup | ||
|  | ||
| export type AstExprConstantNil = luteLuau.AstExprConstantNil | ||
|  | ||
| export type AstExprConstantBool = luteLuau.AstExprConstantBool | ||
|  | ||
| export type AstExprConstantNumber = luteLuau.AstExprConstantNumber | ||
|  | ||
| export type AstExprConstantString = luteLuau.AstExprConstantString | ||
|  | ||
| export type AstExprLocal = luteLuau.AstExprLocal | ||
|  | ||
| export type AstExprGlobal = luteLuau.AstExprGlobal | ||
|  | ||
| export type AstExprVarargs = luteLuau.AstExprVarargs | ||
|  | ||
| export type AstExprCall = luteLuau.AstExprCall | ||
|  | ||
| export type AstExprIndexName = luteLuau.AstExprIndexName | ||
|  | ||
| export type AstExprIndexExpr = luteLuau.AstExprIndexExpr | ||
|  | ||
| export type AstFunctionBody = luteLuau.AstFunctionBody | ||
|  | ||
| export type AstExprAnonymousFunction = luteLuau.AstExprAnonymousFunction | ||
|  | ||
| export type AstExprTableItem = luteLuau.AstExprTableItem | ||
|  | ||
| export type AstExprTable = luteLuau.AstExprTable | ||
|  | ||
| export type AstExprUnary = luteLuau.AstExprUnary | ||
|  | ||
| export type AstExprBinary = luteLuau.AstExprBinary | ||
|  | ||
| export type AstExprInterpString = luteLuau.AstExprInterpString | ||
|  | ||
| export type AstExprTypeAssertion = luteLuau.AstExprTypeAssertion | ||
|  | ||
| export type AstExprIfElseIfs = luteLuau.AstExprIfElseIfs | ||
|  | ||
| export type AstExprIfElse = luteLuau.AstExprIfElse | ||
|  | ||
| export type AstExpr = luteLuau.AstExpr | ||
|  | ||
| export type AstStatBlock = luteLuau.AstStatBlock | ||
|  | ||
| export type AstStatElseIf = luteLuau.AstStatElseIf | ||
|  | ||
| export type AstStatIf = luteLuau.AstStatIf | ||
|  | ||
| export type AstStatWhile = luteLuau.AstStatWhile | ||
|  | ||
| export type AstStatRepeat = luteLuau.AstStatRepeat | ||
|  | ||
| export type AstStatBreak = luteLuau.AstStatBreak | ||
|  | ||
| export type AstStatContinue = luteLuau.AstStatContinue | ||
|  | ||
| export type AstStatReturn = luteLuau.AstStatReturn | ||
|  | ||
| export type AstStatExpr = luteLuau.AstStatExpr | ||
|  | ||
| export type AstStatLocal = luteLuau.AstStatLocal | ||
|  | ||
| export type AstStatFor = luteLuau.AstStatFor | ||
|  | ||
| export type AstStatForIn = luteLuau.AstStatForIn | ||
|  | ||
| export type AstStatAssign = luteLuau.AstStatAssign | ||
|  | ||
| export type AstStatCompoundAssign = luteLuau.AstStatCompoundAssign | ||
|  | ||
| export type AstAttribute = luteLuau.AstAttribute | ||
|  | ||
| export type AstStatFunction = luteLuau.AstStatFunction | ||
|  | ||
| export type AstStatLocalFunction = luteLuau.AstStatLocalFunction | ||
|  | ||
| export type AstStatTypeAlias = luteLuau.AstStatTypeAlias | ||
|  | ||
| export type AstStatTypeFunction = luteLuau.AstStatTypeFunction | ||
|  | ||
| export type AstStat = luteLuau.AstStat | ||
|  | ||
| export type AstGenericType = luteLuau.AstGenericType | ||
|  | ||
| export type AstGenericTypePack = luteLuau.AstGenericTypePack | ||
|  | ||
| export type AstTypeReference = luteLuau.AstTypeReference | ||
|  | ||
| export type AstTypeSingletonBool = luteLuau.AstTypeSingletonBool | ||
|  | ||
| export type AstTypeSingletonString = luteLuau.AstTypeSingletonString | ||
|  | ||
| export type AstTypeTypeof = luteLuau.AstTypeTypeof | ||
|  | ||
| export type AstTypeGroup = luteLuau.AstTypeGroup | ||
|  | ||
| export type AstTypeOptional = luteLuau.AstTypeOptional | ||
|  | ||
| export type AstTypeUnion = luteLuau.AstTypeUnion | ||
|  | ||
| export type AstTypeIntersection = luteLuau.AstTypeIntersection | ||
|  | ||
| export type AstTypeArray = luteLuau.AstTypeArray | ||
|  | ||
| export type AstTypeTableItem = luteLuau.AstTypeTableItem | ||
|  | ||
| export type AstTypeTable = luteLuau.AstTypeTable | ||
|  | ||
| export type AstTypeFunctionParameter = luteLuau.AstTypeFunctionParameter | ||
|  | ||
| export type AstTypeFunction = luteLuau.AstTypeFunction | ||
|  | ||
| export type AstType = luteLuau.AstType | ||
|  | ||
| export type AstTypePackExplicit = luteLuau.AstTypePackExplicit | ||
|  | ||
| export type AstTypePackGeneric = luteLuau.AstTypePackGeneric | ||
|  | ||
| export type AstTypePackVariadic = luteLuau.AstTypePackVariadic | ||
|  | ||
| export type AstTypePack = luteLuau.AstTypePack | ||
|  | ||
| export type ParseResult = luteLuau.ParseResult | ||
|  | ||
| export type Bytecode = luteLuau.Bytecode | ||
| 
      Comment on lines
    
      +9
     to 
      +153
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all of these should become luacase ultimately, but it's okay if that doesn't happen in this PR. | ||
|  | ||
| function luau.parse(source: string): ParseResult | ||
| return luteLuau.parse(source) | ||
| end | ||
|  | ||
| function luau.parseexpr(source: string): AstExpr | ||
| return luteLuau.parseexpr(source) | ||
| end | ||
|  | ||
| function luau.compile(source: string): Bytecode | ||
| return luteLuau.compile(source) | ||
| end | ||
|  | ||
| function luau.load(bytecode: Bytecode, chunkname: string?, env: { [any]: any }?): (...any) -> ...any | ||
| return luteLuau.load(bytecode, if chunkname ~= nil then `@{chunkname}` else "=luau.load", env) | ||
|         
                  vrn-sn marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| end | ||
|  | ||
| function luau.loadbypath(requirePath: path.pathlike): any | ||
| local requirePathStr = if typeof(requirePath) == "string" then requirePath else path.format(requirePath) | ||
|  | ||
| local migrationHandle = fs.open(requirePathStr, "r") | ||
|  | ||
| local migrationBytecode = luau.compile(fs.read(migrationHandle)) | ||
|  | ||
| fs.close(migrationHandle) | ||
|  | ||
| return luau.load(migrationBytecode, requirePathStr)() | ||
| end | ||
|  | ||
| return luau | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| local fs = require("@lute/fs") | ||
| local process = require("@lute/process") | ||
| local path = require("@std/path") | ||
| local test = require("@std/test") | ||
|  | ||
| local REQUIRER_CONTENTS = [[ | ||
| local args = { ... } | ||
| assert(#args == 2, "Expected one argument: path to Luau script to require") | ||
|  | ||
| local luau = require("@std/luau") | ||
| local result = luau.loadbypath(args[2]) | ||
| print(result) | ||
| ]] | ||
|  | ||
| local REQUIREE_CONTENTS = [[return "Success"]] | ||
|  | ||
| local lutePath = process.execpath() | ||
|  | ||
| local tmpDirStr = ".tmp" | ||
| local tmpDirExists = fs.exists(tmpDirStr) | ||
| local testDir = path.join(tmpDirStr, "lute_require_test") | ||
| local testDirStr = path.format(testDir) | ||
|  | ||
| test.suite("Lute CLI", function(suite) | ||
| suite:beforeall(function() | ||
| if not tmpDirExists then | ||
| fs.mkdir(tmpDirStr) | ||
| end | ||
|  | ||
| if not fs.exists(testDirStr) then | ||
| fs.mkdir(testDirStr) | ||
| end | ||
| end) | ||
|  | ||
| suite:case("help1", function(check) | ||
| -- Setup | ||
| -- Create files | ||
| local requirerPath = path.format(path.join(testDir, "requirer.luau")) | ||
| local requirerFile = fs.open(requirerPath, "w+") | ||
| fs.write(requirerFile, REQUIRER_CONTENTS) | ||
| fs.close(requirerFile) | ||
|  | ||
| local requireePath = path.format(path.join(testDir, "requiree.luau")) | ||
| local requireeFile = fs.open(requireePath, "w+") | ||
| fs.write(requireeFile, REQUIREE_CONTENTS) | ||
| fs.close(requireeFile) | ||
|  | ||
| local result = process.run({ lutePath, requirerPath, requireePath }) | ||
| check.eq(result.exitcode, 0) | ||
| check.eq(result.stdout, "Success\n") | ||
|  | ||
| -- Cleanup | ||
| fs.remove(requirerPath) | ||
| fs.remove(requireePath) | ||
| end) | ||
|  | ||
| suite:afterall(function() | ||
| if fs.exists(testDirStr) then | ||
| fs.rmdir(testDirStr) | ||
| end | ||
|  | ||
| if not tmpDirExists then | ||
| fs.rmdir(tmpDirStr) | ||
| end | ||
| end) | ||
| end) | ||
|  | ||
| test.run() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.