Esempio n. 1
0
	// function: dumpTable
	//		This function will dump a specific table.
	//
	// Parameters:
	//
	//		std::string - The filename to dump to
	//		std::string - The table to dump
	//		int - The bitflags of things to dump. See the global DUMP table.
	//
	// Returns:
	//		None
	static int GM_CDECL gmfDumpTable( gmThread *a_thread )
	{
		if ( GM_NUM_PARAMS > 3 )
		{
			GM_EXCEPTION_MSG( "expecting 2 - 3 parameters" );
			return GM_EXCEPTION;
		}

		GM_CHECK_STRING_PARAM( filename, 0 );
		GM_CHECK_STRING_PARAM( tablename, 1 );
		int iFlags = a_thread->ParamInt( 2, gmUtility::DUMP_ALL );
		DumpTable( a_thread->GetMachine(), filename, tablename, iFlags );

		return GM_OK;
	}
Esempio n. 2
0
	static int GM_CDECL gmfEchoTable( gmThread *a_thread )
	{
		GM_CHECK_NUM_PARAMS( 1 );
		GM_CHECK_STRING_PARAM( tablename, 0 );

		const int BUF_SIZE = 512;
		char buffer[ BUF_SIZE ] = { 0 };
		char buffer2[ BUF_SIZE ] = { 0 };

		gmMachine *pMachine = a_thread->GetMachine();
		gmVariable vTable = pMachine->GetGlobals()->Get( pMachine, tablename );
		gmTableObject *pTable = vTable.GetTableObjectSafe();
		if ( pTable )
		{
			gmTableIterator tIt;
			gmTableNode *pNode = pTable->GetFirst( tIt );
			while ( pNode )
			{
				EngineFuncs::ConsoleMessage(
					va( "%s = %s",
					pNode->m_key.AsString( pMachine, buffer, BUF_SIZE ),
					pNode->m_value.AsString( pMachine, buffer2, BUF_SIZE ) ) );
				pNode = pTable->GetNext( tIt );
			}
		}
		return GM_OK;
	}
Esempio n. 3
0
static int GM_CDECL gmfCreateFolder(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_STRING_PARAM(path, 0);
  BOOL result = CreateDirectory(path, NULL);
  if(result)
  {
    a_thread->PushInt(1);
  }
  else
  {
    WIN32_FIND_DATA findData;
    HANDLE handle = FindFirstFile(path, &findData);
    if(handle == INVALID_HANDLE_VALUE)
    {
      a_thread->PushInt(0);
    }
    else
    {
      if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
      {
        a_thread->PushInt(2);
      }
      else
      {
        a_thread->PushInt(0);
      }
      FindClose(handle);
    }
  }
  return GM_OK;
}
Esempio n. 4
0
	static int GM_CDECL gmfLog(gmThread * a_thread)
	{
		GM_CHECK_STRING_PARAM(text, 0);
		GM_INT_PARAM(newLine, 1, 1);

		VirtualMachine::Get()->GetConsole().Log(text, newLine!=0 );
		return GM_OK;
	}
Esempio n. 5
0
	static int GM_CDECL putString(gmThread* a_thread)
	{
		GM_CHECK_NUM_PARAMS(1);
		GM_CHECK_STRING_PARAM(data, 0);

		gmByteBuffer* buf = (gmByteBuffer*)a_thread->ThisUser_NoChecks();
		buf->m_byteBuffer->append((const char*)data, strlen(data) + 1);
		return GM_OK;
	}
Esempio n. 6
0
static int GM_CDECL gmfFileWriteString(gmThread * a_thread) // string, return 1 on success, or NULL on error
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_STRING_PARAM(s, 0);

  gmUserObject * fileObject = a_thread->ThisUserObject();
  GM_ASSERT(fileObject->m_userType == s_gmFileType);
  if(fileObject->m_user)
  {
    if(fputs(s, (FILE *) fileObject->m_user) != EOF) a_thread->PushInt(1);
  }
  return GM_OK;
}
Esempio n. 7
0
	static int GM_CDECL gmfDumpGlobals( gmThread *a_thread )
	{
		if ( GM_NUM_PARAMS > 2 )
		{
			GM_EXCEPTION_MSG( "expecting 1 - 2 parameters" );
			return GM_EXCEPTION;
		}

		GM_CHECK_STRING_PARAM( filename, 0 );
		int iFlags = a_thread->ParamInt( 1, gmUtility::DUMP_ALL );
		DumpGlobals( a_thread->GetMachine(), filename, iFlags );

		return GM_OK;
	}
