Closed nullsoepic closed 4 months ago
require should work with local/relative paths in addition to urls, and Time() should absolutely use milliseconds (preferably unix time) instead of just seconds
require should work with local/relative paths in addition to urls, and Time() should absolutely use milliseconds (preferably unix time) instead of just seconds
I attempted to support relative paths (03006c8) but had a bunch of issues, still not sure how that could be implemented.
time already uses unix time, the reason for using seconds is compatibility with standard lua. We could have a argument/seperate function to get milliseconds
Fetch already supported non Json ?
My bad, looks like it does work, had an issue where github raw urls would just return a table with status 200 and no content so I assumed it just was not supported without looking at it enough.
Though the current implementation is a bit inconsistent, requests that return json will give you the json as a table, where as other requests that don't return json will give you a table with the raw content and status.
My implementation just gives you a table if its valid json, and a string with the raw response if it isn't. Looking at it now, it might be better to return a table with status and content in both cases and just have the content vary?
Should this comply with the sandbox change in #121?
Quoting the code change:
- let ok = lua.load(luacode).eval::<LuaMultiValue>();
+ if let Err(e) = lua.sandbox(true) {
+ lualog!("error", format!("failed to enable sandbox: {}", e));
+ Err(LuaError::runtime("failed to enable sandbox"))
+ } else {
+ let ok = lua.load(luacode).eval::<LuaMultiValue>();
+ }
Also, os.time()
has been added by #121 so there's no need for a dedicated time function.
Considering #121 has been merged, It is probably a good idea to do so, will update asap. Still need an opinion on the changes to fetch and suggestion from the previous comment
it might be better to return a table with status and content in both cases and just have the content vary
I agree with this but it will break current websites, I propose to revert the fetch behavior to the old one
Alright fetch will be reverted. Just to note, require still has to be given a http(s):// url as I could not get the taburl in the context of the function (any suggestions are appreciated). No ideas on how that could be properly implemented atm, will most likely remain as is for now.
It doesn't seem like you've reverted the fetch implementation as I'm getting this error (which doesn't occur on the master
branch):
runtime error: [string "src\b9\lua.rs:445:22"]:57: attempt to concatenate string with nil
I've tested the JSON utility and it seems to work, I'm gonna check out the require feature in a bit
Alright, everything seems to work
epic
This PR adds:
JSON
Can be just used as
json.stringify()
andjson.parse()
, no need to require/import anythingTime
Used as
time()
, returns seconds instead of millis like the standard luaos.time()
Require
Fetches, loads and executes some lua code from a url, and returns the output
Fetch
Fetch now supports responses that do not return JSON, for backwards compatibility and simplicity, a table will be returned if the response is valid JSON