BYOND Hack - "Embed" Python code in DM
Start off by installing Python if you haven't already got it (it comes standard with pretty much any modern OS but Windows). Next grab my byondthon.py script and run it. This script will start a fake web server on port 9001 which we'll be using to execute our Python code.
Now, fire up Dream Maker and start a new project. Paste in the following code:
proc/python(code)
var/http[] = world.Export("http://127.0.0.1:9001?" + code)
if(!http)
usr << "Failed to connect."
return
var/F = http["CONTENT"]
if(F)
usr << html_encode(file2text(F))
mob/verb/test()
python({"
import time, sys
print 'Hello from python', sys.version
print 'The time is: ' + time.asctime()
print 'Did you know that 792 to the power of 42 is ', 792**42, '?'"})
(Yes the indenting within the test verb should be like that. Otherwise Python will get confused by the extra whitespace.)
Now try running it and using the test verb.
Cool, huh? ;-)
Posted by BobOfDoom on Tuesday, March 06, 2007 04:03AM
- 4 comments
(link)
/
Keywords:
byondhacks
(Edited on Tuesday, March 06, 2007 04:14AM)

