File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,22 @@ console.log(add(5, 7)); // 12
9595// Call JS from Lua
9696lua .setGlobal (" add" , (a , b ) => a + b);
9797console .log (lua .eval (" return add(3, 4)" )); // 12
98+
99+ // JS function with multiple returns
100+ lua .setGlobal (" getUser" , () => [" Alice" , 30 ]);
101+ lua .eval (" name, age = getUser()" );
102+ console .log (lua .getGlobal (" name" )); // "Alice"
103+ console .log (lua .getGlobal (" age" )); // 30
104+
105+ // JS function that throws an error
106+ lua .setGlobal (" throwError" , () => {
107+ throw new Error (" Something went wrong" );
108+ });
109+ const result = lua .eval (`
110+ local ok, err = pcall(throwError);
111+ return { ok, err }
112+ ` );
113+ console .log (result); // { 1: false, 2: "Error: Something went wrong" }
98114```
99115
100116** Get Table Length**
You can’t perform that action at this time.
0 commit comments