# Load lua code at runtime

**URL:** <https://forums.solar2d.com/t/load-lua-code-at-runtime/357601>\
**Category:** General Questions/Discussion\
**Created:** [October 23, 2025, 11:32pm UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601 "2025-10-23T23:32:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aryajur](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/87869e/32.png) [@aryajur](https://forums.solar2d.com/u/aryajur)\
**Post date:** [October 23, 2025, 11:32pm UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/1 "2025-10-23T23:32:08Z")

</div>

I am trying to find out how can I enable loading Lua scripts in a sandbox environment that I would create in my App.  
I have seen some previous discussions saying that this would not be allowed by Android and iOS. I don’t know how some of the apps like:  
[Lua-IDE](https://apps.apple.com/us/app/lua-ide/id1549382090) and  
[Luadroid](https://play.google.com/store/apps/details?id=com.alif.ide.lua&hl=en_US)

make that possible?  
Can we make a plugin for solar2d to add that functionality since solar2d api does not have load()?

---

<div class="post-metadata">

**Author:** ![Scott\_Harrison](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Scott\_Harrison](https://forums.solar2d.com/u/Scott_Harrison)\
**Post date:** [October 24, 2025, 12:39am UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/2 "2025-10-24T00:39:29Z")

</div>

It’s possible, I thought about at one point making a host for this but I have been super busy 🙂

I made a plugin for this

> **[GitHub - scottrules44/deploy-source](https://github.com/scottrules44/deploy-source)**
>
> Contribute to scottrules44/deploy-source development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![aryajur](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/87869e/32.png) [@aryajur](https://forums.solar2d.com/u/aryajur)\
**Post date:** [October 24, 2025, 1:20am UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/3 "2025-10-24T01:20:41Z")

</div>

Thanks a lot for sharing this! I see you use loadstring, I did not know that this function is available. It is not documented in the API.

---

<div class="post-metadata">

**Author:** ![tomsk](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/c6cbf5/32.png) [@tomsk](https://forums.solar2d.com/u/tomsk)\
**Post date:** [October 26, 2025, 10:26am UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/4 "2025-10-26T10:26:05Z")

</div>

This is great, thanks Scott. When you say ‘making a host’ what do you mean? It would be _amazing_ to have the equivalent of Live Builds for production with the lua code and images etc stored on a server and synced to each client when it changes. Reading the latest guidelines, it looks to me like Apple allow this now, provided you don’t use it to make your app do something that goes against the published description.

---

<div class="post-metadata">

**Author:** ![bgmadclown](https://forums.solar2d.com/user_avatar/forums.solar2d.com/bgmadclown/32/490_2.png) [@bgmadclown](https://forums.solar2d.com/u/bgmadclown)\
**Post date:** [October 31, 2025, 10:23am UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/5 "2025-10-31T10:23:09Z")

</div>

Would something like “Patcher” work for you?

> **[RG\_FreeStuff/Products/patcher at master · roaminggamer/RG\_FreeStuff](https://github.com/roaminggamer/RG_FreeStuff/tree/master/Products/patcher)**
>
> Roaming Gamer's Free Stuff Repository. Contribute to roaminggamer/RG\_FreeStuff development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![tomsk](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/c6cbf5/32.png) [@tomsk](https://forums.solar2d.com/u/tomsk)\
**Post date:** [November 3, 2025, 8:06am UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/6 "2025-11-03T08:06:49Z")

</div>

Ah thanks for replying @bgmadclown - will check that out. That’s a separate approach to the one @Scott_Harrison posted?

---

<div class="post-metadata">

**Author:** ![aryajur](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/87869e/32.png) [@aryajur](https://forums.solar2d.com/u/aryajur)\
**Post date:** [November 4, 2025, 12:23am UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/7 "2025-11-04T00:23:29Z")

</div>

Thanks for mentioning it. Yes that will work. I did not know if loadstring works. Seems like it does. If it works then I think that will solve my purpose.

---

<div class="post-metadata">

**Author:** ![bgmadclown](https://forums.solar2d.com/user_avatar/forums.solar2d.com/bgmadclown/32/490_2.png) [@bgmadclown](https://forums.solar2d.com/u/bgmadclown)\
**Post date:** [November 5, 2025, 11:21am UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/8 "2025-11-05T11:21:52Z")

</div>

I haven’t used any of them but I believe @Scott_Harrison 's solution is mostly for running code in runtime and `Patcher` is aimed at updating the application, skipping the review process. I don’t want to mess it up for you so I suggest you review both libraries.

---

<div class="post-metadata">

**Author:** ![roaminggamer](https://forums.solar2d.com/user_avatar/forums.solar2d.com/roaminggamer/32/134_2.png) [@roaminggamer](https://forums.solar2d.com/u/roaminggamer)\
**Post date:** [November 9, 2025, 3:46am UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/9 "2025-11-09T03:46:25Z")

</div>

I’m late replying, but I believe patcher still works. I tested it on Windows and it works fine. You’ll want to test it on OS X, Android, and iOS yourself.

Here is a link to an example app using it. Read main.lua to puzzle out what is happening in the example:

[https://github.com/roaminggamer/RG\_FreeStuff/raw/refs/heads/master/myPluginSamples/patcher/patcher-example.zip](https://github.com/roaminggamer/RG_FreeStuff/raw/refs/heads/master/myPluginSamples/patcher/patcher-example.zip)

Also, be aware you don’t have to use it as a plugin. You can get the source for patcher.lua from my RG\_FreeStuff repository on [github.com](http://github.com) here: [https://github.com/roaminggamer/RG\_FreeStuff/raw/refs/heads/master/Products/patcher/patcher.lua](https://github.com/roaminggamer/RG_FreeStuff/raw/refs/heads/master/Products/patcher/patcher.lua)

Just remove the plugin stuff from build.settings:

```auto
	plugins =
    {
        ["plugin.patcher"] = { publisherId = "com.roaminggamer" },
    },  

```

, then include the patcher.lua file in your project and require it directly.

Note: You will want to use patcher’s version of require all the time. Again, see main.lua of the example to puzzle out how it works.

As a starter try this sequence of interactions when you run the example app.

1. Click the top 3 sliders (leave caching off).
2. Click the ‘Load Module’ button.
3. Click the ‘Test Module’ button. This will use the original (local) copy of the module and its functions.
4. Click ‘Download Patch File v3’
5. Click ‘Test Module’ button again. Notice it still runs the original copy of the script file.
6. Click ‘Load Module’ then click ‘Test Module’. Notice it now uses the v3 version of the myModule file.

I think you can puzzle out the rest by reading the example and playing with the app.

RG\_FreeStuff++:

> **[GitHub - roaminggamer/RG\_FreeStuff: Roaming Gamer's Free Stuff Repository](https://github.com/roaminggamer/RG_FreeStuff)**
>
> Roaming Gamer's Free Stuff Repository. Contribute to roaminggamer/RG\_FreeStuff development by creating an account on GitHub.

> **[RG\_FreeStuff/Products at master · roaminggamer/RG\_FreeStuff](https://github.com/roaminggamer/RG_FreeStuff/tree/master/Products)**
>
> Roaming Gamer's Free Stuff Repository. Contribute to roaminggamer/RG\_FreeStuff development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![tomsk](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/c6cbf5/32.png) [@tomsk](https://forums.solar2d.com/u/tomsk)\
**Post date:** [November 17, 2025, 3:27pm UTC](https://forums.solar2d.com/t/load-lua-code-at-runtime/357601/10 "2025-11-17T15:27:20Z")

</div>

Thanks so much for replies! Will experiment!

Tom
