darklua
DocumentationTry itGitHub

inject_global_value


Added in 0.3.5

Parameters


NameTypeDescriptionDefault
identifier

string

The name of the global variable
value

boolean, number or string

The value to inject

nil

env

string

An environment variable to read the value from (added in v0.7.0)

This rule will find a global variable and replace it with a given value. The value can be defined in the rule configuration or taken from an environment variable.

If value is not specified, the env property can be defined to read an environment variable that will be read into a string.

{
  rule: "inject_global_value",
  identifier: "GLOBAL",
  env: "SOME_VARIABLE",
}

This rule can be used in combination with the remove_unused_if_branch, compute_expression, and other rules, to eliminate dead branches. In addition to making your code smaller, it should make it faster (depending on how hot the code path is) since it is eliminating branch condition evaluations at client-side runtime.

Examples


if _G.AMOUNT > 10 or _G.CONSTANT ~= nil then
  --[[ ... ]]
end
InputOutput
if _G.AMOUNT > 10 or _G.CONSTANT ~= nil then
  --[[ ... ]]
end
if 11> 10 or 'Hello'~= nil then
  --[[ ... ]]
end