• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Lua与C++的故事
记录西风的成长...
博客园    首页    新随笔    联系   管理    订阅  订阅

我的Lua小函数之创建iup菜单

  require 'cdlua'
  require 'iuplua'
  require 'iupluacd'

  function event_handler_g (self)
      iup.Message(self.title,'dispatch message')
  end

  function event_handler1 (self)
      iup.Message(self.title,'event 1 dispatch message')
  end
  function event_handler2 (self)
      iup.Message(self.title,'event 2 dispatch message')
  end
  function event_handler3 (self)
      iup.Message(self.title,'event 3 dispatch message')
  end

  my_menu_test =
  {
      nil,'M1',{event_handler_g,'M11','M12','M13',{event_handler3,'M21','M22',},},'M2',{event_handler_g,'M22','M23',},
  }

  function my_create_menu2(menu_define_table)

      local items={}

      for k,v in pairs(menu_define_table) do
          if type(v) == 'function' or type(v)=='nil' then
  --~             event_handler=v
              ___my_library__global__event_handler=v
          end

          if type(v) =='string' then
  --~             local item=iup.item{title=v,action=event_handler}
              local item=iup.item{title=v,action=___my_library__global__event_handler}
              table.insert(items,item)
          end

          if type(v) =='table' then
              local m1_menu_title=table.remove(items)
              local item=iup.submenu {my_create_menu2(v),title=tostring(m1_menu_title.title)}
              table.insert(items,item)
          end
      end--end of for
      return iup.menu(items)
  end

  my_main_frame=iup.frame
      {
          iup.canvas
          {
              cursor='CROSS',
              scrollbar='VERTICAL',
              posy=0.0,
              ymax=0.8,
          }
      }

  dlg = iup.dialog
  {
      my_main_frame,
      size="HALFxHALF",
      title="finally I got the expected result",
      menu=my_create_menu2(my_menu_test),
  }

  dlg:showxy(iup.CENTER,iup.CENTER)

  if (not iup.MainLoopLevel or iup.MainLoopLevel()==0) then
    iup.MainLoop()
  end

后记,已经发布在了我的粘贴里,不过它上面说是根据时间访问来删除旧帖子的,我怕时间久了这点记忆再没有了

posted @ 2009-11-04 18:33  西风飘流  阅读(1570)  评论(3)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3