Esempio n. 8
0
static int GM_CDECL gmfFileOpenText(gmThread * a_thread) // path, readonly(true), return 1 on success.
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_STRING_PARAM(filename, 0);
  GM_INT_PARAM(readonly, 1, 1);

  gmUserObject * fileObject = a_thread->ThisUserObject();
  GM_ASSERT(fileObject->m_userType == s_gmFileType);
  if(fileObject->m_user) fclose((FILE *) fileObject->m_user);
  fileObject->m_user = (void *) fopen(filename, (readonly) ? "r" : "w");
  if(fileObject->m_user) a_thread->PushInt(1);
  else a_thread->PushInt(0);
  return GM_OK;
}
Esempio n. 9
0
static int GM_CDECL gmfFileExists(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_STRING_PARAM(filename, 0);

  FILE * fp = fopen(filename, "rb");
  if(fp)
  {
    a_thread->PushInt(1);
    fclose(fp);
    return GM_OK;
  }
  a_thread->PushInt(0);
  return GM_OK;
}
Esempio n. 10
0
static int GM_CDECL gmfDeleteFolder(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_STRING_PARAM(path, 0);
  GM_INT_PARAM(removeSubFolders, 1, 0);

  if(removeSubFolders)
  {
    a_thread->PushInt(RecurseDeletePath(path) ? 1 : 0);
  }
  else
  {
    a_thread->PushInt(RemoveDirectory(path) ? 1 : 0);
  }
  return GM_OK;
}
Esempio n. 11
0
static int GM_CDECL gmfFindFirstFile(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_STRING_PARAM(filename, 0);

  gmFileFindUser * fileFind = (gmFileFindUser *) a_thread->GetMachine()->Sys_Alloc(sizeof(gmFileFindUser));
  fileFind->m_iterator = FindFirstFile(filename, &fileFind->m_findData);

  if(fileFind->m_iterator == INVALID_HANDLE_VALUE)
  {
    a_thread->GetMachine()->Sys_Free(fileFind);
    return GM_OK;
  }

  a_thread->PushNewUser(fileFind, s_gmFileFindType);
  return GM_OK;
}
Esempio n. 12
0
static int GM_CDECL gmStringTokenize( gmThread * a_thread )
{
	GM_CHECK_NUM_PARAMS( 1 );
	GM_CHECK_STRING_PARAM( delim, 0 );

	DisableGCInScope gcEn( a_thread->GetMachine() );

	const gmVariable * var = a_thread->GetThis();
	gmStringObject * strObj = var->GetStringObjectSafe();

	StringVector tokens;
	Utils::Tokenize( strObj->GetString(), delim, tokens );
	gmTableObject *pTbl = a_thread->GetMachine()->AllocTableObject();
	for ( uint32_t i = 0; i < tokens.size(); ++i )
		pTbl->Set( a_thread->GetMachine(), i, gmVariable( a_thread->GetMachine()->AllocStringObject( tokens[ i ].c_str() ) ) );
	a_thread->PushTable( pTbl );
	return GM_OK;
}
Esempio n. 13
0
static int GM_CDECL gmfDoFile(gmThread * a_thread) // filename, now (1), return thread id, null on error, exception on compile error.
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_STRING_PARAM(filename, 0);
  GM_INT_PARAM(now, 1, 1);
  gmVariable paramThis = a_thread->Param(2, gmVariable::s_null); // 3rd param is 'this'

  int id = GM_INVALID_THREAD;
  if(filename)
  {
    char * string = NULL;

    FILE * fp = fopen(filename, "rb");
    if(fp)
    {
      fseek(fp, 0, SEEK_END);
      int size = ftell(fp);
      rewind(fp);
      string = new char[size + 1];
      fread(string, 1, size, fp);
      string[size] = 0;
      fclose(fp);
    }
    else
    {
      GM_EXCEPTION_MSG("failed to open file '%s'", filename);
      return GM_EXCEPTION;
    }
    if(string == NULL) return GM_OK;

    int errors = a_thread->GetMachine()->ExecuteString(string, &id, (now) ? true : false, filename, &paramThis);
    delete[] string;
    if(errors)
    {
      return GM_EXCEPTION;
    }
    else
    {
      a_thread->PushInt(id);
    }
  }
  return GM_OK;
}
Esempio n. 14
0
static int GM_CDECL gmfFileInfo(gmThread * a_thread)
{
  GM_CHECK_NUM_PARAMS(1);
  GM_CHECK_STRING_PARAM(filename, 0);

#ifdef IS64BIT // Compatible with 64bit OS
  struct _stat32 buf;
  int fh, result;

  if((fh = _open(filename, _O_RDONLY)) ==  -1) return GM_OK; // return null
  result = _fstat32(fh, &buf); // Get data associated with "fh"
  if(result == 0) //function obtained data correctly (0 == success, -1 == fail)
  {
    // create and push a gmFileInfoUser object
    gmFileInfoUser * fileInfo = (gmFileInfoUser *) a_thread->GetMachine()->Sys_Alloc(sizeof(gmFileInfoUser));
    fileInfo->m_creationTime = buf.st_ctime;
    fileInfo->m_accessedTime = buf.st_atime;
    fileInfo->m_modifiedTime = buf.st_mtime;
    fileInfo->m_size = buf.st_size;
    a_thread->PushNewUser(fileInfo, s_gmFileInfoType);
  }
  _close( fh );
#else  
  struct _stat buf;
  int fh, result;

  if((fh = _open(filename, _O_RDONLY)) ==  -1) return GM_OK; // return null
  result = _fstat(fh, &buf); // Get data associated with "fh"
  if(result == 0) //function obtained data correctly (0 == success, -1 == fail)
  {
    // create and push a gmFileInfoUser object
    gmFileInfoUser * fileInfo = (gmFileInfoUser *) a_thread->GetMachine()->Sys_Alloc(sizeof(gmFileInfoUser));
    fileInfo->m_creationTime = buf.st_ctime;
    fileInfo->m_accessedTime = buf.st_atime;
    fileInfo->m_modifiedTime = buf.st_mtime;
    fileInfo->m_size = buf.st_size;
    a_thread->PushNewUser(fileInfo, s_gmFileInfoType);
  }
  _close( fh );
#endif
  return GM_OK;
}