lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


With changing two 'typo', it didn't give any error for me.

Nope, still mysterious. :-)

I got my code to work with your changes, but the code I sent was just an abstraction of the real code I have problems with.I thought the problem stemmed from my erroneous referencing of functions, but maybe it doesn't

I'm trying to build a small wikiwiki in lua. The problem is when I try to convert the wiki-markup to HTML. Parts of my real wikiwiki code has been attached below. The first gsub() in htmlize() works like a charm, printing the wiki-links contained in the raw text. Unfortunately the second gsub(), which is supposed to supply each wiki-link to htmlize_link(), converting it to HTML, doesn't work equally well. The captured part of the text is never propagated to the htmlize_link(). Why is that?

Oh, and I'm sorry if I pollute some developer-only list, but as far as I can tell this list is also suitable for lua-users...?

/ Sebastian Rasmussen

function page(data)
 print("page() called")
 local instance = {}

 instance.Data = data

 -- Convert wiki-link to HTML tags
 function instance:htmlize_link(link)
   print("page:htmlize_link(", link, ") called")

   if link == nil then
     print("page:htmlize_link() exited with error (link was nil)")
     return nil
   end

   print("page:htmlize_link() exited successfully")
   return "<a href=\"/pages/"..link.."\">"..link.."</a>"
 end

 -- Convert all wiki-links to appropriate HTML-tags.
 -- Everything enclosed within [] is considered to be a link.
 function instance:htmlize()
   print("page:htmlize() called")

   if self.Data == nil then
     print("page:htmlize() exited with error (data was nil)")
     return nil
   end

   -- The first gsub() below is for debugging purposes only
   print("Wiki-links:")
   gsub(self.Data, "%[([^]]*)%]", print)

   -- This is the statement that doesn't work
   self.Data = gsub(self.Data, "%[([^]]*)%]", self.htmlize_link)

   print("page:htmlize() exited successfully")
   return 1
 end

 print("page() constructed successfully")
 return instance
end

function main()
local page = page("This is some [Text] to test [Wikification] of raw text")

 page:htmlize()
 print(page.Data)
end

main()


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx