本文整理汇总了C#中NLua.LuaTable类的典型用法代码示例。如果您正苦于以下问题:C# LuaTable类的具体用法?C# LuaTable怎么用?C# LuaTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LuaTable类属于NLua命名空间,在下文中一共展示了LuaTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeLua
/// <summary>
/// Initializes the Lua environment
/// </summary>
private void InitializeLua()
{
// Create the Lua environment
LuaEnvironment = new NLua.Lua();
// Filter useless or potentially malicious libraries/functions
LuaEnvironment["os"] = null;
LuaEnvironment["io"] = null;
LuaEnvironment["require"] = null;
LuaEnvironment["dofile"] = null;
LuaEnvironment["package"] = null;
LuaEnvironment["luanet"] = null;
LuaEnvironment["load"] = null;
// Read util methods
setmetatable = LuaEnvironment["setmetatable"] as LuaFunction;
// Create metatables
//Type mytype = GetType();
LuaEnvironment.NewTable("tmp");
overloadselectormeta = LuaEnvironment["tmp"] as LuaTable;
//LuaEnvironment.RegisterFunction("tmp.__index", mytype.GetMethod("FindOverload", BindingFlags.Public | BindingFlags.Static));
LuaEnvironment.NewTable("tmp");
// Ideally I'd like for this to be implemented C# side, but using C#-bound methods as metamethods seems dodgy
LuaEnvironment.LoadString(
@"function tmp:__index( key )
local sftbl = rawget( self, '_sftbl' )
local field = sftbl[ key ]
if (field) then return field:GetValue( nil ) end
end
function tmp:__newindex( key, value )
local sftbl = rawget( self, '_sftbl' )
local field = sftbl[ key ]
if (field) then field:SetValue( nil, value ) end
end
", "LuaExtension").Call();
//LuaEnvironment.RegisterFunction("tmp.__index", mytype.GetMethod("ReadStaticProperty", BindingFlags.NonPublic | BindingFlags.Static));
//LuaEnvironment.RegisterFunction("tmp.__newindex", mytype.GetMethod("WriteStaticProperty", BindingFlags.NonPublic | BindingFlags.Static));
typetablemeta = LuaEnvironment["tmp"] as LuaTable;
LuaEnvironment["tmp"] = null;
LuaEnvironment.NewTable("tmp");
LuaEnvironment.LoadString(
@"function tmp:__index( key )
if (type( key ) == 'table') then
local baseType = rawget( self, '_type' )
return util.SpecializeType( baseType, key )
end
end
", "LuaExtension").Call();
generictypetablemeta = LuaEnvironment["tmp"] as LuaTable;
LuaEnvironment["tmp"] = null;
LuaEnvironment.NewTable("libraryMetaTable");
LuaEnvironment.LoadString(
@"function libraryMetaTable:__index( key )
local ptbl = rawget( self, '_properties' )
local property = ptbl[ key ]
if (property) then return property:GetValue( rawget( self, '_object' ), null ) end
end
function libraryMetaTable:__newindex( key, value )
local ptbl = rawget( self, '_properties' )
local property = ptbl[ key ]
if (property) then property:SetValue( rawget( self, '_object' ), value ) end
end
", "LuaExtension").Call();
libraryMetaTable = LuaEnvironment["libraryMetaTable"] as LuaTable;
LuaEnvironment["libraryMetaTable"] = null;
LuaEnvironment.NewTable("tmp");
PluginMetatable = LuaEnvironment["tmp"] as LuaTable;
LuaEnvironment.LoadString(
@"function tmp:__newindex( key, value )
if (type( value ) ~= 'function') then return rawset( self, key, value ) end
local activeAttrib = rawget( self, '_activeAttrib' )
if (not activeAttrib) then return rawset( self, key, value ) end
if (activeAttrib == self) then
print( 'PluginMetatable.__newindex - self._activeAttrib was somehow self!' )
rawset( self, key, value )
return
end
local attribArr = rawget( self, '_attribArr' )
if (not attribArr) then
attribArr = {}
rawset( self, '_attribArr', attribArr )
end
activeAttrib._func = value
attribArr[#attribArr + 1] = activeAttrib
rawset( self, '_activeAttrib', nil )
end
", "LuaExtension").Call();
LuaEnvironment["tmp"] = null;
}
示例2: BitwiseOr
public object BitwiseOr(LuaTable table)
{
// First of all, check it's actually an array
int size;
if (!table.IsArray(out size) || size == 0)
{
throw new InvalidOperationException("Specified table is not an array");
}
// Get the length
int result = -1;
Type type = null;
// Create the array
foreach (object key in table.Keys)
{
if (result < 0)
{
result = (int)table[key];
type = table[key].GetType();
continue;
}
result |= (int)table[key];
}
// Return it
return Enum.ToObject(type, result);
}
示例3: LuaGame
public LuaGame(string entryPath)
{
Window.Title = "Bubble Engine";
//create lua state
state = new BubbleLua (new Lua());
state.Lua.LoadCLRPackage ();
state.Bubble ["runtime"] = new LuaAPI.Runtime();
state.Bubble ["fonts"] = new LuaAPI.Fonts (FontContext);
luaGraphics = new LuaAPI.Graphics (null, this);
state.Bubble ["graphics"] = luaGraphics;
state.Bubble ["window"] = new LuaAPI.LWindow (Window);
LuaAPI.Util.RegisterEnum (typeof(Keys), state);
state.Lua ["embedres"] = new LuaAPI.EmbeddedLoader ();
//run init scripts
state.Lua.DoString(EmbeddedResources.GetString("BubbleEngine.LuaAPI.procure.lua"));
state.Lua.DoString(EmbeddedResources.GetString("BubbleEngine.LuaAPI.init.lua"));
//config
state.Lua.DoFile(entryPath);
gameTable = (LuaTable)state.Lua ["game"];
var cfg = (LuaFunction)gameTable ["config"];
if (cfg == null) {
throw new NLua.Exceptions.LuaScriptException ("Script must have a game.config() function", entryPath);
}
cfg.Call ();
updateFunction = (LuaFunction)gameTable ["update"];
drawFunction = (LuaFunction)gameTable ["draw"];
}
示例4: getTableDictionary
public Dictionary<object, object> getTableDictionary(LuaTable table)
{
if (!loaded)
return null;
return lua.GetTableDict(table);
}
示例5: Call
public static object Call(string name, LuaTable args = null)
{
Logger.Default.Log(":", false, MainClass.COLOR).Log(name);
var task = MainClass.GetLua().GetFunction (name);
if (task == null) {
throw new NotImplementedException ("Unknown task '" + name + "'");
}
object result = null;
var project = name.Split ('.')[0];
try {
if (args != null) {
result = task.Call (project, args);
} else {
result = task.Call (project);
}
} catch (Exception e) {
MainClass.Fail (e);
}
return result;
}
示例6: LuaToVector2
public static Vector2 LuaToVector2(LuaTable table)
{
Vector2 vector = new Vector2();
vector.X = (float)(double)table[0];
vector.Y = (float)(double)table[1];
return vector;
}
示例7: BubbleLua
public BubbleLua(Lua lua, bool init = true)
{
Lua = lua;
if (!init)
return;
Lua.NewTable ("bubble");
Bubble = (LuaTable)Lua ["bubble"];
lua.DoString (EmbeddedResources.GetString ("BubbleEngine.LuaAPI.bubbleinternal.lua"));
}
示例8: TableToLangDict
public object TableToLangDict(LuaTable table)
{
var dict = new Dictionary<string, string>();
foreach (var key in table.Keys)
{
if (key is string)
dict.Add((string)key, (string)table[key]);
}
return dict;
}
示例9: SetConfigFromTable
/// <summary>
/// Copies and translates the contents of the specified table into the specified config file
/// </summary>
/// <param name="config"></param>
/// <param name="table"></param>
public static void SetConfigFromTable(DynamicConfigFile config, LuaTable table)
{
config.Clear();
foreach (var key in table.Keys)
{
var keystr = key as string;
if (keystr == null) continue;
var value = TranslateLuaItemToConfigItem(table[key]);
if (value != null) config[keystr] = value;
}
}
示例10: Start
void Start()
{
LuaState = new Lua();
LuaState.LoadCLRPackage();
LuaState.LoadUnityExpand();
var ret = LuaState.DoString(@"return require 'requiretest'");
TestLib = ret[0] as LuaTable;
var startCallback = TestLib["Start"] as LuaFunction;
startCallback.Call(this.gameObject);
}
示例11: RegisterComponent
public static void RegisterComponent(string Name, LuaTable tab)
{
Util.Msg("Registring Component " + Name);
if(ComponentDictionary.ContainsKey(Name))
{
Util.Msg("Warning: Lua Component " + Name + " Already registered! Skipping");
return;
}
ComponentDictionary[Name] = tab;
}
示例12: fillRectangle
public void fillRectangle(double x, double y, double w, double h, LuaTable color)
{
if (color == null) {
Console.WriteLine ("Null color");
throw new Exception ();
}
Batch.FillRectangle (
new Rectangle (
(int)x, (int)y, (int)w, (int)h
),
Util.ColorFromTable (color)
);
}
示例13: SendDecisionMessage
public void SendDecisionMessage( LuaTable decisionsToSend )
{
if ( decisionsToSend != null ) {
if ( decisionsToSend.Values.Count > 1 ) {
//seems to be pulling things in the order they are on the stack, not how they were put there
var d = decisionsToSend.Values.Cast<Decision>().Reverse().ToArray();
Messenger.Default.Send( new DecisionMessage( d ) );
}else {
var d = decisionsToSend.Values.Cast<Decision>().ToArray();
Messenger.Default.Send( new DecisionMessage( d[0] ) );
}
}
}
示例14: ObjFromTable
public static object ObjFromTable(LuaTable t)
{
Dictionary<string, object> args = new Dictionary<string, object>();
foreach (object key in t.Keys)
{
object value = t[key];
object obj;
if (key is double) { return ObjArrayFromTable(t); }
if (value is LuaTable) { obj = ObjFromTable((LuaTable)value); } else { obj = value; }
args.Add(key.ToString(), obj);
}
return args;
}
示例15: ObjArrayFromTable
public static object[] ObjArrayFromTable(LuaTable t)
{
object[] r = new object[t.Values.Count];
int i = 0;
foreach (object value in t.Values)
{
if (value is LuaTable) { r[i] = ObjFromTable((LuaTable)value); }
else
{
r[i] = value;
}
i++;
}
return r;
}