"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["6041"],{142:function(e,t,n){n.r(t),n.d(t,{default:()=>h,frontMatter:()=>a,metadata:()=>s,assets:()=>c,toc:()=>d,contentTitle:()=>l});var s=JSON.parse('{"id":"languages/lua","title":"Lua","description":"Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.","source":"@site/docs/languages/lua.mdx","sourceDirName":"languages","slug":"/languages/lua","permalink":"/docs/languages/lua","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/languages/lua.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Lua (Wasm)","permalink":"/docs/languages/lua-wasm"},"next":{"title":"Malina.js","permalink":"/docs/languages/malina"}}'),i=n("5893"),r=n("65"),o=n("3365");let a={},l="Lua",c={},d=[{value:"Usage",id:"usage",level:2},{value:"Language Info",id:"language-info",level:2},{value:"Name",id:"name",level:3},{value:"Extension",id:"extension",level:3},{value:"Editor",id:"editor",level:3},{value:"Compiler",id:"compiler",level:2},{value:"Version",id:"version",level:3},{value:"Code Formatting",id:"code-formatting",level:2},{value:"Starter Template",id:"starter-template",level:2},{value:"Links",id:"links",level:2}];function u(e){let t={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",p:"p",ul:"ul",...(0,r.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.header,{children:(0,i.jsx)(t.h1,{id:"lua",children:"Lua"})}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.a,{href:"https://www.lua.org/",children:"Lua"})," is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description."]}),"\n",(0,i.jsxs)(t.p,{children:["LiveCodes runs Lua in the browser using ",(0,i.jsx)(t.a,{href:"https://fengari.io/",children:"Fengari"}),"."]}),"\n",(0,i.jsxs)(t.blockquote,{children:["\n",(0,i.jsx)(t.p,{children:"Fengari (Moon in greek) is the Lua VM written in JavaScript. It uses JavaScript's garbage collector so that interoperability with the DOM is non-leaky."}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.a,{href:"https://fengari.io/",children:"fengari.io"})}),"\n"]}),"\n",(0,i.jsx)(t.admonition,{title:"Note",type:"info",children:(0,i.jsxs)(t.p,{children:["LiveCodes also supports running Lua using ",(0,i.jsx)(t.a,{href:"https://github.com/ceifa/wasmoon",children:"Wasmoon"})," which is a real Lua 5.4 VM with JS bindings made with WebAssembly. Read documentation ",(0,i.jsx)(t.a,{href:"/docs/languages/lua-wasm",children:"here"})]})}),"\n",(0,i.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,i.jsxs)(t.p,{children:["LiveCodes runs Lua in the browser. JavaScript interoperability and DOM access is achieved using ",(0,i.jsxs)(t.a,{href:"https://github.com/fengari-lua/fengari-interop",children:[(0,i.jsx)(t.code,{children:'"js"'})," module"]}),"."]}),"\n","\n",(0,i.jsx)(t.p,{children:"This example demonstrates usage, JavaScript interoperability and DOM access:"}),"\n",(0,i.jsx)(o.Z,{template:"lua",height:"80vh"}),"\n",(0,i.jsx)(t.h2,{id:"language-info",children:"Language Info"}),"\n",(0,i.jsx)(t.h3,{id:"name",children:"Name"}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.code,{children:"lua"})}),"\n",(0,i.jsx)(t.h3,{id:"extension",children:"Extension"}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.code,{children:".lua"})}),"\n",(0,i.jsx)(t.h3,{id:"editor",children:"Editor"}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.code,{children:"script"})}),"\n",(0,i.jsx)(t.h2,{id:"compiler",children:"Compiler"}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.a,{href:"https://fengari.io/",children:"Fengari"})}),"\n",(0,i.jsx)(t.h3,{id:"version",children:"Version"}),"\n",(0,i.jsx)(t.p,{children:"Fengari v0.1.4"}),"\n",(0,i.jsx)(t.h2,{id:"code-formatting",children:"Code Formatting"}),"\n",(0,i.jsxs)(t.p,{children:["Using ",(0,i.jsx)(t.a,{href:"https://github.com/trixnz/lua-fmt",children:(0,i.jsx)(t.code,{children:"lua-fmt"})}),"."]}),"\n",(0,i.jsx)(t.h2,{id:"starter-template",children:"Starter Template"}),"\n",(0,i.jsx)(t.p,{children:(0,i.jsx)(t.a,{href:"https://livecodes.io/?template=lua",children:"https://livecodes.io/?template=lua"})}),"\n",(0,i.jsx)(t.h2,{id:"links",children:"Links"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://www.lua.org/",children:"Lua"})}),"\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://www.lua.org/docs.html",children:"Lua documentation"})}),"\n",(0,i.jsx)(t.li,{children:(0,i.jsx)(t.a,{href:"https://fengari.io/",children:"Fengari"})}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.a,{href:"/docs/languages/lua-wasm",children:"lua-wasm"})," in LiveCodes"]}),"\n"]})]})}function h(e={}){let{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}},3365:function(e,t,n){n.d(t,{Z:()=>f});var s=n("5893"),i=n("4200"),r=n("7294"),o=n("8294");function a(e){let t=(0,r.useRef)(null),[n,i]=(0,r.useState)(e.className||""),[a,l]=(0,r.useState)(e.style||{}),[c,d]=(0,r.useState)(e.height),[u,h]=(0,r.useState)(),[g,p]=(0,r.useState)(JSON.stringify(e.config||"")),[m,f]=(0,r.useState)("");return(0,r.useEffect)(()=>{if(!t.current)return;let{className:n,style:s,height:r,sdkReady:a,config:c,...v}=e;if(i(n||""),l(s||{}),d(r),u&&m===JSON.stringify(v)){if(g===JSON.stringify(c))return;p(JSON.stringify(c)),"string"==typeof c?fetch(c).then(e=>e.json()).then(e=>{u?.setConfig(e)}):c&&u.setConfig(c)}else f(JSON.stringify(v)),u?.destroy(),(0,o.T)(t.current,{config:c,...v}).then(e=>{h(e),"function"==typeof a&&a(e)})},[e]),(0,r.useEffect)(()=>()=>{u?.destroy()},[]),(0,s.jsx)("div",{ref:t,className:n,style:a,"data-height":c})}var l=n("1858"),c=n("3262"),d=n("1705"),u=n("7645"),h=n("8168"),g=n("8228"),p=n("5050");function m(e){let[t,n]=(0,r.useState)(e.js),[i,o]=(0,r.useState)(e.ts),[a,l]=(0,r.useState)(e.react),[m,f]=(0,r.useState)(e.vue),[v,y]=(0,r.useState)(e.svelte),j="3.7rem",[x,w]=(0,r.useState)(!0),[b,S]=(0,r.useState)(j),L=(0,r.useRef)(null),C=()=>{setTimeout(()=>{S(`calc(${L.current.offsetHeight}px + ${j})`)},5),setTimeout(()=>{S(`calc(${L.current.offsetHeight}px + ${j})`)},255)};return(0,r.useEffect)(()=>{if(c.Z.canUseDOM){let e=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"js";try{return window.prettier?.format(e,{parser:"html"===t?"html":"babel",plugins:window.prettierPlugins})}catch{return e}};n(e(t,"js")),o(e(i,"ts")),l(e(a,"jsx")),f(e(m,"html")),y(e(v,"html"))}},[]),(0,s.jsxs)("details",{className:`alert alert--info ${p.Z.details} ${g.Z.details}`,"data-collapsed":x,style:{height:x?j:b,overflow:"hidden",willChange:"height",transition:`height ${x?"250ms":"265ms"} ease-in-out 0s`,margin:"1em 0"},children:[(0,s.jsx)("summary",{onClick:()=>{w(!x),C()},children:"show code"}),(0,s.jsx)("div",{ref:L,style:{display:"block",overflow:"hidden"},children:(0,s.jsx)("div",{className:p.Z.collapsibleContent,children:(0,s.jsxs)(h.Z,{groupId:"sdk-code",children:[(0,s.jsx)(u.Z,{value:"js",label:"JS",attributes:{onMouseDown:C},children:(0,s.jsx)(d.Z,{language:"js",children:t})}),(0,s.jsx)(u.Z,{value:"ts",label:"TS",attributes:{onMouseDown:C},children:(0,s.jsx)(d.Z,{language:"ts",children:i})}),(0,s.jsx)(u.Z,{value:"react",label:"React",attributes:{onMouseDown:C},children:(0,s.jsx)(d.Z,{language:"jsx",children:a})}),(0,s.jsx)(u.Z,{value:"vue",label:"Vue",attributes:{onMouseDown:C},children:(0,s.jsx)(d.Z,{language:"html",children:m})}),(0,s.jsx)(u.Z,{value:"svelte",label:"Svelte",attributes:{onMouseDown:C},children:(0,s.jsx)(d.Z,{language:"html",children:v})})]})})})]})}function f(e){let{className:t,style:n,showCode:r,height:o,...c}=e,{colorMode:d}=(0,i.I)(),u=e=>JSON.stringify(e,null,2),h=`
import { createPlayground } from 'livecodes';
const options = ${u(c)};
createPlayground('#container', options);
`.trimStart(),g=`
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = ${u(c)};
createPlayground('#container', options);
`.trimStart(),p=`
import LiveCodes from 'livecodes/react';
export default function App() {
const options = ${u(c)};
return (