本文整理汇总了C#中LuaTable类的典型用法代码示例。如果您正苦于以下问题:C# LuaTable类的具体用法?C# LuaTable怎么用?C# LuaTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LuaTable类属于命名空间,在下文中一共展示了LuaTable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Awake
void Awake()
{
scriptEnv = LuaEnv.NewTable();
LuaTable meta = LuaEnv.NewTable();
meta.Set("__index", LuaEnv.Global);
scriptEnv.SetMetaTable(meta);
meta.Dispose();
scriptEnv.Set("self", this);
foreach (var injection in injections)
{
scriptEnv.Set(injection.name, injection.value);
}
TextAsset text = Application.Make<IResources>().Load<TextAsset>(luaPath);
LuaEnv.DoString(text.text, "LuaBehaviour", scriptEnv);
Action luaAwake = scriptEnv.Get<Action>("awake");
scriptEnv.Get("start", out luaStart);
scriptEnv.Get("update", out luaUpdate);
scriptEnv.Get("ondestroy", out luaOnDestroy);
if (luaAwake != null)
{
luaAwake();
}
}
开发者ID:yb199478,项目名称:CatLib,代码行数:29,代码来源:LuaMonoComponent.cs
示例2: TestMember05
public void TestMember05()
{
dynamic t = new LuaTable();
t.hallo = 42;
t.hallo1 = 43;
TestResult(new LuaResult(t.hallo, t.hallo1), 42, 43);
}
开发者ID:edisonh,项目名称:neolua,代码行数:7,代码来源:LuaTable.cs
示例3: date
public static LuaValue date(LuaValue[] values)
{
LuaString format = values[0] as LuaString;
if (format != null)
{
if (format.Text == "*t")
{
LuaTable table = new LuaTable();
DateTime now = DateTime.Now;
table.SetNameValue("year", new LuaNumber (now.Year));
table.SetNameValue("month", new LuaNumber (now.Month ));
table.SetNameValue("day", new LuaNumber (now.Day));
table.SetNameValue("hour", new LuaNumber (now.Hour));
table.SetNameValue("min", new LuaNumber (now.Minute));
table.SetNameValue("sec", new LuaNumber (now.Second));
table.SetNameValue("wday", new LuaNumber ((int)now.DayOfWeek));
table.SetNameValue("yday", new LuaNumber (now.DayOfYear));
table.SetNameValue("isdst", LuaBoolean.From(now.IsDaylightSavingTime()));
}
else
{
return new LuaString(DateTime.Now.ToString(format.Text));
}
}
return new LuaString (DateTime.Now.ToString ());//[PixelCrushers].ToShortDateString());
}
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:27,代码来源:OSLib.cs
示例4: CreateMetaTable
public static LuaTable CreateMetaTable()
{
LuaTable metatable = new LuaTable();
RegisterFunctions(metatable);
metatable.SetNameValue("__index", metatable);
return metatable;
}
开发者ID:farreltr,项目名称:OneLastSunset,代码行数:7,代码来源:FileLib.cs
示例5: ToLuaTable
public static LuaTable ToLuaTable(object o)
{
LuaTable ret = new LuaTable();
// check if Dictionary...
System.Collections.IDictionary dict = o as System.Collections.IDictionary;
if (dict != null)
{
foreach (object obj in dict.Keys)
{
ret.SetKeyValue(ToLuaValue(obj), ToLuaValue(dict[obj]));
}
return ret;
}
System.Collections.IEnumerable ie = (o as System.Collections.IEnumerable);
if (ie != null)
{
foreach (object obj in ie)
{
ret.AddValue(ToLuaValue(obj));
}
return ret;
}
// check if <type>...
// not an array type
ret.AddValue(ToLuaValue(o));
return ret;
}
开发者ID:Majiir,项目名称:MuMechLib,代码行数:30,代码来源:ObjectToLua.cs
示例6: OnAllKilled
public void OnAllKilled(LuaTable actors, LuaFunction func)
{
List<Actor> group = new List<Actor>();
foreach (var kv in actors)
{
Actor actor;
if (!kv.Value.TryGetClrValue<Actor>(out actor))
throw new LuaException("OnAllKilled requires a table of int,Actor pairs. Recieved {0},{1}".F(kv.Key.GetType().Name, kv.Value.GetType().Name));
group.Add(actor);
}
var copy = (LuaFunction)func.CopyReference();
Action<Actor> OnMemberKilled = m =>
{
group.Remove(m);
if (!group.Any())
{
copy.Call();
copy.Dispose();
}
};
foreach (var a in group)
GetScriptTriggers(a).OnKilledInternal += OnMemberKilled;
}
开发者ID:RunCraze,项目名称:OpenRA,代码行数:26,代码来源:TriggerGlobal.cs
示例7: Awake
void Awake()
{
scriptEnv = luaEnv.NewTable();
LuaTable meta = luaEnv.NewTable();
meta.Set("__index", luaEnv.Global);
scriptEnv.SetMetaTable(meta);
meta.Dispose();
scriptEnv.Set("self", this);
foreach (var injection in injections)
{
scriptEnv.Set(injection.name, injection.value);
}
luaEnv.DoString(luaScript.text, "LuaBehaviour", scriptEnv);
Action luaAwake = scriptEnv.Get<Action>("awake");
scriptEnv.Get("start", out luaStart);
scriptEnv.Get("update", out luaUpdate);
scriptEnv.Get("ondestroy", out luaOnDestroy);
if (luaAwake != null)
{
luaAwake();
}
}
开发者ID:yb199478,项目名称:CatLib,代码行数:27,代码来源:LuaBehaviour.cs
示例8: Reload
public void Reload()
{
CacheTable = null;
var ret = LuaModule.Instance.CallScript(LuaPath);
Debuger.Assert(ret is LuaTable, "{0} Script Must Return Lua Table with functions!", LuaPath);
CacheTable = ret as LuaTable;
}
开发者ID:yonglehou,项目名称:KSFramework,代码行数:7,代码来源:LuaBehaviour.cs
示例9: InsertMarketData
public static void InsertMarketData(int id, int version, LuaTable data)
{
if (dataMap.ContainsKey(id))
{
dataMap.Remove(id);
}
MarketData d = new MarketData();
d.id = id;
d.marketVersion = version;
d.hot = Int32.Parse((string)data["1"]);
d.hotSort = Int32.Parse((string)data["2"]);
d.jewel = Int32.Parse((string)data["3"]);
d.jewelSort = Int32.Parse((string)data["4"]);
d.item = Int32.Parse((string)data["5"]);
d.itemSort = Int32.Parse((string)data["6"]);
d.wing = Int32.Parse((string)data["7"]);
d.wingSort = Int32.Parse((string)data["8"]);
d.mode = Int32.Parse((string)data["9"]);
d.label = Int32.Parse((string)data["10"]);
d.itemId = Int32.Parse((string)data["11"]);
d.itemNumber = Int32.Parse((string)data["12"]);
d.priceOrg = Int32.Parse((string)data["13"]);
d.priceNow = Int32.Parse((string)data["14"]);
d.vipLevel = Int32.Parse((string)data["15"]);
d.totalCount = Int32.Parse((string)data["16"]);
d.startTime = null;
d.duration = Int32.Parse((string)data["18"]);
dataMap.Add(id, d);
}
开发者ID:lbddk,项目名称:ahzs-client,代码行数:29,代码来源:MarketData.cs
示例10: Create
public Actor Create(string type, bool addToWorld, LuaTable initTable)
{
var initDict = new TypeDictionary();
// Convert table entries into ActorInits
foreach (var kv in initTable)
{
// Find the requested type
var typeName = kv.Key.ToString();
var initType = Game.modData.ObjectCreator.FindType(typeName + "Init");
if (initType == null)
throw new LuaException("Unknown initializer type '{0}'".F(typeName));
// Cast it up to an IActorInit<T>
var genericType = initType.GetInterfaces()
.First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IActorInit<>));
var innerType = genericType.GetGenericArguments().First();
// Try and coerce the table value to the required type
object value;
if (!kv.Value.TryGetClrValue(innerType, out value))
throw new LuaException("Invalid data type for '{0}' (expected '{1}')".F(typeName, innerType.Name));
// Construct the ActorInit. Phew!
var test = initType.GetConstructor(new[] { innerType }).Invoke(new[] { value });
initDict.Add(test);
}
// The actor must be added to the world at the end of the tick
var a = context.World.CreateActor(false, type, initDict);
if (addToWorld)
context.World.AddFrameEndTask(w => w.Add(a));
return a;
}
开发者ID:JackKucan,项目名称:OpenRA,代码行数:35,代码来源:ActorGlobal.cs
示例11: SerializeArguments
public static string SerializeArguments(object[] args)
{
if (args == null || args.Length == 0)
{
return "\xC0";
}
var table = new LuaTable();
for (int i = 1; i <= args.Length; i++)
{
table[i] = args[i - 1];
}
/*dynamic luaEnvironment = ScriptEnvironment.CurrentEnvironment.LuaEnvironment;
dynamic msgpack = luaEnvironment.msgpack;
dynamic pack = msgpack.pack;
string str = pack(table);*/
var luaEnvironment = ScriptEnvironment.CurrentEnvironment.LuaEnvironment;
var method = (Func<object, LuaResult>)((LuaTable)luaEnvironment["msgpack"])["pack"];
return method(table).ToString();
}
开发者ID:Preto0203,项目名称:Server_One,代码行数:25,代码来源:EventScriptFunctions.cs
示例12: LoadLibrary
public static void LoadLibrary(LuaInstance lua)
{
LuaTable table = new LuaTable();
table["log"] = new Action<int, string>(log);
lua.Register("aero", table);
}
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:7,代码来源:LuaAerospike.cs
示例13: ToString
public static string ToString(LuaTable table, LuaComment headComment = null)
{
using (var stringWriter = new StringWriter()) {
Write(table, stringWriter, headComment);
return stringWriter.ToString();
}
}
开发者ID:ClaudiuC,项目名称:MoaiUtils,代码行数:7,代码来源:LuaTableWriter.cs
示例14: CreateEnumerateArrayEnumerable
private static IEnumerable<LuaValue> CreateEnumerateArrayEnumerable(LuaTable self)
{
// By convention, the 'n' field refers to the array length, if present.
using (var n = self["n"]) {
var num = n as LuaNumber;
if (num != null) {
var length = (int)num.Value;
for (int i = 1; i <= length; ++i) {
yield return self[i];
}
yield break;
}
}
// If no 'n' then stop at the first nil element.
for (int i = 1; ; ++i) {
var value = self[i];
if (value.IsNil()) {
yield break;
}
yield return value;
}
}
开发者ID:RoosterDragon,项目名称:Eluant,代码行数:26,代码来源:LuaValueExtensions.cs
示例15: Start
void Start()
{
lua = new LuaSvr();
self = (LuaTable)lua.start("LuaFiles/building_txt");
//self = (LuaTable)lua.luaState.getObject("data");
//object o = lua.luaState.getFunction("GetData").call();
Debug.Log("table " + ((LuaTable)self[1])["name"]);
LuaFunction dataFunction = ((LuaFunction)self["GetData"]);
LuaTable dataTable = (LuaTable)dataFunction.call();
LuaFunction callFunction = (LuaFunction)self["CallBack"];
callFunction.call(222);
//lua.luaState.getFunction("CallBack").call();
lua.luaState.getFunction("Call").call(2);
Debug.Log("table " + ((LuaTable)dataTable[1])["use_money"] + " is Null " + (callFunction == null));
LuaTable d = (LuaTable)((LuaFunction)self["GetData1"]).call();
Debug.Log("---------------- : " + ((LuaTable)d[1])["use_money"]);
LuaTable table2 = (LuaTable)lua.start("LuaFiles/building_txt1");
test2 = (LuaFunction)self["test"];
object o = test2.call(self,9,1);
Debug.Log("add function :"+o);
SetTransform = (LuaFunction)self["SetTransform"];
SetTransform.call(self, tr);
//tr.localPosition = new Vector3(2, 2, 2);
}
开发者ID:zhaoyabo,项目名称:GameBase,代码行数:28,代码来源:TestLua.cs
示例16: Awake
void Awake()
{
_instance = this;
svr = new LuaSvr();
self = (LuaTable)svr.start("LuaFiles/LuaCallCsAPI");
self["event"] = DataEventSource.Instance;
self["name"] = "API";
}
开发者ID:zhaoyabo,项目名称:GameBase,代码行数:8,代码来源:LuaCallCSAPI.cs
示例17: Start
void Start () {
svr = new LuaSvr();
svr.init(null, () =>
{
self = (LuaTable)svr.start("circle/circle");
update = (LuaFunction)self["update"];
});
}
开发者ID:Rubiphisto,项目名称:slua,代码行数:8,代码来源:Circle.cs
示例18: Skip
public LuaTable Skip(LuaTable table, int numElements)
{
var t = Context.CreateTable();
for (var i = numElements; i <= table.Count; i++)
t.Add(t.Count + 1, table[i]);
return t;
}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:9,代码来源:UtilsGlobal.cs
示例19: initializeLua
/// <summary>
/// Creates a new Lua environment and registers various classes and functions from the game to it.
/// </summary>
public void initializeLua()
{
global = compiler.CreateEnvironment();
game = new LuaTable();
global["Game"] = game;
global["Log"] = new Action<string>(Logger.Log);
global["GAME_DIR"] = GAME_DIR_DEFAULT;
//TODO: make this load from some kind of config file and only fail to this default
global["runFile"] = new Action<string, LuaTable>(runLuaFile);
LuaTable loadingInterface = new LuaTable();
loadingInterface["display"] = new Action<string>(Screens.LoadingScreen.Display);
loadingInterface["change"] = new Action<string>(Screens.LoadingScreen.ChangeMessage);
game["LoadingScreen"] = loadingInterface;
game["loadVoxtures"] = new Func<string, LuaTable>(loadVoxtures);
LuaType.RegisterTypeAlias("material", typeof(OutpostLibrary.Content.Material));
LuaTable mat = new LuaTable();
game["Material"] = LuaType.GetType(typeof(OutpostLibrary.Content.Material));
game["Transparency"] = LuaType.GetType(typeof(OutpostLibrary.Content.Transparency));
game["Solidity"] = LuaType.GetType(typeof(OutpostLibrary.Content.Solidity));
//TODO: solidity should be a lua-side thing
game["Sizes"] = LuaType.GetType(typeof(OutpostLibrary.Navigation.Sizes));
game["Directions"] = LuaType.GetType(typeof(OutpostLibrary.Navigation.Directions));
game["map"] = MainGame.mainGame;
//TODO: this clearly needs reworked
global["twoDArray"] = new Func<int, LuaTable[,]>(delegate(int size) { return new LuaTable[size, size]; });
global["threeDArray"] = new Func<int, LuaTable[, ,]>(delegate(int size) { return new LuaTable[size, size, size]; });
LuaType.RegisterTypeAlias("IntVector3", typeof(OutpostLibrary.IntVector3));
global["IntVector3"] = LuaType.GetType(typeof(OutpostLibrary.IntVector3));
LuaType.RegisterTypeAlias("Vector3", typeof(Microsoft.Xna.Framework.Vector3));
global["Vector3"] = LuaType.GetType(typeof(Microsoft.Xna.Framework.Vector3));
LuaType.RegisterTypeAlias("Chunk", typeof(Chunk));
global["Chunk"] = LuaType.GetType(typeof(Chunk));
LuaType.RegisterTypeAlias("SolidBlock", typeof(Blocks.SolidBlock));
global["SolidBlock"] = LuaType.GetType(typeof(Blocks.SolidBlock));
LuaType.RegisterTypeAlias("Structure", typeof(MapStructure));
global["Structure"] = LuaType.GetType(typeof(MapStructure));
//global["Double"] = LuaType.GetType(typeof(Double));
runLuaFile("init.lua");
}
开发者ID:littlebeast,项目名称:Outpost,代码行数:60,代码来源:LuaBridge.cs
示例20: getTableFunction
/*
* Gets the function called name from the provided table,
* returning null if it does not exist
*/
public static LuaFunction getTableFunction(LuaTable luaTable, string name)
{
object funcObj = luaTable.rawget(name);
if(funcObj is LuaFunction)
return (LuaFunction)funcObj;
else
return null;
}
开发者ID:rumkex,项目名称:LuaInterface,代码行数:13,代码来源:LuaClassHelper.cs
注:本文中的LuaTable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论