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的更多相关文章
随机推荐
- eclipse package,source folder,folder差别及相互转换
在eclipse下, package, source folder, folder都是目录. 它们的差别例如以下: package:当你在建立一个package时,它自己主动建立到source ...
- Lua学习笔记9:多文件
一 终端中运行多个文件:-l 增加在文件一中定义了一个变量,在还有一文件里输出这个变量.代码例如以下: --file1.lua num = 100 --file2.lua print(num) 终端输 ...
- OCP读书笔记(9) - 诊断数据库
数据库恢复顾问 Data Recovery Advisor的命令行选项 1. 启动 RMAN 进程并连接到目标$ rman target=/ 2. 假设发生了某个错误,希望找出原因,使用 list f ...
- drupal form 中图片上传
1.创建url 链接到form $items['qianfeng/add'] = array( 'title' => t('加入信息'), 'page callback' =&g ...
- ios 6 横竖屏转换
xcode 版本4.5 模拟器:6.0 项目需求:刚进去界面横屏,从这个界面进去的界面全是竖屏. 程序的根控制器用了UINavigationController.下面是代码: 1.在appde ...
- c# winform 子窗体访问父窗体中的方法和变量
今天的工作中突然用到这个了,不过以前没有接触过呢!不过,在有经验的同事的帮助下,这个问题也很快解决了.具体可以分为以下几种方式: 1.在父窗体中构造子窗体对象时,将父窗体传递过去: 如:FrmSub ...
- mindmanager2012打开文件出现runtime error r6025 解决方式
关于mindmanager 2012启动无法执行,提示c++错误 ---------------------------Microsoft Visual C++ Runtime Library---- ...
- linux下查看进城(ps)的方法 与 杀死进程(kill)的N种方法
PS查看进程 inux上进程有5种状态: 1. 运行(正在运行或在运行队列中等待) 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 3. 不可中断(收到信号不唤醒和不可运行, 进程必 ...
- 网络安全之IP伪造
眼下非常多站点的涉及存在一些安全漏洞,黑客easy使用ip伪造.session劫持.xss攻击.session注入等手段危害站点安全.在纪录片<互联网之子>(建议搞IT的都要看下)中.亚伦 ...
- shell加法
echo 1597+1469+1468+2591+1260+1068+1019+993|bc http://bbs.chinaunix.net/thread-161085-1-1.html http: ...