LuaGlobal Improvements - help needed

lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

Re: LuaGlobal Improvements

Post by lex »

Hi Denarii, tsuujin,

I'll take latest code from (http://github.com/babelfish/mudlet-lua.git) and start with logical organisation.

Please let me know if you are agree with proposed plan (previous note) and how can I upload it back

Thanks,
Lex


UPDATE: copy of previous note
My idea was to perform LuaGlobal clean up in following stages:

1. reorder function within LuaGlobal and make sure that's still working (I suppose that we'll sort it to following function groups: StringUtils, TableUtils, GUIUtils, DebugTools, Other - just a suggestion)

2. split LuaGlobal to separate files by functional group and make sure that is still working as whole

3. start to use LuaDoc and convert all documentation to it (ok all API documentation, there still be doc outside that will describe basic concepts and typical usage examples)

4. now we can actually start with new fixes and improvement to code and documentation

lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

Re: LuaGlobal Improvements

Post by lex »

I did reorder functions within LuaGlobal. Please take it (enclosed) and make another set of tests.
(There is also list of contributors, which I extracted.)

I did test it as described within this thread LugGlobal Debug
Everything seem to work fine. I only had issue with cecho function (Mudlet 1.1.1), so I used older one.
This have to be changed back for new Mudlet release.

There are now following groups (which will hopefully matches new files later):
  • String Utils
  • Table Utils
  • GUI Utils
  • Other
  • Debug Tools
I also started with LuaDoc, but I am clearly unimpressed. There are just too many limitations, so I'll try to found some alternative. In any case this could be just improvement, because we'll split the LuaGlobal and hopefully produce some generated doc as well.

I am also wondering where we are maintaining db.lua? I did found LuaGlobal.lua and logging.lua
on http://github.com/babelfish/mudlet-lua. It will probably make sense to manage all lua code at one place.
Attachments
NewLuaGlobal_v01.zip
(13.28 KiB) Downloaded 323 times

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: LuaGlobal Improvements

Post by Denarii »

What issue did you have with cecho?

lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

Re: LuaGlobal Improvements

Post by lex »

Heiko did some fix. See lines 1145 - 1215

Code: [show] | [select all] lua
       --- cecho(window,text)
	-- HEIKO: using this as a replacement until the problems of the real function
	--        are fixed.
	--
	--	function cecho(window, text)
	--		local win = text and window
	--		local s = text or window
	--		local reset
	--		if win then
	--			reset = function() resetFormat(win) end
	--		else
	--			reset = function() resetFormat() end
	--		end
	--		reset()
	--		for color, text in s:gmatch("<([a-zA-Z_:]+)>([^<>]+)") do
	--			if color == "reset" then
	--				reset()
	--				if win then echo(win, text) else echo(text) end
	--			else
	--				local colist  =   string.split(color..":", "%s*:%s*")
	--				local fgcol   =   colist[1] ~= "" and colist[1] or "white"
	--				local bgcol   =   colist[2] ~= "" and colist[2] or "black"
	--				local FGrgb   =   color_table[fgcol]
	--				local BGrgb   =   color_table[bgcol]
	--
	--				if win then
	--					setFgColor(win, FGrgb[1], FGrgb[2], FGrgb[3])
	--					setBgColor(win, BGrgb[1], BGrgb[2], BGrgb[3])
	--					echo(win,text)
	--				else
	--					setFgColor(FGrgb[1], FGrgb[2], FGrgb[3])
	--					setBgColor(BGrgb[1], BGrgb[2], BGrgb[3])
	--					echo(text)
	--				end
	--			end
	--		end
	--		reset()
	--	end
	function cecho(window,text)
       local win = text and window
       local s = text or window
       if win then
            resetFormat(win)
       else
            resetFormat()
       end
       for color,text in string.gmatch("<white>"..s, "<([a-z_0-9, :]+)>([^<>]+)") do
          local colist   =   string.split(color..":", "%s*:%s*")
          local fgcol   =   colist[1] ~= "" and colist[1] or "white"
          local bgcol   =   colist[2] ~= "" and colist[2] or "black"
          local FGrgb   =   color_table[fgcol] or string.split(fgcol, ",")
          local BGrgb   =   color_table[bgcol] or string.split(bgcol, ",")

          if win then
             setFgColor(win, FGrgb[1], FGrgb[2], FGrgb[3])
             setBgColor(win, BGrgb[1], BGrgb[2], BGrgb[3])
             echo(win,text)
          else
             setFgColor(FGrgb[1], FGrgb[2], FGrgb[3])
             setBgColor(BGrgb[1], BGrgb[2], BGrgb[3])
             echo(text)
          end
       end

       if win then
          resetFormat(win)
       else
          resetFormat()
       end
    end


