GUIForDebug
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的更多相关文章
随机推荐
- lucene4.4 索引的增删改查
package com.lucene.test; import java.io.File; import java.io.FileReader; import java.io.IOException; ...
- Android照片墙完整版,的完美结合LruCache和DiskLruCache
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/34093441 在上一篇文章其中,我们学习了DiskLruCache的概念和基本使用 ...
- 一则简单演示样例看Oracle的“无私”健壮性
Oracle的强大之处就在于他能总帮助让你选择正确的运行计划,即使你给了它错误的指示. 实验: 1. 创建測试表: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZ ...
- JavaScript 中的事件流和事件处理程序(读书笔记思维导图)
JavaScript 程序采用了异步事件驱动编程模型.在这种程序设计风格下,当文档.浏览器.元素或与之相关的对象发生某些有趣的事情时,Web 浏览器就会产生事件(event). JavaScript ...
- nginx源代码分析--event事件驱动初始化
1.在nginx.c中设置每一个核心模块的index ngx_max_module = 0; for (i = 0; ngx_modules[i]; i++) { ngx_modules[i]-> ...
- Nagios的客户端的安装
一.Linux服务器的nagios客户端的安装 步骤: 1. 创建目录,上传文件到该目录 mkdir /data nagios-plugins-2.1.1.tar.gz nrpe-2.12.tar. ...
- java -D參数简化增加多个jar【简化设置classpath】
1.-D<name>=<value> set a system property 设置系统属性. java命令引入jar时能够-cp參数,但时-cp不能用通配符(多个jar时 ...
- 【足迹C++primer】30、概要(泛型算法)
概要(泛型算法) 大多数算法的头文件中定义algorithm在. 标准库也是第一个文件numeric它定义了一套通用算法. #include<iostream> #include<n ...
- Knockout获取数组元素索引的2种方法,在MVC中实现
原文:Knockout获取数组元素索引的2种方法,在MVC中实现 在遍历数组.集合的时候,通常要获取元素的索引,本篇体验使用Knockout获取索引的2种方法. 假设有这样的一个模型: namespa ...
- U6Linux的文件权限与目录配置
1.ll查看文件信息:[权限][连接][所有者][用户组][文件容量][修改日期][文件名] 2.第一个字符代表文件的属性:若为[d]则是目录.若为[-]则是文件.若为[l]则为连接. 3.chgrp ...