Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

LuaContext

Francesco Bertolaccini edited this page Nov 28, 2013 · 2 revisions

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

Constructor

_LuaContext_s can also be created specifying a parent context. This affects the behavior of the class' methods.

Methods

LuaContext.SetLocal

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.

LuaContext.SetGlobal

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.

LuaContext.Set

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.

LuaContext.Get

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.

Clone this wiki locally