博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GUIForDebug
阅读量:7252 次
发布时间:2019-06-29

本文共 5532 字,大约阅读时间需要 18 分钟。

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("" + 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, miendprint(maximum({8,10,23,12,5}))     --> 23   3

  

  

 

转载地址:http://rnebm.baihongyu.com/

你可能感兴趣的文章
vue-cli 脚手架项目简介(一) - package.json
查看>>
Step By Step(Lua目录)
查看>>
linux下使用多线程编写的聊天室
查看>>
react-router-dom Link search 传参
查看>>
js的数据类型及类型转换
查看>>
wpa_cli 关联无线网络
查看>>
MySQL批量数据脚本示例
查看>>
Can realize the needs of the individual, MBT Sini
查看>>
规则引擎以及blaze 规则库的集成初探之二——JSR94 的规则引擎API和实现
查看>>
core dump文件生成
查看>>
同步异步, 阻塞和非阻塞
查看>>
SQL查询案例:行列转换[行转列, 使用 CASE WHEN 处理]
查看>>
XML文档注释
查看>>
【MongoDB】1、MongoDB for Java
查看>>
p3396 哈希冲突(暴力)
查看>>
C++面向对象类的实例题目十二
查看>>
细说new与malloc的10点区别(转载)
查看>>
2017年上半年软件设计师试题-02
查看>>
Asp.net mvc 3 - JSON post & AOP
查看>>
LIS 最长递增子序列
查看>>