Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Error when attempting to "require" tprint

Error when attempting to "require" tprint

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Bobble   Canada  (76 posts)  Bio
Date Wed 31 Dec 2008 12:32 AM (UTC)

Amended on Wed 31 Dec 2008 12:34 AM (UTC) by Bobble

Message
Greets everyone,

I wanted to try using the tprint function that Nick so kindly included with MUSHclient. However, when I tried to put it in my script file, I get an error.

I put:
require "tprint"

at the beginning of my script file. Now when it is loaded I get this error:

Run-time error
World: Curing - Plugin
Immediate execution
error loading module 'tprint' from file 'C:\Program Files\Games\MUSHclient\lua\tprint.lua':
        C:\Program Files\Games\MUSHclient\lua\tprint.lua:50: '<eof>' expected near 'function'
stack traceback:
        [C]: ?
        [C]: in function 'require'
        [string "Script file"]:13: in main chunk

I wish I could make sense of it. It seems it's missing an <eof> but I have no idea what that means or where to put it. Does anyone know what's causing this?

On a related note, I had been fooling around with tprint a few weeks ago. I wanted to call it from an alias so that I could specify the table I wanted printed in a wildcard, such as tprint * So I could type:

tprint cures

And have it print out the table cures. I copied and pasted the tprint function into my script file and then had my alias call this function.

function print_table (name, line, wildcards)
   tprint(wildcards[1])
end

I got an error when doing this because tprint was expecting a table, but got a string (wildcards[1]).

Does anyone know how I might create an alias that will have the tprint function print out a table specified in the wildcard?

Open the watch.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 31 Dec 2008 12:50 AM (UTC)
Message
Sounds like tprint.lua has become corrupted. Try deleting that file and then reinstalling MUSHclient, to get a new copy.

As for "tprint cures" - tprint is a function, and unless you are sending a string literal, you have to put its arguments into quotes, like this:


tprint (cures)


This is also wrong:


tprint(wildcards[1])


Wildcards is a table, but wildcards [1] is a string, as it said. To look at your wildcards you need:


tprint(wildcards)


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Bobble   Canada  (76 posts)  Bio
Date Reply #2 on Wed 31 Dec 2008 01:09 AM (UTC)
Message
Hi Nick,

I think I was unclear about what I was trying to achieve. I wasn't trying to print the list of wildcards. I was trying to call tprint from an alias where the wildcard specified which table I wanted to print.

Thus if I had a table titled cures:

cures = {
 {name = "goldenseal"  , type = "herb"},
 {name = "epidermal"   , type = "salve"},
 {name = "bloodroot"   , type = "herb"}
}

I could use this alias:
<aliases>
  <alias
   name="print_table"
   script="print_table"
   match="tprint *"
   enabled="y"
   sequence="100"
  >
  </alias>
</aliases>

to call function that would pass the wildcard on to the tprint function and have it print out the table that corresponds with the wildcard name.

So if I typed

tprint cures

it would print out the cures table I specified above. But, like I said, wildcards are strings and it won't accept them. I was just wondering if there was a way to remove the "strigness" from them so that it would realize that the wildcard matches a table that has been created.


Open the watch.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 31 Dec 2008 01:20 AM (UTC)
Message
Oh. You mixed what looked like a script with what was really an alias. Try this:


function print_table (name, line, wildcards)
   tprint(_G [wildcards[1]])
end



_G is the global table, and thus indexing into it will give the appropriate table in the global variable space.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 31 Dec 2008 01:23 AM (UTC)
Message
I would normally do that without an alias, just type into the command window:


/tprint (cures)


I would need to ' require "tprint" ' before that would work, but I could put that into the sandbox to be executed every time the script engine loaded, if I was worried about it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Bobble   Canada  (76 posts)  Bio
Date Reply #5 on Wed 31 Dec 2008 03:40 AM (UTC)
Message
I reinstalled mushclient, still no dice with require "tprint"

I've copied and pasted the function into my script file instead. Everything's hunkey dorey with that.

I tried making the function called by the alias a little less error prone:
function print_table (name, line, wildcards)
	if _G [wildcards[1]] and type(_G [wildcards[1]]) == "table" then
     	tprint(_G [wildcards[1]])
	else
	    Note ("No such table. Check your capitalization.")
	end
end

It works very well and has been making my scripting a great deal easier.

Thanks for your help, take care.

Open the watch.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #6 on Wed 31 Dec 2008 07:20 PM (UTC)
Message
I'm not sure about the error requiring tprint. For one thing, my copy of the file is 48 lines long, so it appears that the error must be at the very end of the file (ie. the <eof> - End Of File).

You must have an eof - every file ends, yes?

If the exact same file, copied and pasted in, works, I don't know what to suggest there.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


24,897 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.