Merge branch 'brachyonic-LuaQuirks-chdir'
This commit is contained in:
commit
1a80f607f1
1 changed files with 23 additions and 6 deletions
27
luaquirks.py
27
luaquirks.py
|
@ -10,9 +10,18 @@ class LuaQuirks(ScriptQuirks):
|
||||||
def loadModule(self, name, filename):
|
def loadModule(self, name, filename):
|
||||||
if lua is None:
|
if lua is None:
|
||||||
return None
|
return None
|
||||||
fullname = os.path.join('quirks', name)
|
|
||||||
lua.globals().package.loaded[fullname] = None
|
lua.globals().package.loaded[name] = None
|
||||||
return lua.require(fullname)
|
|
||||||
|
CurrentDir = os.getcwd()
|
||||||
|
os.chdir('quirks')
|
||||||
|
try:
|
||||||
|
return lua.require(name)
|
||||||
|
except Error as e:
|
||||||
|
print e
|
||||||
|
return None
|
||||||
|
finally:
|
||||||
|
os.chdir(CurrentDir)
|
||||||
|
|
||||||
def getExtension(self):
|
def getExtension(self):
|
||||||
return '.lua'
|
return '.lua'
|
||||||
|
@ -27,11 +36,19 @@ class LuaQuirks(ScriptQuirks):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def __call__(self, text):
|
def __call__(self, text):
|
||||||
|
CurrentDir = os.getcwd()
|
||||||
|
os.chdir('quirks')
|
||||||
|
try:
|
||||||
return self.module.commands[self.name](lua.globals().tostring(text))
|
return self.module.commands[self.name](lua.globals().tostring(text))
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
finally:
|
||||||
|
os.chdir(CurrentDir)
|
||||||
|
|
||||||
for name in module.commands:
|
for name in module.commands:
|
||||||
|
CommandWrapper = Wrapper(module,name)
|
||||||
try:
|
try:
|
||||||
if not isinstance(module.commands[name]("test"), basestring):
|
if not isinstance(CommandWrapper("test"), basestring):
|
||||||
raise Exception
|
raise Exception
|
||||||
except:
|
except:
|
||||||
print "Quirk malformed: %s" % (name)
|
print "Quirk malformed: %s" % (name)
|
||||||
|
@ -40,5 +57,5 @@ class LuaQuirks(ScriptQuirks):
|
||||||
msgbox.setText("Quirk malformed: %s" % (name))
|
msgbox.setText("Quirk malformed: %s" % (name))
|
||||||
msgbox.exec_()
|
msgbox.exec_()
|
||||||
else:
|
else:
|
||||||
self.quirks[name] = Wrapper(module, name)
|
self.quirks[name] = CommandWrapper
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue