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

  

  

GUIForDebug的更多相关文章

随机推荐

  1. C语言中scanf/fscanf 的%[]和%n说明符的使用方法

    标准输入输出函数%[]和%n说明符的使用方法     scanf fscanf,均从第一个非空格的可显示字符开始读起!         标准输入输出函数scanf具有相对较多的转换说明符,它常常作为入 ...

  2. RVDS 3.1 下载地址及破解方法

    RealView Development Suite 3.1  RVDS 3.1下载地址:https://silver.arm.com/download/Development_Tools/RVDS/ ...

  3. java 参数传递

    由一个问题来引入参数传递的问题 public static void main(String[] args) { int x=1; int[] y =new int[10]; m(x,y); Syst ...

  4. cocos2d-x 消类游戏,类似Diamond dash 设计

    前几天刚刚在学习cocos2d-x,无聊之下自己做了一个类似Diamond dash的消类游戏,今天放到网上来和大家分享一下.我相信Diamond dash这个游戏大家都玩过,游戏的规则是这样的,有一 ...

  5. 《火球——UML大战需求分析》(第1章 大话UML)——1.3 行为型的UML(Behavior Diagram)

    说明: <火球——UML大战需求分析>是我撰写的一本关于需求分析及UML方面的书,我将会在CSDN上为大家分享前面几章的内容,总字数在几万以上,图片有数十张.欢迎你按文章的序号顺序阅读,谢 ...

  6. Spark技术内幕:Stage划分及提交源代码分析

    当触发一个RDD的action后.以count为例,调用关系例如以下: org.apache.spark.rdd.RDD#count org.apache.spark.SparkContext#run ...

  7. 【Cloud Foundry】Could Foundry学习(三)——Router

    在阅读的过程中有不论什么问题.欢迎一起交流 邮箱:1494713801@qq.com    QQ:1494713801 一.概述 Router组件在Cloud Foundry中是对全部进来的Reque ...

  8. Linux下hp打印机驱动hplip分析

    Hplip分析 版本号是2.14,源代码位置:http://hplipopensource.com. 图的来源:http://hplipopensource.com/node/128. 实践中使用的打 ...

  9. Javascrpt 页面工具

    /**  *  笔者:DL  *  时间:2014-3-19   * PagingTool模块提供最基本的.网页工具栏.和页面数据 回电话 可扩展性 分页工具栏介绍,和页面呈现的数据   *   主意 ...

  10. varchar 分享影响记忆 试

    准备数据 sysbench --test=oltp --oltp-nontrx-mode=update_key --mysql-table-engine=innodb --oltp-table-siz ...