-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Feature Request: Promise Feature #206
Comments
The lua API is synchronous. Why/when would you have a promise? |
My apologizes- late night last night lol. In that case - how does one execute a function via the JS API so that if an error occurs in Lua - a nim value is returned. You can console log it / use it in the HTML document etc. When I tried executing a false function via JS API such as something random like "bshfhfjgh". It throws an error in console log. Tho I do not know how to handle the error message / return the Lua error message in preferably in Pure JS (not in Lua such as the REPL example on homepage). ps; thanks for quick reply @daurnimator 👌 |
@MarketingPip I think what you want is this |
@catwell thank you 👌 |
@catwell - can you give me a demo of usage please... sorry to be a noob but I can't seem to catch the errors properly still. |
See the code that @catwell linked: let status = lua_pcall(L, nargs, 1, 0);
let r = tojs(L, -1);
lua_pop(L, 1);
switch(status) {
case LUA_OK:
return r;
default:
throw r;
} To use the fengari API, you call
What is "a nim value"? Or is your whole question about how to use |
@daurnimator sorry to be a complete noob again. 😞 I'm trying my best to find the documentation / repo etc I need to do this properly. But I'm thinking I should ask directly here. Plus I would assume you might want to possibly document this / make it stick out more in the documentation. I am trying to evaluate Lua commands from a user input in the browser (like the demo on homepage - but NOT in Lua.) Can you please provide the the import statements / usage on how to do this. As I can't seem to figure this out myself. Just to clarify - I know I'll need the feature / example usage to properly change error messages from being displayed in console etc. & example of calling p_call with usage of a import module in the web browser. A example with import from CDN link would be great. Off topic as well - I was hoping to ask this. Is the CSS for the terminal on the home page taken from somewhere etc..? Or is it custom made? And am I allowed to use it commercially or non commercially? Thanks in advanced 👌 |
error messages aren't shown in the console unless you put them there. (which e.g. fengari-web does for |
@daurnimator - my apologizes I said that at the start! I didn't know what repo I should be posting under :( Should I redirect my question / issue there? And if not - can I ask for example of usage via I am looking looking to achieve something like the following - import {fengari-web} from "CDN-URL"
function runLuaCommand(command){
try {
// display Fengari Web output to DOM
document.body.innerHTML =jscall(command)
} catch (error) {
// display Fengari Web errors to DOM
document.body.innerHTML = error;
} Which I do understand know I need to check if NIL value is included (not use a try / catch statement) - but again still confused on what library I need to use / the proper command to call and how to disable console log messages etc... Sorry again to ask you to literally spoon feed this to me - but I am struggling trying to find the proper usage via Fengari to do this. (hence I figured this was best repo to post in! not knowing if I require web version or etc...).
|
@MarketingPip perhaps have a look at how we do it on the fengari website itself: ==> we replace the |
@daurnimator - yeah I seen the website version (hence I also asked about the CSS licensing used / if it's a public library etc as well!) But didn't know if there was a way to write it in purely JS to call the Lua Compiler - without allowing access to the DOM. < which I guess would be my feature request if again - there is no way to directly do this already. |
There is. That is the lower level on top of which everything else is built. It's the standard Lua C API. And then you have fengari-interop to help you marshall values to/from. fengari-web is to make it so you can write Lua in the browser just like you can write Javascript. You're simultaneously asking for low level features and high level features, and it doesn't quite make sense. |
@daurnimator I am sorry to be a noob but can I please get a demo / sample of what I need. I did figure out how to execute code in a try / catch etc. But I do not get Nil returned - and only other error messages in (stack, message). As well the online demo - the same random commands "just some random letters" typed would return sometimes a Nil message other times the error .message key (I do believe) |
It would be nice to have a promise based feature to execute code via the JavaScript API.
Maybe - I missed this in documentation (but I am searching deeply & don't see anything).
An await function would be more than ideal that either throws an error so you can catch it or etc...
The text was updated successfully, but these errors were encountered: