[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Python
. . -> [Subject]  Python?

Python?

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


Pages: 1  2 

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #15 on Fri 25 Apr 2003 01:45 AM (UTC)

Amended on Fri 25 Apr 2003 03:21 AM (UTC) by Nick Gammon

Message
Never mind, I seem to have worked that out.


x = world.GetInternalCommandsList

#
# show length of array
#

world.note (len (x))

#
# interate through array
#

for cmd in world.GetInternalCommandsList: world.Note (cmd)


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ixokai   USA  (24 posts)  [Biography] bio
Date Reply #16 on Fri 25 Apr 2003 02:58 AM (UTC)
Message
*laugh* Mark, you answer your own questions faster then I can even think about trying to pretend to answer them. The only question I see that you don't appear to have answered yourself is the constants list. There is no conception of 'constant' in python, although I can build a class to do it for you rather easily. Its unnessecary though, really... Just spit out a list of variables.

eOK = 0 # No Error
eWorldOpen = 30001 # The world is already open.

..etc... that's it.. Python is very not-force-you-to-obey-the-rules. Python programmers do what they're supposed to without it. :)
[Go to top] top

Posted by Ixokai   USA  (24 posts)  [Biography] bio
Date Reply #17 on Fri 25 Apr 2003 03:01 AM (UTC)
Message
One comment: is GetInternalCommandList a function or the /actual/ array? If its a function you need ()'s at the end..

x = world.GetInternalCommandList()

world.note(len(x))

for cmd in world.GetInternalCommandList():
world.note(cmd)
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #18 on Fri 25 Apr 2003 03:26 AM (UTC)
Message
I misspelt it, it is GetInternalCommandsList, not GetInternalCommandList, however my example worked apart from that.

Adding the brackets stops it working, however GetInternalCommandsList is a function returning a variant array, not an actual array.

for cmd in world.GetInternalCommandsList: world.Note (cmd)

If I add the brackets I get the error "'tuple' object is not callable".


The only remaining problem seems to be that the script engine doesn't seem to support "global" members. so I need to explicitly use world.X whereas in the other languages I can omit "world." which I am starting to do in recent examples. Unless you know a way of working around that, eg. something like the old Pascal syntax:

with world do
Note ("aha")
end

instead of world.Note ("aha")

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #19 on Fri 25 Apr 2003 03:53 AM (UTC)
Message
OK, check out Script error codes - the Python list is now there.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ixokai   USA  (24 posts)  [Biography] bio
Date Reply #20 on Fri 25 Apr 2003 03:56 AM (UTC)
Message
That's odd. Python is seeing that GetInternalCommandsList as an array. A tuple is an array which can't change size, basically. Interesting.

You can't do that whole "with" type of thing in Pyhton. If world was a module, you might be able to:

from world import *

But i highly doubt that'll work in this situation. You'll probably havae to 'world.Note' etc. Its pythonic.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #21 on Fri 25 Apr 2003 10:33 PM (UTC)

Amended on Sat 26 Apr 2003 04:13 AM (UTC) by Nick Gammon

Message
In case someone is searching the Net for this one day, here is how I fixed it.

The error message was:

"The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."

Module: chkesp.c line 42

The solution was to change the CoCreateInstance call slightly. No change was made to calling conventions.



Old, did not work:


IActiveScript       * m_IActiveScript;

::CoCreateInstance(clsid,  
    NULL, 
    CLSCTX_ALL, 
    IID_IUnknown,
    reinterpret_cast<void**>(&m_IActiveScript));




New, this works:


IActiveScript       * m_IActiveScript;

::CoCreateInstance(clsid,  
    NULL, 
    CLSCTX_ALL, 
    IID_IActiveScript,
    reinterpret_cast<void**>(&m_IActiveScript));



- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ixokai   USA  (24 posts)  [Biography] bio
Date Reply #22 on Fri 25 Apr 2003 11:38 PM (UTC)
Message
The only way I can think of to achieve that global members issue, is for you to do:

import __builtin__

__builtin__.Note = world.Note

... for each of the functions. A short cut that may or may not work is:

__builtin__.__dict__.update(world.__dict__)

If 'world' doesn't have a dictionary, this won't work... I dont know how these activex objects work in python internally. If it does work it'll copy world's dictionary into the global namespace. __dict__ is an associative array that represents a perticular namespace, essentially.

I *personally* think this is a bad idea and that everything should be 'world.Note' etc... Standard pythonism is 'explicit is better then implicit' :)
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #23 on Fri 25 Apr 2003 11:49 PM (UTC)
Message
Quote:

import __builtin__

__builtin__.Note = world.Note



This idea seems to work, however I agree there isn't much point, especially if you need to only do one line.


world.Note ("hello")


seems shorter to me than:


import __builtin__
__builtin__.Note = world.Note
Note ("hello")


I only asked because I was starting to get used to the way VBscript lets me get away without typing "world." all the time.

I am about ready to release the Python-compatible version, if you look at the scripting functions pages you see there is now an entry for the Python example for each script function.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #24 on Fri 25 Apr 2003 11:54 PM (UTC)

Amended on Fri 25 Apr 2003 11:55 PM (UTC) by Nick Gammon

Message
Hey, this is pretty cute. In Python I can do this:

/world.note (str(world.GetInternalCommandsList))

This gives me:


(u'ActivityList', u'ActivityToolbar', u'AltDownArrow', u'AltUpArrow', u'AlwaysOnTop', u'AutoSay', u'BookmarkSelection', u'BugReports', u'ClearCommandHistory', u'ClearOutput', u'CloseAllNotepadWindows', u'ColourPicker', u'CommandEnd', u'CommandHistory', u'CommandHome', u'ConfigureAliases', u'ConfigureAutosay', u'ConfigureColours', u'ConfigureCommands', u'ConfigureCustomColours', u'ConfigureHighlighting', u'ConfigureKeypad', u'ConfigureLogging', u'ConfigureMacros', u'ConfigureMudaddress', u'ConfigureMxpPueblo', u'ConfigureNameAndPassword', u'ConfigureNotes', u'ConfigureOutput', u'ConfigurePasteToWorld', u'ConfigurePrinting', u'ConfigureScripting', u'ConfigureSendFile', u'ConfigureTimers', u'ConfigureTriggers', u'ConfigureVariables', u'Connect', u'ConnectToAllOpenWorlds', u'ConnectToWorldsInStartupList', u'ContextHelp', u'Copy', u'CopyAsHTML', u'CtrlN', u'CtrlP', u'CtrlZ', u'Cut', u'DebugIncomingPackets', u'DebugWorldInput', u'DiscardQueuedCommands', u'Disconnect', u'DoMapperComment', u'DoMapperSpecial', u'East', u'EditScriptFile', u'End', u'Examine', u'Find', u'FindAgain', u'FlipToNotepad', u'Forum', u'FreezeOutput', u'FullScreenMode', u'FunctionsWebPage', u'GettingStarted', u'GenerateCharacterName', u'GlobalPreferences', u'GoToBookmark', u'GoToLine', u'GoToURL', u'Help', u'HelpContents', u'Immediate', u'Import', u'Info', u'InfoBar', u'InputGlobalChange', u'Keypad0', u'Keypad1', u'Keypad2', u'Keypad3', u'Keypad4', u'Keypad5', u'Keypad6', u'Keypad7', u'Keypad8', u'Keypad9', u'KeypadDash', u'KeypadDot', u'KeypadPlus', u'KeypadSlash', u'KeypadStar', u'KeysEscape', u'KeysTab', u'LineDown', u'LineUp', u'LogSession', u'Look', u'MacroCtrlF10', u'MacroCtrlF11', u'MacroCtrlF12', u'MacroCtrlF2', u'MacroCtrlF3', u'MacroCtrlF5', u'MacroCtrlF7', u'MacroCtrlF8', u'MacroCtrlF9', u'MacroF10', u'MacroF11', u'MacroF12', u'MacroF2', u'MacroF3', u'MacroF4', u'MacroF5', u'MacroF7', u'MacroF8', u'MacroF9', u'MacroShiftF10', u'MacroShiftF11', u'MacroShiftF12', u'MacroShiftF2', u'MacroShiftF3', u'MacroShiftF4', u'MacroShiftF5', u'MacroShiftF6', u'MacroShiftF7', u'MacroShiftF8', u'MacroShiftF9', u'Mapper', u'MinimiseProgram', u'Minimize', u'MudLists', u'NextCommand', u'NextPane', u'NoCommandEcho', u'North', u'NotesWorkArea', u'OpenWorldsInStartupList', u'PageDown', u'Pageup', u'Paste', u'Paste', u'PasteFile', u'PasteToMush', u'PluginWizard', u'Plugins', u'Preferences', u'PreviousCommand', u'Print', u'QuickConnect', u'Quit', u'RecallText', u'ReconnectOnDisconnect', u'Register', u'ReloadDefaults', u'ReloadNamesFile', u'ReloadScriptFile', u'RepeatLastCommand', u'RepeatLastWord', u'ResetAllTimers', u'ResetToolbars', u'Save', u'SelectAll', u'SendToAllWorlds', u'South', u'SpellCheck', u'Start', u'StopSoundPlaying', u'Take', u'TestCommand', u'TestTrigger', u'TextAttributes', u'TipOfTheDay', u'Trace', u'Undo', u'Up', u'WebPage', u'West', u'Whisper', u'WindowsSocketInformation', u'WrapOutput')


I presume the "u" is for Unicode.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ixokai   USA  (24 posts)  [Biography] bio
Date Reply #25 on Sat 26 Apr 2003 02:14 AM (UTC)
Message
Yep. u'' is a unicode string. r'' is a raw-string... They're used for regexps or paths, so you don't have to constantly escape slashes. Etc, etc. :)

In reference to the builtin thing, I was confused and thought you wanted to do this in some global-default sort of way.
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #26 on Mon 05 May 2003 07:38 AM (UTC)
Message
Quote:
*laugh* Mark, you answer your own questions faster then I can even think about trying to pretend to answer them.

Who's Mark? :p

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Ixokai   USA  (24 posts)  [Biography] bio
Date Reply #27 on Tue 06 May 2003 03:31 AM (UTC)
Message
Er. Me in a stupid-moment. Mark is Nick. Nick is Mark. Come on, I can rename whoever I want.
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #28 on Wed 07 May 2003 11:30 AM (UTC)
Message
Just kidding :p

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] 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.


60,559 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]