-
Notifications
You must be signed in to change notification settings - Fork 13
LuaContext
LuaContext represents a Lua scope. Its use is pretty straightforward:
LuaContext ctx = new LuaContext();
var a = ctx.Get("a"); // Gets variable a.
// Returns LuaObject.Nil if the variable doesn't exist.
ctx.SetGlobal("print", (LuaFunction)print); // Sets a global variable with a function value_LuaContext_s can also be created specifying a parent context. This affects the behavior of the class' methods.
ctx.SetLocal(string Name, LuaObject Value)SetLocal checks whether a variable with the same name exists in the current scope. If it does, it updates its value with the specified one. Else, it creates a new variable and sets it.
ctx.SetGlobal(string Name, LuaObject Value)SetGlobal acts like SetLocal if the current context has no parent. If it has, it calls SetGlobal with the same arguments on its parent and so on, until the root context is found.
ctx.Set(string Name, LuaObject Value)Set checks if the specified variable already exists in the context. If it does, it updates its value. Else, it calls Set on the parent node. If the current context has no parent context, it creates a new variable.
LuaObject obj = ctx.Get(string Name)Get returns the nearest variable with the specified name. I.e, if the current context contains the specified variable, it returns it. If it doesn't, it calls Get on the parent context.