GUIForDebug

简介: package gui; import org.luaj.vm2.Globals; import org.luaj.vm2.LuaValue; import org.luaj.vm2.ast.
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

  

  

 

相关文章
|
8月前
|
Linux Go Docker
goland如何把go项目打包进docker镜像
goland如何把go项目打包进docker镜像
310 0
|
11月前
|
机器学习/深度学习 iOS开发 计算机视觉
iOS MachineLearning 系列(16)—— 几个常用的图片分类CoreML模型
对于图片识别分类的模型来说,其输入和输出都一样,输入都为图像参数,输入为两部分,一部分为最佳预测结果,一部分为可能得预测结果及其可信度。
258 0
|
iOS开发 Docker MacOS
macOS Docker Volume数据卷存放的位置
macOS Docker Volume数据卷存放的位置
465 0
|
缓存 Kubernetes 负载均衡
注册中心原理和选型:Zookeeper、Eureka、Nacos、Consul和Etcd(一)
经过近2周的学习,原来注册中心除了ETCD和Zookeeper,常用的还有Eureka、Nacos、Consul,下面我们就对这些常用的注册中心,初探它们的异同,便于后续技术选型。
651 0
注册中心原理和选型:Zookeeper、Eureka、Nacos、Consul和Etcd(一)
|
缓存 网络协议 Shell
OpenSSL SSL_read: Connection was reset, errno 10054
Git 报错信息 OpenSSL SSL_read: Connection was reset, errno 10054 解决方案
2233 0
OpenSSL SSL_read: Connection was reset, errno 10054
|
Java Linux Windows
Logback:只输出Info和Error级别的日志,并输出到不同的文件
Logback:只输出Info和Error级别的日志,并输出到不同的文件
1690 0
Logback:只输出Info和Error级别的日志,并输出到不同的文件
H2Engine游戏服务器设计之属性管理器
游戏服务器设计之属性管理器   游戏中角色拥有的属性值很多,运营多年的游戏,往往会有很多个成长线,每个属性都有可能被N个成长线模块增减数值。举例当角色戴上武器时候hp+100点,卸下武器时HP-100点,这样加减逻辑只有一处还比较好控制,如果某天有个特殊功能当被某技能攻击时,角色武器会被击落,这样就会出现减数值的操作不止一处。
1222 0
|
7天前
|
NoSQL Cloud Native Redis
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新
阿里云瑶池数据库团队后续将持续参与Valkey社区,如过往在Redis社区一样耕耘,为开源社区作出持续贡献。
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新

热门文章

最新文章