diff --git a/Library/Std/Export.md b/Library/Std/Export.md index e601f594..677c0d7a 100644 --- a/Library/Std/Export.md +++ b/Library/Std/Export.md @@ -89,7 +89,7 @@ event.listen { local mdTree = markdown.parseMarkdown(event.data.text) mdTree = markdown.expandMarkdown(mdTree) local html = markdown.markdownToHtml(markdown.renderParseTree(mdTree)) - editor.copyToClipboard(js.Blob({html}, {type="text/html"})) + editor.copyToClipboard(js.new(js.window.Blob, {html}, {type="text/html"})) editor.flashNotification "Copied rich text to clip board!" end } diff --git a/Library/Std/Widget.md b/Library/Std/Widget.md index 5f7f0b70..35f6f766 100644 --- a/Library/Std/Widget.md +++ b/Library/Std/Widget.md @@ -18,8 +18,10 @@ local widgetSchema = { markdown = { type = "string"}, html = { anyOf = { + -- HTMLElement { type = "object"}, - { type = "string" } + -- Plain HTML code + { type = "string" } } }, cssClasses = { @@ -48,4 +50,11 @@ function widget.new(spec) spec._isWidget = true return spec end + +-- Convenience function for HTML widgets +function widget.html(html) + return widget.new { + html = html + } +end ``` diff --git a/common/space_lua/runtime.ts b/common/space_lua/runtime.ts index 5889d5a4..49403ef1 100644 --- a/common/space_lua/runtime.ts +++ b/common/space_lua/runtime.ts @@ -586,7 +586,7 @@ export function luaGet( key: any, sf: LuaStackFrame, ): Promise | any { - if (!obj) { + if (obj === null || obj === undefined) { throw new LuaRuntimeError( `Attempting to index a nil value`, sf, diff --git a/common/space_lua/stdlib.ts b/common/space_lua/stdlib.ts index 0b49bbf3..4d717673 100644 --- a/common/space_lua/stdlib.ts +++ b/common/space_lua/stdlib.ts @@ -55,7 +55,11 @@ const pairsFunction = new LuaBuiltinFunction( } else if (t.keys) { keys = t.keys(); } else { - keys = Object.keys(t); // For plain JavaScript objects + // For plain JavaScript objects case, note: this will also includes keys from the prototype + keys = []; + for (const key in t) { + keys.push(key); + } } let i = 0; diff --git a/common/space_lua/stdlib/js.ts b/common/space_lua/stdlib/js.ts index 58f97845..ad63a3d2 100644 --- a/common/space_lua/stdlib/js.ts +++ b/common/space_lua/stdlib/js.ts @@ -69,17 +69,6 @@ export const jsApi = new LuaTable({ */ stringify: new LuaBuiltinFunction((_sf, val) => JSON.stringify(val)), - // Exposing DOM functions - createElement: new LuaBuiltinFunction((_sf, tag) => - document.createElement(tag) - ), - createTextNode: new LuaBuiltinFunction((_sf, text) => - document.createTextNode(text) - ), - Blob: new LuaNativeJSFunction(( - blobParts: any[], - options: BlobPropertyBag, - ) => { - return new Blob(blobParts, options); - }), + // Expose the global window object + window: window, });