Esempio n. 1
0
SquirrelScript *LoadAddon(const char *Path) {
  SquirrelScript *NewAddon = NULL;

  // check if the addon already exists
  const char *ScriptName = FilenameOnly(Path);

  if(!AllScripts) {
    NewAddon = (SquirrelScript*)calloc(1,sizeof(SquirrelScript));
    AllScripts = NewAddon;
  } else {
    SquirrelScript *Find = AllScripts;
    while(Find->Next) {
      if(!strcasecmp(ScriptName, Find->Name)) // don't load same addon more than once
        return NULL;
      Find = Find->Next;
    }
    NewAddon = (SquirrelScript*)calloc(1,sizeof(SquirrelScript)); // all pointers NULL
    Find->Next = NewAddon;
    NewAddon->Prev = Find;
  }
  if(!NewAddon)
    return NULL;

  NewAddon->Script = Sq_Open(Path);
  strlcpy(NewAddon->Name, ScriptName, sizeof(NewAddon->Name));
  sq_setforeignptr(NewAddon->Script, (SQUserPointer)NewAddon);
  return NewAddon;
}
Esempio n. 2
0
/*
 * Return the filename extension found in a full pathname.
 *
 * An extension is the stuff following the last '.' in the filename.  If
 * there is nothing following the last '.', then there is no extension.
 *
 * Returns a pointer to the '.' preceding the extension, or NULL if no
 * extension was found.
 */
const char* FindExtension(NulibState* pState, const char* pathname)
{
    const char* pFilename;
    const char* pExt;

    /*
     * We have to isolate the filename so that we don't get excited
     * about "/foo.bar/file".
     */
    pFilename = FilenameOnly(pState, pathname);
    Assert(pFilename != NULL);
    pExt = strrchr(pFilename, kFilenameExtDelim);

    /* also check for "/blah/foo.", which doesn't count */
    if (pExt != NULL && *(pExt+1) != '\0')
        return pExt;

    return NULL;
}
Esempio n. 3
0
SQInteger Sq_GetInfo(HSQUIRRELVM v) {
  const SQChar *What;
  sq_getstring(v, 2, &What);

  if(!strcasecmp(What, "filename"))
    sq_pushstring(v, FilenameOnly(LevelFilename), -1);
  else if(!strcasecmp(What, "numlayers"))
    sq_pushinteger(v, NumLayers);
  else if(!strcasecmp(What, "width"))
    sq_pushinteger(v, LevelW);
  else if(!strcasecmp(What, "height"))
    sq_pushinteger(v, LevelH);
  else if(!strcasecmp(What, "cameraX"))
    sq_pushinteger(v, CameraX);
  else if(!strcasecmp(What, "cameraY"))
    sq_pushinteger(v, CameraY);
  else
    sq_pushnull(v);
  return 1;
}