Exemplo n.º 1
0
        public static int lua_load(lua_State L, lua_Reader reader, object data, string chunkname, string mode)
        {
            lua_lock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }
            Zio z = new Zio();

            imp.luaZ_init(L, z, reader, data);
            int status = imp.luaD_protectedparser(L, z, chunkname, mode);

            if (status == LUA_OK)                        /* no errors? */
            {
                LClosure f = imp.clLvalue(L, L.top - 1); /* get newly created function */
                if (f.nupvalues >= 1)                    /* does it have an upvalue? */
                /* get global table from registry */
                {
                    Table  reg = imp.hvalue(imp.G(L).l_registry);
                    TValue gt  = imp.luaH_getint(reg, LUA_RIDX_GLOBALS);
                    /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
                    imp.setobj(L, f.upvals[0].v, gt);
                    imp.luaC_upvalbarrier(L, f.upvals[0]);
                }
            }
            lua_unlock(L);
            return(status);
        }
Exemplo n.º 2
0
        public static int lua_load(lua_State L, lua_Reader reader, object data,
                                   CharPtr chunkname, CharPtr mode)
        {
            ZIO z = new ZIO();
            int status;

            lua_lock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }
            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname, mode);
            if (status == LUA_OK)                 /* no errors? */
            {
                LClosure f = clLvalue(L.top - 1); /* get newly created function */
                if (f.nupvalues == 1)             /* does it have one upvalue? */
                /* get global table from registry */
                {
                    Table            reg = hvalue(G(L).l_registry);
                    /*const*/ TValue gt  = luaH_getint(reg, LUA_RIDX_GLOBALS);
                    /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
                    setobj(L, f.upvals[0].v, gt);
                    luaC_barrier(L, f.upvals[0], gt);
                }
            }
            lua_unlock(L);
            return(status);
        }
Exemplo n.º 3
0
 public static void luaZ_init(lua_State L, ZIO z, lua_Reader reader, object data)
 {
     z.L = L;
       z.reader = reader;
       z.data = data;
       z.n = 0;
       z.p = null;
 }
Exemplo n.º 4
0
 public static void luaZ_init(lua_State L, ZIO z, lua_Reader reader, object data)
 {
     z.L      = L;
     z.reader = reader;
     z.data   = data;
     z.n      = 0;
     z.p      = null;
 }
Exemplo n.º 5
0
        public static int LuaLoad(LuaState L, lua_Reader reader, object data,
                                  CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;

            LuaLock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }
            luaZ_init(L, z, reader, data);
            status = LuaDProtectedParser(L, z, chunkname);
            LuaUnlock(L);
            return(status);
        }
Exemplo n.º 6
0
        public static int lua_load(lua_State L, lua_Reader reader, object data,
                                   CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;

            lua_lock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }
            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname);
            lua_unlock(L);
            return(status);
        }
Exemplo n.º 7
0
 public static unsafe int lua_loadx(lua_Reader reader, void* dt, string chunkname, string mode) => lua_loadx(_state, reader, dt, chunkname, mode);
Exemplo n.º 8
0
 public static unsafe int lua_load(lua_Reader reader, void* data, string chunkname) => lua_load(_state, reader, data, chunkname);
Exemplo n.º 9
0
 public static extern unsafe int lua_load(LuaState luaState, lua_Reader reader, void *data, string chunkname);
