News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
testing presence of ML feature
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
RE: testing presence of ML feature

Another possible test is for a specific version of murgaLua, in the event that you have multiple new features in your script and just don't want to support older versions. You could check for a feature that was added to that specific version, but it's *possible* that sometime in the future that feature could be removed or renamed. You would always need to make sure you use a feature that is specific to your script, rather than just a generic cut-and-paste test. That's not a serious issue, but anything that can reuse existing code makes development go more smoothly.

I couldn't figure out why I couldn't use tonumber(murgaLua.version) for comparison, so I didn't bother with it. Then it struck me that a string with two decimals in it can't be converted into a number, so I decided to do string comparisons instead:

Code:
-- find the smallest negative index in the arg table
-- this is the Lua interpreter
for i in pairs(arg) do
if not low or i < low then low=i end
end
lua_interpreter=arg[low]

-- test the murgaLua version
err="This program requires murgaLua 0.5.5 or newer.\nhttp://www.murga-projects.com/murgaLua/index.html"
notallowed={"0.1","0.2","0.3","0.4","0.4.1","0.5"} -- add "0.5.5" if you need 0.6
for k,v in ipairs(notallowed) do
  if not murgaLua.version or v == murgaLua.version then
    print(lua_interpreter..": "..err) -- print error in case it's tried in regular Lua
    fltk.fl_alert(err) -- popup error
    os.exit(1)
  end
end


This method allows you to simply copy and paste the code reliably into any script that needs at least version 0.5.5
It also uses an additional print() just in case the end user tries to run the script in some other kind of Lua interpreter. I haven't tested this in Lua proper yet, but i think it would exit cleanly just from not finding murgaLua.version

Maybe there are simpler ways to do this, but this at least is more reliable for general use.

02-07-2008 05:45 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
testing presence of ML feature - mikshaw - 01-20-2008, 05:37 AM
RE: testing presence of ML feature - mikshaw - 02-07-2008 05:45 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: