public
Last active

mruby interface for vim

  • Download Gist
vim7-if_mruby.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591
diff -r ccbde540a714 runtime/doc/eval.txt
--- a/runtime/doc/eval.txt Wed Apr 03 21:14:29 2013 +0200
+++ b/runtime/doc/eval.txt Fri Apr 05 21:20:11 2013 +0900
@@ -6412,6 +6412,7 @@
mouse_urxvt Compiled with support for urxvt mouse.
mouse_xterm Compiled with support for xterm mouse.
mouseshape Compiled with support for 'mouseshape'.
+mruby Compiled with MRuby interface |mruby|.
multi_byte Compiled with support for 'encoding'
multi_byte_encoding 'encoding' is set to a multi-byte encoding.
multi_byte_ime Compiled with support for IME input method.
diff -r ccbde540a714 runtime/doc/help.txt
--- a/runtime/doc/help.txt Wed Apr 03 21:14:29 2013 +0200
+++ b/runtime/doc/help.txt Fri Apr 05 21:20:11 2013 +0900
@@ -166,6 +166,7 @@
|if_tcl.txt| Tcl interface
|if_ole.txt| OLE automation interface for Win32
|if_ruby.txt| Ruby interface
+|if_mruby.txt| MRuby interface
|debugger.txt| Interface with a debugger
|workshop.txt| Sun Visual Workshop interface
|netbeans.txt| NetBeans External Editor interface
diff -r ccbde540a714 runtime/doc/if_mruby.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/runtime/doc/if_mruby.txt Fri Apr 05 21:20:11 2013 +0900
@@ -0,0 +1,207 @@
+*if_mruby.txt* For Vim version 7.3. Last change: 2013 Jan 30
+
+
+ VIM REFERENCE MANUAL by Yasuhiro Matsumoto
+
+The MRuby Interface to Vim *mruby* *MRuby*
+
+
+1. Commands |mruby-commands|
+2. The VIM module |mruby-vim|
+3. VIM::Buffer objects |mruby-buffer|
+4. VIM::Window objects |mruby-window|
+5. Global variables |mruby-globals|
+6. Using mrbgems |mruby-mrbgems|
+
+{Vi does not have any of these commands}
+
+The MRuby interface only works when Vim was compiled with the |+mruby| feature.
+Most of features in if_mruby are similar to if_ruby.
+
+The home page for mruby is https://github.com/mruby/mruby/. You can find
+links for downloading MRuby there.
+
+==============================================================================
+1. Commands *mruby-commands*
+
+ *:mruby* *:mrub*
+:mrub[y] {cmd} Execute MRuby command {cmd}. A command to try it out: >
+ :mruby print "Hello"
+
+:mrub[y] << {endpattern}
+{script}
+{endpattern}
+ Execute MRuby script {script}.
+ {endpattern} must NOT be preceded by any white space.
+ If {endpattern} is omitted, it defaults to a dot '.'
+ like for the |:append| and |:insert| commands. This
+ form of the |:mruby| command is mainly useful for
+ including mruby code in vim scripts.
+ Note: This command doesn't work when the MRuby feature
+ wasn't compiled in. To avoid errors, see
+ |script-here|.
+
+Example Vim script: >
+
+ function! RedGem()
+ mruby << EOF
+ class Garnet
+ def initialize(s)
+ @buffer = VIM::Buffer.current
+ vimputs(s)
+ end
+ def vimputs(s)
+ @buffer.append(@buffer.count,s)
+ end
+ end
+ gem = Garnet.new("pretty")
+ EOF
+ endfunction
+<
+
+ *:mrubydo* *:mrubyd*
+:[range]mrubyd[o] {cmd} Evaluate MRuby command {cmd} for each line in the
+ [range], with $_ being set to the text of each line in
+ turn, without a trailing <EOL>. Setting $_ will change
+ the text, but note that it is not possible to add or
+ delete lines using this command.
+ The default for [range] is the whole file: "1,$".
+
+ *:mrubyfile* *:mrubyf*
+:mrubyf[ile] {file} Execute the MRuby script in {file}. This is the same
+ as ":mruby load 'file'", but allows file name
+ completion.
+
+Executing MRuby commands is not possible in the |sandbox|.
+
+==============================================================================
+2. The VIM module *mruby-vim*
+
+MRuby code gets all of its access to vim via the "VIM" module.
+
+Overview >
+ print "Hello" # displays a message
+ VIM.command(cmd) # execute an Ex command
+ num = VIM::Window.count # gets the number of windows
+ w = VIM::Window[n] # gets window "n"
+ cw = VIM::Window.current # gets the current window
+ num = VIM::Buffer.count # gets the number of buffers
+ b = VIM::Buffer[n] # gets buffer "n"
+ cb = VIM::Buffer.current # gets the current buffer
+ w.height = lines # sets the window height
+ w.cursor = [row, col] # sets the window cursor position
+ pos = w.cursor # gets an array [row, col]
+ name = b.name # gets the buffer file name
+ line = b[n] # gets a line from the buffer
+ num = b.count # gets the number of lines
+ b[n] = str # sets a line in the buffer
+ b.delete(n) # deletes a line
+ b.append(n, str) # appends a line after n
+ line = VIM::Buffer.current.line # gets the current line
+ num = VIM::Buffer.current.line_number # gets the current line number
+ VIM::Buffer.current.line = "test" # sets the current line number
+<
+
+Module Functions:
+
+ *mruby-message*
+VIM::message({msg})
+ Displays the message {msg}.
+
+ *mruby-set_option*
+VIM::set_option({arg})
+ Sets a vim option. {arg} can be any argument that the ":set" command
+ accepts. Note that this means that no spaces are allowed in the
+ argument! See |:set|.
+
+ *mruby-command*
+VIM::command({cmd})
+ Executes Ex command {cmd}.
+
+ *mruby-evaluate*
+VIM::evaluate({expr})
+ Evaluates {expr} using the vim internal expression evaluator (see
+ |expression|). Returns the expression result as a string.
+ A |List| is turned into a string by joining the items and inserting
+ line breaks.
+
+==============================================================================
+3. VIM::Buffer objects *mruby-buffer*
+
+VIM::Buffer objects represent vim buffers.
+
+Class Methods:
+
+current Returns the current buffer object.
+count Returns the number of buffers.
+self[{n}] Returns the buffer object for the number {n}. The first number
+ is 0.
+
+Methods:
+
+name Returns the name of the buffer.
+number Returns the number of the buffer.
+count Returns the number of lines.
+length Returns the number of lines.
+self[{n}] Returns a line from the buffer. {n} is the line number.
+self[{n}] = {str}
+ Sets a line in the buffer. {n} is the line number.
+delete({n}) Deletes a line from the buffer. {n} is the line number.
+append({n}, {str})
+ Appends a line after the line {n}.
+line Returns the current line of the buffer if the buffer is
+ active.
+line = {str} Sets the current line of the buffer if the buffer is active.
+line_number Returns the number of the current line if the buffer is
+ active.
+
+==============================================================================
+4. VIM::Window objects *mruby-window*
+
+VIM::Window objects represent vim windows.
+
+Class Methods:
+
+current Returns the current window object.
+count Returns the number of windows.
+self[{n}] Returns the window object for the number {n}. The first number
+ is 0.
+
+Methods:
+
+buffer Returns the buffer displayed in the window.
+height Returns the height of the window.
+height = {n} Sets the window height to {n}.
+width Returns the width of the window.
+width = {n} Sets the window width to {n}.
+cursor Returns a [row, col] array for the cursor position.
+cursor = [{row}, {col}]
+ Sets the cursor position to {row} and {col}.
+
+==============================================================================
+5. Global variables *mruby-globals*
+
+There are two global variables.
+
+__curwin The current window object.
+__$curbuf The current buffer object.
+
+==============================================================================
+6. Using mrbgems *mruby-mrbgems*
+
+MRuby support CRuby like package system. But it's not dynamic loading packages.
+The dynamic loading package will not be provided by mruby official.
+
+ https://github.com/mattn/mruby-require
+
+This mrbgem provide dynamic loading packages. If you want to add new feature
+to mruby interface, you should build libmruby.a with this mrbgem. And call
+require in mruby:
+>
+ mruby << EOF
+ require 'mruby-env'
+ puts ENV["HOME"]
+ EOF
+<
+==============================================================================
+ vim:tw=78:ts=8:ft=help:norl:
diff -r ccbde540a714 runtime/doc/if_perl.txt
--- a/runtime/doc/if_perl.txt Wed Apr 03 21:14:29 2013 +0200
+++ b/runtime/doc/if_perl.txt Fri Apr 05 21:20:11 2013 +0900
@@ -253,8 +253,8 @@
this will NOT work!
EOF
endif
-Instead, put the Perl/Python/Ruby/etc. command in a function and call that
-function: >
+Instead, put the Perl/Python/Ruby/MRuby/etc. command in a function and call
+that function: >
if has('perl')
function DefPerl()
perl << EOF
diff -r ccbde540a714 runtime/doc/index.txt
--- a/runtime/doc/index.txt Wed Apr 03 21:14:29 2013 +0200
+++ b/runtime/doc/index.txt Fri Apr 05 21:20:11 2013 +0900
@@ -1339,6 +1339,9 @@
|:mkvimrc| :mkv[imrc] write current mappings and settings to a file
|:mkview| :mkvie[w] write view of current window to a file
|:mode| :mod[e] show or change the screen mode
+|:mruby| :mrub[y] execute MRuby command
+|:mrubydo| :mrubyd[o] execute MRuby command for each line
+|:mrubyfile| :mrubyf[ile] execute MRuby script file
|:mzscheme| :mz[scheme] execute MzScheme command
|:mzfile| :mzf[ile] execute MzScheme script file
|:nbclose| :nbc[lose] close the current Netbeans session
diff -r ccbde540a714 src/Make_ming.mak
--- a/src/Make_ming.mak Wed Apr 03 21:14:29 2013 +0200
+++ b/src/Make_ming.mak Fri Apr 05 21:20:11 2013 +0900
@@ -405,6 +405,12 @@
endif
endif
+ifdef MRUBY
+include $(MRUBY)/build/host/lib/libmruby.flags.mak
+CFLAGS += -DFEAT_MRUBY -I$(MRUBY)/include $(MRUBY_CFLAGS)
+MRUBYLIB = -L$(MRUBY)/build/host/lib -lmruby -lmruby_core $(MRUBY_LD_FLAGS) $(MRUBY_LIBS)
+endif
+
ifdef PYTHON
CFLAGS += -DFEAT_PYTHON
ifeq (yes, $(DYNAMIC_PYTHON))
@@ -575,6 +581,9 @@
ifdef RUBY
OBJ += $(OUTDIR)/if_ruby.o
endif
+ifdef MRUBY
+OBJ += $(OUTDIR)/if_mruby.o
+endif
ifdef TCL
OBJ += $(OUTDIR)/if_tcl.o
endif
@@ -685,7 +694,7 @@
$(CC) $(CFLAGS) -o uninstal.exe uninstal.c $(LIB)
$(TARGET): $(OUTDIR) $(OBJ)
- $(CC) $(CFLAGS) $(LFLAGS) -o $@ $(OBJ) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB)
+ $(CC) $(CFLAGS) $(LFLAGS) -o $@ $(OBJ) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB) $(MRUBYLIB)
upx: exes
upx gvim.exe
@@ -758,6 +767,9 @@
$(CC) $(CFLAGS) -U_WIN32 -c -o $(OUTDIR)/if_ruby.o if_ruby.c
endif
+$(OUTDIR)/if_mruby.o: if_mruby.c $(INCL)
+ $(CC) -c $(CFLAGS) if_mruby.c -o $(OUTDIR)/if_mruby.o
+
if_perl.c: if_perl.xs typemap
$(XSUBPP) -prototypes -typemap \
$(PERLLIB)/ExtUtils/typemap if_perl.xs > $@
@@ -779,7 +791,7 @@
@echo 'char_u *default_vim_dir = (char_u *)"$(VIMRCLOC)";' >> pathdef.c
@echo 'char_u *default_vimruntime_dir = (char_u *)"$(VIMRUNTIMEDIR)";' >> pathdef.c
@echo 'char_u *all_cflags = (char_u *)"$(CC) $(CFLAGS)";' >> pathdef.c
- @echo 'char_u *all_lflags = (char_u *)"$(CC) $(CFLAGS) $(LFLAGS) -o $(TARGET) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB)";' >> pathdef.c
+ @echo 'char_u *all_lflags = (char_u *)"$(CC) $(CFLAGS) $(LFLAGS) -o $(TARGET) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB) $(MRUBYLIB)";' >> pathdef.c
@echo 'char_u *compiled_user = (char_u *)"$(USERNAME)";' >> pathdef.c
@echo 'char_u *compiled_sys = (char_u *)"$(USERDOMAIN)";' >> pathdef.c
else
@@ -789,7 +801,7 @@
@echo char_u *default_vim_dir = (char_u *)"$(VIMRCLOC)"; >> pathdef.c
@echo char_u *default_vimruntime_dir = (char_u *)"$(VIMRUNTIMEDIR)"; >> pathdef.c
@echo char_u *all_cflags = (char_u *)"$(CC) $(CFLAGS)"; >> pathdef.c
- @echo char_u *all_lflags = (char_u *)"$(CC) $(CFLAGS) $(LFLAGS) -o $(TARGET) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB)"; >> pathdef.c
+ @echo char_u *all_lflags = (char_u *)"$(CC) $(CFLAGS) $(LFLAGS) -o $(TARGET) $(LIB) -lole32 -luuid $(LUA_LIB) $(MZSCHEME_LIBDIR) $(MZSCHEME_LIB) $(PYTHONLIB) $(PYTHON3LIB) $(RUBYLIB) $(MRUBYLIB)"; >> pathdef.c
@echo char_u *compiled_user = (char_u *)"$(USERNAME)"; >> pathdef.c
@echo char_u *compiled_sys = (char_u *)"$(USERDOMAIN)"; >> pathdef.c
endif
diff -r ccbde540a714 src/Make_mvc.mak
--- a/src/Make_mvc.mak Wed Apr 03 21:14:29 2013 +0200
+++ b/src/Make_mvc.mak Fri Apr 05 21:20:11 2013 +0900
@@ -69,6 +69,9 @@
# You must set RUBY_API_VER to RUBY_VER_LONG.
# Don't set ruby API version to RUBY_VER like 191.
#
+# MRuby interface:
+# MRUBY=[Path to Ruby directory]
+#
# Tcl interface:
# TCL=[Path to Tcl directory]
# DYNAMIC_TCL=yes (to load the Tcl DLL dynamically)
@@ -187,6 +190,9 @@
!ifdef RUBY
OBJDIR = $(OBJDIR)R
!endif
+!ifdef MRUBY
+OBJDIR = $(OBJDIR)MR
+!endif
!ifdef MZSCHEME
OBJDIR = $(OBJDIR)Z
!endif
@@ -883,6 +889,18 @@
!endif # RUBY
#
+# Support MRuby interface
+#
+!ifdef MRUBY
+# TODO: libmruby.flags.mak doesn't need on MSVC.
+#!include $(MRUBY)/build/host/lib/libmruby.flags.mak
+CFLAGS = $(CFLAGS) -DFEAT_MRUBY /I $(MRUBY)/include
+MRUBY_OBJ = $(OUTDIR)\if_mruby.obj
+MRUBY_INC = /I "$(MRUBY)\include"
+MRUBY_LIB = /LIBPATH:"$(MRUBY)\build\host\lib" libmruby.lib
+!endif #MRUBY
+
+#
# Support PostScript printing
#
!if "$(POSTSCRIPT)" == "yes"
@@ -926,7 +944,7 @@
LINKARGS1 = $(linkdebug) $(conflags)
LINKARGS2 = $(CON_LIB) $(GUI_LIB) $(LIBC) $(OLE_LIB) user32.lib $(SNIFF_LIB) \
$(LUA_LIB) $(MZSCHEME_LIB) $(PERL_LIB) $(PYTHON_LIB) $(PYTHON3_LIB) $(RUBY_LIB) \
- $(TCL_LIB) $(NETBEANS_LIB) $(XPM_LIB) $(LINK_PDB)
+ $(MRUBY_LIB) $(TCL_LIB) $(NETBEANS_LIB) $(XPM_LIB) $(LINK_PDB)
# Report link time code generation progress if used.
!ifdef NODEBUG
@@ -942,12 +960,12 @@
$(VIM).exe: $(OUTDIR) $(OBJ) $(GUI_OBJ) $(OLE_OBJ) $(OLE_IDL) $(MZSCHEME_OBJ) \
$(LUA_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(PYTHON3_OBJ) $(RUBY_OBJ) $(TCL_OBJ) \
- $(SNIFF_OBJ) $(CSCOPE_OBJ) $(NETBEANS_OBJ) $(XPM_OBJ) \
+ $(MRUBY_OBJ) $(SNIFF_OBJ) $(CSCOPE_OBJ) $(NETBEANS_OBJ) $(XPM_OBJ) \
version.c version.h
$(CC) $(CFLAGS) version.c
$(link) $(LINKARGS1) -out:$(VIM).exe $(OBJ) $(GUI_OBJ) $(OLE_OBJ) \
$(LUA_OBJ) $(MZSCHEME_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(PYTHON3_OBJ) $(RUBY_OBJ) \
- $(TCL_OBJ) $(SNIFF_OBJ) $(CSCOPE_OBJ) $(NETBEANS_OBJ) \
+ $(MRUBY_OBJ) $(TCL_OBJ) $(SNIFF_OBJ) $(CSCOPE_OBJ) $(NETBEANS_OBJ) \
$(XPM_OBJ) $(OUTDIR)\version.obj $(LINKARGS2)
$(VIM): $(VIM).exe
@@ -1114,6 +1132,9 @@
$(OUTDIR)/if_ruby.obj: $(OUTDIR) if_ruby.c $(INCL)
$(CC) $(CFLAGS) $(RUBY_INC) if_ruby.c
+$(OUTDIR)/if_mruby.obj: $(OUTDIR) if_mruby.c $(INCL)
+ $(CC) $(CFLAGS) $(MRUBY_INC) if_mruby.c
+
$(OUTDIR)/if_sniff.obj: $(OUTDIR) if_sniff.c $(INCL)
$(CC) $(CFLAGS) if_sniff.c
diff -r ccbde540a714 src/Makefile
--- a/src/Makefile Wed Apr 03 21:14:29 2013 +0200
+++ b/src/Makefile Fri Apr 05 21:20:11 2013 +0900
@@ -44,6 +44,7 @@
# --enable-python3interp for Python3 interpreter
# --enable-pythoninterp for Python interpreter
# --enable-rubyinterp for Ruby interpreter
+# --enable-mrubyinterp for MRuby interpreter
# --enable-tclinterp for Tcl interpreter
# --enable-cscope for Cscope interface
# - Uncomment one of the lines with --with-features= to enable a set of
@@ -432,6 +433,9 @@
#CONF_OPT_RUBY = --enable-rubyinterp=dynamic
#CONF_OPT_RUBY = --enable-rubyinterp --with-ruby-command=ruby1.9.1
+# MRUBY
+#CONF_OPT_MRUBY = --enable-rubyinterp
+
# TCL
# Uncomment this when you want to include the Tcl interface.
#CONF_OPT_TCL = --enable-tclinterp
@@ -1339,7 +1343,7 @@
# with "-E".
OSDEF_CFLAGS = $(PRE_DEFS) $(POST_DEFS)
-LINT_CFLAGS = -DLINT -I. $(PRE_DEFS) $(POST_DEFS) $(RUBY_CFLAGS) $(LUA_CFLAGS) $(PERL_CFLAGS) $(PYTHON_CFLAGS) $(PYTHON3_CFLAGS) -Dinline= -D__extension__= -Dalloca=alloca
+LINT_CFLAGS = -DLINT -I. $(PRE_DEFS) $(POST_DEFS) $(RUBY_CFLAGS) $(MRUBY_CFLAGS) $(LUA_CFLAGS) $(PERL_CFLAGS) $(PYTHON_CFLAGS) $(PYTHON3_CFLAGS) -Dinline= -D__extension__= -Dalloca=alloca
LINT_EXTRA = -DUSE_SNIFF -DHANGUL_INPUT -D"__attribute__(x)="
@@ -1364,6 +1368,7 @@
$(PYTHON3_LIBS) \
$(TCL_LIBS) \
$(RUBY_LIBS) \
+ $(MRUBY_LIBS) \
$(PROFILE_LIBS) \
$(LEAK_LIBS)
@@ -1477,6 +1482,7 @@
$(PYTHON_SRC) $(PYTHON3_SRC) \
$(TCL_SRC) \
$(RUBY_SRC) \
+ $(MRUBY_SRC) \
$(SNIFF_SRC) \
$(WORKSHOP_SRC) \
$(WSDEBUG_SRC)
@@ -1484,7 +1490,7 @@
TAGS_SRC = *.c *.cpp if_perl.xs
EXTRA_SRC = hangulin.c if_lua.c if_mzsch.c auto/if_perl.c if_perlsfio.c \
- if_python.c if_python3.c if_tcl.c if_ruby.c if_sniff.c \
+ if_python.c if_python3.c if_tcl.c if_ruby.c if_mruby.c if_sniff.c \
gui_beval.c workshop.c wsdebug.c integration.c netbeans.c
# Unittest files
@@ -1563,6 +1569,7 @@
$(PYTHON3_OBJ) \
$(TCL_OBJ) \
$(RUBY_OBJ) \
+ $(MRUBY_OBJ) \
$(OS_EXTRA_OBJ) \
$(WORKSHOP_OBJ) \
$(NETBEANS_OBJ) \
@@ -1599,6 +1606,7 @@
if_python.pro \
if_python3.pro \
if_ruby.pro \
+ if_mruby.pro \
main.pro \
mark.pro \
memfile.pro \
@@ -1661,7 +1669,7 @@
./configure $(CONF_OPT_GUI) $(CONF_OPT_X) $(CONF_OPT_XSMP) \
$(CONF_OPT_DARWIN) $(CONF_OPT_FAIL) \
$(CONF_OPT_PERL) $(CONF_OPT_PYTHON) $(CONF_OPT_PYTHON3) \
- $(CONF_OPT_TCL) $(CONF_OPT_RUBY) $(CONF_OPT_NLS) \
+ $(CONF_OPT_TCL) $(CONF_OPT_RUBY) $(CONF_OPT_MRUBY) $(CONF_OPT_NLS) \
$(CONF_OPT_CSCOPE) $(CONF_OPT_MULTIBYTE) $(CONF_OPT_INPUT) \
$(CONF_OPT_OUTPUT) $(CONF_OPT_GPM) $(CONF_OPT_WORKSHOP) \
$(CONF_OPT_SNIFF) $(CONF_OPT_FEAT) $(CONF_TERM_LIB) \
@@ -2580,6 +2588,9 @@
objects/if_ruby.o: if_ruby.c
$(CCC) $(RUBY_CFLAGS) -o $@ if_ruby.c
+objects/if_mruby.o: if_mruby.c
+ $(CCC) $(MRUBY_CFLAGS) -o $@ if_mruby.c
+
objects/if_sniff.o: if_sniff.c
$(CCC) -o $@ if_sniff.c
@@ -3108,6 +3119,10 @@
ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
arabic.h version.h
+objects/if_mruby.o: if_mruby.c auto/config.h vim.h feature.h os_unix.h auto/osdef.h \
+ ascii.h keymap.h term.h macros.h option.h structs.h regexp.h gui.h \
+ gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h globals.h farsi.h \
+ arabic.h version.h
objects/if_sniff.o: if_sniff.c vim.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h gui_beval.h proto/gui_beval.pro ex_cmds.h proto.h \
diff -r ccbde540a714 src/buffer.c
--- a/src/buffer.c Wed Apr 03 21:14:29 2013 +0200
+++ b/src/buffer.c Fri Apr 05 21:20:11 2013 +0900
@@ -666,6 +666,9 @@
#ifdef FEAT_RUBY
ruby_buffer_free(buf);
#endif
+#ifdef FEAT_MRUBY
+ mruby_buffer_free(buf);
+#endif
#ifdef FEAT_AUTOCMD
aubuflocal_remove(buf);
#endif
diff -r ccbde540a714 src/config.aap.in
--- a/src/config.aap.in Wed Apr 03 21:14:29 2013 +0200
+++ b/src/config.aap.in Fri Apr 05 21:20:11 2013 +0900
@@ -73,6 +73,12 @@
RUBY_CFLAGS = @RUBY_CFLAGS@
RUBY_LIBS = @RUBY_LIBS@
+MRUBY_SRC = @MRUBY_SRC@
+MRUBY_OBJ = @MRUBY_OBJ@
+MRUBY_PRO = @MRUBY_PRO@
+MRUBY_CFLAGS = @MRUBY_CFLAGS@
+MRUBY_LIBS = @MRUBY_LIBS@
+
SNIFF_SRC = @SNIFF_SRC@
SNIFF_OBJ = @SNIFF_OBJ@
diff -r ccbde540a714 src/config.h.in
--- a/src/config.h.in Wed Apr 03 21:14:29 2013 +0200
+++ b/src/config.h.in Fri Apr 05 21:20:11 2013 +0900
@@ -356,6 +356,9 @@
/* Define for linking via dlopen() or LoadLibrary() */
#undef DYNAMIC_RUBY
+/* Define if you want to include the MRuby interpreter. */
+#undef FEAT_MRUBY
+
/* Define if you want to include the Tcl interpreter. */
#undef FEAT_TCL
diff -r ccbde540a714 src/config.mk.in
--- a/src/config.mk.in Wed Apr 03 21:14:29 2013 +0200
+++ b/src/config.mk.in Fri Apr 05 21:20:11 2013 +0900
@@ -96,6 +96,12 @@
RUBY_CFLAGS = @RUBY_CFLAGS@
RUBY_LIBS = @RUBY_LIBS@
+MRUBY_SRC = @MRUBY_SRC@
+MRUBY_OBJ = @MRUBY_OBJ@
+MRUBY_PRO = @MRUBY_PRO@
+MRUBY_CFLAGS = @MRUBY_CFLAGS@
+MRUBY_LIBS = @MRUBY_LIBS@
+
SNIFF_SRC = @SNIFF_SRC@
SNIFF_OBJ = @SNIFF_OBJ@
diff -r ccbde540a714 src/configure.in
--- a/src/configure.in Wed Apr 03 21:14:29 2013 +0200
+++ b/src/configure.in Fri Apr 05 21:20:11 2013 +0900
@@ -1540,6 +1540,32 @@
AC_SUBST(RUBY_CFLAGS)
AC_SUBST(RUBY_LIBS)
+AC_MSG_CHECKING(--enable-mrubyinterp argument)
+AC_ARG_ENABLE(mrubyinterp,
+ [ --enable-mrubyinterp[=OPTS] Include MRuby interpreter. [default=no] [OPTS=no/yes/dynamic]], ,
+ [enable_mrubyinterp="no"])
+AC_MSG_RESULT($enable_mrubyinterp)
+if test "$enable_mrubyinterp" = "yes"; then
+ if test "x$MRUBY_ROOT" != "x" -a -f "$MRUBY_ROOT/build/host/lib/libmruby.flags.mak"; then
+ MRUBY_CFLAGS=`grep MRUBY_CFLAGS $MRUBY_ROOT/build/host/lib/libmruby.flags.mak | sed 's/MRUBY_CFLAGS\s*=\s*//'`
+ MRUBY_LIBS=`grep MRUBY_LIBS $MRUBY_ROOT/build/host/lib/libmruby.flags.mak | sed 's/MRUBY_LIBS\s*=\s*//'`
+ MRUBY_LIBS="$MRUBY_LIBS $MRUBY_ROOT/build/host/lib/libmruby.a $MRUBY_ROOT/build/host/lib/libmruby_core.a"
+ MRUBY_SRC="if_mruby.c"
+ MRUBY_OBJ="objects/if_mruby.o"
+ MRUBY_PRO="if_mruby.pro"
+ AC_DEFINE(FEAT_MRUBY)
+ else
+ AC_MSG_ERROR(not found; disabling MRuby)
+ fi
+else
+ AC_MSG_ERROR(not found; disabling MRuby)
+fi
+AC_SUBST(MRUBY_SRC)
+AC_SUBST(MRUBY_OBJ)
+AC_SUBST(MRUBY_PRO)
+AC_SUBST(MRUBY_CFLAGS)
+AC_SUBST(MRUBY_LIBS)
+
AC_MSG_CHECKING(--enable-cscope argument)
AC_ARG_ENABLE(cscope,
[ --enable-cscope Include cscope interface.], ,
diff -r ccbde540a714 src/eval.c
--- a/src/eval.c Wed Apr 03 21:14:29 2013 +0200
+++ b/src/eval.c Fri Apr 05 21:20:11 2013 +0900
@@ -6026,8 +6026,9 @@
return item1 == NULL && item2 == NULL;
}
-#if defined(FEAT_RUBY) || defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) \
- || defined(FEAT_MZSCHEME) || defined(FEAT_LUA) || defined(PROTO)
+#if defined(FEAT_RUBY) || defined(FEAT_MRUBY) || defined(FEAT_PYTHON) || \
+ defined(FEAT_PYTHON3) || defined(FEAT_MZSCHEME) || defined(FEAT_LUA) || \
+ defined(PROTO)
/*
* Return the dictitem that an entry in a hashtable points to.
*/
@@ -12377,6 +12378,9 @@
#if defined(FEAT_RUBY) && !defined(DYNAMIC_RUBY)
"ruby",
#endif
+#if defined(FEAT_MRUBY)
+ "mruby",
+#endif
#ifdef FEAT_SCROLLBIND
"scrollbind",
#endif
diff -r ccbde540a714 src/ex_cmds.h
--- a/src/ex_cmds.h Wed Apr 03 21:14:29 2013 +0200
+++ b/src/ex_cmds.h Fri Apr 05 21:20:11 2013 +0900
@@ -619,6 +619,12 @@
BANG|FILE1|TRLBAR),
EX(CMD_mode, "mode", ex_mode,
WORD1|TRLBAR|CMDWIN),
+EX(CMD_mruby, "mruby", ex_mruby,
+ RANGE|EXTRA|NEEDARG|CMDWIN),
+EX(CMD_mrubydo, "mrubydo", ex_mrubydo,
+ RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN),
+EX(CMD_mrubyfile, "mrubyfile", ex_mrubyfile,
+ RANGE|FILE1|NEEDARG|CMDWIN),
EX(CMD_mzscheme, "mzscheme", ex_mzscheme,
RANGE|EXTRA|DFLALL|NEEDARG|CMDWIN|SBOXOK),
EX(CMD_mzfile, "mzfile", ex_mzfile,
diff -r ccbde540a714 src/ex_docmd.c
--- a/src/ex_docmd.c Wed Apr 03 21:14:29 2013 +0200
+++ b/src/ex_docmd.c Fri Apr 05 21:20:11 2013 +0900
@@ -134,6 +134,7 @@
|| !defined(FEAT_PYTHON) || !defined(FEAT_PYTHON3) \
|| !defined(FEAT_TCL) \
|| !defined(FEAT_RUBY) \
+ || !defined(FEAT_MRUBY) \
|| !defined(FEAT_LUA) \
|| !defined(FEAT_MZSCHEME)
# define HAVE_EX_SCRIPT_NI
@@ -284,6 +285,11 @@
# define ex_rubydo ex_ni
# define ex_rubyfile ex_ni
#endif
+#ifndef FEAT_MRUBY
+# define ex_mruby ex_script_ni
+# define ex_mrubydo ex_ni
+# define ex_mrubyfile ex_ni
+#endif
#ifndef FEAT_SNIFF
# define ex_sniff ex_ni
#endif
@@ -2593,6 +2599,7 @@
case CMD_return:
case CMD_rightbelow:
case CMD_ruby:
+ case CMD_mruby:
case CMD_silent:
case CMD_smagic:
case CMD_snomagic:
diff -r ccbde540a714 src/if_mruby.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/if_mruby.c Fri Apr 05 21:20:11 2013 +0900
@@ -0,0 +1,812 @@
+/* vi:set ts=8 sts=4 sw=4:
+ *
+ * VIM - Vi IMproved by Bram Moolenaar
+ *
+ * MRuby interface by Yasuhiro Matsumoto
+ *
+ * Do ":help uganda" in Vim to read copying and usage conditions.
+ * Do ":help credits" in Vim to see a list of people who contributed.
+ * See README.txt for an overview of the Vim source code.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "auto/config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+#include <mruby.h>
+#include <mruby/compile.h>
+#include <mruby/class.h>
+#include <mruby/proc.h>
+#include <mruby/data.h>
+#include <mruby/array.h>
+#include <mruby/hash.h>
+#include <mruby/string.h>
+#include <mruby/variable.h>
+
+#include "vim.h"
+#include "version.h"
+
+static mrb_state* mrb = NULL;
+static struct mrbc_context* context = NULL;
+static mrb_value objtbl;
+static struct RObject* mrb_stdout;
+
+static struct RClass* mVIM;
+static struct RClass* cBuffer;
+static struct RClass* cVimWindow;
+static struct RClass* eDeletedBufferError;
+static struct RClass* eDeletedWindowError;
+
+static int ensure_mruby_initialized(void);
+static void error_print();
+static void mruby_io_init(void);
+static void mruby_vim_init(void);
+
+static void
+mrb_vim_free(mrb_state *mrb, void *p) {
+}
+
+static const struct mrb_data_type VIM_Window_type = {
+ "VIM::Window", mrb_vim_free,
+};
+
+static const struct mrb_data_type VIM_Buffer_type = {
+ "VIM::Buffer", mrb_vim_free,
+};
+
+void
+mruby_end()
+{
+ if (context) {
+ mrbc_context_free(mrb, context);
+ context = NULL;
+ }
+ if (mrb) {
+ mrb_close(mrb);
+ mrb = NULL;
+ }
+}
+
+static mrb_value
+eval_string(const char *str)
+{
+ mrb_value result;
+ struct mrb_parser_state *parser;
+ int ai = mrb_gc_arena_save(mrb);
+ parser = mrb_parser_new(mrb);
+ parser->s = str;
+ parser->send = str + strlen(str);
+ parser->lineno = 1;
+ mrb_parser_parse(parser, context);
+ result = mrb_nil_value();
+ if (0 < parser->nerr) {
+ MSG(parser->error_buffer[0].message);
+ } else {
+ int n = mrb_generate_code(mrb, parser);
+ result = mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
+ }
+ mrb_gc_arena_restore(mrb, ai);
+ mrb_parser_free(parser);
+ return result;
+}
+
+void
+ex_mruby(exarg_T *eap)
+{
+ char *script = NULL;
+
+ script = (char *)script_get(eap, eap->arg);
+ if (!eap->skip && ensure_mruby_initialized()) {
+ eval_string(script ? script : (char *)eap->arg);
+ if (mrb->exc)
+ error_print();
+ }
+ vim_free(script);
+}
+
+void ex_mrubydo(exarg_T *eap)
+{
+ linenr_T i;
+
+ if (ensure_mruby_initialized())
+ {
+ if (u_save(eap->line1 - 1, eap->line2 + 1) != OK)
+ return;
+ for (i = eap->line1; i <= eap->line2; i++) {
+ mrb_value line;
+
+ line = mrb_str_new_cstr(mrb, (char *)ml_get(i));
+ mrb_vm_const_set(mrb, mrb_intern(mrb, "$_"), line);
+ line = eval_string((char *) eap->arg);
+ if (mrb->exc) {
+ error_print();
+ break;
+ }
+ line = mrb_vm_const_get(mrb, mrb_intern(mrb, "$_"));
+ if (!mrb_nil_p(line)) {
+ if (mrb_type(line) != MRB_TT_STRING) {
+ EMSG(_("E265: $_ must be an instance of String"));
+ return;
+ }
+ ml_replace(i, (char_u *) mrb_string_value_ptr(mrb, line), 1);
+ changed();
+#ifdef SYNTAX_HL
+ syn_changed(i); /* recompute syntax hl. for this line */
+#endif
+ }
+ }
+ check_cursor();
+ update_curbuf(NOT_VALID);
+ }
+}
+
+void ex_mrubyfile(exarg_T *eap)
+{
+ if (ensure_mruby_initialized())
+ {
+ FILE* fp = fopen((char *) eap->arg, "rb");
+ if (fp) {
+ mrbc_filename(mrb, context, (char *) eap->arg);
+ mrb_load_file_cxt(mrb, fp, context);
+ fclose(fp);
+ if (mrb->exc)
+ error_print();
+ } else {
+ EMSG("Cannot open file");
+ }
+
+ }
+}
+
+void mruby_buffer_free(buf_T *buf)
+{
+ if (buf->b_mruby_ref)
+ {
+ mrb_funcall(mrb, objtbl, "[]=", 2,
+ mrb_fixnum_value(mrb_obj_id(*(mrb_value*) buf->b_mruby_ref)),
+ mrb_nil_value());
+ ((struct RData*) buf->b_mruby_ref)->data = NULL;
+ }
+}
+
+void mruby_window_free(win_T *win)
+{
+ if (win->w_mruby_ref)
+ {
+ mrb_funcall(mrb, objtbl, "[]=", 2,
+ mrb_fixnum_value(mrb_obj_id(*(mrb_value*) win->w_mruby_ref)),
+ mrb_nil_value());
+ ((struct RData*) win->w_mruby_ref)->data = NULL;
+ }
+}
+
+static int ensure_mruby_initialized(void)
+{
+ if (!mrb)
+ {
+ mrb = mrb_open();
+ if (mrb) {
+ context = mrbc_context_new(mrb);
+ context->capture_errors = 1;
+ mruby_io_init();
+ mruby_vim_init();
+ }
+ }
+ return mrb != NULL;
+}
+
+static void
+error_print()
+{
+ EMSG(mrb_string_value_ptr(mrb, mrb_obj_value(mrb->exc)));
+ mrb->exc = 0;
+}
+
+static mrb_value vim_message(mrb_state *mrb, mrb_value self)
+{
+ char *buff, *p;
+ mrb_value str;
+ int ai = mrb_gc_arena_save(mrb);
+
+ mrb_get_args(mrb, "o", &str);
+
+ str = mrb_obj_as_string(mrb, str);
+ if (RSTRING_LEN(str) > 0) {
+ MSG(RSTRING_PTR(str));
+ } else {
+ MSG("");
+ }
+ mrb_gc_arena_restore(mrb, ai);
+ return mrb_nil_value();
+}
+
+static mrb_value vim_set_option(mrb_state* mrb, mrb_value self)
+{
+ mrb_value str;
+ mrb_get_args(mrb, "S", &str);
+ do_set((char_u *) mrb_string_value_ptr(mrb, str), 0);
+ update_screen(NOT_VALID);
+ return mrb_nil_value();
+}
+
+static mrb_value vim_command(mrb_state* mrb, mrb_value self)
+{
+ mrb_value str;
+ mrb_get_args(mrb, "S", &str);
+ do_cmdline_cmd((char_u *) mrb_string_value_ptr(mrb, str));
+ return mrb_nil_value();
+}
+
+#ifdef FEAT_EVAL
+static mrb_value vim_to_mruby(typval_T *tv)
+{
+ mrb_value result = mrb_nil_value();
+
+ if (tv->v_type == VAR_STRING)
+ {
+ result = mrb_str_new_cstr(mrb, tv->vval.v_string == NULL
+ ? "" : (char *)(tv->vval.v_string));
+ }
+ else if (tv->v_type == VAR_NUMBER)
+ {
+ result = mrb_fixnum_value(tv->vval.v_number);
+ }
+# ifdef FEAT_FLOAT
+ else if (tv->v_type == VAR_FLOAT)
+ {
+ result = mrb_float_value(tv->vval.v_float);
+ }
+# endif
+ else if (tv->v_type == VAR_LIST)
+ {
+ list_T *list = tv->vval.v_list;
+ listitem_T *curr;
+
+ result = mrb_ary_new(mrb);
+
+ if (list != NULL)
+ {
+ for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
+ {
+ mrb_ary_push(mrb, result, vim_to_mruby(&curr->li_tv));
+ }
+ }
+ }
+ else if (tv->v_type == VAR_DICT)
+ {
+ result = mrb_hash_new(mrb);
+
+ if (tv->vval.v_dict != NULL)
+ {
+ hashtab_T *ht = &tv->vval.v_dict->dv_hashtab;
+ long_u todo = ht->ht_used;
+ hashitem_T *hi;
+ dictitem_T *di;
+
+ for (hi = ht->ht_array; todo > 0; ++hi)
+ {
+ if (!HASHITEM_EMPTY(hi))
+ {
+ --todo;
+
+ di = dict_lookup(hi);
+ mrb_funcall(mrb, result, "[]=", 2,
+ mrb_str_new_cstr(mrb, (char *)hi->hi_key),
+ vim_to_mruby(&di->di_tv));
+ }
+ }
+ }
+ } /* else return mrb_nil_value(); */
+
+ return result;
+}
+#endif
+
+static mrb_value vim_evaluate(mrb_state* mrb, mrb_value self)
+{
+#ifdef FEAT_EVAL
+ typval_T *tv;
+ mrb_value result;
+ mrb_value str;
+ mrb_get_args(mrb, "S", &str);
+
+ tv = eval_expr((char_u *) mrb_string_value_ptr(mrb, str), NULL);
+ if (tv == NULL)
+ {
+ return mrb_nil_value();
+ }
+ result = vim_to_mruby(tv);
+
+ free_tv(tv);
+
+ return result;
+#else
+ return mrb_nil_value();
+#endif
+}
+
+static mrb_value buffer_new(buf_T *buf)
+{
+ if (buf->b_mruby_ref)
+ {
+ return mrb_obj_value((struct RData*) buf->b_mruby_ref);
+ }
+ else
+ {
+ struct RData* obj = mrb_data_object_alloc(mrb, cBuffer, buf, &VIM_Buffer_type);
+ buf->b_mruby_ref = (void *) obj;
+ mrb_funcall(mrb, objtbl, "[]=", 2,
+ mrb_fixnum_value(mrb_obj_id(mrb_obj_value(obj))),
+ mrb_obj_value(obj));
+ return mrb_obj_value(obj);
+ }
+}
+
+static buf_T *get_buf(mrb_value obj)
+{
+ buf_T *buf;
+
+ Data_Get_Struct(mrb, obj, &VIM_Buffer_type, buf);
+ if (buf == NULL)
+ mrb_raise(mrb, eDeletedBufferError, "attempt to refer to deleted buffer");
+ return buf;
+}
+
+static mrb_value buffer_s_current(mrb_state* mrb, mrb_value self)
+{
+ return buffer_new(curbuf);
+}
+
+static mrb_value buffer_s_count(mrb_state* mrb, mrb_value self)
+{
+ buf_T *b;
+ int n = 0;
+
+ for (b = firstbuf; b != NULL; b = b->b_next)
+ {
+ /* Deleted buffers should not be counted
+ * SegPhault - 01/07/05 */
+ if (b->b_p_bl)
+ n++;
+ }
+
+ return mrb_fixnum_value(n);
+}
+
+static mrb_value buffer_s_aref(mrb_state* mrb, mrb_value self)
+{
+ mrb_value num;
+ buf_T *b;
+ int n;
+
+ mrb_get_args(mrb, "i", &num);
+ n = mrb_fixnum(num);
+
+ for (b = firstbuf; b != NULL; b = b->b_next)
+ {
+ /* Deleted buffers should not be counted
+ * SegPhault - 01/07/05 */
+ if (!b->b_p_bl)
+ continue;
+
+ if (n == 0)
+ return buffer_new(b);
+
+ n--;
+ }
+ return mrb_nil_value();
+}
+
+static mrb_value buffer_name(mrb_state* mrb, mrb_value self)
+{
+ buf_T *buf = get_buf(self);
+
+ return buf->b_ffname ? mrb_str_new_cstr(mrb, (char *)buf->b_ffname) : mrb_nil_value();
+}
+
+static mrb_value buffer_number(mrb_state* mrb, mrb_value self)
+{
+ buf_T *buf = get_buf(self);
+
+ return mrb_fixnum_value(buf->b_fnum);
+}
+
+static mrb_value buffer_count(mrb_state* mrb, mrb_value self)
+{
+ buf_T *buf = get_buf(self);
+
+ return mrb_fixnum_value(buf->b_ml.ml_line_count);
+}
+
+static mrb_value get_buffer_line(buf_T *buf, linenr_T n)
+{
+ if (n <= 0 || n > buf->b_ml.ml_line_count)
+ mrb_raisef(mrb, E_INDEX_ERROR, "line number %ld out of range", (long)n);
+ return mrb_str_new_cstr(mrb, (char *)ml_get_buf(buf, n, FALSE));
+}
+
+static mrb_value buffer_aref(mrb_state* mrb, mrb_value self)
+{
+ buf_T *buf = get_buf(self);
+
+ if (buf != NULL) {
+ mrb_value num;
+ mrb_get_args(mrb, "i", &num);
+ return get_buffer_line(buf, (linenr_T)mrb_fixnum(num));
+ }
+ return mrb_nil_value(); /* For stop warning */
+}
+
+static mrb_value set_buffer_line(buf_T *buf, linenr_T n, mrb_value str)
+{
+ char *line = mrb_string_value_ptr(mrb, str);
+ aco_save_T aco;
+
+ if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL)
+ {
+ /* set curwin/curbuf for "buf" and save some things */
+ aucmd_prepbuf(&aco, buf);
+
+ if (u_savesub(n) == OK) {
+ ml_replace(n, (char_u *)line, TRUE);
+ changed();
+#ifdef SYNTAX_HL
+ syn_changed(n); /* recompute syntax hl. for this line */
+#endif
+ }
+
+ /* restore curwin/curbuf and a few other things */
+ aucmd_restbuf(&aco);
+ /* Careful: autocommands may have made "buf" invalid! */
+
+ update_curbuf(NOT_VALID);
+ }
+ else
+ {
+ mrb_raisef(mrb, E_INDEX_ERROR, "line number %ld out of range", (long)n);
+ }
+ return str;
+}
+
+static mrb_value buffer_aset(mrb_state* mrb, mrb_value self)
+{
+ buf_T *buf = get_buf(self);
+ mrb_value num, str;
+
+ mrb_get_args(mrb, "iS", &num, &str);
+ if (buf != NULL) {
+ return set_buffer_line(buf, (linenr_T)mrb_fixnum(num), str);
+ }
+ return str;
+}
+
+static mrb_value buffer_delete(mrb_state* mrb, mrb_value self)
+{
+ buf_T *buf = get_buf(self);
+ mrb_value num;
+ long n;
+ aco_save_T aco;
+
+ mrb_get_args(mrb, "i", &num);
+ n = mrb_fixnum(num);
+ if (n > 0 && n <= buf->b_ml.ml_line_count)
+ {
+ /* set curwin/curbuf for "buf" and save some things */
+ aucmd_prepbuf(&aco, buf);
+
+ if (u_savedel(n, 1) == OK) {
+ ml_delete(n, 0);
+
+ /* Changes to non-active buffers should properly refresh
+ * SegPhault - 01/09/05 */
+ deleted_lines_mark(n, 1L);
+
+ changed();
+ }
+
+ /* restore curwin/curbuf and a few other things */
+ aucmd_restbuf(&aco);
+ /* Careful: autocommands may have made "buf" invalid! */
+
+ update_curbuf(NOT_VALID);
+ }
+ else
+ {
+ mrb_raisef(mrb, E_INDEX_ERROR, "line number %ld out of range", n);
+ }
+ return mrb_nil_value();
+}
+
+static mrb_value buffer_append(mrb_state* mrb, mrb_value self)
+{
+ buf_T *buf = get_buf(self);
+ mrb_value num, str;
+ char *line;
+ long n;
+ aco_save_T aco;
+
+ mrb_get_args(mrb, "iS", &num, &str);
+ line = mrb_string_value_ptr(mrb, str);
+ n = mrb_fixnum(num);
+ if (line == NULL)
+ {
+ mrb_raise(mrb, E_INDEX_ERROR, "NULL line");
+ }
+ else if (n >= 0 && n <= buf->b_ml.ml_line_count)
+ {
+ /* set curwin/curbuf for "buf" and save some things */
+ aucmd_prepbuf(&aco, buf);
+
+ if (u_inssub(n + 1) == OK) {
+ ml_append(n, (char_u *) line, (colnr_T) 0, FALSE);
+
+ /* Changes to non-active buffers should properly refresh screen
+ * SegPhault - 12/20/04 */
+ appended_lines_mark(n, 1L);
+
+ changed();
+ }
+
+ /* restore curwin/curbuf and a few other things */
+ aucmd_restbuf(&aco);
+ /* Careful: autocommands may have made "buf" invalid! */
+
+ update_curbuf(NOT_VALID);
+ }
+ else
+ {
+ mrb_raisef(mrb, E_INDEX_ERROR, "line number %ld out of range", n);
+ }
+ return str;
+}
+
+static mrb_value window_new(win_T *win)
+{
+ if (win->w_mruby_ref)
+ {
+ return mrb_obj_value((struct RData*) win->w_mruby_ref);
+ }
+ else
+ {
+ struct RData* obj = mrb_data_object_alloc(mrb, cVimWindow, win, &VIM_Window_type);
+ win->w_mruby_ref = (void *) obj;
+ mrb_funcall(mrb, objtbl, "[]=", 2,
+ mrb_fixnum_value(mrb_obj_id(mrb_obj_value(obj))),
+ mrb_obj_value(obj));
+ return mrb_obj_value(obj);
+ }
+}
+
+static win_T *get_win(mrb_value obj)
+{
+ win_T *win;
+
+ Data_Get_Struct(mrb, obj, &VIM_Window_type, win);
+ if (win == NULL)
+ mrb_raise(mrb, eDeletedWindowError, "attempt to refer to deleted window");
+ return win;
+}
+
+static mrb_value window_s_current(mrb_state* mrb, mrb_value self)
+{
+ return window_new(curwin);
+}
+
+/*
+ * Added line manipulation functions
+ * SegPhault - 03/07/05
+ */
+static mrb_value line_s_current(mrb_state* mrb, mrb_value self)
+{
+ return get_buffer_line(curbuf, curwin->w_cursor.lnum);
+}
+
+static mrb_value set_current_line(mrb_state* mrb, mrb_value self)
+{
+ mrb_value str;
+ mrb_get_args(mrb, "S", &str);
+ return set_buffer_line(curbuf, curwin->w_cursor.lnum, str);
+}
+
+static mrb_value current_line_number(mrb_state* mrb, mrb_value self)
+{
+ return mrb_fixnum_value((int)curwin->w_cursor.lnum);
+}
+
+
+
+static mrb_value window_s_count(mrb_state* mrb, mrb_value self)
+{
+#ifdef FEAT_WINDOWS
+ win_T *w;
+ int n = 0;
+
+ for (w = firstwin; w != NULL; w = w->w_next)
+ n++;
+ return mrb_fixnum_value(n);
+#else
+ return mrb_fixnum_value(1);
+#endif
+}
+
+static mrb_value window_s_aref(mrb_state* mrb, mrb_value self)
+{
+ win_T *w;
+ int n;
+ mrb_value num;
+
+ mrb_get_args(mrb, "i", &num);
+ n = mrb_fixnum(num);
+#ifndef FEAT_WINDOWS
+ w = curwin;
+#else
+ for (w = firstwin; w != NULL; w = w->w_next, --n)
+#endif
+ if (n == 0)
+ return window_new(w);
+ return mrb_nil_value();
+}
+
+static mrb_value window_buffer(mrb_state* mrb, mrb_value self)
+{
+ win_T *win = get_win(self);
+
+ return buffer_new(win->w_buffer);
+}
+
+static mrb_value window_height(mrb_state* mrb, mrb_value self)
+{
+ win_T *win = get_win(self);
+
+ return mrb_fixnum_value(win->w_height);
+}
+
+static mrb_value window_set_height(mrb_state* mrb, mrb_value self)
+{
+ win_T *win = get_win(self);
+ win_T *savewin = curwin;
+ mrb_value height;
+
+ mrb_get_args(mrb, "i", &height);
+ curwin = win;
+ win_setheight(mrb_fixnum(height));
+ curwin = savewin;
+ return height;
+}
+
+static mrb_value window_width(mrb_state* mrb, mrb_value self)
+{
+ win_T *win = get_win(self);
+
+ return mrb_fixnum_value(win->w_width);
+}
+
+static mrb_value window_set_width(mrb_state* mrb, mrb_value self)
+{
+ win_T *win = get_win(self);
+ win_T *savewin = curwin;
+ mrb_value width;
+
+ mrb_get_args(mrb, "i", &width);
+ curwin = win;
+ win_setwidth(mrb_fixnum(width));
+ curwin = savewin;
+ return width;
+}
+
+static mrb_value window_cursor(mrb_value self)
+{
+ win_T *win = get_win(self);
+
+ return mrb_assoc_new(mrb, mrb_fixnum_value(win->w_cursor.lnum), mrb_fixnum_value(win->w_cursor.col));
+}
+
+static mrb_value window_set_cursor(mrb_state* mrb, mrb_value self)
+{
+ mrb_value lnum, col;
+ win_T *win = get_win(self);
+ mrb_value pos;
+
+ mrb_get_args(mrb, "A", &pos);
+ mrb_check_type(mrb, pos, MRB_TT_ARRAY);
+ if (RARRAY_LEN(pos) != 2)
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "array length must be 2");
+ lnum = RARRAY_PTR(pos)[0];
+ col = RARRAY_PTR(pos)[1];
+ win->w_cursor.lnum = mrb_fixnum(lnum);
+ win->w_cursor.col = mrb_fixnum(col);
+ check_cursor(); /* put cursor on an existing line */
+ update_screen(NOT_VALID);
+ return mrb_nil_value();
+}
+
+static mrb_value f_nop(mrb_state* mrb, mrb_value self)
+{
+ return mrb_nil_value();
+}
+
+static mrb_value f_p(mrb_state* mrb, mrb_value self)
+{
+ int argc;
+ mrb_value *argv;
+ int i;
+ mrb_value str;
+
+ mrb_get_args(mrb, "*", &argv, &argc);
+ str = mrb_str_new(mrb, "", 0);
+
+ for (i = 0; i < argc; i++) {
+ if (i > 0) mrb_str_cat(mrb, str, ", ", 2);
+ mrb_str_concat(mrb, str, mrb_inspect(mrb, argv[i]));
+ }
+ MSG(RSTRING_PTR(str));
+ return mrb_nil_value();
+}
+
+static void mruby_io_init(void)
+{
+ mrb_define_method(mrb, mrb->kernel_module, "p", f_p, ARGS_OPT(1));
+ mrb_define_method(mrb, mrb->kernel_module, "puts", vim_message, ARGS_OPT(1));
+}
+
+static void mruby_vim_init(void)
+{
+ objtbl = mrb_hash_new(mrb);
+ mrb_gv_set(mrb, mrb_intern(mrb, "$VIM_OBJECTS"), objtbl);
+
+ mVIM = mrb_define_module(mrb, "Vim");
+ mrb_define_const(mrb, mrb->object_class, "VIM", mrb_obj_value(mVIM));
+ mrb_define_const(mrb, mVIM, "VERSION_MAJOR", mrb_fixnum_value(VIM_VERSION_MAJOR));
+ mrb_define_const(mrb, mVIM, "VERSION_MINOR", mrb_fixnum_value(VIM_VERSION_MINOR));
+ mrb_define_const(mrb, mVIM, "VERSION_BUILD", mrb_fixnum_value(VIM_VERSION_BUILD));
+ mrb_define_const(mrb, mVIM, "VERSION_PATCHLEVEL", mrb_fixnum_value(VIM_VERSION_PATCHLEVEL));
+ mrb_define_const(mrb, mVIM, "VERSION_SHORT", mrb_str_new_cstr(mrb, VIM_VERSION_SHORT));
+ mrb_define_const(mrb, mVIM, "VERSION_MEDIUM", mrb_str_new_cstr(mrb, VIM_VERSION_MEDIUM));
+ mrb_define_const(mrb, mVIM, "VERSION_LONG", mrb_str_new_cstr(mrb, VIM_VERSION_LONG));
+ mrb_define_const(mrb, mVIM, "VERSION_LONG_DATE", mrb_str_new_cstr(mrb, VIM_VERSION_LONG_DATE));
+ mrb_define_module_function(mrb, mVIM, "message", vim_message, ARGS_REQ(1));
+ mrb_define_module_function(mrb, mVIM, "set_option", vim_set_option, ARGS_REQ(1));
+ mrb_define_module_function(mrb, mVIM, "command", vim_command, ARGS_REQ(1));
+ mrb_define_module_function(mrb, mVIM, "evaluate", vim_evaluate, ARGS_REQ(1));
+
+ eDeletedBufferError = mrb_define_class_under(mrb, mVIM, "DeletedBufferError",
+ mrb->eStandardError_class);
+ eDeletedWindowError = mrb_define_class_under(mrb, mVIM, "DeletedWindowError",
+ mrb->eStandardError_class);
+
+ cBuffer = mrb_define_class_under(mrb, mVIM, "Buffer", mrb->object_class);
+ mrb_define_singleton_method(mrb, cBuffer, "current", buffer_s_current, ARGS_NONE());
+ mrb_define_singleton_method(mrb, cBuffer, "count", buffer_s_count, ARGS_NONE());
+ mrb_define_singleton_method(mrb, cBuffer, "[]", buffer_s_aref, 1);
+ mrb_define_method(mrb, cBuffer, "name", buffer_name, ARGS_NONE());
+ mrb_define_method(mrb, cBuffer, "number", buffer_number, ARGS_NONE());
+ mrb_define_method(mrb, cBuffer, "count", buffer_count, ARGS_NONE());
+ mrb_define_method(mrb, cBuffer, "length", buffer_count, ARGS_NONE());
+ mrb_define_method(mrb, cBuffer, "[]", buffer_aref, ARGS_REQ(1));
+ mrb_define_method(mrb, cBuffer, "[]=", buffer_aset, ARGS_REQ(2));
+ mrb_define_method(mrb, cBuffer, "delete", buffer_delete, ARGS_REQ(1));
+ mrb_define_method(mrb, cBuffer, "append", buffer_append, ARGS_REQ(2));
+
+ mrb_define_method(mrb, cBuffer, "line_number", current_line_number, ARGS_NONE());
+ mrb_define_method(mrb, cBuffer, "line", line_s_current, ARGS_NONE());
+ mrb_define_method(mrb, cBuffer, "line=", set_current_line, ARGS_REQ(1));
+
+
+ cVimWindow = mrb_define_class_under(mrb, mVIM, "Window", mrb->object_class);
+ mrb_define_singleton_method(mrb, cVimWindow, "current", window_s_current, ARGS_NONE());
+ mrb_define_singleton_method(mrb, cVimWindow, "count", window_s_count, ARGS_NONE());
+ mrb_define_singleton_method(mrb, cVimWindow, "[]", window_s_aref, ARGS_REQ(1));
+ mrb_define_method(mrb, cVimWindow, "buffer", window_buffer, ARGS_NONE());
+ mrb_define_method(mrb, cVimWindow, "height", window_height, ARGS_NONE());
+ mrb_define_method(mrb, cVimWindow, "height=", window_set_height, ARGS_REQ(1));
+ mrb_define_method(mrb, cVimWindow, "width", window_width, ARGS_NONE());
+ mrb_define_method(mrb, cVimWindow, "width=", window_set_width, ARGS_REQ(1));
+ mrb_define_method(mrb, cVimWindow, "cursor", window_cursor, ARGS_NONE());
+ mrb_define_method(mrb, cVimWindow, "cursor=", window_set_cursor, ARGS_REQ(1));
+
+ mrb_define_method(mrb, mrb->kernel_module, "__curbuf", buffer_s_current, ARGS_NONE());
+ mrb_define_method(mrb, mrb->kernel_module, "__curwin", window_s_current, ARGS_NONE());
+}
diff -r ccbde540a714 src/main.c
--- a/src/main.c Wed Apr 03 21:14:29 2013 +0200
+++ b/src/main.c Fri Apr 05 21:20:11 2013 +0900
@@ -1471,6 +1471,9 @@
#ifdef FEAT_RUBY
ruby_end();
#endif
+#ifdef FEAT_MRUBY
+ mruby_end();
+#endif
#ifdef FEAT_PYTHON
python_end();
#endif
diff -r ccbde540a714 src/proto.h
--- a/src/proto.h Wed Apr 03 21:14:29 2013 +0200
+++ b/src/proto.h Fri Apr 05 21:20:11 2013 +0900
@@ -197,6 +197,10 @@
# include "if_ruby.pro"
# endif
+# ifdef FEAT_MRUBY
+# include "if_mruby.pro"
+# endif
+
/* Ugly solution for "BalloonEval" not being defined while it's used in some
* .pro files. */
# ifndef FEAT_BEVAL
diff -r ccbde540a714 src/proto/if_mruby.pro
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/proto/if_mruby.pro Fri Apr 05 21:20:11 2013 +0900
@@ -0,0 +1,9 @@
+/* if_ruby.c */
+int mruby_enabled __ARGS((int verbose));
+void mruby_end __ARGS((void));
+void ex_mruby __ARGS((exarg_T *eap));
+void ex_mrubydo __ARGS((exarg_T *eap));
+void ex_mrubyfile __ARGS((exarg_T *eap));
+void mruby_buffer_free __ARGS((buf_T *buf));
+void mruby_window_free __ARGS((win_T *win));
+/* vim: set ft=c : */
diff -r ccbde540a714 src/screen.c
--- a/src/screen.c Wed Apr 03 21:14:29 2013 +0200
+++ b/src/screen.c Fri Apr 05 21:20:11 2013 +0900
@@ -301,8 +301,9 @@
#endif
}
-#if defined(FEAT_RUBY) || defined(FEAT_PERL) || defined(FEAT_VISUAL) || \
- (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO)
+#if defined(FEAT_RUBY) || defined(FEAT_MRUBY) || defined(FEAT_PERL) || \
+ defined(FEAT_VISUAL) || (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || \
+ defined(PROTO)
/*
* update all windows that are editing the current buffer
*/
diff -r ccbde540a714 src/structs.h
--- a/src/structs.h Wed Apr 03 21:14:29 2013 +0200
+++ b/src/structs.h Fri Apr 05 21:20:11 2013 +0900
@@ -1671,6 +1671,10 @@
void *b_ruby_ref;
#endif
+#ifdef FEAT_MRUBY
+ void *b_mruby_ref;
+#endif
+
#if defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
synblock_T b_s; /* Info related to syntax highlighting. w_s
* normally points to this, but some windows
@@ -2172,6 +2176,10 @@
#ifdef FEAT_RUBY
void *w_ruby_ref;
#endif
+
+#ifdef FEAT_MRUBY
+ void *w_mruby_ref;
+#endif
};
/*
diff -r ccbde540a714 src/version.c
--- a/src/version.c Wed Apr 03 21:14:29 2013 +0200
+++ b/src/version.c Fri Apr 05 21:20:11 2013 +0900
@@ -521,6 +521,11 @@
#else
"-ruby",
#endif
+#ifdef FEAT_RUBY
+ "+mruby",
+#else
+ "-mruby",
+#endif
#ifdef FEAT_SCROLLBIND
"+scrollbind",
#else
diff -r ccbde540a714 src/window.c
--- a/src/window.c Wed Apr 03 21:14:29 2013 +0200
+++ b/src/window.c Fri Apr 05 21:20:11 2013 +0900
@@ -4484,6 +4484,10 @@
ruby_window_free(wp);
#endif
+#ifdef FEAT_MRUBY
+ mruby_window_free(wp);
+#endif
+
clear_winopt(&wp->w_onebuf_opt);
clear_winopt(&wp->w_allbuf_opt);

How to apply this patch

$ cd /path/to/vim
$ curl https://gist.github.com/raw/4662845/vim7-if_mruby.diff | patch -p1
$ make autoconf
$ export MRUBY_ROOT=/path/to/mruby
$ ./configure --enable-mrubyinterp=yes
$ make
+++ b/src/proto/if_mruby.pro Thu Jan 31 11:31:22 2013 +0900
@@ -0,0 +1,9 @@
+/* if_ruby.c */

if_ruby.c -> if_mruby.c

--- a/src/version.c Wed Jan 30 21:56:21 2013 +0100
+++ b/src/version.c Thu Jan 31 11:31:22 2013 +0900
@@ -518,6 +518,11 @@
 #else
 "-ruby",
 #endif
+#ifdef FEAT_RUBY
+ "+mruby",
+#else
+ "-mruby",
+#endif

FEAT_RUBY -> FEAT_MRUBY

+# MRUBY
+#CONF_OPT_MRUBY = --enable-rubyinterp
+

--enable-rubyinterp -> --enable-mrubyinterp

あざます
configureで指定してない時にエラー出てたの直しました。

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.