Exemplo n.º 10
0
        public static int lua_load(LuaState L, lua_Reader reader, object data,
                                   CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;
            lua_lock(L);
            if (chunkname == null) chunkname = "?";

            #if OVERRIDE_LOAD || true
            //#if false
            if (data is LoadS)
            {
                LoadS d = data as LoadS;
                if (d.size > 0 && d.s.chars[0] != LUA_SIGNATURE[0]) // if its not binary
                {
                    Lexer l = new Lexer();
                    try
                    {
                        //Console.WriteLine(d.s);
                        TokenReader tr = l.Lex(d.s);
                        Parser p = new Parser(tr);
                        Ast.Chunk c = p.Parse();

                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        d.s = s;
                        d.size = (lu_mem)s.Length;
                    }
                    catch (LuaSourceException ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    d.s.index = 0;

                    // Why isn't the size equal to the chars.Length?
                    Debug.WriteLine("Binary data: d.size=" + d.size + " d.s.chars.Length=" + d.s.chars.Length);
                    Debug.WriteLine("Equal: " + (d.size == d.s.chars.Length));
                    //Debug.Assert(d.size == d.s.chars.Length);
                    d.size = (uint)d.s.chars.Length;
                }
            }
            else if (data is LoadF)
            {
                LoadF lf = data as LoadF;

                if (lf.f.ReadByte() != LUA_SIGNATURE[0]) // if its not binary
                {
                    lf.f.Position = 0;
                    MemoryStream ms = new MemoryStream();
                    while (lf.f.Position < lf.f.Length)
                        ms.WriteByte((byte)lf.f.ReadByte());
                    ms.Position = 0;

                    // not binary file
                    ms.Position = 0;
                    StringBuilder sb = new StringBuilder();
                    while (ms.Position < ms.Length)
                        sb.Append((char)ms.ReadByte());

                    try
                    {
                        Lexer l = new Lexer();
                        TokenReader tr = l.Lex(sb.ToString());
                        Parser p = new Parser(tr);
                        Ast.Chunk c = p.Parse();
                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        ms = new MemoryStream();
                        // TODO: there HAS to be a better way...
                        foreach (char c2 in s)
                            ms.WriteByte((byte)c2);
                        ms.Position = 0;
                        lf.f = ms;
                    }
                    catch (LuaSourceException ex)
                    {
                        lua_pushstring(L, ex.GenerateMessage(chunkname));
                        return 1;
                        //throw ex;
                    }
                }
                else
                {
                    lf.f.Position = 0; // reset the read character
                }
            }
            #endif
            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname);
            lua_unlock(L);
            if (data is LoadF)
            {
                LoadF f = data as LoadF;
                if (f.f != null)
                {
                    f.f.Close();
                    f.f.Dispose();
                }
            }
            return status;
        }
Exemplo n.º 11
0
 public static extern unsafe int lua_loadx(LuaState luaState, lua_Reader reader, void *dt, string chunkname, string mode);
Exemplo n.º 12
0
 public static unsafe int lua_load(lua_Reader reader, void *data, string chunkname) => lua_load(_state, reader, data, chunkname);
 public static unsafe int lua_loadx(this LuaState luaState, lua_Reader reader, void* dt, string chunkname, string mode) => Lua.lua_loadx(luaState, reader, dt, chunkname, mode);
Exemplo n.º 14
0
 public static extern int lua_load(lua_StatePtr L, lua_Reader reader, IntPtr dt,
                                   string chunkname);
Exemplo n.º 15
0
 public static int LuaLoad(LuaState L, lua_Reader reader, object data,
                       CharPtr chunkname)
 {
     ZIO z = new ZIO();
     int status;
     LuaLock(L);
     if (chunkname == null) chunkname = "?";
     luaZ_init(L, z, reader, data);
     status = LuaDProtectedParser(L, z, chunkname);
     LuaUnlock(L);
     return status;
 }
Exemplo n.º 16
0
 public static extern int lua_load(lua_State L, lua_Reader reader, IntPtr dt, String chunkname, String mode);
Exemplo n.º 17
0
        public static int lua_load(LuaState L, lua_Reader reader, object data,
                                   CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;

            lua_lock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }

            if (data is LoadS)
            {
                LoadS d = data as LoadS;
                if (d.size > 0)
                {
                    Lexer l = new Lexer();
                    try
                    {
                        //Console.WriteLine(d.s);
                        TokenReader tr = l.Lex(d.s);
                        Parser      p  = new Parser(tr);
                        Ast.Chunk   c  = p.Parse();

                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        d.s    = s;
                        d.size = (lu_mem)s.Length;
                    }
                    catch (LuaSourceException ex)
                    {
                        throw ex;
                    }
                }
            }
            else if (data is LoadF)
            {
                LoadF lf = data as LoadF;

                MemoryStream ms = new MemoryStream();
                while (lf.f.Position < lf.f.Length)
                {
                    ms.WriteByte((byte)lf.f.ReadByte());
                }
                ms.Position = 0;
                if (ms.ReadByte() != 27)
                {
                    // not binary file
                    ms.Position = 0;
                    StringBuilder sb = new StringBuilder();
                    while (ms.Position < ms.Length)
                    {
                        sb.Append((char)ms.ReadByte());
                    }

                    try
                    {
                        Lexer       l  = new Lexer();
                        TokenReader tr = l.Lex(sb.ToString());
                        Parser      p  = new Parser(tr);
                        Ast.Chunk   c  = p.Parse();

                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        ms = new MemoryStream();
                        // TODO: there HAS to be a better way...
                        foreach (char c2 in s)
                        {
                            ms.WriteByte((byte)c2);
                        }
                        ms.Position = 0;
                        lf.f        = ms;
                    }
                    catch (LuaSourceException ex)
                    {
                        throw ex;
                    }
                }
            }

            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname);
            lua_unlock(L);
            return(status);
        }
Exemplo n.º 18
0
 public static unsafe int lua_loadx(lua_Reader reader, void *dt, string chunkname, string mode) => lua_loadx(_state, reader, dt, chunkname, mode);
Exemplo n.º 19
0
 public static unsafe int lua_load(this LuaState luaState, lua_Reader reader, void *data, string chunkname) => Lua.lua_load(luaState, reader, data, chunkname);
Exemplo n.º 20
0
 [DllImport("lua")] extern public static int lua_load(IntPtr L, lua_Reader reader, /* void* */ IntPtr data, /* const char* */ string chunkname, /* const char* */ string mode);
Exemplo n.º 21
0
 public static unsafe int lua_loadx(this LuaState luaState, lua_Reader reader, void *dt, string chunkname, string mode) => Lua.lua_loadx(luaState, reader, dt, chunkname, mode);
 public static unsafe int lua_load(this LuaState luaState, lua_Reader reader, void* data, string chunkname) => Lua.lua_load(luaState, reader, data, chunkname);
Exemplo n.º 23
0
 public static extern int lua_load(lua_StatePtr L, lua_Reader reader, IntPtr dt,
                                        string chunkname);
Exemplo n.º 24
0
 public extern static int lua_load(lua_State L, lua_Reader reader, IntPtr dt, String chunkname, String mode);
Exemplo n.º 25
0
 public static extern int lua_load(IntPtr L, lua_Reader reader, IntPtr dt, IntPtr chunkname, IntPtr mode);
Exemplo n.º 26
0
 public static extern int lua_load( IntPtr state, lua_Reader reader, IntPtr data, string source, string mode );
Exemplo n.º 27
0
 public static extern int lua_load(IntPtr L, lua_Reader reader, IntPtr data, string chunkname, string mode);
Exemplo n.º 28
0
 public static extern LuaResult lua_load(IntPtr L, lua_Reader reader, IntPtr data, [MarshalAs(UnmanagedType.LPStr)] string chunkname);
Exemplo n.º 29
0
 public static int lua_load(lua_State L, lua_Reader reader, IntPtr dt, string chunkname, string mode) =>
 lua_load(L, reader == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(reader), dt, chunkname, mode);
