Skip to content

Instantly share code, notes, and snippets.

lua_getglobal(L, "plugins");
lua_pushnil(L);
string pname;
bool loaded = false;
while (lua_next(L, -2) != 0) {
/* key is at -2, value at -1 */
if (lua_isstring(L, -2)) {
pname = lua_tostring(L, -2);
if (pname == name) {
loaded = true;
@FurryHead
FurryHead / test.ini
Created June 27, 2011 16:24
ConfigParser test ini file
; This is a comment
# This is also a comment
; This is a variable defined outside a section,
; you can access _these_ by using section name "DEFAULT"
; (Note: "DEFAULT" doesn't appear when you use ConfigParser.sections();)
foo = bar
[ freenode ] ;This is a section, leading/trailing whitespace trimmed, always enclosed by [ ]
host = irc.freenode.net ;This is a unquoted variable
@FurryHead
FurryHead / main.cxx
Created June 27, 2011 16:23
ConfigParser test file
/*
* main.cxx
*
* Copyright 2011 FurryHead <furryhead14@yahoo.com>
*
* ConfigParser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
@FurryHead
FurryHead / configparser.hxx
Created June 27, 2011 16:22
ConfigParser header file
/*
* configparser.hxx
*
* Copyright 2011 FurryHead <furryhead14@yahoo.com>
*
* ConfigParser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
@FurryHead
FurryHead / configparser.cxx
Created June 27, 2011 16:21
Code file for ConfigParser
/*
* configparser.cxx
*
* Copyright 2011 FurryHead <furryhead14@yahoo.com>
*
* ConfigParser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
@FurryHead
FurryHead / gist:1045197
Created June 24, 2011 16:58
Class user to parse raw irc user chunk.
class User(str):
def __new__(cls, user):
if getattr(user, "nick", None) is not None:
cls.nick = user.nick
cls.ident = user.ident
cls.host = user.host
else:
if re.match(".+!.+@.+", user):
cls.nick = user.split("!")[0]
cls.ident = user.split("!")[1].split("@")[0]
import threading
import inspect
import ctypes
def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
if not inspect.isclass(exctype):
raise TypeError("Only types can be raised (not instances)")
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
@FurryHead
FurryHead / TimeoutThread.py
Created June 14, 2011 22:15
Timeout thread.
import threading
class TimeoutException(Exception):
pass
class TimeoutThread(threading.Thread):
def run(self):
def timeout_handler(signum, frame):
raise TimeoutException()
@FurryHead
FurryHead / moduleloader.py
Created June 8, 2011 18:58
Module loader, to replace (somewhat) python's import. Does not work on .pyc - it's mainly for user files.
import os, sys, new
modules = { }
def loadModule(moduleName, locals_dict={}):
"""
Imports a module without using the built-in import functions.
Parameters:
moduleName - The name of the module, same as if you were using __import__ or import
@FurryHead
FurryHead / __init__.py
Created June 7, 2011 22:36
New plugin loader
import os, inspect, collections
pList = { }
mList = collections.defaultdict(list)
class NoSuchPluginError(Exception): pass
def plugin(cls):
#Using inspect, figure out what file is calling this function (using @plugin)
clsFile = inspect.stack()[1][1]