-
Notifications
You must be signed in to change notification settings - Fork 194
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
Lua support #878
Draft
ihaveamac
wants to merge
140
commits into
d0k3:master
Choose a base branch
from
ihaveamac:real-lua-attempt
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Lua support #878
Conversation
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
Silence warnings
… ShowPrompt calls
…remove luacmd command
…ripts..." option to home/power menu
This reverts commit 6ef14b6.
ihaveamac
force-pushed
the
real-lua-attempt
branch
from
December 13, 2024 19:30
4a789d2
to
0996219
Compare
I wrote a bunch of documentation which I think is complete for now: https://github.com/ihaveamac/GodMode9/blob/real-lua-attempt/resources/lua-doc.md |
This reverts commit 2524e77.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Very very work in progress! This was originally at https://github.com/ihaveamac/GM9-lua-attempt but I have moved it to a fork of this repo. (This also means there's currently some changes that should not be here, like the temporary README.)
API proposal and status
Thinking about this again, I want to figure out what a GM9 lua API would look like. So let's try this out...
Most of these should be self-explanatory, I put notes next to ones that aren't.
For functions I have actually implemented on
real-lua-attempt
, there will be a ✅ with the actual function signature. Ones I think could be delayed until later I have a ➡️ next to it.Function naming
I'm not sure what's the best way to name these functions. For example, one that could check if the SD is mounted could be called:
sdmounted()
sd_mounted()
sd_is_mounted()
is_sd_mounted()
SDMounted()
SD_Mounted()
IsSDMounted()
maybe moreI decided to go with the first one where possible but I'm not invested in that being the format.API proposal
Global constants
ui
void ui.echo(string text)
bool ui.ask(string text)
int ui.ask_hex(string text, int initial, int n_digits)
int ui.ask_number(string text, int initial)
string ui.ask_text(string prompt, string initial, int max_length)
int ui.ask_selection(string prompt, array options)
void ui.clear()
void ui.show_png(string path)
void ui.show_text(string text)
void ui.show_game_info(string path)
void ui.show_qr(string text, string data)
void ui.show_text_viewer(string text)
void ui.show_file_text_viewer(string path)
string ui.format_bytes(int bytes)
bool ui.check_key(string key)
fs
void fs.move(string src, string dst[, table opts {bool no_cancel, bool silent, bool overwrite, bool skip_all}])
void fs.remove(string path[, table opts {bool recursive}])
void fs.copy(string src, string dst[, table opts {bool calc_sha, bool sha1, bool no_cancel, bool silent, bool overwrite, bool skip_all, bool append, bool recursive}])
void fs.mkdir(string path)
array fs.list_dir(string path)
array fs.stat(string path)
array fs.stat_fs(string path)
array fs.dir_info(string path)
string fs.ask_select_file(string prompt, string path[, bool opts {bool include_dirs, bool explorer}])
string fs.ask_select_dir(string prompt, string path[, bool opts {bool explorer}])
string fs.find(string pattern[, bool opts {bool first}])
string fs.find_not(string pattern)
array fs.find_all(string dir, string pattern[, table opts {bool recursive}])
bool fs.allow(string path[, table flags {bool ask_all}])
- will prompt for permissionvoid fs.img_mount(string path)
void fs.img_umount()
string fs.get_img_mount()
string fs.hash_file(string path, int offset, int size[, table opts {bool sha1}])
string fs.hash_data(string data[, table opts {bool sha1}])
bool fs.verify(string path)
bool fs.verify_with_sha_file(string path)
- Check a file's hash with a.sha
file next to it. true if passed, false if corrupt, nil if no sha filebool fs.exists(string path)
bool fs.is_dir(string path)
bool fs.is_file(string path)
bool fs.sd_is_mounted()
void fs.sd_switch([string message])
void fs.fix_cmacs(string path)
string fs.read_file(string path, int offset, int size)
int fs.write_file(string path, int offset, string data)
void fs.fill_file(string path, int offset, int size, int byte)
- byte should be an integer between 0x00 and 0xFFvoid fs.make_dummy_file(string path, int size)
void fs.truncate(string path, int size)
void fs.key_dump(string file[, table opts {bool overwrite}])
void fs.cart_dump(string path, int size[, table opts {bool encrypted}])
title
array title.get_installed(int media)
- some way to determine SD or NAND, as well as EmuNANDvoid title.decrypt(string path)
void title.encrypt(string path)
void title.install(string path[, table opts {bool to_emunand}])
void title.build_cia(string path[, table opts {bool legit}])
void title.extract_code(string src, string dst)
void title.compress_code(string src, string dst)
void title.apply_ips(string patch, string src, string target)
void title.apply_bps(string patch, string src, string target)
void title.apply_bpm(string patch, string src, string target)
sys
void sys.boot(string path)
void sys.reboot()
void sys.power_off()
string sys.region
string sys.serial
string sys.secureinfo_letter
- A or B, whichever is found, ornil
if somehow it's missingstring sys.sys_id0
string sys.emu_id0
int sys.emu_base
void sys.refresh_info()
- refreshes the upper six variables, automatically called by preload script, but can be manually invoked if SecureInfo_* is changedvoid sys.next_emu()
- callssys.refresh_info()
automaticallybool sys.check_embedded_backup()
- true if found or created, false if failed or user declines, nil if NCSD genuine check failsbool sys.check_raw_rtc()
- true if set, false if user declinesutil
string util.bytes_to_hex(string data)
string util.hex_to_bytes(string hexstring)
string util.get_datestamp()
string util.get_timestamp()
bool util.running_as_module()
io
This is a Lua built-in module but liolib.c can't be used as-is due to fopen and friends not working properly. To have this module we need to either:
make fopen/etc. work (maybe with a newlib device? i don't know what i'm doing here)update liolib.c to use fatfs functions (this is much harder than it seems, i already tried this before, and could make it harder to update Lua)create a custom io library in Cos
This is also a Lua built-in module, but @Gruetzig has already re-implemented most, if not all, of it.
Other stuff
Call a function likeset_flags()
beforefs.copy("S:/nand.bin", "0:/nand.bin", {silent=true, no_cancel=true})
Use bit flags as an extra argument e.g.fs.copy("S:/nand.bin", "0:/nand.bin", CMD_SILENT | CMD_NO_CANCEL)
GM9Script and Lua comparison
Preview
Unlike the
PREVIEW_MODE
GM9Script variable, this has been split into multiple functions.Other constants