-
-
Notifications
You must be signed in to change notification settings - Fork 640
Requireopt #1905
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
base: master
Are you sure you want to change the base?
Requireopt #1905
Changes from all commits
55ea6ba
1e187db
1af25eb
f9207c9
5eaee3e
10abcf3
f115554
a52c3c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| -- | ||
|
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. This should probably be named "test_globals.lua" to match the name of the file we are testing. 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. File was named based on existing test named "tests/base/test_module_loader.lua" |
||
| -- tests/base/test_module_loader_silent.lua | ||
| -- Test the custom module loader with silent option. | ||
| -- Copyright (c) 2012-2022 Jason Perkins and the Premake project | ||
| -- | ||
|
|
||
| local p = premake | ||
| local suite = test.declare("module_loader_silent") | ||
|
|
||
| -- | ||
| -- Setup | ||
| -- | ||
|
|
||
| function suite.setup() | ||
| end | ||
|
|
||
| function suite.teardown() | ||
| end | ||
|
|
||
| -- | ||
| -- Check that premake's module loader will failed to | ||
| -- load module silently | ||
| -- | ||
|
|
||
| function suite.silentLoadingFailure() | ||
| local result, msg = require("i-am-not-a-module", nil, true) | ||
| test.isfalse(result) | ||
| p.w(msg) | ||
| test.capture("module 'i-am-not-a-module' not found") | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| Require a module or return `false` if module could not be loaded. | ||
|
|
||
|
|
||
| ```lua | ||
| requireopt ("modname", "versions") | ||
| ``` | ||
|
|
||
| `requireopt` is an alias of `require(modname, versions, true)` | ||
|
|
||
| ### Returns ### | ||
|
|
||
| * The module on success | ||
| * `false`, `error_message` on error | ||
|
|
||
| ### Examples ### | ||
|
|
||
| ``` | ||
| local optionalmodule, message = requireopt "not-mandatory-but-recommended" | ||
| if not optionalmodule | ||
| then | ||
| premake.warn ("You will not run this at full power: " .. message) | ||
| end | ||
| ``` | ||
|
|
||
| ### See Also ### | ||
|
|
||
| * [require](require.md) | ||
| * [dofileopt](dofileopt.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation? I'm not completely sold on "requireopt", as that feels like an oxymoron to me. What about "tryrequire"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. It was named
requireoptin an effort to follow existing naming convention, based on the existingdofilepot.IMO, both of them should be renamed
try<thing>