2012-11-12 23:52:26 -05:00
|
|
|
import os, sys, re, ostools
|
|
|
|
try:
|
|
|
|
import lua
|
|
|
|
except ImportError:
|
|
|
|
lua = None
|
|
|
|
from quirks import ScriptQuirks
|
|
|
|
from PyQt4 import QtGui, QtCore
|
|
|
|
|
|
|
|
class LuaQuirks(ScriptQuirks):
|
|
|
|
def loadModule(self, name, filename):
|
|
|
|
if lua is None:
|
|
|
|
return None
|
2013-02-10 12:49:44 -05:00
|
|
|
|
|
|
|
lua.globals().package.loaded[name] = None
|
2013-02-26 01:02:30 -05:00
|
|
|
|
2013-02-10 12:49:44 -05:00
|
|
|
CurrentDir = os.getcwd()
|
|
|
|
os.chdir('quirks')
|
|
|
|
try:
|
|
|
|
return lua.require(name)
|
|
|
|
except Error as e:
|
2013-02-26 01:02:30 -05:00
|
|
|
print e
|
2013-02-10 12:49:44 -05:00
|
|
|
return None
|
|
|
|
finally:
|
|
|
|
os.chdir(CurrentDir)
|
2012-11-12 23:52:26 -05:00
|
|
|
|
|
|
|
def getExtension(self):
|
|
|
|
return '.lua'
|
|
|
|
|
|
|
|
def modHas(self, module, attr):
|
|
|
|
return module[attr] is not None
|
|
|
|
|
|
|
|
def register(self, module):
|
|
|
|
class Wrapper(object):
|
|
|
|
def __init__(self, module, name):
|
|
|
|
self.module = module
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def __call__(self, text):
|
2013-02-10 12:49:44 -05:00
|
|
|
CurrentDir = os.getcwd()
|
|
|
|
os.chdir('quirks')
|
|
|
|
try:
|
|
|
|
return self.module.commands[self.name](lua.globals().tostring(text))
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
finally:
|
|
|
|
os.chdir(CurrentDir)
|
2012-11-12 23:52:26 -05:00
|
|
|
|
|
|
|
for name in module.commands:
|
2013-02-10 12:49:44 -05:00
|
|
|
CommandWrapper = Wrapper(module,name)
|
2012-11-12 23:52:26 -05:00
|
|
|
try:
|
2013-02-10 12:49:44 -05:00
|
|
|
if not isinstance(CommandWrapper("test"), basestring):
|
2012-11-12 23:52:26 -05:00
|
|
|
raise Exception
|
|
|
|
except:
|
|
|
|
print "Quirk malformed: %s" % (name)
|
|
|
|
msgbox = QtGui.QMessageBox()
|
|
|
|
msgbox.setWindowTitle("Error!")
|
|
|
|
msgbox.setText("Quirk malformed: %s" % (name))
|
|
|
|
msgbox.exec_()
|
|
|
|
else:
|
2013-02-10 12:49:44 -05:00
|
|
|
self.quirks[name] = CommandWrapper
|
2012-11-12 23:52:26 -05:00
|
|
|
|