-
Notifications
You must be signed in to change notification settings - Fork 14
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
Http tools for Finale Lua #333
Comments
Last time I just emailed him. Will do that again. |
My initial thoughts is that I like this proposal. I'd almost say that anything that isn't core to RGP Lua should probably be in a separate, public repository. Do you have a strong preference towards using C or C++? In my opinion, Rust would be a better language for this project for a few reasons:
Rust also has the exact same runtime performance as C++, so performance should not be an issue. There are just two main hurdles I see if using Rust:
https://firefox-source-docs.mozilla.org/writing-rust-code/cpp-interop.html |
I know nothing about Rust, so I can't comment, except as follows:
C++ is not for the faint of heart. Having said that, I'm not sure how much onboarding there needs to be. Hopefully this project is limited in scope. This is a lua project, after all. 🤣 |
I did a little more research and realized that luasocket already has http running over luasocket. It should simply be a matter of installing these in a sub-directory called "socket" and then all the requires should work. (Similar to the "library" sub-directory we use.) I need to make sure that RGP Lua is including all the C components. |
Including luasocket sounds like a good and easy solution to me. Currently my plug-ins on macOS use "curl" and on Windows PowerShell with WebClient.DownloadFile ( https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadfile?view=net-6.0 ). |
You can probably get luasocket to work without waiting for a release of RGP Lua. Building the full version in has its challenges, but I'm hoping they are surmountable. |
In considering this further, I'm thinking it would be much cleaner not to have this embedded in RGP Lua at all. (Embedding more than the core luasocket library starts to get right messy, because of the mix of lua and c code.) Right now the challenge with luasocket is accessing it in a way that isn't highly dependent on the end-user setup. Maybe the time would be better spend creating a full luasocket package that's easy to have self-contained with any script that needs it. |
Following up on this, RGP Lua 0.64, when luasocket is requested, will load both local socket = require('socket')
local socket = require('socket.core') I've run into both variants in various scripts that use luasocket. In addition, when luasocket is requested, RGP Lua 0.64 will preload |
To get it to work the way we'd like (so that the
-- This require function would be pre-loaded. I'm showing here for now.
raw_require = require
function require(item)
if item ~= "socket.core" then
local _, end_index = item:find("^socket%.")
if end_index then
item = item:sub(end_index+1)
end
end
return raw_require(item)
end This allows all the luasocket lua sources to reside in an arbitrary directory. For my testing I'm pulling them straight out of the luasocket repo. The following code is working for me with script debugging enabled on the latest dev build of RGP Lua. -- This require function would be pre-loaded. I'm showing here for now.
raw_require = require
function require(item)
if item ~= "socket.core" then
local _, end_index = item:find("^socket%.")
if end_index then
item = item:sub(end_index+1)
end
end
return raw_require(item)
end
if finenv.IsRGPLua then
require('mobdebug').start()
end
local socket_source_path = finenv.RunningLuaFolderPath() .. "../lua-source/luasocket/?.lua"
socket_source_path = socket_source_path .. ";" .. finenv.RunningLuaFolderPath() .. "../lua-source/luasocket/src/?.lua"
package.path = package.path .. ";" .. socket_source_path
local http = require 'http'
print("http:")
for k, v in pairs(http) do
print(k, v)
end
local mime = require 'mime'
print("")
print("mime")
for k, v in pairs(mime) do
print(k, v)
end I would only replace the |
I think the best approach for this is, if only debugging is requested ("Enable Debugging" in the configuration or What about making the override of the |
More followup. I realized we don't need an additional option in |
After working with @JAngermueller with So I'm back to the idea of a C++ module. It seems like my time would be better spent creating a simple file downloader using built-in OS tools than trying to get Assuming that we may need to grow it past a simple https file downloader, what would be a good open-ended name for it? How about |
I have created a luaostools repository. The release binaries I'm still working on cleaning up some of the error reporting, but the |
Requirement
It is becoming apparent that there is a need to be able to download files from the web and manipulate them in various ways. This includes potentially updating script files and the like. One of the challenges is that it is very bad form to download files from the web in synchronous calls. An asynchronous approach would be ideal.
Describe the solution you'd like
I would like to keep the core RGP Lua functions clean from this for a few reasons:
luasocket
currently is (and add an option to load or not load it per script).dll
ordylib
andrequire
the latest version without dependence on a new version release of RGP Lua.Therefore I am proposing a new C++ repository, perhaps called
lua-httptools
to live in thefinalelua
organization. It will make use of OS-level http calls, or any other tools available to C++ development environments, to process http calls.Describe alternatives you've considered
I have considered a built-in
finenv
function to download a file. But this is very problematic becausefinenv
. It has nothing to do with Finale and will not be dependent on the PDK Framework.I also looked for existing open-source projects. There are a fair number of them, but they are all quite heavy and have lots of dependencies. It's more work than I have interest in to figure them out, but it would probably be possible to get one of them to work if someone wants to try. This might be a good first step for an interested party.
Ultimately, I suspect that a C/C++ library that can directly access the OS apis and is more tailored to the needs of Finale lua will be a good compromise. It can be built into RGP Lua (as an automatic load-in to the Lua state) but it can also be loaded externally if needed.
Next Steps
If someone is interested, they can look into a 3rd party library and see if it can be made to work in RGP Lua. That might short-circuit the whole conversation.
I will migrate the code I have put into
finenv
into a shell library that can be built with RGP Lua but be independent as a code base. It will be very rudimentary and ultimately probably not the final API. But it will at least start the project.We need to be thinking about how to structure the api. To start with, the library will have a single function,
httptools.get_file_synchronous
. Then more interested parties than I can start adding to it in ways that seem interesting to them. Initially it will not be included in RGP Lua until we can gauge the interest and utility. Instead, it will be built as an external library that can be required by any script that needs it. In fact, you'll be able to debug it through Finale as described at sample-clib. I intend to use that libary as my starting point.@Nick-Mazuk could you set things up so that we can tag Jan Angermüller? I suspect he will be quite interested in this as well.
The text was updated successfully, but these errors were encountered: