Ok, I understand now. Requires are a bit specially treated in Defold to statically include them in the build/bundling process.
You have to use sys.load_resource() to get custom content into the game. You can use lua’s loadfile() function, but that will only work locally as long as the loaded file exist in the local filesystem. As soon as you bundle, that changes and everything is packed in archives. sys.load_resource() is required to load files off the bundled archive. loadstring() returns a function that evaluates the code in the string when the function is called.
local code_str = sys.load_resource("/main/test.lua")
local f = assert(loadstring(code_str))
pprint(f()) -- Note that we call f()!
main/test.lua:
test = "4711"
return test
Also remember to add the lua file to custom resources in “game.project”:
[project]
title = My project
version = 0.1
custom_resources = main/test.lua
...