Rua: テーブルまわりとか

http://storehouse.sakura.ne.jp/viewvc/viewvc.cgi/rua/rua/rua.c?root=svn&view=markup
Array→テーブルは1オリジンにした。

  • Luaで定義した関数をRubyで呼ぶ
  • Rubyで定義した関数をLuaで呼ぶ
  • Hashとテーブルの相互互換
  • Array→テーブル
require 'rua'

rua = Rua.new
rua[:rtbl] = { 0 => 'AAA', 'XXX' => 100, 'ary' => [1, 2, 3] }
rua[:rary] = ['AAA', 'BBB', 'CCC']

p rua.eval(<<EOS)
  for k, v in pairs(rtbl) do
    print('key:' .. k)
    print(v)
  end

  print();

  for i, v in ipairs(rary) do
    print('idx:' .. i)
    print(v)
  end

  retval = {}
  retval[0] = nil
  retval[1] = 'xxxx'
  retval[2] = {}
  retval[2]['AAA'] = 'aaa'
  retval[2]['BBB'] = 'bbb'
  return retval
EOS


{1.0=>"xxxx", 2.0=>{"AAA"=>"aaa", "BBB"=>"bbb"}}
key:0
AAA
key:XXX
100
key:ary
table: 003F9D80

idx:1
AAA
idx:2
BBB
idx:3
CCC