User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: LuaGlobal Improvements

Post by Vadi »

It no longer applies

lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

Re: LuaGlobal Improvements

Post by lex »

well, cecho issue it certainly applied in my situation (Mudlet 1.1.1).

I suppose that this will go away in next Mudlet release - please correct me if I am wrong.

lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

Re: LuaGlobal Improvements

Post by lex »

I did split the LuaGlobal to separate files also added basic LuaDoc for logging and add it to group.
I was looking at some better doc tool, but haven't find anything standard and easy. I did generate documentation
so you can make idea what we'll get. I can see quite good improvement on separate lua files.
Please download it and have a look - we'll add some function documentation latter.

Unfortunately I have no idea how should I test this (separate lua files).

Once this will work than we need to add any other lua code to bundle - DB, Geyser, ... anything in upcoming release. (We also need to set order of file loading - if it's matter.)
Attachments
NewLuaGlobal_v02.zip
(32.51 KiB) Downloaded 329 times

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: LuaGlobal Improvements

Post by Vadi »

To test, just make a script that calls dofile. Scripts are run after LuaGlobal is.

lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

Re: LuaGlobal Improvements

Post by lex »

Testing:
Ok, I'll done some testing and everything looks fine too me. I would appreciate if someone else can confirm this, so we can take code and put it in GIT (all is enclosed). How did I test.
  • I created script (__NilAllExistingFunctions.lua) which should set all existing LuaGlobal functions to nil.
  • I run import (LuaGlobalLoader.lua) to reload all from separate files
  • test few function (ok, everything used by MAG which is depending on Geyser)
  • directly call few random functions to ensure that there are still working
Changes:
  • added DB.lua and Logging.lua (I used capitalized names to make it consistent with other files)
  • introduced LuaGlobalLoader.lua for loading all files in specific order
  • few LuaDoc updates
LuaDoc:
I did few tests in LuaDoc and it's starting to look better (see GUIUtils.lua > setGaugeText enclosed doc).
Wecan use some html tags, so it won't be so bad in the end. Only thing that I haven't manage is pre-formatted text. (I guess that we have to live with that, in any case this will be huge improvement.) I will update few more LuaDoc in meantime.
Attachments
NewLuaGlobal_v03.zip
Next Gen LuaGlobal v0.3
(47.73 KiB) Downloaded 328 times

lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

Re: LuaGlobal Improvements

Post by lex »

This update is demonstrating how can we use same documentation style for function implemented within Core Mudlet. See CoreMudlet.lua for details. See enclosed zip for documentation example.

Now we just need to :
  • use GIT for code changes.
  • Make some extra tests and
  • transform all remaining documentation to LuaDoc (and solve some problematic LuaDoc formatting).
Note: I was trying to extract list of functions implemented within Mudlet and I did try discover some weird thing with debug function. Debug is registered twice. Do you think that this was intended?
  • src/TLuaInterpreter.cpp:5290: lua_register( pGlobalLua, "debug", TLuaInterpreter::debug );
  • src/TLuaInterpreter.cpp:5311: lua_register( pGlobalLua, "debug", TLuaInterpreter::debug );
Attachments
NewLuaGlobal_v04.zip
New Gen LuaGlobal v4
(56.54 KiB) Downloaded 349 times

Post Reply