Exemplo n.º 30
0
        public static int lua_load(LuaState L, lua_Reader reader, object data,
                                   CharPtr chunkname)
        {
            ZIO z = new ZIO();
            int status;

            lua_lock(L);
            if (chunkname == null)
            {
                chunkname = "?";
            }

            #if OVERRIDE_LOAD || true
            //#if false
            if (data is LoadS)
            {
                LoadS d = data as LoadS;
                if (d.size > 0 && d.s.chars[0] != LUA_SIGNATURE[0]) // if its not binary
                {
                    Lexer l = new Lexer();
                    try
                    {
                        //Console.WriteLine(d.s);
                        TokenReader tr = l.Lex(d.s);
                        Parser      p  = new Parser(tr);
                        Ast.Chunk   c  = p.Parse();

                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        d.s    = s;
                        d.size = (lu_mem)s.Length;
                    }
                    catch (LuaSourceException ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    d.s.index = 0;

                    // Why isn't the size equal to the chars.Length?
                    Debug.WriteLine("Binary data: d.size=" + d.size + " d.s.chars.Length=" + d.s.chars.Length);
                    Debug.WriteLine("Equal: " + (d.size == d.s.chars.Length));
                    //Debug.Assert(d.size == d.s.chars.Length);
                    d.size = (uint)d.s.chars.Length;
                }
            }
            else if (data is LoadF)
            {
                LoadF lf = data as LoadF;

                if (lf.f.ReadByte() != LUA_SIGNATURE[0]) // if its not binary
                {
                    lf.f.Position = 0;
                    MemoryStream ms = new MemoryStream();
                    while (lf.f.Position < lf.f.Length)
                    {
                        ms.WriteByte((byte)lf.f.ReadByte());
                    }
                    ms.Position = 0;

                    // not binary file
                    ms.Position = 0;
                    StringBuilder sb = new StringBuilder();
                    while (ms.Position < ms.Length)
                    {
                        sb.Append((char)ms.ReadByte());
                    }

                    try
                    {
                        Lexer       l  = new Lexer();
                        TokenReader tr = l.Lex(sb.ToString());
                        Parser      p  = new Parser(tr);
                        Ast.Chunk   c  = p.Parse();
                        Visitors.LuaCompatibleOutput lco = new Visitors.LuaCompatibleOutput();
                        string s = lco.Format(c);
                        ms = new MemoryStream();
                        // TODO: there HAS to be a better way...
                        foreach (char c2 in s)
                        {
                            ms.WriteByte((byte)c2);
                        }
                        ms.Position = 0;
                        lf.f        = ms;
                    }
                    catch (LuaSourceException ex)
                    {
                        lua_pushstring(L, ex.GenerateMessage(chunkname));
                        return(1);
                        //throw ex;
                    }
                }
                else
                {
                    lf.f.Position = 0; // reset the read character
                }
            }
            #endif
            luaZ_init(L, z, reader, data);
            status = luaD_protectedparser(L, z, chunkname);
            lua_unlock(L);
            if (data is LoadF)
            {
                LoadF f = data as LoadF;
                if (f.f != null)
                {
                    f.f.Close();
                    f.f.Dispose();
                }
            }
            return(status);
        }
Exemplo n.º 31
0
 public static extern unsafe int lua_load(LuaState luaState, lua_Reader reader, void* data, string chunkname);
Exemplo n.º 32
0
 public static extern unsafe int lua_loadx(LuaState luaState, lua_Reader reader, void* dt, string chunkname, string mode);
Exemplo n.º 33
0
 public static int lua_load(lua_State L, lua_Reader reader, object data,
     CharPtr chunkname)
 {
     ZIO z = new ZIO();
       int status;
       lua_lock(L);
       if (chunkname == null) chunkname = "?";
       luaZ_init(L, z, reader, data);
       status = luaD_protectedparser(L, z, chunkname);
       lua_unlock(L);
       return status;
 }
Exemplo n.º 34
0
 public extern static int lua_load(lua_State L, lua_Reader reader, IntPtr data, string chunkname);