Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request / QOL] Environment proxy #8

Open
davidkra230 opened this issue Dec 30, 2024 · 0 comments
Open

[Feature Request / QOL] Environment proxy #8

davidkra230 opened this issue Dec 30, 2024 · 0 comments

Comments

@davidkra230
Copy link

An environment proxy (like getfenv(0)) or a way to define the environment through a table through an extra parameter in luau_run

The traditional method for compiling and running Luau via this project would be:

local bc = module.luau_compile([[
	print(getsetfenv())
]], 2, 0, 0, 0)

print("compiled: " .. bc)

print("execution return: " .. tostring(module.luau_run(bc)))

The proposed way of after implementation:

local bc = module.luau_compile([[
	print(getsetfenv())
]], 2, 0, 0, 0)

print("compiled: " .. bc)

print("execution return: " .. tostring(module.luau_run(bc, getfenv(0))))

-- OR --

local bc = module.luau_compile([[
	print(getsetfenv())
]], 2, 0, 0, 0)

print("compiled: " .. bc)

local environment = {
	game = game,
	workspace = workspace,
	script = script,
	...
}

print("execution return: " .. tostring(module.luau_run(bc, environment)))

you could traverse the table and add the globals with the Lua C api, but that wouldn't work with getfenv and custom datatypes could be problematic.
or maybe by hooking lua_getglobal in some way?
or even by modifying LUA_GLOBALSINDEX?
perhaps this stackoverflow question could have relevant information?

This is somewhat of a draft & just a suggestion, if I find anything related or make any progress, I can reply with the new information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant