# How does work Lua interprerer for HTML5?

**URL:** <https://forum.defold.com/t/how-does-work-lua-interprerer-for-html5/79062>\
**Category:** Questions\
**Created:** [December 5, 2024, 8:01am UTC](https://forum.defold.com/t/how-does-work-lua-interprerer-for-html5/79062 "2024-12-05T08:01:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![errorstrike](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/errorstrike/32/35094_2.png) [@errorstrike](https://forum.defold.com/u/errorstrike)\
**Post date:** [December 5, 2024, 8:01am UTC](https://forum.defold.com/t/how-does-work-lua-interprerer-for-html5/79062/1 "2024-12-05T08:01:58Z")

</div>

I did read that an interpretered Lua (not LuaJIT) compiles and execute line by line (step by step) the code.  
However, are compiled fragments of code stored in RAM? Or does Lua compile same line again and again?  
If I declaired a local function before “init” function, and this local function was used in first frame in “update”, does this function compiled again and again every frame? Or the system stores this function as a binary in RAM and uses it?  
And second question. About garbage collector. I did read, that it’s possible to switch it in the manual mode in another Lua apps. So, is it possible to use a manual gabage collector in Defold?  
For example, the gabage collector can be launched then game menu is opened, a mission is complete etc.

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [December 5, 2024, 8:29am UTC](https://forum.defold.com/t/how-does-work-lua-interprerer-for-html5/79062/2 "2024-12-05T08:29:03Z")

</div>

> [@errorstrike](#):
>
> And second question. About garbage collector. I did read, that it’s possible to switch it in the manual mode in another Lua apps. So, is it possible to use a manual gabage collector in Defold?  
> For example, the gabage collector can be launched then game menu is opened, a mission is complete etc.

> **[Memory and garbage collection - Lua programming in Defold](https://defold.com/manuals/lua/?q=collectgarbage#memory-and-garbage-collection)**
>
> The Defold engine has the Lua language embedded for scripting. Lua is a lightweight dynamic language that is powerful, fast, and easy to embed. It is widely used as a videogame scripting language. Lua programs are written in a simple procedural...

> **[API reference (Base)](https://defold.com/ref/stable/base/?q=collectgarbage#collectgarbage:%5Bopt%5D-%5Barg%5D)**
>
> Defold is a free and open game engine used for development of console, desktop, mobile and web games.

---

<div class="post-metadata">

**Author:** ![errorstrike](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/errorstrike/32/35094_2.png) [@errorstrike](https://forum.defold.com/u/errorstrike)\
**Post date:** [December 6, 2024, 6:50am UTC](https://forum.defold.com/t/how-does-work-lua-interprerer-for-html5/79062/3 "2024-12-06T06:50:32Z")

</div>

I made game object “system”, and added the script, where in “update” function the gabarge collector forcely collects everything and stop itself after it (every frame). Performance became absolutly smooth! Thanx!  
I didn’t ubderstand before that every function with arguments makes garbage table. But real-time games needs “go.set\_position()”, “go.set\_rotation()” every frame. So, I guess it is better, to collect in every frame explicitly.

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [December 6, 2024, 8:39am UTC](https://forum.defold.com/t/how-does-work-lua-interprerer-for-html5/79062/4 "2024-12-06T08:39:36Z")

</div>

> [@errorstrike](#):
>
> I made game object “system”, and added the script, where in “update” function the gabarge collector forcely collects everything and stop itself after it (every frame). Performance became absolutly smooth! Thanx!

Other approach: [Bore blasters - #8 by Alex\_8BitSkull](https://forum.defold.com/t/bore-blasters/73228/8)
