luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau-lang.org
MIT License
3.8k stars 352 forks source link

Add fully global functionality to Luau. (_G) #1198

Closed creepersaur closed 3 months ago

creepersaur commented 3 months ago

I've made a post on the devforum if there's a better/correct way of achieving it here

Currently the _G table needs to be indexed before being able to access any of it's values. It would be a lot better if it worked like it does in Lua (from what I've seen) where _G would be declared globally and all functions inside would be accessible without indexing it.

Lua

function _G.hello()
    print('hi')
end

hello()

Luau

function _G.hello()
    print('hi')
end

_G.hello()

It's just a feature request so to speak, and I might be wrong about how this works, from what I've used in Roblox Studio though _G is used like that.

vegorov-rbx commented 3 months ago

It's up to the user of the Luau library to setup the environment in a way they like. If you compile Luau, you can keep _G unsandboxed and it will work like you describe.

The way Roblox setups their environment is up to them. This repository is not a support forum for Roblox.