Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Murga Lua FLTK Editor, Crashing problems< Next Oldest | Next Newest >
Jason W Offline





Group: Members
Posts: 260
Joined: Nov. 2006
Posted: Mar. 26 2008,00:53 QUOTE

Has anyone else experienced the Murga Lua FLTK Editor crashing upon usage in DSL 4.2.5 and DSL 4.3RC1?  It crashes with me when i run in either regular live cd mode or in toram mode.  Trying to use any of it's menus (like open file) makes it crash, and gives this error:

/bin/lua: attempt to call a number value
stack traceback:
             [C]: in function 'run'
             /usr/local/bin/editor.lua:332: in main chunk
             [C]: ?

I have no knowledge of FLTK/Lua or I would try to fix it instead of just complain.  I would like to use the editor, and any help would be appreciated.
Back to top
Profile PM 
roberts Offline





Group: Members
Posts: 4983
Joined: Oct. 2003
Posted: Mar. 26 2008,03:43 QUOTE

Likely the menu construct changed with muragLua v0.6+

Try changing the menu items to this:
Code Sample

mb:add("&File/&New File",       0, new_cb)
mb:add("&File/&Open File",      0, open_cb)
mb:add("&File/&Insert File",    0, insert_cb)
mb:add("&File/&Save File",      0, save_cb)
mb:add("&File/Save File &As",   0, saveas_cb)
mb:add("&File/E&xit",           0, exit_cb)


mb:add("&Edit/&Undo",           0, undo_cb)
mb:add("&Edit/Cu&t",            0, cut_cb)

mb:add("&Edit/&Copy",           0, copy_cb)
mb:add("&Edit/&Paste",          0, paste_cb)
mb:add("&Edit/&Delete",         0, delete_cb)


mb:add("&Search/&Find...",      0, find_cb)
mb:add("&Search/Find &Again",   0, findagain_cb)
mb:add("&Search/&Replace...",   0, replace_cb)

mb:add("&Tools/&Insert Date",   0, insertdate_cb)

mb:add("&Help/&About",          0, about_cb)


Then of course you could delete the duplicate menu callback if-elseif stuff.

There might be more needed - not sure. But this will be a start.
Back to top
Profile PM WEB 
Jason W Offline





Group: Members
Posts: 260
Joined: Nov. 2006
Posted: Mar. 26 2008,14:05 QUOTE

I simply changed the menu items you mentioned and it works like a charm.  All menu functions work.  I tried to delete the elseif stuff you mentioned and one menu item made it crash, I believe the Save As option.  No doubt I deleted something that was supposed to stay, or vice versa.   I will look at  it more this afternoon when I have more time, and hopefully learn some MurgaLua in the process.  Thanks Robert for your help.
Back to top
Profile PM 
jaapz Offline





Group: Members
Posts: 129
Joined: May 2007
Posted: Mar. 26 2008,16:01 QUOTE

yep with me it just crashes on startup, i'll try the code
Back to top
Profile PM 
Jason W Offline





Group: Members
Posts: 260
Joined: Nov. 2006
Posted: Mar. 26 2008,22:47 QUOTE

This below seems to work for me.   I replaced the menu items with what Robert posted and simply deleted the duplicate callback stuff.  Thanks again.

Code Sample


#!/bin/lua

version = "0.02"
version = "0.03" -- added resizable, get argument for DND, default 800x600 - by RS

ww = 800
wh = 600

title = "MURGA LUA FLTK EDITOR - "

-- Main window
w = fltk:Fl_Double_Window(ww,wh,title)
w:resizable(w)

-- Text Buffer to hold file to edit
tb = fltk:Fl_Text_Buffer();

changed         = false
filename        = ""
saved           = true
newfile         = false
lastsearch      = ""
startPos        = 1

-- This will be used to hold copied / cutted text
clipboard = ""

-- Editor widget will work for standard keyboard shortcuts
ed = fltk:Fl_Text_Editor(10,30,ww-20,wh-60)
ed:buffer(tb)


function ask_save(object)
  if (not saved) then
       if fltk.fl_choice("There are unsevd Buffers. Do you want to save ?","No",nil,"Yes") >= 1 then
          save_cb()
      end
  end
end

-- check if we need to save to close
function check_save(object)
  if (not saved) then
      if fltk.fl_choice("There are unsaved Buffers. Do you Really want to exit ?","No",nil,"Yes") >= 1 then
          w:hide()
      end
  else
      w:hide()
  end
end
                                               
-- FILE MENU CALLBACKS

function new_cb()
  ask_save()
  newfile     = true
  filename    = "untitled"
  saved       = false
  tb:remove(0,tb:length())
  w:label(title .. filename)
end

function open_cb()
  ask_save()
  filename = fltk.fl_file_chooser("Select File to open", nil, nil, 0)
  if (filename ~= nil) then
      tb:loadfile(filename)
      w:label(title .. filename)
      saved = false
  end
end

function insert_cb()
  local fname = fltk.fl_file_chooser("Select File to insert", nil, nil, 0)
  if (fname ~= nil) then
      local pos = ed:insert_position()
      tb:insertfile(fname,pos)
  end
end


function save_cb()
  if (newfile) then
      saveas_cb()
  elseif (not saved) then
      if (tb:savefile(filename)) then
          saved = true
          fltk.fl_message("File " .. filename .. " Saved.")
      else
          fltk.fl_alert("Error writing file " .. filename)
      end
  end

end

function saveas_cb()
  local fname = fltk.fl_file_chooser("FILENAME TO SAVE", nil, nil, 0)
  if (fname ~= nil) then
      if (tb:savefile(fname)) then
          filename = fname
          w:label(title .. filename)
          saved = true
          fltk.fl_message("File " .. filename .. " Saved.")
      else
          fltk.fl_alert("Error writing file " .. filename)
      end
  end
end

function close_cb()
  ask_saved()
end


function exit_cb()
  check_save()
end

-- EDIT MENU CALLBACKS
function undo_cb()
end

function cut_cb()
  if ( tb:selected() ~= 0) then
      clipboard = tb:selection_text()
      tb:remove_selection()
  end
end

function copy_cb()
  if (tb:selected() ~= 0) then
      clipboard = tb:selection_text()
  end
end

function paste_cb()
  local pos = ed:insert_position()
  tb:insert(pos,clipboard)
end

function delete_cb()
  if (tb:selected() ~= 0) then
      tb:remove_selection()
  end
end


function delete_cb()
  if (tb:selected() ~= 0) then
      tb:remove_selection()
  end
end

-- SEARCH MENU CALLBACKS
function find_cb()
  local str, fnd, fndEnd
  startPos=1
  str = fltk.fl_input("Insert a string to search", lastsearch)
  if (str ~= nil) then
      --fnd = tb:search_forward(0,str,fnd,0)
      fnd,fndEnd = string.find(tb:text(),str,startPos)
      if (fnd ~= nil) then
          tb:select(fnd-1, fndEnd)
          lastsearch = str
          startPos = fndEnd
      else
          fltk.fl_message("String '" .. str .. "' Not found!")
      end
  end

end

function findagain_cb()

  if (lastsearch == "") then
      find_cb()
  else
      fnd,fndEnd= string.find(tb:text(),lastsearch,startPos)
      if (fnd ~= nil) then
          tb:select(fnd-1, fndEnd)
          startPos = fndEnd
      else
          fltk.fl_message("String '" .. lastsearch .. "' Not found!")
          startPos=1
      end
  end
end

function replace_cb()
  replace_dlg:show()
end

-- TOOLS CALLBACKS
function insertdate_cb()
  local pos = ed:insert_position()
  local date = os.date()
  tb:insert(pos,date)
end


-- HELP CALLBACKS
function about_cb()
  fltk.fl_message("MURGA LUA FLTK EDITOR\n\nMurga Lua Version of FLTK editor example\nBy Mauro Viarizzo (mav_it)\n\nVersion " .. version)
end

--- Build Up dynamically the menu:
mb = fltk:Fl_Menu_Bar(0,0,ww,30)
mb:callback(menuItem)

mb:add("&File/&New File",       0, new_cb)
mb:add("&File/&Open File",      0, open_cb)
mb:add("&File/&Insert File",    0, insert_cb)
mb:add("&File/&Save File",      0, save_cb)
mb:add("&File/Save File &As",   0, saveas_cb)
mb:add("&File/E&xit",           0, exit_cb)


mb:add("&Edit/&Undo",           0, undo_cb)
mb:add("&Edit/Cu&t",            0, cut_cb)

mb:add("&Edit/&Copy",           0, copy_cb)
mb:add("&Edit/&Paste",          0, paste_cb)
mb:add("&Edit/&Delete",         0, delete_cb)


mb:add("&Search/&Find...",      0, find_cb)
mb:add("&Search/Find &Again",   0, findagain_cb)
mb:add("&Search/&Replace...",   0, replace_cb)

mb:add("&Tools/&Insert Date",   0, insertdate_cb)

mb:add("&Help/&About",          0, about_cb)

--This does not seem to be implemented in MurgaLua FLTK
--tb:add_modify_callback(changed_cb, w)
--tb:call_modify_callbacks()

-- REPLACE DIALOG
replace_dlg     = fltk:Fl_Window    (420, 105, "Replace")
replace_find    = fltk:Fl_Input         ( 70, 10, 330, 25, "Find:")
replace_with    = fltk:Fl_Input         ( 70, 40, 330, 25, "Replace:")
replace_all     = fltk:Fl_Button        ( 10, 70,  90, 25, "Replace All")
replace_next    = fltk:Fl_Return_Button (105, 70, 120, 25, "Replace Next")
replace_skip    = fltk:Fl_Button        (230, 70, 120, 25, "Skip to Next")
replace_cancel  = fltk:Fl_Button        (355, 70,  60, 25, "Cancel")

replPos=1

-- CALLBACKS FOR REPLACE DIALOG
function replace_next_cb(mesg,doRepl)
  local findTxt = replace_find:value()
  local replTxt = replace_with:value()
  local fnd, fndEnd

  fnd,fndEnd = string.find(tb:text(),findTxt,replPos)
  if (fnd ~= nil) then
      if (doRepl) then
          tb:replace(fnd-1, fndEnd, replTxt)
      end
      replPos = tb:word_end(fnd)+1
      return true
  else
      if (mesg) then
          fltk.fl_message("String '" .. findTxt .. "' Not found!")
      end
      replPos = 1
      return false
  end
end

function replace_all_cb()
  local replaces = 0
  while (replace_next_cb(false, true)) do
      replaces = replaces + 1
  end
  fltk.fl_message("Replaced " .. replaces .. " occurrences")
end

function replace_skip_cb()
  replace_next_cb(true,false)
end

replace_cancel:callback(function () replace_dlg:hide() end )
replace_next:callback(function () replace_next_cb(true, true) end)
replace_skip:callback(function () replace_skip_cb() end)
replace_all:callback(function () replace_all_cb() end)


-- MAIN PROGRAM
if #arg == 1 then
  filename = arg[1]
  tb:loadfile(filename)
  w:label(title .. filename)
  saved=false
end
w:show()
Fl:run()

Back to top
Profile PM 
4 replies since Mar. 26 2008,00:53 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: Murga Lua FLTK Editor

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code