Guest User

Untitled

a guest
Jan 7th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.54 KB | None | 0 0
  1. using Gtk;
  2. using Lua;
  3. public void text_edit_moved_cursor(TextView source)
  4. {
  5.     inputCode = textEdit.buffer.text;
  6.     vm.do_string(inputCode);
  7.     var sum = vm.to_string(-1);
  8.     textView.buffer.text = sum;
  9.     //vm.pop(1);
  10. }
  11. static int my_func(LuaVM vmm)
  12. {
  13.     print(@"vm to number $(vmm.to_number(1))");
  14.     //textView.buffer.text = vm.to_number(1).to_string();
  15.     return 1;
  16. }
  17.  
  18. LuaVM vm;
  19. TextView textEdit;
  20. TextView textView;
  21. string inputCode;
  22. string outputResult;
  23.  
  24. string vmCode;
  25. int main(string[] args)
  26. {
  27.     Gtk.init(ref args);
  28.  
  29.     try {
  30.         vm = new LuaVM();
  31.         textEdit = new TextView();
  32.         var builder = new Builder();
  33.         builder.add_from_file("ui.ui");
  34.         builder.connect_signals(null);
  35.         //инициализация интерфейса
  36.         var window = builder.get_object("window") as Window;
  37.         window.destroy.connect(Gtk.main_quit);
  38.         textEdit = builder.get_object("textEdit") as TextView;
  39.         textView = builder.get_object("textView") as TextView;
  40.  
  41.         //VM
  42.         vmCode =
  43.             """
  44.         function dostring(strname)
  45.             local f = assert(loadstring(strname))
  46.             return f()
  47.         end
  48.        
  49.        return tostring dostring("..inputCode..")
  50.        
  51.        """;
  52.         //"
  53.  
  54.         vm.open_libs();
  55.         vm.push_string(inputCode);
  56.         vm.set_global("inputCode");
  57.         vm.push_string(outputResult);
  58.         vm.set_global("outputResult");
  59.         vm.register("my_func", my_func);
  60.  
  61.      
  62.         textEdit.buffer.text = "SAS";
  63.  
  64.  
  65.  
  66.         window.show_all();
  67.         Gtk.main();
  68.     } catch (Error e) {
  69.         stderr.printf("Could not load UI: %s\n", e.message);
  70.         return 1;
  71.     }
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment