-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
luci-app-example: rewrite RPC side using ucode #7602
Merged
systemcrash
merged 1 commit into
openwrt:master
from
GeorgeSapkin:rewrite-example-to-ucode
Feb 3, 2025
+64
β266
Merged
Changes from all commits
Commits
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 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 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 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 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
248 changes: 0 additions & 248 deletions
248
applications/luci-app-example/root/usr/libexec/rpcd/luci.example
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
applications/luci-app-example/root/usr/share/rpcd/ucode/example.uc
This file contains 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,48 @@ | ||
#!/usr/bin/env ucode | ||
|
||
'use strict'; | ||
|
||
import { cursor } from 'uci'; | ||
|
||
// Rather than parse files in /etc/config, we can use `cursor`. | ||
const uci = cursor(); | ||
|
||
const methods = { | ||
get_sample1: { | ||
call: function() { | ||
const num_cats = uci.get('example', 'animals', 'num_cats'); | ||
const num_dogs = uci.get('example', 'animals', 'num_dogs'); | ||
const num_parakeets = uci.get('example', 'animals', 'num_parakeets'); | ||
const result = { | ||
num_cats, | ||
num_dogs, | ||
num_parakeets, | ||
is_this_real: false, | ||
not_found: null, | ||
}; | ||
|
||
uci.unload(); | ||
return result; | ||
} | ||
}, | ||
|
||
get_sample2: { | ||
call: function() { | ||
const result = { | ||
option_one: { | ||
name: "Some string value", | ||
value: "A value string", | ||
parakeets: ["one", "two", "three"], | ||
}, | ||
option_two: { | ||
name: "Another string value", | ||
value: "And another value", | ||
parakeets: [3, 4, 5], | ||
}, | ||
}; | ||
return result; | ||
} | ||
} | ||
}; | ||
|
||
return { 'luci.example': methods }; |
This file contains 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
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.
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.
Technically, if we're to use the shebang and be able to call this uc file externally, set the +x bit on it also.
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.
Do ucode files under rpcd actually need a shebang? I can only find one example in luci-app-ddns which has it, but all ucode files outside of rpcd don't.
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.
They rpcd ones don't IIUC, but if the shebang is there, it's just good style and intention, so +x should likely also apply. The shebang likely aids testing also :)