1
SFML projects / Re: critique my snake implementation? (relative beginner, source included)
« on: January 08, 2018, 08:27:25 pm »
You should set this up in github so that I can look at it from my web browser.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I would use this feature to test out a lua script
I get what you're saying, but couldn't you just use a certain reserved key or in-game command to do that for you? How would your game know where to use the script (assuming you're using more than a single script, which is usually)?
class DynamicLoader
{
public:
class Library
{
friend class DynamicLoader;
public:
// We dont unload our plugins manually, but here is where we would do it
// ~Library();
// return a named, exported function pointer
virtual void * getFunction(const char* inName);
// system-specific path to this loaded library
virtual const std::string& getPath() const;
protected:
void * mLibrary;
std::string mPath;
private:
Library(const char* inFile);
};
static Library * Load(const std::string& inName);
protected:
DynamicLoader();
};
#ifdef _WIN32
mLibrary = (void *) LoadLibrary(inName);
#else
mLibrary = (void *) dlopen(inName, DL_OPEN_MODE);
#endif
#ifdef _WIN32
void* funcAddr = (void *) GetProcAddress((HMODULE) mLibrary, inName);
#else
void* funcAddr = (void *) dlsym(mLibrary, inName);
#endif
extern "C"
#ifdef _WIN32
__declspec( dllexport )
#endif
Plugin* MakePlugin()
{
return new ThisSpecificPlugin();
}
DynamicLoader::Library *l = DynamicLoader::Load(plugin.c_str());
if (!l) {
throw "specified plugin '" + plugin + "' can't load!";
}
typedef Plugin* (*Plugin_Factory)();
Plugin_Factory makeit;
try {
makeit = (Plugin_Factory)l->getFunction("MakePlugin");
if (!makeit) {
throw "plugin function 'MakePlugin' not found in library!";
}
Plugin* p = makeit();
...
} catch (...) {
printf("Error during plugin initialization\n");
}