mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-30 17:03:31 +00:00
Added new script used by new embedded python implementation.
This makes it easier to control restricted/unrestricted python environments without requiring a client recompilation. Future enhancements are now more likely to be strictly python code changes.
This commit is contained in:
parent
7c36c0f0ef
commit
b47d5722eb
@ -16,6 +16,9 @@ Version 1.5.2+svn:
|
||||
areas and their schedules during scenario events. Removal requires to
|
||||
associate an id. to [time_area]s, or it won't work.
|
||||
* Python AI
|
||||
* Added ai_init.py and ai_launcher.py to make it easier to customize
|
||||
AI environment and startup. Both are used by the new embedded python
|
||||
implementation.
|
||||
* reversed builtin is now allowed. This allows for random.shuffle to be
|
||||
called.
|
||||
|
||||
|
47
data/ais/ai_launcher.py
Normal file
47
data/ais/ai_launcher.py
Normal file
@ -0,0 +1,47 @@
|
||||
#!/bin/env python
|
||||
# Copyright Greg Copeland, 2008
|
||||
# Released under GPL license for Wesnoth. See Wesnoth's
|
||||
# licensing terms for this module's specific license.
|
||||
#
|
||||
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
print "launch has been imported!"
|
||||
|
||||
def launch( script, restrict ):
|
||||
# Launch one of two possible environments
|
||||
# If restrict arg is True, run inside the available
|
||||
# restrictied python environment (safe.py). If restrict
|
||||
# is False, then run without any type of restrictions.
|
||||
if restrict:
|
||||
print "restricted environment detected - running parse/safe"
|
||||
try:
|
||||
import safe
|
||||
import parse
|
||||
|
||||
parse.paths = ""
|
||||
code, context = parse.parse( script )
|
||||
safe.safe_exec( code, context, restrict )
|
||||
|
||||
except:
|
||||
err = str( traceback.format_exc() )
|
||||
raise
|
||||
|
||||
else:
|
||||
print "unrestricted environment detected...running directly."
|
||||
__import__( script )
|
||||
scrpt = sys.modules[ script ]
|
||||
|
||||
# Call our entry points
|
||||
scrpt.start()
|
||||
scrpt.turn()
|
||||
scrpt.end()
|
||||
|
||||
print "launch has completed."
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user