GUIForDebug

简介: package gui; import org.luaj.vm2.Globals; import org.luaj.vm2.LuaValue; import org.luaj.vm2.ast.
package gui;

import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.ast.Chunk;
import org.luaj.vm2.ast.Exp;
import org.luaj.vm2.ast.Stat;
import org.luaj.vm2.ast.Visitor;
import org.luaj.vm2.lib.jse.JsePlatform;
import org.luaj.vm2.parser.LuaParser;
import org.luaj.vm2.parser.ParseException;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * Created by 10159705 on 16-3-7.
 */
public class GUIForDebug {

    public static final int WIDTH = 400;

    public static void main(String[] args) {
        final JFrame jFrame = new JFrame("For Lua Debug");
        jFrame.setLayout(new FlowLayout());

        final JTextField jTextField = new JTextField("Lua Path:", WIDTH - 10);
        jFrame.add(jTextField);
        final JFileChooser jFileChooser = new JFileChooser();
        jFileChooser.setSelectedFile(new File("E:\\lang\\lua\\workspace\\LuaProject\\src\\main.lua"));
        jFileChooser.setFileFilter(new FileFilter() {
            @Override
            public String getDescription() {
                return "Lua(.lua)";
            }

            @Override
            public boolean accept(File f) {
                if (f.isDirectory()) {
                    return true;
                }
                return f.getName().toLowerCase().endsWith(".lua");
            }
        });


        JButton jButton = new JButton("click");
        jFrame.add(jButton);
        jButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int result = jFileChooser.showOpenDialog(jFrame);
                if (result == JFileChooser.CANCEL_OPTION) {
                    return;
                }
                File chooseFile = jFileChooser.getSelectedFile();

                String luaFilePath = chooseFile.getAbsolutePath();
                jFrame.add(new JLabel("<html><font color=blue>" + luaFilePath));
                jTextField.setText(luaFilePath);
                jFrame.validate();
                // create an environment to run in
                Globals globals = JsePlatform.standardGlobals();

                // Use the convenience function on Globals to load a chunk.
                LuaValue chunk = globals.loadfile(luaFilePath);

                // Use any of the "call()" or "invoke()" functions directly on the chunk.
                chunk.call(LuaValue.valueOf(luaFilePath));
            }
        });

        SwingConsole.run(jFrame, WIDTH, 200);
    }

    protected static void parserUT(File fileFullName) {
        try {

            // Create a LuaParser. This will fill in line and column number
            // information for most exceptions.
            LuaParser parser = new LuaParser(new FileInputStream(fileFullName));

            // Perform the parsing.
            Chunk chunk = parser.Chunk();

            // Print out line info for all function definitions.
            chunk.accept(new Visitor() {
                public void visit(Exp.AnonFuncDef exp) {
                    System.out.println("Anonymous function definition at "
                            + exp.beginLine + "." + exp.beginColumn + ","
                            + exp.endLine + "." + exp.endColumn);
                }

                public void visit(Stat.FuncDef stat) {
                    System.out.println("Function definition '" + stat.name.name.name + "' at "
                            + stat.beginLine + "." + stat.beginColumn + ","
                            + stat.endLine + "." + stat.endColumn);

                    System.out.println("\tName location "
                            + stat.name.beginLine + "." + stat.name.beginColumn + ","
                            + stat.name.endLine + "." + stat.name.endColumn);
                }

                public void visit(Stat.LocalFuncDef stat) {
                    System.out.println("Local function definition '" + stat.name.name + "' at "
                            + stat.beginLine + "." + stat.beginColumn + ","
                            + stat.endLine + "." + stat.endColumn);
                }
            });

        } catch (ParseException e) {
            System.out.println("parse failed: " + e.getMessage() + "\n"
                    + "Token Image: '" + e.currentToken.image + "'\n"
                    + "Location: " + e.currentToken.beginLine + ":" + e.currentToken.beginColumn
                    + "-" + e.currentToken.endLine + "," + e.currentToken.endColumn);

        } catch (IOException e) {
            System.out.println("IOException occurred: " + e);
            e.printStackTrace();
        }
    }

}


class SwingConsole {

    public static void run(final JFrame frame, final int width, final int height) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                frame.setSize(width, height);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }
}
--array={1,2,3,4,5}
--for key, var in pairs(array) do
--  print(key,var)
--end

--
--function f(a, b)
--return a or b
--end
--
--print ("output:",f(1,3));

require('mobdebug')
function maximum (a)
  local mi = 1             -- maximum index
  local m = a[mi]          -- maximum value
  for i,val in ipairs(a) do
    if val > m then
      mi = i
      m = val
    end
  end
  return m, mi
end

print(maximum({8,10,23,12,5}))     --> 23   3

  

  

 

相关文章
|
9月前
|
Linux iOS开发 MacOS
DeepSeek爆火,如何免费部署到你的电脑上?获取顶级推理能力教程来了
如何在本地电脑上免费部署DeepSeek,获取顶级推理能力?只需三步:1. 访问Ollama官网下载并安装对应操作系统的版本(支持macOS、Linux和Windows)。2. 打开Ollama并确保其正常运行。3. 在Ollama官网搜索并选择DeepSeek模型(如deepseek-r1),根据电脑配置选择合适的模型大小(1.5B至671B)。通过终端命令(如ollama run deepseek-r1:1.5b)运行模型,即可开始使用DeepSeek进行推理。退出模型时,在终端输入/bye。更多详情请参考Ollama官方文档。
|
存储 缓存 前端开发
掌握Nginx缓存策略:提高网站性能,降低响应时间
掌握Nginx缓存策略:提高网站性能,降低响应时间
756 1
|
安全 Linux 数据安全/隐私保护
阿里云镜像仓库:拉取和推送Docker镜像
阿里云镜像仓库:拉取和推送Docker镜像
41826 2
阿里云镜像仓库:拉取和推送Docker镜像
|
移动开发 前端开发 JavaScript
构建一个动态交互式图表
构建一个动态交互式图表
|
前端开发 Linux Android开发
请问阿里云rpa可以模拟手机app操作么?
请问阿里云rpa可以模拟手机app操作么?
376 1
|
消息中间件 缓存 JSON
【性能】性能比较:REST vs gRPC vs 异步通信
【性能】性能比较:REST vs gRPC vs 异步通信
|
SQL 存储 Oracle
数据库、数据库管理系统、SQL和图形界面工具的关系
数据库、数据库管理系统、SQL和图形界面工具的关系
351 0
|
SQL 关系型数据库 测试技术
实践教程之在PolarDB-X中进行Online DDL
PolarDB-X 为了方便用户体验,提供了免费的实验环境,您可以在实验环境里体验 PolarDB-X 的安装部署和各种内核特性。除了免费的实验,PolarDB-X 也提供免费的视频课程,手把手教你玩转 PolarDB-X 分布式数据库。
实践教程之在PolarDB-X中进行Online DDL
|
监控 安全 Serverless
AAS即As-a-Service的概念
列举一些接触到的AAS即As-a-Service的概念
642 0