本文整理汇总了C#中LuaTable类的典型用法代码示例。如果您正苦于以下问题:C# LuaTable类的具体用法?C# LuaTable怎么用?C# LuaTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LuaTable类属于命名空间,在下文中一共展示了LuaTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例2: TestMember05
public void TestMember05()
{
dynamic t = new LuaTable();
t.hallo = 42;
t.hallo1 = 43;
TestResult(new LuaResult(t.hallo, t.hallo1), 42, 43);
}
示例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());
}
示例4: CreateMetaTable
public static LuaTable CreateMetaTable()
{
LuaTable metatable = new LuaTable();
RegisterFunctions(metatable);
metatable.SetNameValue("__index", metatable);
return metatable;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例12: LoadLibrary
public static void LoadLibrary(LuaInstance lua)
{
LuaTable table = new LuaTable();
table["log"] = new Action<int, string>(log);
lua.Register("aero", table);
}
示例13: ToString
public static string ToString(LuaTable table, LuaComment headComment = null)
{
using (var stringWriter = new StringWriter()) {
Write(table, stringWriter, headComment);
return stringWriter.ToString();
}
}
示例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;
}
}
示例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);
}