static void LoadConstants(Stream stream, LuaPrototype proto, bool native) { int n = LoadInt(stream); proto.Constants = new LuaObject[n]; for (int i = 0; i < n; i++) { var o = new LuaObject(); int t = -((int)ReadByte(stream)); o.Type = (LuaTypes)t; switch (o.Type) { case LuaTypes.Number: o.Value = (float)LoadNumber(stream, native); break; case LuaTypes.String: o.Value = LoadTString(stream); break; case LuaTypes.Proto: o.Value = LoadFunction(stream, native); break; case LuaTypes.Nil: break; default: throw new Exception("Constant can't be type " + o.Type.ToString()); } proto.Constants [i] = o; } }
public static bool Load(Stream stream, out LuaPrototype result) { int c = stream.ReadByte(); if (c == IDCHUNK) { result = LoadChunk(stream); return(result != null); } else { result = null; return(false); } }
static LuaPrototype LoadFunction(Stream stream, bool native) { var proto = new LuaPrototype(); proto.LinesDefined = LoadInt(stream); proto.Source = LoadTString(stream); if (proto.Source == null) { proto.Source = ""; } proto.Code = LoadCode(stream); LoadLocals(stream, proto); LoadConstants(stream, proto, native); return(proto); }
static void LoadLocals(Stream stream, LuaPrototype proto) { int n = LoadInt(stream); if (n == 0) { return; } proto.Locals = new LuaLocal[n + 1]; for (int i = 0; i < n; i++) { proto.Locals [i].Line = LoadInt(stream); proto.Locals [i].Name = LoadTString(stream); } proto.Locals [n].Line = -1; proto.Locals [n].Name = null; }
public LuaBinaryRuntime(LuaPrototype proto) { data = proto; }