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. JAVA NIO 选择器

    为什么要使用选择器 通道处于就绪状态后,就可以在缓冲区之间传送数据.可以采用非阻塞模式来检查通道是否就绪,但非阻塞模式还会做别的任务,当有多个通道同时存在时,很难将检查通道是否就绪与其他任务剥离开来, ...

  2. 改动file header (測)

    --改动file header ------------------------------------------------------------------------- cd $ORACLE ...

  3. cocos2d 走动椭圆

    1.效果图 艺术与规划说他想与我合作在全国率先主角光环加,椭圆形走动. cocos2d自带没有,參考网上的写了一个. 2.椭圆数学知识 有关椭圆的数学知识我已经忘光了.网上找了点资料: a是椭圆的长半 ...

  4. 使用Django创建简易Blog

    网上看了个例子,但是自己却运行不同,最后终于知道了原因,记录下来.原来没有给settings.py里的INSTALLED_APPS添加blog.就像这样: 这是一个手把手的实例教程,本来学习笔记一样, ...

  5. PHP实现快速排序算法

    快速排序(Quick Sort)是对冒泡排序的一种改进,属不稳定排序算法,由东尼·霍尔在1962年提出.快速排序基本步骤:从数列中挑出一个元素(一般称为称为“基准”),通过一趟排序将要排序的数据分割成 ...

  6. java 处理时间的各种方式——获取时间——时间格式化

    TimeUtil.java package com.snow; import java.text.DateFormat; import java.text.ParseException; import ...

  7. linux su,sudo命令

    linux su 命令 建议大家切换用户的时候 使用 su - root 这样,否则可能发现某些命令执行不了 关于su .su - 及 sudo的区别 请往下看 1.命令作用 su的作用是变更为其它使 ...

  8. vb.net WPF webbrowser window.close 关闭后不触发 WindowClosing 事件 WNDPROC解决方式

     vb.net WPF webbrowser window.close 关闭后不触发 WindowClosing 事件 WNDPROC解决方式 #Region "WPF 当浏览器窗体关闭 ...

  9. 測试JSON RPC远程调用(JSONclient)

    #include <string> #include <iostream> #include <curl/curl.h> /* 标题:JSonclient Auth ...

  10. wscript:329: error: Could not autodetect OpenSSL support. Make sure OpenSSL development packages are

    安装node错: wscript:329: error: Could not autodetect OpenSSL support. Make sure OpenSSL development pac ...